LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - ConnectionHelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 319 0.0 %
Date: 2014-04-14 Functions: 0 25 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 "dsnItem.hxx"
      21             : #include "ConnectionHelper.hxx"
      22             : #include "AutoControls.hrc"
      23             : #include "dbu_dlg.hrc"
      24             : #include "dbu_misc.hrc"
      25             : #include <svl/itemset.hxx>
      26             : #include <unotools/moduleoptions.hxx>
      27             : #include <sfx2/fcontnr.hxx>
      28             : #include <unotools/pathoptions.hxx>
      29             : #include <svl/stritem.hxx>
      30             : #include <svl/eitem.hxx>
      31             : #include <svl/intitem.hxx>
      32             : #include "dsitems.hxx"
      33             : #include "dbaccess_helpid.hrc"
      34             : #include "localresaccess.hxx"
      35             : #include <osl/process.h>
      36             : #include <osl/diagnose.h>
      37             : #include <vcl/msgbox.hxx>
      38             : #include <sfx2/filedlghelper.hxx>
      39             : #include "dbadmin.hxx"
      40             : #include <comphelper/types.hxx>
      41             : #include <vcl/stdtext.hxx>
      42             : #include "sqlmessage.hxx"
      43             : #include "odbcconfig.hxx"
      44             : #include "dsselect.hxx"
      45             : #include <svl/filenotation.hxx>
      46             : #include "dbustrings.hrc"
      47             : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
      48             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      49             : #include <com/sun/star/sdbc/XRow.hpp>
      50             : #include <com/sun/star/awt/XWindow.hpp>
      51             : #include <com/sun/star/mozilla/MozillaBootstrap.hpp>
      52             : #include <com/sun/star/task/InteractionHandler.hpp>
      53             : #include <com/sun/star/ucb/XProgressHandler.hpp>
      54             : #include "UITools.hxx"
      55             : #include <unotools/localfilehelper.hxx>
      56             : #include <unotools/ucbhelper.hxx>
      57             : #include <ucbhelper/commandenvironment.hxx>
      58             : #include "finteraction.hxx"
      59             : #include <connectivity/CommonTools.hxx>
      60             : #include <tools/urlobj.hxx>
      61             : #include <tools/diagnose_ex.h>
      62             : #include <sfx2/docfilt.hxx>
      63             : 
      64             : #if defined(WNT)
      65             : #define _ADO_DATALINK_BROWSE_
      66             : #endif
      67             : 
      68             : #ifdef _ADO_DATALINK_BROWSE_
      69             : #include <vcl/sysdata.hxx>
      70             : #include "adodatalinks.hxx"
      71             : #endif //_ADO_DATALINK_BROWSE_
      72             : 
      73             : #include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
      74             : #include <comphelper/processfactory.hxx>
      75             : #include <comphelper/string.hxx>
      76             : 
      77             : namespace dbaui
      78             : {
      79             :     using namespace ::com::sun::star;
      80             :     using namespace ::com::sun::star::uno;
      81             :     using namespace ::com::sun::star::ucb;
      82             :     using namespace ::com::sun::star::ui::dialogs;
      83             :     using namespace ::com::sun::star::sdbc;
      84             :     using namespace ::com::sun::star::beans;
      85             :     using namespace ::com::sun::star::lang;
      86             :     using namespace ::com::sun::star::container;
      87             :     using namespace ::com::sun::star::mozilla;
      88             :     using namespace ::dbtools;
      89             :     using namespace ::svt;
      90             : 
      91             : 
      92           0 :     OConnectionHelper::OConnectionHelper( Window* pParent, const ResId& _rId, const SfxItemSet& _rCoreAttrs)
      93             :         : OGenericAdministrationPage(pParent, _rId, _rCoreAttrs)
      94             :         , m_bUserGrabFocus(false)
      95           0 :         , m_aFT_Connection(this, ResId(FT_AUTOBROWSEURL, *_rId.GetResMgr()))
      96           0 :         , m_aConnectionURL(this, ResId(ET_AUTOBROWSEURL, *_rId.GetResMgr()))
      97           0 :         , m_aPB_Connection(this, ResId(PB_AUTOBROWSEURL, *_rId.GetResMgr()))
      98           0 :         , m_aPB_CreateDB(this, ResId(PB_CREATEDB, *_rId.GetResMgr()))
      99           0 :         , m_pCollection(NULL)
     100             :     {
     101             :         // extract the datasource type collection from the item set
     102           0 :         DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _rCoreAttrs.GetItem(DSID_TYPECOLLECTION));
     103           0 :         if (pCollectionItem)
     104           0 :             m_pCollection = pCollectionItem->getCollection();
     105           0 :         m_aPB_Connection.SetClickHdl(LINK(this, OConnectionHelper, OnBrowseConnections));
     106           0 :         m_aPB_CreateDB.SetClickHdl(LINK(this, OConnectionHelper, OnCreateDatabase));
     107             :         OSL_ENSURE(m_pCollection, "OConnectionHelper::OConnectionHelper : really need a DSN type collection !");
     108           0 :         m_aConnectionURL.SetTypeCollection(m_pCollection);
     109           0 :     }
     110             : 
     111           0 :     OConnectionHelper::~OConnectionHelper()
     112             :     {
     113             : 
     114           0 :     }
     115             : 
     116           0 :     void OConnectionHelper::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
     117             :     {
     118             :         // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
     119             :         sal_Bool bValid, bReadonly;
     120           0 :         getFlags(_rSet, bValid, bReadonly);
     121             : 
     122           0 :         m_aFT_Connection.Show();
     123           0 :         m_aConnectionURL.Show();
     124           0 :         m_aConnectionURL.ShowPrefix( ::dbaccess::DST_JDBC == m_pCollection->determineType(m_eType) );
     125             : 
     126           0 :         sal_Bool bEnableBrowseButton = m_pCollection->supportsBrowsing( m_eType );
     127           0 :         m_aPB_Connection.Show( bEnableBrowseButton );
     128             : 
     129           0 :         sal_Bool bEnableCreateButton = m_pCollection->supportsDBCreation( m_eType );
     130           0 :         m_aPB_CreateDB.Show( bEnableCreateButton );
     131             : 
     132           0 :         SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, true);
     133             : 
     134             :         // forward the values to the controls
     135           0 :         if ( bValid )
     136             :         {
     137           0 :             OUString sUrl = pUrlItem->GetValue();
     138           0 :             setURL( sUrl );
     139             : 
     140           0 :             checkTestConnection();
     141           0 :             m_aConnectionURL.ClearModifyFlag();
     142             :         }
     143             : 
     144           0 :         OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
     145           0 :     }
     146             : 
     147           0 :     void OConnectionHelper::implUpdateURLDependentStates() const
     148             :     {
     149             :         OSL_PRECOND( m_pAdminDialog && m_pCollection, "OConnectionHelper::implUpdateURLDependentStates: no admin dialog!" );
     150           0 :         if ( !m_pAdminDialog || !m_pCollection )
     151           0 :             return;
     152             : 
     153           0 :         if ( m_pCollection->isFileSystemBased(m_eType) )
     154           0 :             m_pAdminDialog->enableConfirmSettings( !getURLNoPrefix().isEmpty() );
     155             :     }
     156             : 
     157           0 :     IMPL_LINK(OConnectionHelper, OnBrowseConnections, PushButton*, /*_pButton*/)
     158             :     {
     159             :         OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
     160           0 :         const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
     161           0 :         switch ( eType )
     162             :         {
     163             :             case  ::dbaccess::DST_DBASE:
     164             :             case  ::dbaccess::DST_FLAT:
     165             :             {
     166             :                 try
     167             :                 {
     168           0 :                     Reference< XFolderPicker2 > xFolderPicker = FolderPicker::create(m_xORB);
     169             : 
     170           0 :                     sal_Bool bDoBrowse = sal_False;
     171           0 :                     OUString sOldPath = getURLNoPrefix();
     172           0 :                     do
     173             :                     {
     174           0 :                         if (!sOldPath.isEmpty())
     175           0 :                             xFolderPicker->setDisplayDirectory(sOldPath);
     176           0 :                         if (0 == xFolderPicker->execute())
     177             :                             // cancelled by the user
     178           0 :                             return 0L;
     179             : 
     180           0 :                         sOldPath = xFolderPicker->getDirectory();
     181           0 :                         switch (checkPathExistence(sOldPath))
     182             :                         {
     183             :                             case RET_RETRY:
     184           0 :                                 bDoBrowse = sal_True;
     185           0 :                                 break;
     186             :                             case RET_CANCEL:
     187           0 :                                 return 0L;
     188             :                             default:
     189           0 :                                 break;
     190             :                         }
     191             :                     }
     192             :                     while (bDoBrowse);
     193             : 
     194           0 :                     OUString sSelectedDirectory = xFolderPicker->getDirectory();
     195           0 :                     INetURLObject aSelectedDirectory( sSelectedDirectory, INetURLObject::WAS_ENCODED, RTL_TEXTENCODING_UTF8 );
     196             : 
     197             :                     // for UI purpose, we don't want to have the path encoded
     198           0 :                     sSelectedDirectory = aSelectedDirectory.GetMainURL( INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8  );
     199             : 
     200           0 :                     setURLNoPrefix( sSelectedDirectory );
     201           0 :                     SetRoadmapStateValue(sal_True);
     202           0 :                     callModifiedHdl();
     203             :                 }
     204           0 :                 catch( const Exception& )
     205             :                 {
     206             :                     DBG_UNHANDLED_EXCEPTION();
     207             :                 }
     208             :             }
     209           0 :             break;
     210             :             case  ::dbaccess::DST_CALC:
     211             :             {
     212           0 :                 SvtModuleOptions aModule;
     213             :                 ::sfx2::FileDialogHelper aFileDlg(
     214             :                     ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
     215             :                     0,
     216             :                     aModule.GetFactoryEmptyDocumentURL(SvtModuleOptions::E_CALC)
     217           0 :                     ,SFX_FILTER_IMPORT);
     218           0 :                 askForFileName(aFileDlg);
     219             :             }
     220           0 :             break;
     221             :             case  ::dbaccess::DST_MSACCESS:
     222             :             {
     223           0 :                 const OUString sExt("*.mdb");
     224           0 :                 OUString sFilterName(ModuleRes (STR_MSACCESS_FILTERNAME));
     225             :                 ::sfx2::FileDialogHelper aFileDlg(
     226             :                     ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
     227           0 :                     0);
     228           0 :                 aFileDlg.AddFilter(sFilterName,sExt);
     229           0 :                 aFileDlg.SetCurrentFilter(sFilterName);
     230           0 :                 askForFileName(aFileDlg);
     231             :             }
     232           0 :             break;
     233             :             case  ::dbaccess::DST_MSACCESS_2007:
     234             :             {
     235           0 :                 const OUString sAccdb("*.accdb");
     236           0 :                 OUString sFilterName2(ModuleRes (STR_MSACCESS_2007_FILTERNAME));
     237             :                 ::sfx2::FileDialogHelper aFileDlg(
     238             :                     ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
     239           0 :                     0);
     240           0 :                 aFileDlg.AddFilter(sFilterName2,sAccdb);
     241           0 :                 aFileDlg.SetCurrentFilter(sFilterName2);
     242           0 :                 askForFileName(aFileDlg);
     243             :             }
     244           0 :             break;
     245             :             case  ::dbaccess::DST_MYSQL_ODBC:
     246             :             case  ::dbaccess::DST_ODBC:
     247             :             {
     248             :                 // collect all ODBC data source names
     249           0 :                 OUString sCurrDatasource = getURLNoPrefix();
     250           0 :                 OUString sDataSource;
     251           0 :                 if ( getSelectedDataSource(sDataSource,sCurrDatasource) && !sDataSource.isEmpty() )
     252             :                 {
     253           0 :                     setURLNoPrefix(sDataSource);
     254           0 :                     SetRoadmapStateValue(sal_True);
     255           0 :                     callModifiedHdl();
     256             :                 }
     257             :                 else
     258           0 :                     return 1L;
     259             :             }
     260           0 :             break;
     261             : #ifdef _ADO_DATALINK_BROWSE_
     262             :             case  ::dbaccess::DST_ADO:
     263             :             {
     264             :                 OUString sOldDataSource=getURLNoPrefix();
     265             :                 OUString sNewDataSource;
     266             :                 HWND hWnd = GetParent()->GetSystemData()->hWnd;
     267             :                 sNewDataSource = getAdoDatalink((LONG_PTR)hWnd,sOldDataSource);
     268             :                 if ( !sNewDataSource.isEmpty() )
     269             :                 {
     270             :                     setURLNoPrefix(sNewDataSource);
     271             :                     SetRoadmapStateValue(sal_True);
     272             :                     callModifiedHdl();
     273             :                 }
     274             :                 else
     275             :                     return 1L;
     276             :             }
     277             :             break;
     278             : #endif
     279             :             case  ::dbaccess::DST_MOZILLA:
     280             :             case  ::dbaccess::DST_THUNDERBIRD:
     281             :             {
     282           0 :                 MozillaProductType profileType = MozillaProductType_Mozilla;
     283           0 :                 if (eType ==  ::dbaccess::DST_THUNDERBIRD)
     284           0 :                     profileType = MozillaProductType_Thunderbird;
     285             : 
     286           0 :                 Reference<XComponentContext> xContext = ::comphelper::getProcessComponentContext();
     287           0 :                 Reference<XMozillaBootstrap> xMozillaBootstrap = MozillaBootstrap::create(xContext);
     288             : 
     289             :                 // collect all Mozilla Profiles
     290           0 :                 ::com::sun::star::uno::Sequence< OUString > list;
     291             : 
     292           0 :                 xMozillaBootstrap->getProfileList( profileType, list );
     293           0 :                 const OUString * pArray = list.getConstArray();
     294             : 
     295           0 :                 sal_Int32 count = list.getLength();
     296             : 
     297           0 :                 StringBag aProfiles;
     298           0 :                 for (sal_Int32 index=0; index < count; index++)
     299           0 :                     aProfiles.insert(pArray[index]);
     300             : 
     301             :                 // execute the select dialog
     302           0 :                 ODatasourceSelectDialog aSelector(GetParent(), aProfiles);
     303           0 :                 OUString sOldProfile=getURLNoPrefix();
     304             : 
     305           0 :                 if (!sOldProfile.isEmpty())
     306           0 :                     aSelector.Select(sOldProfile);
     307             :                 else
     308           0 :                     aSelector.Select(xMozillaBootstrap->getDefaultProfile(profileType));
     309             : 
     310           0 :                 if ( RET_OK == aSelector.Execute() )
     311           0 :                     setURLNoPrefix(aSelector.GetSelected());
     312           0 :                 break;
     313             :             }
     314             :             case ::dbaccess::DST_FIREBIRD:
     315             :             {
     316           0 :                 const OUString sExt("*.fdb");
     317           0 :                 OUString sFilterName(ModuleRes (STR_FIREBIRD_FILTERNAME));
     318             :                 ::sfx2::FileDialogHelper aFileDlg(
     319             :                     ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
     320           0 :                     0);
     321           0 :                 aFileDlg.AddFilter(sFilterName,sExt);
     322           0 :                 aFileDlg.SetCurrentFilter(sFilterName);
     323           0 :                 askForFileName(aFileDlg);
     324             :             }
     325             :             default:
     326           0 :                 break;
     327             :         }
     328             : 
     329           0 :         checkTestConnection();
     330             : 
     331           0 :         return 0L;
     332             :     }
     333             : 
     334           0 :     IMPL_LINK(OConnectionHelper, OnCreateDatabase, PushButton*, /*_pButton*/)
     335             :     {
     336             :         OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
     337           0 :         const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
     338           0 :         switch ( eType )
     339             :         {
     340             :         case ::dbaccess::DST_FIREBIRD:
     341             :             {
     342           0 :                 const OUString sExt("*.fdb");
     343           0 :                 OUString sFilterName(ModuleRes (STR_FIREBIRD_FILTERNAME));
     344             :                 ::sfx2::FileDialogHelper aFileDlg(
     345             :                     ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
     346           0 :                     0);
     347           0 :                 aFileDlg.AddFilter(sFilterName,sExt);
     348           0 :                 aFileDlg.SetCurrentFilter(sFilterName);
     349           0 :                 askForFileName(aFileDlg);
     350             :             }
     351             :             default:
     352           0 :                 break;
     353             :         }
     354             : 
     355           0 :         checkTestConnection();
     356             : 
     357           0 :         return 0L;
     358             :     }
     359             : 
     360           0 :     bool OConnectionHelper::checkTestConnection()
     361             :     {
     362           0 :         return true;
     363             :     }
     364             : 
     365           0 :     void OConnectionHelper::impl_setURL( const OUString& _rURL, sal_Bool _bPrefix )
     366             :     {
     367           0 :         OUString sURL( comphelper::string::stripEnd(_rURL, '*') );
     368             :         OSL_ENSURE( m_pCollection, "OConnectionHelper::impl_setURL: have no interpreter for the URLs!" );
     369             : 
     370           0 :         if ( m_pCollection && !sURL.isEmpty() )
     371             :         {
     372           0 :             if ( m_pCollection->isFileSystemBased( m_eType ) )
     373             :             {
     374             :                 // get the two parts: prefix and file URL
     375           0 :                 OUString sTypePrefix, sFileURLEncoded;
     376           0 :                 if ( _bPrefix )
     377             :                 {
     378           0 :                     sTypePrefix = m_pCollection->getPrefix( m_eType );
     379           0 :                     sFileURLEncoded = m_pCollection->cutPrefix( sURL );
     380             :                 }
     381             :                 else
     382             :                 {
     383           0 :                     sFileURLEncoded = sURL;
     384             :                 }
     385             : 
     386             :                 // substitute any variables
     387           0 :                 sFileURLEncoded = SvtPathOptions().SubstituteVariable( sFileURLEncoded );
     388             : 
     389             :                 // decode the URL
     390           0 :                 sURL = sTypePrefix;
     391           0 :                 if ( !sFileURLEncoded.isEmpty() )
     392             :                 {
     393           0 :                     OFileNotation aFileNotation(sFileURLEncoded);
     394             :                     // set this decoded URL as text
     395           0 :                     sURL += aFileNotation.get(OFileNotation::N_SYSTEM);
     396           0 :                 }
     397             :             }
     398             :         }
     399             : 
     400           0 :         if ( _bPrefix )
     401           0 :             m_aConnectionURL.SetText( sURL );
     402             :         else
     403           0 :             m_aConnectionURL.SetTextNoPrefix( sURL );
     404             : 
     405           0 :         implUpdateURLDependentStates();
     406           0 :     }
     407             : 
     408           0 :     OUString OConnectionHelper::impl_getURL( sal_Bool _bPrefix ) const
     409             :     {
     410             :         // get the pure text
     411           0 :         OUString sURL = _bPrefix ? m_aConnectionURL.GetText() : OUString(m_aConnectionURL.GetTextNoPrefix());
     412             : 
     413             :         OSL_ENSURE( m_pCollection, "OConnectionHelper::impl_getURL: have no interpreter for the URLs!" );
     414             : 
     415           0 :         if ( m_pCollection && !sURL.isEmpty() )
     416             :         {
     417           0 :             if ( m_pCollection->isFileSystemBased( m_eType ) )
     418             :             {
     419             :                 // get the two parts: prefix and file URL
     420           0 :                 OUString sTypePrefix, sFileURLDecoded;
     421           0 :                 if ( _bPrefix )
     422             :                 {
     423           0 :                     sTypePrefix = m_pCollection->getPrefix( m_eType );
     424           0 :                     sFileURLDecoded = m_pCollection->cutPrefix( sURL );
     425             :                 }
     426             :                 else
     427             :                 {
     428           0 :                     sFileURLDecoded = sURL;
     429             :                 }
     430             : 
     431           0 :                 sURL = sTypePrefix;
     432           0 :                 if ( !sFileURLDecoded.isEmpty() )
     433             :                 {
     434           0 :                     OFileNotation aFileNotation( sFileURLDecoded, OFileNotation::N_SYSTEM );
     435           0 :                     sURL += aFileNotation.get( OFileNotation::N_URL );
     436             :                 }
     437             : 
     438             :                 // encode the URL
     439           0 :                 INetURLObject aFileURL( sFileURLDecoded, INetURLObject::ENCODE_ALL, RTL_TEXTENCODING_UTF8 );
     440           0 :                 sFileURLDecoded = aFileURL.GetMainURL( INetURLObject::NO_DECODE );
     441             :             }
     442             :         }
     443           0 :         return sURL;
     444             :     }
     445             : 
     446           0 :     void OConnectionHelper::setURL( const OUString& _rURL )
     447             :     {
     448           0 :         impl_setURL( _rURL, sal_True );
     449           0 :     }
     450             : 
     451           0 :     OUString OConnectionHelper::getURLNoPrefix( ) const
     452             :     {
     453           0 :         return impl_getURL( sal_False );
     454             :     }
     455             : 
     456           0 :     void OConnectionHelper::setURLNoPrefix( const OUString& _rURL )
     457             :     {
     458           0 :         impl_setURL( _rURL, sal_False );
     459           0 :     }
     460             : 
     461           0 :     sal_Int32 OConnectionHelper::checkPathExistence(const OUString& _rURL)
     462             :     {
     463           0 :         IS_PATH_EXIST e_exists = pathExists(_rURL, sal_False);
     464           0 :         if (!m_pCollection->supportsDBCreation(m_eType) &&
     465           0 :             (( e_exists == PATH_NOT_EXIST) || ( e_exists == PATH_NOT_KNOWN)))
     466             :         {
     467           0 :             OUString sQuery(ModuleRes(STR_ASK_FOR_DIRECTORY_CREATION));
     468           0 :             OFileNotation aTransformer(_rURL);
     469           0 :             sQuery = sQuery.replaceFirst("$path$", aTransformer.get(OFileNotation::N_SYSTEM));
     470             : 
     471           0 :             m_bUserGrabFocus = sal_False;
     472           0 :             QueryBox aQuery(GetParent(), WB_YES_NO | WB_DEF_YES, sQuery);
     473           0 :             sal_Int32 nQueryResult = aQuery.Execute();
     474           0 :             m_bUserGrabFocus = sal_True;
     475             : 
     476           0 :             switch (nQueryResult)
     477             :             {
     478             :                 case RET_YES:
     479             :                 {
     480           0 :                     sal_Bool bTryCreate = sal_False;
     481           0 :                     do
     482             :                     {
     483           0 :                         if ( !createDirectoryDeep(_rURL) )
     484             :                         {   // could not create the directory
     485           0 :                             sQuery = ModuleRes(STR_COULD_NOT_CREATE_DIRECTORY);
     486           0 :                             sQuery = sQuery.replaceFirst("$name$", aTransformer.get(OFileNotation::N_SYSTEM));
     487             : 
     488           0 :                             m_bUserGrabFocus = sal_False;
     489           0 :                             QueryBox aWhatToDo(GetParent(), WB_RETRY_CANCEL | WB_DEF_RETRY, sQuery);
     490           0 :                             nQueryResult = aWhatToDo.Execute();
     491           0 :                             m_bUserGrabFocus = sal_True;
     492             : 
     493           0 :                             if (RET_RETRY == nQueryResult)
     494           0 :                                 bTryCreate = sal_True;
     495             :                             else
     496             :                             {
     497           0 :                                 SetRoadmapStateValue(sal_False);
     498           0 :                                 callModifiedHdl();
     499           0 :                                 return RET_RETRY;
     500           0 :                             }
     501             :                         }
     502             :                     }
     503             :                     while (bTryCreate);
     504             :                 }
     505           0 :                 break;
     506             : 
     507             :                 case RET_NO:
     508           0 :                     callModifiedHdl();
     509           0 :                     return RET_OK;
     510             : 
     511             :                 default:
     512             :                     // cancelled
     513           0 :                     SetRoadmapStateValue(sal_False);
     514           0 :                     callModifiedHdl();
     515           0 :                     return RET_CANCEL;
     516           0 :             }
     517             :         }
     518             : /*        else
     519             :         {
     520             :             // TODO: error msg
     521             :             return RET_CANCEL;
     522             :         } */
     523           0 :         SetRoadmapStateValue(sal_True);
     524           0 :         callModifiedHdl();
     525           0 :         return RET_OK;
     526             :     }
     527             : 
     528           0 :     IS_PATH_EXIST OConnectionHelper::pathExists(const OUString& _rURL, sal_Bool bIsFile) const
     529             :     {
     530           0 :         ::ucbhelper::Content aCheckExistence;
     531           0 :         sal_Bool bExists = sal_False;
     532           0 :         IS_PATH_EXIST eExists = PATH_NOT_EXIST;
     533             :         Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler(
     534           0 :             task::InteractionHandler::createWithParent(m_xORB, 0), UNO_QUERY );
     535           0 :         OFilePickerInteractionHandler* pHandler = new OFilePickerInteractionHandler(xInteractionHandler);
     536           0 :         xInteractionHandler = pHandler;
     537             : 
     538           0 :         Reference< XCommandEnvironment > xCmdEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
     539             :         try
     540             :         {
     541           0 :             aCheckExistence = ::ucbhelper::Content(_rURL, xCmdEnv, comphelper::getProcessComponentContext());
     542           0 :             bExists = bIsFile? aCheckExistence.isDocument(): aCheckExistence.isFolder();
     543           0 :             eExists = bExists? PATH_EXIST: PATH_NOT_EXIST;
     544             :         }
     545           0 :         catch(const Exception&)
     546             :         {
     547           0 :             eExists = ( pHandler && pHandler->isDoesNotExist() ) ? PATH_NOT_EXIST: (bIsFile ? PATH_NOT_EXIST : PATH_NOT_KNOWN);
     548             :            }
     549           0 :         return eExists;
     550             :     }
     551           0 :     bool OConnectionHelper::PreNotify( NotifyEvent& _rNEvt )
     552             :     {
     553           0 :         if ( m_pCollection->isFileSystemBased(m_eType) )
     554             :         {
     555           0 :             switch (_rNEvt.GetType())
     556             :             {
     557             :                 case EVENT_GETFOCUS:
     558           0 :                     if (m_aConnectionURL.IsWindowOrChild(_rNEvt.GetWindow()) && m_bUserGrabFocus)
     559             :                     {   // a descendant of the URL edit field got the focus
     560           0 :                         m_aConnectionURL.SaveValueNoPrefix();
     561             :                     }
     562           0 :                     break;
     563             : 
     564             :                 case EVENT_LOSEFOCUS:
     565           0 :                     if (m_aConnectionURL.IsWindowOrChild(_rNEvt.GetWindow()) && m_bUserGrabFocus)
     566             :                     {   // a descendant of the URL edit field lost the focus
     567           0 :                         if (!commitURL())
     568           0 :                             return true;  // handled
     569             :                     }
     570           0 :                     break;
     571             :             }
     572             :         }
     573             : 
     574           0 :         return OGenericAdministrationPage::PreNotify( _rNEvt );
     575             :     }
     576             : 
     577           0 :     sal_Bool OConnectionHelper::createDirectoryDeep(const OUString& _rPathURL)
     578             :     {
     579             :         // get an URL object analyzing the URL for us ...
     580           0 :         INetURLObject aParser;
     581           0 :         aParser.SetURL(_rPathURL);
     582             : 
     583           0 :         INetProtocol eProtocol = aParser.GetProtocol();
     584             : 
     585           0 :         ::std::vector< OUString > aToBeCreated;  // the to-be-created levels
     586             : 
     587             :         // search a level which exists
     588           0 :         IS_PATH_EXIST eParentExists = PATH_NOT_EXIST;
     589           0 :         while ( eParentExists == PATH_NOT_EXIST && aParser.getSegmentCount())
     590             :         {
     591           0 :             aToBeCreated.push_back(aParser.getName());  // remember the local name for creation
     592           0 :             aParser.removeSegment();                    // cut the local name
     593           0 :             eParentExists = pathExists(aParser.GetMainURL(INetURLObject::NO_DECODE), sal_False);
     594             :         }
     595             : 
     596           0 :         if (!aParser.getSegmentCount())
     597           0 :             return sal_False;
     598             : 
     599             :         // create all the missing levels
     600             :         try
     601             :         {
     602             :             // the parent content
     603           0 :             Reference< XCommandEnvironment > xEmptyEnv;
     604           0 :             ::ucbhelper::Content aParent(aParser.GetMainURL(INetURLObject::NO_DECODE), xEmptyEnv, comphelper::getProcessComponentContext());
     605             : 
     606           0 :             OUString sContentType;
     607           0 :             if ( INET_PROT_FILE == eProtocol )
     608             :             {
     609           0 :                 sContentType = "application/vnd.sun.staroffice.fsys-folder";
     610             :                 // the file UCP currently does not support the ContentType property
     611             :             }
     612             :             else
     613             :             {
     614           0 :                 Any aContentType = aParent.getPropertyValue("ContentType");
     615           0 :                 aContentType >>= sContentType;
     616             :             }
     617             : 
     618             :             // the properties which need to be set on the new content
     619           0 :             Sequence< OUString > aNewDirectoryProperties(1);
     620           0 :             aNewDirectoryProperties[0] = "Title";
     621             : 
     622             :             // the values to be set
     623           0 :             Sequence< Any > aNewDirectoryAttributes(1);
     624             : 
     625             :             // loop
     626           0 :             for (   ::std::vector< OUString >::reverse_iterator aLocalName = aToBeCreated.rbegin();
     627           0 :                     aLocalName != aToBeCreated.rend();
     628             :                     ++aLocalName
     629             :                 )
     630             :             {
     631           0 :                 aNewDirectoryAttributes[0] <<= *aLocalName;
     632           0 :                 if (!aParent.insertNewContent(sContentType, aNewDirectoryProperties, aNewDirectoryAttributes, aParent))
     633           0 :                     return sal_False;
     634           0 :             }
     635             :         }
     636           0 :         catch ( const Exception& )
     637             :         {
     638             :             DBG_UNHANDLED_EXCEPTION();
     639           0 :             return sal_False;
     640             :         }
     641             : 
     642           0 :         return sal_True;
     643             :     }
     644             : 
     645           0 :     void OConnectionHelper::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
     646             :     {
     647           0 :         _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFT_Connection));
     648           0 :         _rControlList.push_back(new ODisableWrapper<PushButton>(&m_aPB_Connection));
     649           0 :         _rControlList.push_back(new ODisableWrapper<PushButton>(&m_aPB_CreateDB));
     650           0 :     }
     651             : 
     652           0 :     void OConnectionHelper::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
     653             :     {
     654           0 :         _rControlList.push_back( new OSaveValueWrapper<Edit>( &m_aConnectionURL ) );
     655           0 :     }
     656             : 
     657           0 :     sal_Bool OConnectionHelper::commitURL()
     658             :     {
     659           0 :         OUString sURL;
     660           0 :         OUString sOldPath;
     661           0 :         sOldPath = m_aConnectionURL.GetSavedValueNoPrefix();
     662           0 :         sURL = m_aConnectionURL.GetTextNoPrefix();
     663             : 
     664           0 :         if ( m_pCollection->isFileSystemBased(m_eType) )
     665             :         {
     666           0 :             if ( ( sURL != sOldPath ) && !sURL.isEmpty() )
     667             :             {   // the text changed since entering the control
     668             : 
     669             :                 // the path may be in system notation ....
     670           0 :                 OFileNotation aTransformer(sURL);
     671           0 :                 sURL = aTransformer.get(OFileNotation::N_URL);
     672             : 
     673           0 :                 const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
     674             : 
     675           0 :                 if ( ( ::dbaccess::DST_CALC == eType) || ( ::dbaccess::DST_MSACCESS == eType) || ( ::dbaccess::DST_MSACCESS_2007 == eType) )
     676             :                 {
     677           0 :                     if( pathExists(sURL, sal_True) == PATH_NOT_EXIST )
     678             :                     {
     679           0 :                         OUString sFile = ModuleRes( STR_FILE_DOES_NOT_EXIST );
     680           0 :                         sFile = sFile.replaceFirst("$file$", aTransformer.get(OFileNotation::N_SYSTEM));
     681           0 :                         OSQLWarningBox( this, sFile ).Execute();
     682           0 :                         setURLNoPrefix(sOldPath);
     683           0 :                         SetRoadmapStateValue(sal_False);
     684           0 :                         callModifiedHdl();
     685           0 :                         return sal_False;
     686           0 :                     }
     687             :                 }
     688             :                 else
     689             :                 {
     690           0 :                     switch (checkPathExistence(sURL))
     691             :                     {
     692             :                         case RET_RETRY:
     693           0 :                             m_bUserGrabFocus = sal_False;
     694           0 :                             m_aConnectionURL.GrabFocus();
     695           0 :                             m_bUserGrabFocus = sal_True;
     696           0 :                             return sal_False;
     697             : 
     698             :                         case RET_CANCEL:
     699           0 :                             setURLNoPrefix(sOldPath);
     700           0 :                             return sal_False;
     701             :                     }
     702           0 :                 }
     703             :             }
     704             :         }
     705             : 
     706           0 :         setURLNoPrefix(sURL);
     707           0 :         m_aConnectionURL.SaveValueNoPrefix();
     708           0 :         return sal_True;
     709             :     }
     710           0 :     void OConnectionHelper::askForFileName(::sfx2::FileDialogHelper& _aFileOpen)
     711             :     {
     712           0 :         OUString sOldPath = getURLNoPrefix();
     713           0 :         if ( !sOldPath.isEmpty() )
     714           0 :             _aFileOpen.SetDisplayDirectory(sOldPath);
     715             :         else
     716           0 :             _aFileOpen.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
     717           0 :         if (0 == _aFileOpen.Execute())
     718             :         {
     719           0 :             setURLNoPrefix(_aFileOpen.GetPath());
     720           0 :             SetRoadmapStateValue(checkTestConnection());
     721           0 :             callModifiedHdl();
     722           0 :         }
     723           0 :     }
     724             : 
     725           0 : }   // namespace dbaui
     726             : 
     727             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10