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

Generated by: LCOV version 1.10