LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - dbwizsetup.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 489 0.0 %
Date: 2014-04-14 Functions: 0 59 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 "dbwizsetup.hxx"
      21             : #include "dsmeta.hxx"
      22             : #include "DBSetupConnectionPages.hxx"
      23             : #include "dbadminsetup.hrc"
      24             : #include "dbu_dlg.hrc"
      25             : #include "dsitems.hxx"
      26             : #include "dsnItem.hxx"
      27             : 
      28             : #include <unotools/pathoptions.hxx>
      29             : #include <svl/stritem.hxx>
      30             : #include <svl/eitem.hxx>
      31             : #include <svl/intitem.hxx>
      32             : #include <vcl/msgbox.hxx>
      33             : #include "dbustrings.hrc"
      34             : #include "adminpages.hxx"
      35             : #include <sfx2/docfilt.hxx>
      36             : #include <unotools/ucbhelper.hxx>
      37             : #include "generalpage.hxx"
      38             : #include "localresaccess.hxx"
      39             : #include "stringlistitem.hxx"
      40             : #include "propertysetitem.hxx"
      41             : #include <unotools/confignode.hxx>
      42             : #include "DbAdminImpl.hxx"
      43             : #include "dbaccess_helpid.hrc"
      44             : #include "ConnectionPageSetup.hxx"
      45             : #include "UITools.hxx"
      46             : #include "dbadmin.hrc"
      47             : #include <dbaccess/AsyncronousLink.hxx>
      48             : #include <sfx2/filedlghelper.hxx>
      49             : #include <cppuhelper/exc_hlp.hxx>
      50             : 
      51             : #include <com/sun/star/frame/XStorable.hpp>
      52             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      53             : #include <com/sun/star/sdbc/XDataSource.hpp>
      54             : #include <com/sun/star/container/XNameAccess.hpp>
      55             : #include <com/sun/star/sdb/DatabaseContext.hpp>
      56             : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
      57             : #include <com/sun/star/frame/Desktop.hpp>
      58             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      59             : #include <com/sun/star/frame/XComponentLoader.hpp>
      60             : #include <com/sun/star/frame/XModel.hpp>
      61             : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
      62             : #include <com/sun/star/lang/XInitialization.hpp>
      63             : #include <com/sun/star/sdb/CommandType.hpp>
      64             : #include <com/sun/star/ucb/InteractiveIOException.hpp>
      65             : #include <com/sun/star/io/IOException.hpp>
      66             : #include <com/sun/star/frame/XTerminateListener.hpp>
      67             : #include <com/sun/star/sdbc/XDriverAccess.hpp>
      68             : #include <com/sun/star/document/MacroExecMode.hpp>
      69             : #include <com/sun/star/ucb/IOErrorCode.hpp>
      70             : #include <com/sun/star/task/InteractionHandler.hpp>
      71             : #include <com/sun/star/task/XInteractionHandler2.hpp>
      72             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      73             : 
      74             : #include <svl/filenotation.hxx>
      75             : #include <comphelper/interaction.hxx>
      76             : #include <comphelper/namedvaluecollection.hxx>
      77             : #include <comphelper/processfactory.hxx>
      78             : #include <comphelper/sequenceashashmap.hxx>
      79             : #include <tools/diagnose_ex.h>
      80             : #include <osl/diagnose.h>
      81             : #include <connectivity/DriversConfig.hxx>
      82             : 
      83             : namespace dbaui
      84             : {
      85             : using namespace dbtools;
      86             : using namespace svt;
      87             : using namespace com::sun::star;
      88             : using namespace com::sun::star::uno;
      89             : using namespace com::sun::star::sdbc;
      90             : using namespace com::sun::star::sdbcx;
      91             : using namespace com::sun::star::task;
      92             : using namespace com::sun::star::lang;
      93             : using namespace com::sun::star::io;
      94             : using namespace com::sun::star::util;
      95             : using namespace com::sun::star::beans;
      96             : using namespace com::sun::star::container;
      97             : using namespace com::sun::star::frame;
      98             : using namespace com::sun::star::ucb;
      99             : using namespace ::com::sun::star::sdb;
     100             : using namespace ::com::sun::star::document;
     101             : using namespace ::comphelper;
     102             : using namespace ::cppu;
     103             : 
     104             : // ODbTypeWizDialogSetup
     105           0 : ODbTypeWizDialogSetup::ODbTypeWizDialogSetup(Window* _pParent
     106             :                                ,SfxItemSet* _pItems
     107             :                                ,const Reference< XComponentContext >& _rxORB
     108             :                                ,const ::com::sun::star::uno::Any& _aDataSourceName
     109             :                                )
     110             :     :svt::RoadmapWizard( _pParent, ModuleRes(DLG_DATABASE_WIZARD),
     111             :                         WZB_NEXT | WZB_PREVIOUS | WZB_FINISH | WZB_CANCEL | WZB_HELP )
     112             : 
     113             :     , m_pOutSet(NULL)
     114             :     , m_bResetting(sal_False)
     115             :     , m_bApplied(sal_False)
     116             :     , m_bUIEnabled( sal_True )
     117             :     , m_bIsConnectable( sal_False)
     118             :     , m_sRM_IntroText( ModuleRes( STR_PAGETITLE_INTROPAGE ) )
     119             :     , m_sRM_dBaseText( ModuleRes( STR_PAGETITLE_DBASE ) )
     120             :     , m_sRM_TextText( ModuleRes( STR_PAGETITLE_TEXT ) )
     121             :     , m_sRM_MSAccessText( ModuleRes( STR_PAGETITLE_MSACCESS ) )
     122             :     , m_sRM_LDAPText( ModuleRes( STR_PAGETITLE_LDAP ) )
     123             :     , m_sRM_ADOText( ModuleRes( STR_PAGETITLE_ADO ) )
     124             :     , m_sRM_JDBCText( ModuleRes( STR_PAGETITLE_JDBC ) )
     125             :     , m_sRM_MySQLNativePageTitle( ModuleRes( STR_PAGETITLE_MYSQL_NATIVE ) )
     126             :     , m_sRM_OracleText( ModuleRes( STR_PAGETITLE_ORACLE ) )
     127             :     , m_sRM_MySQLText( ModuleRes( STR_PAGETITLE_MYSQL ) )
     128             :     , m_sRM_ODBCText( ModuleRes( STR_PAGETITLE_ODBC ) )
     129             :     , m_sRM_SpreadSheetText( ModuleRes( STR_PAGETITLE_SPREADSHEET ) )
     130             :     , m_sRM_AuthentificationText( ModuleRes( STR_PAGETITLE_AUTHENTIFICATION ) )
     131             :     , m_sRM_FinalText( ModuleRes( STR_PAGETITLE_FINAL ) )
     132           0 :     , m_sWorkPath( SvtPathOptions().GetWorkPath() )
     133             :     , m_pGeneralPage( NULL )
     134             :     , m_pMySQLIntroPage( NULL )
     135             :     , m_pFinalPage( NULL )
     136           0 :     , m_pCollection( NULL )
     137             : {
     138             :     // no local resources needed anymore
     139             :     // extract the datasource type collection from the item set
     140           0 :     DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _pItems->GetItem(DSID_TYPECOLLECTION));
     141           0 :     if (pCollectionItem)
     142           0 :         m_pCollection = pCollectionItem->getCollection();
     143             : 
     144             :     OSL_ENSURE(m_pCollection, "ODbTypeWizDialogSetup::ODbTypeWizDialogSetup : really need a DSN type collection !");
     145             : 
     146           0 :     FreeResource();
     147             : 
     148           0 :     m_pImpl.reset(new ODbDataSourceAdministrationHelper(_rxORB,this,this));
     149           0 :     m_pImpl->setDataSourceOrName(_aDataSourceName);
     150           0 :     Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
     151           0 :     m_pOutSet = new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() );
     152             : 
     153           0 :     m_pImpl->translateProperties(xDatasource, *m_pOutSet);
     154             : 
     155           0 :     SetPageSizePixel(LogicToPixel(::Size(WIZARD_PAGE_X, WIZARD_PAGE_Y), MAP_APPFONT));
     156           0 :     ShowButtonFixedLine(true);
     157           0 :     defaultButton(WZB_NEXT);
     158           0 :     enableButtons(WZB_FINISH, true);
     159           0 :     enableAutomaticNextButtonState();
     160             : 
     161           0 :     ::dbaccess::ODsnTypeCollection::TypeIterator aIter = m_pCollection->begin();
     162           0 :     ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
     163           0 :     for(PathId i = 1;aIter != aEnd;++aIter,++i)
     164             :     {
     165           0 :         const OUString sURLPrefix = aIter.getURLPrefix();
     166           0 :         svt::RoadmapWizardTypes::WizardPath aPath;
     167           0 :         aPath.push_back(PAGE_DBSETUPWIZARD_INTRO);
     168           0 :         m_pCollection->fillPageIds(sURLPrefix,aPath);
     169           0 :         aPath.push_back(PAGE_DBSETUPWIZARD_AUTHENTIFICATION);
     170           0 :         aPath.push_back(PAGE_DBSETUPWIZARD_FINAL);
     171             : 
     172           0 :         declareAuthDepPath(sURLPrefix,i,aPath);
     173           0 :     }
     174             : 
     175           0 :     svt::RoadmapWizardTypes::WizardPath aPath;
     176           0 :     aPath.push_back(PAGE_DBSETUPWIZARD_INTRO);
     177           0 :     declarePath( static_cast<PathId>(m_pCollection->size()+1), aPath);
     178             : 
     179           0 :     m_pPrevPage->SetHelpId(HID_DBWIZ_PREVIOUS);
     180           0 :     m_pNextPage->SetHelpId(HID_DBWIZ_NEXT);
     181           0 :     m_pCancel->SetHelpId(HID_DBWIZ_CANCEL);
     182           0 :     m_pFinish->SetHelpId(HID_DBWIZ_FINISH);
     183           0 :     m_pHelp->SetUniqueId(UID_DBWIZ_HELP);
     184           0 :     SetRoadmapInteractive( true );
     185           0 :     ActivatePage();
     186           0 : }
     187             : 
     188           0 : void ODbTypeWizDialogSetup::declareAuthDepPath( const OUString& _sURL, PathId _nPathId, const svt::RoadmapWizardTypes::WizardPath& _rPaths)
     189             : {
     190           0 :     bool bHasAuthentication = DataSourceMetaData::getAuthentication( _sURL ) != AuthNone;
     191             : 
     192             :     // collect the elements of the path
     193           0 :     WizardPath aPath;
     194             : 
     195           0 :     svt::RoadmapWizardTypes::WizardPath::const_iterator aIter = _rPaths.begin();
     196           0 :     svt::RoadmapWizardTypes::WizardPath::const_iterator aEnd = _rPaths.end();
     197           0 :     for(;aIter != aEnd;++aIter)
     198             :     {
     199           0 :         if ( bHasAuthentication || ( *aIter != PAGE_DBSETUPWIZARD_AUTHENTIFICATION ) )
     200           0 :             aPath.push_back( *aIter );
     201             :     }
     202             : 
     203             :     // call base method
     204           0 :     ::svt::RoadmapWizard::declarePath( _nPathId, aPath );
     205           0 : }
     206             : 
     207           0 : OUString ODbTypeWizDialogSetup::getStateDisplayName( WizardState _nState ) const
     208             : {
     209           0 :     OUString sRoadmapItem;
     210           0 :     switch( _nState )
     211             :     {
     212             :         case PAGE_DBSETUPWIZARD_INTRO:
     213           0 :             sRoadmapItem = m_sRM_IntroText;
     214           0 :             break;
     215             : 
     216             :         case PAGE_DBSETUPWIZARD_DBASE:
     217           0 :             sRoadmapItem = m_sRM_dBaseText;
     218           0 :             break;
     219             :         case PAGE_DBSETUPWIZARD_ADO:
     220           0 :             sRoadmapItem = m_sRM_ADOText;
     221           0 :             break;
     222             :         case PAGE_DBSETUPWIZARD_TEXT:
     223           0 :             sRoadmapItem = m_sRM_TextText;
     224           0 :             break;
     225             :         case PAGE_DBSETUPWIZARD_MSACCESS:
     226           0 :             sRoadmapItem = m_sRM_MSAccessText;
     227           0 :             break;
     228             :         case PAGE_DBSETUPWIZARD_LDAP:
     229           0 :             sRoadmapItem = m_sRM_LDAPText;
     230           0 :             break;
     231             :         case PAGE_DBSETUPWIZARD_JDBC:
     232           0 :             sRoadmapItem = m_sRM_JDBCText;
     233           0 :             break;
     234             :         case PAGE_DBSETUPWIZARD_ORACLE:
     235           0 :             sRoadmapItem = m_sRM_OracleText;
     236           0 :             break;
     237             :         case PAGE_DBSETUPWIZARD_MYSQL_INTRO:
     238           0 :             sRoadmapItem = m_sRM_MySQLText;
     239           0 :             break;
     240             :         case PAGE_DBSETUPWIZARD_MYSQL_JDBC:
     241           0 :             sRoadmapItem = m_sRM_JDBCText;
     242           0 :             break;
     243             :         case PAGE_DBSETUPWIZARD_MYSQL_NATIVE:
     244           0 :             sRoadmapItem = m_sRM_MySQLNativePageTitle;
     245           0 :             break;
     246             :         case PAGE_DBSETUPWIZARD_MYSQL_ODBC:
     247           0 :             sRoadmapItem = m_sRM_ODBCText;
     248           0 :             break;
     249             :         case PAGE_DBSETUPWIZARD_ODBC:
     250           0 :             sRoadmapItem = m_sRM_ODBCText;
     251           0 :             break;
     252             :         case PAGE_DBSETUPWIZARD_SPREADSHEET:
     253           0 :             sRoadmapItem = m_sRM_SpreadSheetText;
     254           0 :             break;
     255             :         case PAGE_DBSETUPWIZARD_AUTHENTIFICATION:
     256           0 :             sRoadmapItem = m_sRM_AuthentificationText;
     257           0 :             break;
     258             :         case PAGE_DBSETUPWIZARD_USERDEFINED:
     259           0 :             sRoadmapItem = ModuleRes(STR_PAGETITLE_CONNECTION);
     260           0 :             break;
     261             :         case PAGE_DBSETUPWIZARD_FINAL:
     262           0 :             sRoadmapItem = m_sRM_FinalText;
     263           0 :             break;
     264             :         default:
     265           0 :             break;
     266             :     }
     267           0 :     return sRoadmapItem;
     268             : }
     269             : 
     270           0 : ODbTypeWizDialogSetup::~ODbTypeWizDialogSetup()
     271             : {
     272           0 :     delete m_pOutSet;
     273           0 : }
     274             : 
     275           0 : IMPL_LINK(ODbTypeWizDialogSetup, OnTypeSelected, OGeneralPage*, /*_pTabPage*/)
     276             : {
     277           0 :     activateDatabasePath();
     278           0 :     return 1L;
     279             : }
     280             : 
     281           0 : void lcl_removeUnused(const ::comphelper::NamedValueCollection& _aOld,const ::comphelper::NamedValueCollection& _aNew,::comphelper::NamedValueCollection& _rDSInfo)
     282             : {
     283           0 :     _rDSInfo.merge(_aNew,true);
     284           0 :     uno::Sequence< beans::NamedValue > aOldValues = _aOld.getNamedValues();
     285           0 :     const beans::NamedValue* pIter = aOldValues.getConstArray();
     286           0 :     const beans::NamedValue* pEnd  = pIter + aOldValues.getLength();
     287           0 :     for(;pIter != pEnd;++pIter)
     288             :     {
     289           0 :         if ( !_aNew.has(pIter->Name) )
     290             :         {
     291           0 :             _rDSInfo.remove(pIter->Name);
     292             :         }
     293           0 :     }
     294           0 : }
     295             : 
     296           0 : void DataSourceInfoConverter::convert(const Reference<XComponentContext> & xContext, const ::dbaccess::ODsnTypeCollection* _pCollection,const OUString& _sOldURLPrefix,const OUString& _sNewURLPrefix,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xDatasource)
     297             : {
     298           0 :     if ( _pCollection->getPrefix(_sOldURLPrefix) == _pCollection->getPrefix(_sNewURLPrefix) )
     299           0 :         return ;
     300           0 :     uno::Sequence< beans::PropertyValue> aInfo;
     301           0 :     _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
     302           0 :     ::comphelper::NamedValueCollection aDS(aInfo);
     303             : 
     304           0 :     ::connectivity::DriversConfig aDriverConfig(xContext);
     305             : 
     306           0 :     const ::comphelper::NamedValueCollection&  aOldProperties   = aDriverConfig.getProperties(_sOldURLPrefix);
     307           0 :     const ::comphelper::NamedValueCollection&  aNewProperties   = aDriverConfig.getProperties(_sNewURLPrefix);
     308           0 :     lcl_removeUnused(aOldProperties,aNewProperties,aDS);
     309             : 
     310           0 :     aDS >>= aInfo;
     311           0 :     _xDatasource->setPropertyValue(PROPERTY_INFO,uno::makeAny(aInfo));
     312             : }
     313             : 
     314           0 : void ODbTypeWizDialogSetup::activateDatabasePath()
     315             : {
     316           0 :     switch ( m_pGeneralPage->GetDatabaseCreationMode() )
     317             :     {
     318             :     case OGeneralPageWizard::eCreateNew:
     319             :     {
     320           0 :         sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( m_pGeneralPage->GetSelectedType() );
     321           0 :         if ( nCreateNewDBIndex == -1 )
     322           0 :             nCreateNewDBIndex = m_pCollection->getIndexOf( OUString("sdbc:dbase:") );
     323             :         OSL_ENSURE( nCreateNewDBIndex != -1, "ODbTypeWizDialogSetup::activateDatabasePath: the GeneralPage should have prevented this!" );
     324           0 :         activatePath( static_cast< PathId >( nCreateNewDBIndex + 1 ), true );
     325             : 
     326           0 :         enableState(PAGE_DBSETUPWIZARD_FINAL, true );
     327           0 :         enableButtons( WZB_FINISH, true);
     328             :     }
     329           0 :     break;
     330             :     case OGeneralPageWizard::eConnectExternal:
     331             :     {
     332           0 :         OUString sOld = m_sURL;
     333           0 :         m_sURL = m_pGeneralPage->GetSelectedType();
     334           0 :         DataSourceInfoConverter::convert(getORB(), m_pCollection,sOld,m_sURL,m_pImpl->getCurrentDataSource());
     335           0 :         ::dbaccess::DATASOURCE_TYPE eType = VerifyDataSourceType(m_pCollection->determineType(m_sURL));
     336           0 :         if (eType ==  ::dbaccess::DST_UNKNOWN)
     337           0 :             eType = m_pCollection->determineType(m_sOldURL);
     338             : 
     339           0 :         activatePath( static_cast<PathId>(m_pCollection->getIndexOf(m_sURL) + 1), true);
     340           0 :         updateTypeDependentStates();
     341             :     }
     342           0 :     break;
     343             :     case OGeneralPageWizard::eOpenExisting:
     344             :     {
     345           0 :         activatePath( static_cast<PathId>(m_pCollection->size() + 1), true );
     346           0 :         enableButtons( WZB_FINISH, !m_pGeneralPage->GetSelectedDocument().sURL.isEmpty() );
     347             :     }
     348           0 :     break;
     349             :     default:
     350             :         OSL_FAIL( "ODbTypeWizDialogSetup::activateDatabasePath: unknown creation mode!" );
     351             :     }
     352             : 
     353           0 :     enableButtons( WZB_NEXT, m_pGeneralPage->GetDatabaseCreationMode() != OGeneralPageWizard::eOpenExisting );
     354             :         // TODO: this should go into the base class. Point is, we activate a path whose *last*
     355             :         // step is also the current one. The base class should automatically disable
     356             :         // the Next button in such a case. However, not for this patch ...
     357           0 : }
     358             : 
     359           0 : void ODbTypeWizDialogSetup::updateTypeDependentStates()
     360             : {
     361           0 :     sal_Bool bDoEnable = sal_False;
     362           0 :     sal_Bool bIsConnectionRequired = IsConnectionUrlRequired();
     363           0 :     if (!bIsConnectionRequired)
     364             :     {
     365           0 :         bDoEnable = sal_True;
     366             :     }
     367           0 :     else if ( m_sURL == m_sOldURL )
     368             :     {
     369           0 :         bDoEnable = m_bIsConnectable;
     370             :     }
     371           0 :     enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, bDoEnable);
     372           0 :     enableState(PAGE_DBSETUPWIZARD_FINAL, bDoEnable );
     373           0 :     enableButtons( WZB_FINISH, bDoEnable);
     374           0 : }
     375             : 
     376           0 : sal_Bool ODbTypeWizDialogSetup::IsConnectionUrlRequired()
     377             : {
     378           0 :     return m_pCollection->isConnectionUrlRequired(m_sURL);
     379             : }
     380             : 
     381           0 : void ODbTypeWizDialogSetup::resetPages(const Reference< XPropertySet >& _rxDatasource)
     382             : {
     383             :     // remove all items which relate to indirect properties from the input set
     384             :     // (without this, the following may happen: select an arbitrary data source where some indirect properties
     385             :     // are set. Select another data source of the same type, where the indirect props are not set (yet). Then,
     386             :     // the indirect property values of the first ds are shown in the second ds ...)
     387           0 :     const ODbDataSourceAdministrationHelper::MapInt2String& rMap = m_pImpl->getIndirectProperties();
     388           0 :     for (   ODbDataSourceAdministrationHelper::MapInt2String::const_iterator aIndirect = rMap.begin();
     389           0 :             aIndirect != rMap.end();
     390             :             ++aIndirect
     391             :         )
     392           0 :         getWriteOutputSet()->ClearItem( (sal_uInt16)aIndirect->first );
     393             : 
     394             :     // extract all relevant data from the property set of the data source
     395           0 :     m_pImpl->translateProperties(_rxDatasource, *getWriteOutputSet());
     396           0 : }
     397             : 
     398           0 : const SfxItemSet* ODbTypeWizDialogSetup::getOutputSet() const
     399             : {
     400           0 :     return m_pOutSet;
     401             : }
     402             : 
     403           0 : SfxItemSet* ODbTypeWizDialogSetup::getWriteOutputSet()
     404             : {
     405           0 :     return m_pOutSet;
     406             : }
     407             : 
     408           0 : ::std::pair< Reference<XConnection>,sal_Bool> ODbTypeWizDialogSetup::createConnection()
     409             : {
     410           0 :     return m_pImpl->createConnection();
     411             : }
     412             : 
     413           0 : Reference< XComponentContext > ODbTypeWizDialogSetup::getORB() const
     414             : {
     415           0 :     return m_pImpl->getORB();
     416             : }
     417             : 
     418           0 : Reference< XDriver > ODbTypeWizDialogSetup::getDriver()
     419             : {
     420           0 :     return m_pImpl->getDriver();
     421             : }
     422             : 
     423           0 : ::dbaccess::DATASOURCE_TYPE ODbTypeWizDialogSetup::VerifyDataSourceType(const ::dbaccess::DATASOURCE_TYPE _DatabaseType) const
     424             : {
     425           0 :     ::dbaccess::DATASOURCE_TYPE LocDatabaseType = _DatabaseType;
     426           0 :     if ((LocDatabaseType ==  ::dbaccess::DST_MYSQL_JDBC) || (LocDatabaseType ==  ::dbaccess::DST_MYSQL_ODBC) || (LocDatabaseType ==  ::dbaccess::DST_MYSQL_NATIVE))
     427             :     {
     428           0 :         if (m_pMySQLIntroPage != NULL)
     429             :         {
     430           0 :             switch( m_pMySQLIntroPage->getMySQLMode() )
     431             :             {
     432             :                 case OMySQLIntroPageSetup::VIA_JDBC:
     433           0 :                     return  ::dbaccess::DST_MYSQL_JDBC;
     434             :                 case OMySQLIntroPageSetup::VIA_NATIVE:
     435           0 :                     return  ::dbaccess::DST_MYSQL_NATIVE;
     436             :                 case OMySQLIntroPageSetup::VIA_ODBC:
     437           0 :                     return  ::dbaccess::DST_MYSQL_ODBC;
     438             :             }
     439             :         }
     440             :     }
     441           0 :     return LocDatabaseType;
     442             : }
     443             : 
     444           0 : OUString ODbTypeWizDialogSetup::getDatasourceType(const SfxItemSet& _rSet) const
     445             : {
     446           0 :     OUString sRet = m_pImpl->getDatasourceType(_rSet);
     447           0 :     if (m_pMySQLIntroPage != NULL && m_pMySQLIntroPage->IsVisible() )
     448             :     {
     449           0 :         switch( m_pMySQLIntroPage->getMySQLMode() )
     450             :         {
     451             :             case OMySQLIntroPageSetup::VIA_JDBC:
     452           0 :                 sRet = "sdbc:mysql:jdbc:";
     453           0 :                 break;
     454             :             case OMySQLIntroPageSetup::VIA_NATIVE:
     455           0 :                 sRet = "sdbc:mysql:mysqlc:";
     456           0 :                 break;
     457             :             case OMySQLIntroPageSetup::VIA_ODBC:
     458           0 :                 sRet = "sdbc:mysql:odbc:";
     459           0 :                 break;
     460             :         }
     461             :     }
     462           0 :     return sRet;
     463             : }
     464             : 
     465           0 : void ODbTypeWizDialogSetup::clearPassword()
     466             : {
     467           0 :     m_pImpl->clearPassword();
     468           0 : }
     469             : 
     470           0 : TabPage* ODbTypeWizDialogSetup::createPage(WizardState _nState)
     471             : {
     472             :     SfxTabPage* pFirstPage;
     473           0 :     OGenericAdministrationPage* pPage = NULL;
     474           0 :     switch(_nState)
     475             :     {
     476             :         case PAGE_DBSETUPWIZARD_INTRO:
     477           0 :             pFirstPage = new OGeneralPageWizard(this,*m_pOutSet);
     478           0 :             pPage = static_cast<OGenericAdministrationPage*> (pFirstPage);
     479           0 :             m_pGeneralPage = static_cast<OGeneralPageWizard*>(pFirstPage);
     480           0 :             m_pGeneralPage->SetTypeSelectHandler(LINK(this, ODbTypeWizDialogSetup, OnTypeSelected));
     481           0 :             m_pGeneralPage->SetCreationModeHandler(LINK( this, ODbTypeWizDialogSetup, OnChangeCreationMode ) );
     482           0 :             m_pGeneralPage->SetDocumentSelectionHandler(LINK( this, ODbTypeWizDialogSetup, OnRecentDocumentSelected ) );
     483           0 :             m_pGeneralPage->SetChooseDocumentHandler(LINK( this, ODbTypeWizDialogSetup, OnSingleDocumentChosen ) );
     484           0 :             break;
     485             : 
     486             :         case PAGE_DBSETUPWIZARD_DBASE:
     487           0 :             pPage = OConnectionTabPageSetup::CreateDbaseTabPage(this,*m_pOutSet);
     488           0 :             break;
     489             : 
     490             :         case PAGE_DBSETUPWIZARD_ADO:
     491           0 :             pPage = OConnectionTabPageSetup::CreateADOTabPage( this, *m_pOutSet);
     492           0 :             break;
     493             : 
     494             :         case PAGE_DBSETUPWIZARD_TEXT:
     495           0 :             pPage = OTextConnectionPageSetup::CreateTextTabPage(this,*m_pOutSet);
     496           0 :             break;
     497             : 
     498             :         case PAGE_DBSETUPWIZARD_ODBC:
     499           0 :             pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet);
     500           0 :             break;
     501             : 
     502             :         case PAGE_DBSETUPWIZARD_JDBC:
     503           0 :             pPage = OJDBCConnectionPageSetup::CreateJDBCTabPage( this, *m_pOutSet);
     504           0 :             break;
     505             : 
     506             :         case PAGE_DBSETUPWIZARD_MYSQL_ODBC:
     507           0 :             m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(OUString("sdbc:mysql:odbc:"))));
     508           0 :             pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet);
     509           0 :             break;
     510             : 
     511             :         case PAGE_DBSETUPWIZARD_MYSQL_JDBC:
     512           0 :             m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(OUString("sdbc:mysql:jdbc:"))));
     513           0 :             pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateMySQLJDBCTabPage( this, *m_pOutSet);
     514           0 :             break;
     515             :         case PAGE_DBSETUPWIZARD_MYSQL_NATIVE:
     516           0 :             m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(OUString("sdbc:mysql:mysqlc:"))));
     517           0 :             pPage = MySQLNativeSetupPage::Create( this, *m_pOutSet);
     518           0 :             break;
     519             : 
     520             :         case PAGE_DBSETUPWIZARD_ORACLE:
     521           0 :             pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateOracleJDBCTabPage( this, *m_pOutSet);
     522           0 :             break;
     523             : 
     524             :         case PAGE_DBSETUPWIZARD_LDAP:
     525           0 :             pPage = OLDAPConnectionPageSetup::CreateLDAPTabPage(this,*m_pOutSet);
     526           0 :             break;
     527             : 
     528             :         case PAGE_DBSETUPWIZARD_SPREADSHEET:    /// first user defined driver
     529           0 :             pPage = OSpreadSheetConnectionPageSetup::CreateSpreadSheetTabPage(this,*m_pOutSet);
     530           0 :             break;
     531             : 
     532             :         case PAGE_DBSETUPWIZARD_MSACCESS:
     533           0 :             pPage  = OConnectionTabPageSetup::CreateMSAccessTabPage(this,*m_pOutSet);
     534           0 :             break;
     535             :         case PAGE_DBSETUPWIZARD_MYSQL_INTRO:
     536           0 :             m_pMySQLIntroPage = OMySQLIntroPageSetup::CreateMySQLIntroTabPage(this,*m_pOutSet);
     537           0 :             m_pMySQLIntroPage->SetClickHdl(LINK( this, ODbTypeWizDialogSetup, ImplClickHdl ) );
     538           0 :             pPage = m_pMySQLIntroPage;
     539           0 :             break;
     540             : 
     541             :         case PAGE_DBSETUPWIZARD_AUTHENTIFICATION:
     542           0 :             pPage = OAuthentificationPageSetup::CreateAuthentificationTabPage(this,*m_pOutSet);
     543           0 :             break;
     544             : 
     545             :         case PAGE_DBSETUPWIZARD_USERDEFINED:
     546           0 :             pPage = OConnectionTabPageSetup::CreateUserDefinedTabPage(this,*m_pOutSet);
     547           0 :             break;
     548             : 
     549             :         case PAGE_DBSETUPWIZARD_FINAL:
     550           0 :             pPage = OFinalDBPageSetup::CreateFinalDBTabPageSetup(this,*m_pOutSet);
     551           0 :             m_pFinalPage = static_cast<OFinalDBPageSetup*> (pPage);
     552           0 :             break;
     553             :     }
     554             : 
     555           0 :     if ( pPage )
     556             :     {
     557           0 :         if ((_nState != PAGE_DBSETUPWIZARD_INTRO) && (_nState != PAGE_DBSETUPWIZARD_AUTHENTIFICATION))
     558             :         {
     559           0 :             pPage->SetModifiedHandler(LINK( this, ODbTypeWizDialogSetup, ImplModifiedHdl ) );
     560             :         }
     561             : 
     562           0 :         pPage->SetServiceFactory( m_pImpl->getORB() );
     563           0 :         pPage->SetAdminDialog(this, this);
     564             : 
     565           0 :         defaultButton( _nState == PAGE_DBSETUPWIZARD_FINAL ? WZB_FINISH : WZB_NEXT );
     566           0 :         enableButtons( WZB_FINISH, _nState == PAGE_DBSETUPWIZARD_FINAL );
     567           0 :         enableButtons( WZB_NEXT, _nState == PAGE_DBSETUPWIZARD_FINAL ? sal_False : sal_True);
     568           0 :         pPage->Show();
     569             :     }
     570           0 :     return pPage;
     571             : }
     572             : 
     573           0 : IMPL_LINK(ODbTypeWizDialogSetup, ImplModifiedHdl, OGenericAdministrationPage*, _pConnectionPageSetup)
     574             : {
     575           0 :     m_bIsConnectable = _pConnectionPageSetup->GetRoadmapStateValue( );
     576           0 :     enableState(PAGE_DBSETUPWIZARD_FINAL, m_bIsConnectable);
     577           0 :     enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, m_bIsConnectable);
     578           0 :     if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL)
     579           0 :         enableButtons( WZB_FINISH, true);
     580             :     else
     581           0 :         enableButtons( WZB_FINISH, m_bIsConnectable);
     582           0 :     enableButtons( WZB_NEXT, m_bIsConnectable  && (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL));
     583           0 :     return sal_True;
     584             : }
     585             : 
     586           0 : IMPL_LINK(ODbTypeWizDialogSetup, ImplClickHdl, OMySQLIntroPageSetup*, _pMySQLIntroPageSetup)
     587             : {
     588           0 :     OUString sURLPrefix;
     589           0 :     switch( _pMySQLIntroPageSetup->getMySQLMode() )
     590             :     {
     591             :         case  OMySQLIntroPageSetup::VIA_ODBC:
     592           0 :             sURLPrefix = "sdbc:mysql:odbc:";
     593           0 :             break;
     594             :         case  OMySQLIntroPageSetup::VIA_JDBC:
     595           0 :             sURLPrefix = "sdbc:mysql:jdbc:";
     596           0 :             break;
     597             :         case  OMySQLIntroPageSetup::VIA_NATIVE:
     598           0 :             sURLPrefix = "sdbc:mysql:mysqlc:";
     599           0 :             break;
     600             :     }
     601           0 :     activatePath( static_cast<PathId>(m_pCollection->getIndexOf(sURLPrefix) + 1), true);
     602           0 :     return sal_True;
     603             : }
     604             : 
     605           0 : IMPL_LINK(ODbTypeWizDialogSetup, OnChangeCreationMode, OGeneralPageWizard*, /*_pGeneralPage*/)
     606             : {
     607           0 :     activateDatabasePath();
     608           0 :     return sal_True;
     609             : }
     610             : 
     611           0 : IMPL_LINK(ODbTypeWizDialogSetup, OnRecentDocumentSelected, OGeneralPageWizard*, /*_pGeneralPage*/)
     612             : {
     613           0 :     enableButtons( WZB_FINISH, !m_pGeneralPage->GetSelectedDocument().sURL.isEmpty() );
     614           0 :     return 0L;
     615             : }
     616             : 
     617           0 : IMPL_LINK(ODbTypeWizDialogSetup, OnSingleDocumentChosen, OGeneralPageWizard*, /*_pGeneralPage*/)
     618             : {
     619           0 :     if ( prepareLeaveCurrentState( eFinish ) )
     620           0 :         onFinish();
     621           0 :     return 0L;
     622             : }
     623             : 
     624           0 : void ODbTypeWizDialogSetup::enterState(WizardState _nState)
     625             : {
     626           0 :     m_sURL = m_pImpl->getDatasourceType(*m_pOutSet);
     627           0 :     RoadmapWizard::enterState(_nState);
     628           0 :     switch(_nState)
     629             :     {
     630             :         case PAGE_DBSETUPWIZARD_INTRO:
     631           0 :             m_sOldURL = m_sURL;
     632           0 :             break;
     633             :         case PAGE_DBSETUPWIZARD_FINAL:
     634           0 :             enableButtons( WZB_FINISH, true);
     635           0 :             if ( m_pFinalPage )
     636           0 :                 m_pFinalPage->enableTableWizardCheckBox(m_pCollection->supportsTableCreation(m_sURL));
     637           0 :             break;
     638             :     }
     639           0 : }
     640             : 
     641           0 : sal_Bool ODbTypeWizDialogSetup::saveDatasource()
     642             : {
     643           0 :     SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(getCurrentState()));
     644           0 :     if ( pPage )
     645           0 :         pPage->FillItemSet(*m_pOutSet);
     646           0 :     return sal_True;
     647             : }
     648             : 
     649           0 : bool ODbTypeWizDialogSetup::leaveState(WizardState _nState)
     650             : {
     651           0 :     if (_nState == PAGE_DBSETUPWIZARD_MYSQL_INTRO)
     652           0 :         return true;
     653           0 :     if ( _nState == PAGE_DBSETUPWIZARD_INTRO && m_sURL != m_sOldURL )
     654             :     {
     655           0 :         resetPages(m_pImpl->getCurrentDataSource());
     656             :     }
     657           0 :     SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState));
     658           0 :     return pPage && pPage->DeactivatePage(m_pOutSet) != 0;
     659             : }
     660             : 
     661           0 : void ODbTypeWizDialogSetup::setTitle(const OUString& /*_sTitle*/)
     662             : {
     663             :     OSL_FAIL( "ODbTypeWizDialogSetup::setTitle: not implemented!" );
     664             :         // why?
     665           0 : }
     666             : 
     667           0 : void ODbTypeWizDialogSetup::enableConfirmSettings( bool _bEnable )
     668             : {
     669             :     (void)_bEnable;
     670           0 : }
     671             : 
     672             : namespace
     673             : {
     674           0 :     bool lcl_handle( const Reference< XInteractionHandler2 >& _rxHandler, const Any& _rRequest )
     675             :     {
     676           0 :         OInteractionRequest* pRequest = new OInteractionRequest( _rRequest );
     677           0 :         Reference < XInteractionRequest > xRequest( pRequest );
     678           0 :         OInteractionAbort* pAbort = new OInteractionAbort;
     679           0 :         pRequest->addContinuation( pAbort );
     680             : 
     681           0 :         return _rxHandler->handleInteractionRequest( xRequest );
     682             :     }
     683             : }
     684             : 
     685           0 : sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument()
     686             : {
     687           0 :     Reference< XInteractionHandler2 > xHandler( InteractionHandler::createWithParent(getORB(), 0) );
     688             :     try
     689             :     {
     690           0 :         if (callSaveAsDialog() == sal_True)
     691             :         {
     692           0 :             m_pImpl->saveChanges(*m_pOutSet);
     693           0 :             Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
     694           0 :             Reference< XModel > xModel( getDataSourceOrModel( xDatasource ), UNO_QUERY_THROW );
     695           0 :             Reference< XStorable > xStore( xModel, UNO_QUERY_THROW );
     696             : 
     697           0 :             if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPageWizard::eCreateNew )
     698           0 :                 CreateDatabase();
     699             : 
     700           0 :             ::comphelper::NamedValueCollection aArgs( xModel->getArgs() );
     701           0 :             aArgs.put( "Overwrite", sal_Bool( sal_True ) );
     702           0 :             aArgs.put( "InteractionHandler", xHandler );
     703           0 :             aArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
     704             : 
     705           0 :             OUString sPath = m_pImpl->getDocumentUrl( *m_pOutSet );
     706           0 :             xStore->storeAsURL( sPath, aArgs.getPropertyValues() );
     707             : 
     708           0 :             if ( !m_pFinalPage || m_pFinalPage->IsDatabaseDocumentToBeRegistered() )
     709           0 :                 RegisterDataSourceByLocation( sPath );
     710             : 
     711           0 :             return sal_True;
     712             :         }
     713             :     }
     714           0 :     catch ( const Exception& e )
     715             :     {
     716           0 :         Any aError = ::cppu::getCaughtException();
     717           0 :         if ( xHandler.is() )
     718             :         {
     719           0 :             if ( !lcl_handle( xHandler, aError ) )
     720             :             {
     721           0 :                 InteractiveIOException aRequest;
     722           0 :                 aRequest.Classification = InteractionClassification_ERROR;
     723           0 :                 if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) )
     724             :                     // assume savint the document faile
     725           0 :                     aRequest.Code = IOErrorCode_CANT_WRITE;
     726             :                 else
     727           0 :                     aRequest.Code = IOErrorCode_GENERAL;
     728           0 :                 aRequest.Message = e.Message;
     729           0 :                 aRequest.Context = e.Context;
     730           0 :                 lcl_handle( xHandler, makeAny( aRequest ) );
     731             :             }
     732           0 :         }
     733             :     }
     734           0 :     return sal_False;
     735             : }
     736             : 
     737           0 :     sal_Bool ODbTypeWizDialogSetup::IsDatabaseDocumentToBeOpened() const
     738             :     {
     739           0 :         if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPageWizard::eOpenExisting )
     740           0 :             return sal_True;
     741             : 
     742           0 :         if ( m_pFinalPage != NULL )
     743           0 :             return m_pFinalPage->IsDatabaseDocumentToBeOpened();
     744             : 
     745           0 :         return sal_True;
     746             :     }
     747             : 
     748           0 :     sal_Bool ODbTypeWizDialogSetup::IsTableWizardToBeStarted() const
     749             :     {
     750           0 :         if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPageWizard::eOpenExisting )
     751           0 :             return sal_False;
     752             : 
     753           0 :         if ( m_pFinalPage != NULL )
     754           0 :             return m_pFinalPage->IsTableWizardToBeStarted();
     755             : 
     756           0 :         return sal_False;
     757             :     }
     758             : 
     759           0 :     void ODbTypeWizDialogSetup::CreateDatabase()
     760             :     {
     761           0 :         OUString sUrl;
     762           0 :         OUString eType = m_pGeneralPage->GetSelectedType();
     763           0 :         if ( m_pCollection->isEmbeddedDatabase(eType) )
     764             :         {
     765           0 :             sUrl = eType;
     766           0 :             Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
     767             :             OSL_ENSURE(xDatasource.is(),"DataSource is null!");
     768           0 :             if ( xDatasource.is() )
     769           0 :                 xDatasource->setPropertyValue( PROPERTY_INFO, makeAny( m_pCollection->getDefaultDBSettings( eType ) ) );
     770           0 :             m_pImpl->translateProperties(xDatasource,*m_pOutSet);
     771             :         }
     772           0 :         else if ( m_pCollection->isFileSystemBased(eType) )
     773             :         {
     774           0 :             Reference< XSimpleFileAccess3 > xSimpleFileAccess(ucb::SimpleFileAccess::create(getORB()));
     775           0 :             INetURLObject aDBPathURL(m_sWorkPath);
     776           0 :             aDBPathURL.Append(m_aDocURL.getBase());
     777           0 :             createUniqueFolderName(&aDBPathURL);
     778           0 :             OUString sPrefix = eType;
     779           0 :             sUrl = aDBPathURL.GetMainURL( INetURLObject::NO_DECODE);
     780           0 :             xSimpleFileAccess->createFolder(sUrl);
     781           0 :              sUrl = sPrefix.concat(sUrl);
     782             :         }
     783           0 :         m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, sUrl));
     784           0 :         m_pImpl->saveChanges(*m_pOutSet);
     785           0 :     }
     786             : 
     787           0 :     void ODbTypeWizDialogSetup::RegisterDataSourceByLocation(const OUString& _sPath)
     788             :     {
     789           0 :         Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
     790           0 :         Reference< XDatabaseContext > xDatabaseContext( DatabaseContext::create(getORB()) );
     791           0 :         INetURLObject aURL( _sPath );
     792           0 :         OUString sFilename = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
     793           0 :         OUString sDatabaseName = ::dbtools::createUniqueName(xDatabaseContext, sFilename, false);
     794           0 :         xDatabaseContext->registerObject(sDatabaseName, xDatasource);
     795           0 :     }
     796             : 
     797           0 :     sal_Bool ODbTypeWizDialogSetup::callSaveAsDialog()
     798             :     {
     799           0 :         sal_Bool bRet = sal_False;
     800             :         ::sfx2::FileDialogHelper aFileDlg(
     801             :                 ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
     802           0 :                 0, this);
     803           0 :         const SfxFilter* pFilter = getStandardDatabaseFilter();
     804           0 :         if ( pFilter )
     805             :         {
     806           0 :             INetURLObject aWorkURL( m_sWorkPath );
     807           0 :             aFileDlg.SetDisplayFolder( aWorkURL.GetMainURL( INetURLObject::NO_DECODE ));
     808             : 
     809           0 :             OUString sDefaultName = ModuleRes( STR_DATABASEDEFAULTNAME );
     810           0 :             OUString sExtension = pFilter->GetDefaultExtension();
     811           0 :             sDefaultName += sExtension.replaceAt( 0, 1, OUString() );
     812           0 :             aWorkURL.Append( sDefaultName );
     813           0 :             sDefaultName = createUniqueFileName( aWorkURL );
     814           0 :             aFileDlg.SetFileName( sDefaultName );
     815             : 
     816           0 :             aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
     817           0 :             aFileDlg.SetCurrentFilter(pFilter->GetUIName());
     818             :         }
     819           0 :         if ( aFileDlg.Execute() == ERRCODE_NONE )
     820             :         {
     821           0 :             m_aDocURL = INetURLObject(aFileDlg.GetPath());
     822             : 
     823           0 :             if( m_aDocURL.GetProtocol() != INET_PROT_NOT_VALID )
     824             :             {
     825           0 :                 OUString sFileName = m_aDocURL.GetMainURL( INetURLObject::NO_DECODE );
     826           0 :                 if ( ::utl::UCBContentHelper::IsDocument(sFileName) )
     827           0 :                     ::utl::UCBContentHelper::Kill(sFileName);
     828           0 :                 m_pOutSet->Put(SfxStringItem(DSID_DOCUMENT_URL, sFileName));
     829           0 :                 bRet = sal_True;
     830             :             }
     831             :         }
     832           0 :         return bRet;
     833             :     }
     834             : 
     835           0 :     void ODbTypeWizDialogSetup::createUniqueFolderName(INetURLObject* pURL)
     836             :     {
     837           0 :         Reference< XSimpleFileAccess3 > xSimpleFileAccess(ucb::SimpleFileAccess::create(getORB()));
     838           0 :         :: OUString sLastSegmentName = pURL->getName();
     839           0 :         sal_Bool bFolderExists = sal_True;
     840           0 :         sal_Int32 i = 1;
     841           0 :         while (bFolderExists == sal_True)
     842             :         {
     843           0 :             bFolderExists = xSimpleFileAccess->isFolder(pURL->GetMainURL( INetURLObject::NO_DECODE ));
     844           0 :             if (bFolderExists == sal_True)
     845             :             {
     846           0 :                 i++;
     847           0 :                 pURL->setName(sLastSegmentName.concat(OUString::number(i)));
     848             :             }
     849           0 :         }
     850           0 :     }
     851             : 
     852           0 :     OUString ODbTypeWizDialogSetup::createUniqueFileName(const INetURLObject& _rURL)
     853             :     {
     854           0 :         Reference< XSimpleFileAccess3 > xSimpleFileAccess(ucb::SimpleFileAccess::create(getORB()));
     855           0 :         OUString BaseName = _rURL.getBase();
     856             : 
     857           0 :         sal_Bool bElementExists = sal_True;
     858             : 
     859           0 :         INetURLObject aExistenceCheck( _rURL );
     860           0 :         for ( sal_Int32 i = 1; bElementExists; )
     861             :         {
     862           0 :             bElementExists = xSimpleFileAccess->exists( aExistenceCheck.GetMainURL( INetURLObject::NO_DECODE ) );
     863           0 :             if ( bElementExists )
     864             :             {
     865           0 :                 aExistenceCheck.setBase( BaseName.concat( OUString::number( i ) ) );
     866           0 :                 ++i;
     867             :             }
     868             :         }
     869           0 :         return aExistenceCheck.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
     870             :     }
     871           0 :     IWizardPageController* ODbTypeWizDialogSetup::getPageController( TabPage* _pCurrentPage ) const
     872             :     {
     873           0 :         OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage);
     874           0 :         return pPage;
     875             :     }
     876             : 
     877             :     namespace
     878             :     {
     879             :         typedef ::cppu::WeakImplHelper1 <   XTerminateListener
     880             :                                         >   AsyncLoader_Base;
     881           0 :         class AsyncLoader : public AsyncLoader_Base
     882             :         {
     883             :         private:
     884             :             Reference< XComponentLoader >       m_xFrameLoader;
     885             :             Reference< XDesktop2 >              m_xDesktop;
     886             :             Reference< XInteractionHandler2 >   m_xInteractionHandler;
     887             :             OUString                     m_sURL;
     888             :             OAsyncronousLink                    m_aAsyncCaller;
     889             : 
     890             :         public:
     891             :             AsyncLoader( const Reference< XComponentContext >& _rxORB, const OUString& _rURL );
     892             : 
     893             :             void doLoadAsync();
     894             : 
     895             :             // XTerminateListener
     896             :             virtual void SAL_CALL queryTermination( const com::sun::star::lang::EventObject& Event ) throw (TerminationVetoException, RuntimeException, std::exception) SAL_OVERRIDE;
     897             :             virtual void SAL_CALL notifyTermination( const com::sun::star::lang::EventObject& Event ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     898             :             // XEventListener
     899             :             virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     900             : 
     901             :         private:
     902             :             DECL_LINK( OnOpenDocument, void* );
     903             :         };
     904             : 
     905           0 :         AsyncLoader::AsyncLoader( const Reference< XComponentContext >& _rxORB, const OUString& _rURL )
     906             :             :m_sURL( _rURL )
     907           0 :             ,m_aAsyncCaller( LINK( this, AsyncLoader, OnOpenDocument ) )
     908             :         {
     909             :             try
     910             :             {
     911           0 :                 m_xDesktop.set( Desktop::create(_rxORB) );
     912           0 :                 m_xFrameLoader.set( m_xDesktop, UNO_QUERY_THROW );
     913           0 :                 m_xInteractionHandler = InteractionHandler::createWithParent(_rxORB, 0);
     914             :             }
     915           0 :             catch( const Exception& )
     916             :             {
     917             :                 DBG_UNHANDLED_EXCEPTION();
     918             :             }
     919           0 :         }
     920             : 
     921           0 :         void AsyncLoader::doLoadAsync()
     922             :         {
     923             :             OSL_ENSURE( !m_aAsyncCaller.IsRunning(), "AsyncLoader:doLoadAsync: already running!" );
     924             : 
     925           0 :             acquire();
     926             :             try
     927             :             {
     928           0 :                 if ( m_xDesktop.is() )
     929           0 :                     m_xDesktop->addTerminateListener( this );
     930             :             }
     931           0 :             catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
     932             : 
     933           0 :             m_aAsyncCaller.Call( NULL );
     934           0 :         }
     935             : 
     936           0 :         IMPL_LINK( AsyncLoader, OnOpenDocument, void*, /*_pEmptyArg*/ )
     937             :         {
     938             :             try
     939             :             {
     940           0 :                 if ( m_xFrameLoader.is() )
     941             :                 {
     942           0 :                     ::comphelper::NamedValueCollection aLoadArgs;
     943           0 :                     aLoadArgs.put( "InteractionHandler", m_xInteractionHandler );
     944           0 :                     aLoadArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
     945             : 
     946           0 :                     Sequence< PropertyValue > aLoadArgPV;
     947           0 :                     aLoadArgs >>= aLoadArgPV;
     948             : 
     949           0 :                     m_xFrameLoader->loadComponentFromURL( m_sURL,
     950             :                         OUString( "_default" ),
     951             :                         FrameSearchFlag::ALL,
     952             :                         aLoadArgPV
     953           0 :                     );
     954             :                 }
     955             :             }
     956           0 :             catch( const Exception& )
     957             :             {
     958             :                 // do not assert.
     959             :                 // Such an exception happens for instance of the to-be-loaded document does not exist anymore.
     960             :             }
     961             : 
     962             :             try
     963             :             {
     964           0 :                 if ( m_xDesktop.is() )
     965           0 :                     m_xDesktop->removeTerminateListener( this );
     966             :             }
     967           0 :             catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
     968             : 
     969           0 :             release();
     970           0 :             return 0L;
     971             :         }
     972             : 
     973           0 :         void SAL_CALL AsyncLoader::queryTermination( const com::sun::star::lang::EventObject& /*Event*/ ) throw (TerminationVetoException, RuntimeException, std::exception)
     974             :         {
     975           0 :             throw TerminationVetoException();
     976             :         }
     977             : 
     978           0 :         void SAL_CALL AsyncLoader::notifyTermination( const com::sun::star::lang::EventObject& /*Event*/ ) throw (RuntimeException, std::exception)
     979             :         {
     980           0 :         }
     981           0 :         void SAL_CALL AsyncLoader::disposing( const com::sun::star::lang::EventObject& /*Source*/ ) throw (RuntimeException, std::exception)
     982             :         {
     983           0 :         }
     984             :     }
     985             : 
     986           0 :     bool ODbTypeWizDialogSetup::onFinish()
     987             :     {
     988           0 :         if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPageWizard::eOpenExisting )
     989             :         {
     990             :             // we're not going to re-use the XModel we have - since the document the user
     991             :             // wants us to load could be a non-database document. Instead, we asynchronously
     992             :             // open the selected document. Thus, the wizard's return value is RET_CANCEL,
     993             :             // which means to not continue loading the database document
     994           0 :             if ( !OWizardMachine::Finish( RET_CANCEL ) )
     995           0 :                 return false;
     996             : 
     997             :             try
     998             :             {
     999           0 :                 AsyncLoader* pAsyncLoader = new AsyncLoader( getORB(), m_pGeneralPage->GetSelectedDocument().sURL );
    1000           0 :                 ::rtl::Reference< AsyncLoader > xKeepAlive( pAsyncLoader );
    1001           0 :                 pAsyncLoader->doLoadAsync();
    1002             :             }
    1003           0 :             catch( const Exception& )
    1004             :             {
    1005             :                 DBG_UNHANDLED_EXCEPTION();
    1006             :             }
    1007             : 
    1008           0 :             return true;
    1009             :         }
    1010             : 
    1011           0 :         if (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL)
    1012             :         {
    1013           0 :             skipUntil(PAGE_DBSETUPWIZARD_FINAL);
    1014             :         }
    1015           0 :         if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL)
    1016           0 :             return SaveDatabaseDocument() && OWizardMachine::onFinish();
    1017             :         else
    1018             :         {
    1019           0 :             enableButtons( WZB_FINISH, false );
    1020           0 :             return false;
    1021             :         }
    1022             :     }
    1023             : 
    1024           0 : }   // namespace dbaui
    1025             : 
    1026             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10