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

Generated by: LCOV version 1.10