LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - dbwiz.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 148 0.7 %
Date: 2014-11-03 Functions: 2 22 9.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "dbwiz.hxx"
      21             : #include "dbu_dlg.hrc"
      22             : #include "dsitems.hxx"
      23             : #include "dsnItem.hxx"
      24             : #include <svl/stritem.hxx>
      25             : #include <svl/eitem.hxx>
      26             : #include <svl/intitem.hxx>
      27             : #include <vcl/msgbox.hxx>
      28             : #include "dbustrings.hrc"
      29             : #include "adminpages.hxx"
      30             : #include "generalpage.hxx"
      31             : #include "localresaccess.hxx"
      32             : #include "stringlistitem.hxx"
      33             : #include "propertysetitem.hxx"
      34             : #include <unotools/confignode.hxx>
      35             : #include "ConnectionPage.hxx"
      36             : #include "DriverSettings.hxx"
      37             : #include "DbAdminImpl.hxx"
      38             : #include "dbaccess_helpid.hrc"
      39             : 
      40             : namespace dbaui
      41             : {
      42             : using namespace svt;
      43             : using namespace com::sun::star::uno;
      44             : using namespace com::sun::star::sdbc;
      45             : using namespace com::sun::star::lang;
      46             : using namespace com::sun::star::util;
      47             : using namespace com::sun::star::beans;
      48             : using namespace com::sun::star::container;
      49             : 
      50             : #define START_PAGE                      0
      51             : #define CONNECTION_PAGE                 1
      52             : #define ADDITIONAL_PAGE_DBASE           2
      53             : #define ADDITIONAL_PAGE_FLAT            3
      54             : #define ADDITIONAL_PAGE_LDAP            4
      55             : //5 was ADDITIONAL_PAGE_ADABAS
      56             : #define ADDITIONAL_PAGE_MYSQL_JDBC      6
      57             : #define ADDITIONAL_PAGE_MYSQL_ODBC      7
      58             : #define ADDITIONAL_PAGE_ORACLE_JDBC     8
      59             : #define ADDITIONAL_PAGE_ADO             9
      60             : #define ADDITIONAL_PAGE_ODBC           10
      61             : #define ADDITIONAL_USERDEFINED         11
      62             : #define ADDITIONAL_PAGE_MYSQL_NATIVE   12
      63             : 
      64             : // ODbTypeWizDialog
      65           0 : ODbTypeWizDialog::ODbTypeWizDialog(vcl::Window* _pParent
      66             :                                ,SfxItemSet* _pItems
      67             :                                ,const Reference< XComponentContext >& _rxORB
      68             :                                ,const ::com::sun::star::uno::Any& _aDataSourceName
      69             :                                )
      70             :     :OWizardMachine(_pParent, WZB_NEXT | WZB_PREVIOUS | WZB_FINISH | WZB_CANCEL | WZB_HELP )
      71             :     ,m_pOutSet(NULL)
      72             :     ,m_bResetting(false)
      73             :     ,m_bApplied(false)
      74           0 :     ,m_bUIEnabled( true )
      75             : {
      76           0 :     m_pImpl.reset(new ODbDataSourceAdministrationHelper(_rxORB,this,this));
      77           0 :     m_pImpl->setDataSourceOrName(_aDataSourceName);
      78           0 :     Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
      79           0 :     m_pOutSet = new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() );
      80             : 
      81           0 :     m_pImpl->translateProperties(xDatasource, *m_pOutSet);
      82           0 :     m_eType = dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(*m_pOutSet);
      83             : 
      84           0 :     SetPageSizePixel(LogicToPixel(::Size(PAGE_X, PAGE_Y), MAP_APPFONT));
      85           0 :     defaultButton(WZB_NEXT);
      86           0 :     enableButtons(WZB_FINISH, false);
      87           0 :     enableAutomaticNextButtonState( true );
      88             : 
      89           0 :     m_pPrevPage->SetHelpId(HID_DBWIZ_PREVIOUS);
      90           0 :     m_pNextPage->SetHelpId(HID_DBWIZ_NEXT);
      91           0 :     m_pCancel->SetHelpId(HID_DBWIZ_CANCEL);
      92           0 :     m_pFinish->SetHelpId(HID_DBWIZ_FINISH);
      93           0 :     m_pHelp->SetUniqueId(UID_DBWIZ_HELP);
      94             :     // no local resources needed anymore
      95             : 
      96           0 :     const DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _pItems->GetItem(DSID_TYPECOLLECTION));
      97           0 :     m_pCollection = pCollectionItem->getCollection();
      98             : 
      99           0 :     ActivatePage();
     100           0 :     setTitleBase(ModuleRes(STR_DATABASE_TYPE_CHANGE));
     101           0 : }
     102             : 
     103           0 : ODbTypeWizDialog::~ODbTypeWizDialog()
     104             : {
     105           0 :     delete m_pOutSet;
     106           0 : }
     107             : 
     108           0 : IMPL_LINK(ODbTypeWizDialog, OnTypeSelected, OGeneralPage*, _pTabPage)
     109             : {
     110           0 :     m_eType = _pTabPage->GetSelectedType();
     111           0 :     const bool bURLRequired = m_pCollection->isConnectionUrlRequired(m_eType);
     112           0 :     enableButtons(WZB_NEXT,bURLRequired);
     113           0 :     enableButtons(WZB_FINISH,!bURLRequired);
     114           0 :     return 1L;
     115             : }
     116             : 
     117           0 : WizardTypes::WizardState ODbTypeWizDialog::determineNextState( WizardState _nCurrentState ) const
     118             : {
     119           0 :     WizardTypes::WizardState nNextState = WZS_INVALID_STATE;
     120           0 :     switch(_nCurrentState)
     121             :     {
     122             :         case START_PAGE:
     123           0 :             switch(m_pCollection->determineType(m_eType))
     124             :             {
     125             :                 case  ::dbaccess::DST_MOZILLA:
     126             :                 case  ::dbaccess::DST_OUTLOOK:
     127             :                 case  ::dbaccess::DST_OUTLOOKEXP:
     128             :                 case  ::dbaccess::DST_EVOLUTION:
     129             :                 case  ::dbaccess::DST_EVOLUTION_GROUPWISE:
     130             :                 case  ::dbaccess::DST_EVOLUTION_LDAP:
     131             :                 case  ::dbaccess::DST_KAB:
     132             :                 case  ::dbaccess::DST_MACAB:
     133           0 :                     nNextState = WZS_INVALID_STATE;
     134           0 :                     break;
     135             :                 case  ::dbaccess::DST_MYSQL_NATIVE:
     136           0 :                     nNextState = ADDITIONAL_PAGE_MYSQL_NATIVE;
     137           0 :                     break;
     138             :                 default:
     139           0 :                     nNextState = CONNECTION_PAGE;
     140           0 :                     break;
     141             :             }
     142           0 :             break;
     143             :         case CONNECTION_PAGE:
     144           0 :             switch(m_pCollection->determineType(m_eType))
     145             :             {
     146             :                 case  ::dbaccess::DST_MOZILLA:
     147             :                 case  ::dbaccess::DST_THUNDERBIRD:
     148             :                 case  ::dbaccess::DST_OUTLOOK:
     149             :                 case  ::dbaccess::DST_OUTLOOKEXP:
     150             :                 case  ::dbaccess::DST_EVOLUTION:
     151             :                 case  ::dbaccess::DST_EVOLUTION_GROUPWISE:
     152             :                 case  ::dbaccess::DST_EVOLUTION_LDAP:
     153             :                 case  ::dbaccess::DST_KAB:
     154             :                 case  ::dbaccess::DST_MACAB:
     155             :                 case  ::dbaccess::DST_MSACCESS:
     156             :                 case  ::dbaccess::DST_MSACCESS_2007:
     157             :                 case  ::dbaccess::DST_JDBC:
     158             :                 case  ::dbaccess::DST_CALC:
     159           0 :                     nNextState = WZS_INVALID_STATE;
     160           0 :                     break;
     161             :                 case  ::dbaccess::DST_DBASE:
     162           0 :                     nNextState = ADDITIONAL_PAGE_DBASE;
     163           0 :                     break;
     164             :                 case  ::dbaccess::DST_FLAT:
     165           0 :                     nNextState = ADDITIONAL_PAGE_FLAT;
     166           0 :                     break;
     167             :                 case  ::dbaccess::DST_LDAP:
     168           0 :                     nNextState = ADDITIONAL_PAGE_LDAP;
     169           0 :                     break;
     170             :                 case  ::dbaccess::DST_MYSQL_JDBC:
     171           0 :                     nNextState = ADDITIONAL_PAGE_MYSQL_JDBC;
     172           0 :                     break;
     173             :                 case  ::dbaccess::DST_MYSQL_ODBC:
     174           0 :                     nNextState = ADDITIONAL_PAGE_MYSQL_ODBC;
     175           0 :                     break;
     176             :                 case  ::dbaccess::DST_ORACLE_JDBC:
     177           0 :                     nNextState = ADDITIONAL_PAGE_ORACLE_JDBC;
     178           0 :                     break;
     179             :                 case  ::dbaccess::DST_ADO:
     180           0 :                     nNextState = ADDITIONAL_PAGE_ADO;
     181           0 :                     break;
     182             :                 case  ::dbaccess::DST_ODBC:
     183           0 :                     nNextState = ADDITIONAL_PAGE_ODBC;
     184           0 :                     break;
     185             :                 default:
     186           0 :                     nNextState = WZS_INVALID_STATE;
     187           0 :                     break;
     188             :             }
     189           0 :             break;
     190             :     }
     191             : 
     192           0 :     return nNextState;
     193             : }
     194             : 
     195           0 : const SfxItemSet* ODbTypeWizDialog::getOutputSet() const
     196             : {
     197           0 :     return m_pOutSet;
     198             : }
     199             : 
     200           0 : SfxItemSet* ODbTypeWizDialog::getWriteOutputSet()
     201             : {
     202           0 :     return m_pOutSet;
     203             : }
     204             : 
     205           0 : ::std::pair< Reference<XConnection>,sal_Bool> ODbTypeWizDialog::createConnection()
     206             : {
     207           0 :     return m_pImpl->createConnection();
     208             : }
     209             : 
     210           0 : Reference< XComponentContext > ODbTypeWizDialog::getORB() const
     211             : {
     212           0 :     return m_pImpl->getORB();
     213             : }
     214             : 
     215           0 : Reference< XDriver > ODbTypeWizDialog::getDriver()
     216             : {
     217           0 :     return m_pImpl->getDriver();
     218             : }
     219             : 
     220           0 : OUString ODbTypeWizDialog::getDatasourceType(const SfxItemSet& _rSet) const
     221             : {
     222           0 :     return dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(_rSet);
     223             : }
     224             : 
     225           0 : void ODbTypeWizDialog::clearPassword()
     226             : {
     227           0 :     m_pImpl->clearPassword();
     228           0 : }
     229             : 
     230           0 : TabPage* ODbTypeWizDialog::createPage(WizardState _nState)
     231             : {
     232           0 :     sal_uInt16 nStringId = STR_PAGETITLE_ADVANCED;
     233           0 :     TabPage* pPage = NULL;
     234           0 :     switch(_nState)
     235             :     {
     236             :         case START_PAGE: // start state
     237             :         {
     238           0 :             pPage = new OGeneralPageDialog(this,*m_pOutSet);
     239           0 :             OGeneralPage* pGeneralPage = static_cast< OGeneralPage* >( pPage );
     240           0 :             pGeneralPage->SetTypeSelectHandler( LINK( this, ODbTypeWizDialog, OnTypeSelected));
     241           0 :             nStringId = STR_PAGETITLE_GENERAL;
     242             :         }
     243           0 :         break;
     244             :         case CONNECTION_PAGE:
     245           0 :             pPage = OConnectionTabPage::Create(this,m_pOutSet);
     246           0 :             nStringId = STR_PAGETITLE_CONNECTION;
     247           0 :             break;
     248             : 
     249             :         case ADDITIONAL_PAGE_DBASE:
     250           0 :             pPage = ODriversSettings::CreateDbase(this,m_pOutSet);
     251           0 :             break;
     252             :         case ADDITIONAL_PAGE_FLAT:
     253           0 :             pPage = ODriversSettings::CreateText(this,m_pOutSet);
     254           0 :             break;
     255             :         case ADDITIONAL_PAGE_LDAP:
     256           0 :             pPage = ODriversSettings::CreateLDAP(this,m_pOutSet);
     257           0 :             break;
     258             :         case ADDITIONAL_PAGE_MYSQL_JDBC:
     259           0 :             pPage = ODriversSettings::CreateMySQLJDBC(this,m_pOutSet);
     260           0 :             break;
     261             :         case ADDITIONAL_PAGE_MYSQL_NATIVE:
     262           0 :             pPage = ODriversSettings::CreateMySQLNATIVE(this,m_pOutSet);
     263           0 :             break;
     264             :         case ADDITIONAL_PAGE_MYSQL_ODBC:
     265           0 :             pPage = ODriversSettings::CreateMySQLODBC(this,m_pOutSet);
     266           0 :             break;
     267             :         case ADDITIONAL_PAGE_ORACLE_JDBC:
     268           0 :             pPage = ODriversSettings::CreateOracleJDBC(this,m_pOutSet);
     269           0 :             break;
     270             :         case ADDITIONAL_PAGE_ADO:
     271           0 :             pPage = ODriversSettings::CreateAdo(this,m_pOutSet);
     272           0 :             break;
     273             :         case ADDITIONAL_PAGE_ODBC:
     274           0 :             pPage = ODriversSettings::CreateODBC(this,m_pOutSet);
     275           0 :             break;
     276             :         case ADDITIONAL_USERDEFINED:
     277           0 :             pPage = ODriversSettings::CreateUser(this,m_pOutSet);
     278           0 :             break;
     279             :         default:
     280             :             OSL_FAIL("Wrong state!");
     281           0 :             break;
     282             :     }
     283             : 
     284             :     // register ourself as modified listener
     285           0 :     if ( pPage )
     286             :     {
     287           0 :         static_cast<OGenericAdministrationPage*>(pPage)->SetServiceFactory( m_pImpl->getORB() );
     288           0 :         static_cast<OGenericAdministrationPage*>(pPage)->SetAdminDialog(this,this);
     289           0 :         pPage->SetText(ModuleRes(nStringId));
     290           0 :         defaultButton( _nState == START_PAGE ? WZB_NEXT : WZB_FINISH );
     291           0 :         enableButtons( WZB_FINISH, _nState == START_PAGE ? sal_False : sal_True);
     292           0 :         pPage->Show();
     293             :     }
     294           0 :     return pPage;
     295             : }
     296             : 
     297           0 : bool ODbTypeWizDialog::leaveState(WizardState _nState)
     298             : {
     299           0 :     SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState));
     300           0 :     if ( pPage )
     301           0 :         pPage->FillItemSet(m_pOutSet);
     302           0 :     return true;
     303             : }
     304             : 
     305           0 : void ODbTypeWizDialog::setTitle(const OUString& _sTitle)
     306             : {
     307           0 :     SetText(_sTitle);
     308           0 : }
     309             : 
     310           0 : void ODbTypeWizDialog::enableConfirmSettings( bool _bEnable )
     311             : {
     312           0 :     enableButtons( WZB_FINISH, _bEnable );
     313             :     // TODO:
     314             :     // this is hacky. At the moment, this method is used in only one case.
     315             :     // As soon as it is to be used more wide-spread, we should find a proper concept
     316             :     // for enabling both the Next and Finish buttons, depending on the current page state.
     317             :     // Plus, the concept must also care for the case where those pages are embedded into
     318             :     // anormal tab dialog.
     319           0 : }
     320             : 
     321           0 : bool ODbTypeWizDialog::saveDatasource()
     322             : {
     323           0 :     SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(getCurrentState()));
     324           0 :     if ( pPage )
     325           0 :         pPage->FillItemSet(m_pOutSet);
     326             : 
     327           0 :     OUString sOldURL;
     328           0 :     if ( m_pImpl->getCurrentDataSource().is() )
     329           0 :         m_pImpl->getCurrentDataSource()->getPropertyValue(PROPERTY_URL) >>= sOldURL;
     330           0 :     DataSourceInfoConverter::convert( getORB(), m_pCollection,sOldURL,m_eType,m_pImpl->getCurrentDataSource());
     331           0 :     return true;
     332             : }
     333             : 
     334           0 : IWizardPageController* ODbTypeWizDialog::getPageController( TabPage* _pCurrentPage ) const
     335             : {
     336           0 :     OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage);
     337           0 :     return pPage;
     338             : }
     339             : 
     340           0 : bool ODbTypeWizDialog::onFinish()
     341             : {
     342           0 :     saveDatasource();
     343           0 :     return m_pImpl->saveChanges(*m_pOutSet) && OWizardMachine::onFinish();
     344             : }
     345             : 
     346          72 : }   // namespace dbaui
     347             : 
     348             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10