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

Generated by: LCOV version 1.11