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

Generated by: LCOV version 1.10