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

Generated by: LCOV version 1.11