1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ConnectionHelper.cxx,v $
10 * $Revision: 1.19.48.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "dsnItem.hxx"
35 #ifndef DBAUI_CONNECTIONHELPER_HXX
36 #include "ConnectionHelper.hxx"
38 #ifndef _DBAUI_AUTOCONTROLS_HRC_
39 #include "AutoControls.hrc"
42 #include "dbu_dlg.hrc"
44 #ifndef _DBU_MISC_HRC_
45 #include "dbu_misc.hrc"
47 #ifndef _SFXITEMSET_HXX
48 #include <svtools/itemset.hxx>
50 #ifndef INCLUDED_SVTOOLS_MODULEOPTIONS_HXX
51 #include <svtools/moduleoptions.hxx>
53 #ifndef _SFX_FCONTNR_HXX
54 #include <sfx2/fcontnr.hxx>
56 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
57 #include <svtools/pathoptions.hxx>
59 #ifndef _SFXSTRITEM_HXX
60 #include <svtools/stritem.hxx>
62 #ifndef _SFXENUMITEM_HXX
63 #include <svtools/eitem.hxx>
65 #ifndef _SFXINTITEM_HXX
66 #include <svtools/intitem.hxx>
68 #ifndef _DBAUI_DATASOURCEITEMS_HXX_
69 #include "dsitems.hxx"
71 #ifndef _DBA_DBACCESS_HELPID_HRC_
72 #include "dbaccess_helpid.hrc"
74 #ifndef _DBAUI_LOCALRESACCESS_HXX_
75 #include "localresaccess.hxx"
77 #ifndef _OSL_PROCESS_H_
78 #include <osl/process.h>
80 #ifndef _SV_MSGBOX_HXX
81 #include <vcl/msgbox.hxx>
83 #ifndef _FILEDLGHELPER_HXX
84 #include <sfx2/filedlghelper.hxx>
86 #ifndef _DBAUI_DBADMIN_HXX_
87 #include "dbadmin.hxx"
89 #ifndef _COMPHELPER_TYPES_HXX_
90 #include <comphelper/types.hxx>
92 #ifndef _VCL_STDTEXT_HXX
93 #include <vcl/stdtext.hxx>
95 #ifndef _DBAUI_SQLMESSAGE_HXX_
96 #include "sqlmessage.hxx"
98 #ifndef _DBAUI_ODBC_CONFIG_HXX_
99 #include "odbcconfig.hxx"
101 #ifndef _DBAUI_DSSELECT_HXX_
102 #include "dsselect.hxx"
104 #ifndef SVTOOLS_FILENOTATION_HXX_
105 #include <svtools/filenotation.hxx>
107 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
108 #include "dbustrings.hrc"
110 #ifndef _COM_SUN_STAR_UI_DIALOGS_XFOLDERPICKER_HPP_
111 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
113 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
114 #include <com/sun/star/sdbc/XRow.hpp>
116 #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
117 #include <com/sun/star/awt/XWindow.hpp>
119 // #106016# ------------------------------------
120 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
121 #include <com/sun/star/task/XInteractionHandler.hpp>
123 #ifndef _COM_SUN_STAR_TASK_XPROGRESSHANDLER_HPP_
124 #include <com/sun/star/ucb/XProgressHandler.hpp>
126 #ifndef DBAUI_TOOLS_HXX
127 #include "UITools.hxx"
129 #ifndef _UNOTOOLS_LOCALFILEHELPER_HXX
130 #include <unotools/localfilehelper.hxx>
132 #ifndef _UNOTOOLS_UCBHELPER_HXX
133 #include <unotools/ucbhelper.hxx>
135 #ifndef _UCBHELPER_COMMANDENVIRONMENT_HXX
136 #include <ucbhelper/commandenvironment.hxx>
138 #ifndef DBAUI_FILEPICKER_INTERACTION_HXX
139 #include "finteraction.hxx"
141 #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
142 #include <connectivity/CommonTools.hxx>
145 #include <tools/urlobj.hxx>
147 #ifndef TOOLS_DIAGNOSE_EX_H
148 #include <tools/diagnose_ex.h>
150 #ifndef _SFX_DOCFILT_HACK_HXX
151 #include <sfx2/docfilt.hxx>
153 #if !defined(WINDOWS_VISTA_PSDK) && (defined(WIN) || defined(WNT))
154 #define _ADO_DATALINK_BROWSE_
157 #ifdef _ADO_DATALINK_BROWSE_
159 #include <tools/prewin.h>
161 #include <tools/postwin.h>
163 #ifndef _SV_SYSDATA_HXX
164 #include <vcl/sysdata.hxx>
166 #ifndef _DBAUI_ADO_DATALINK_HXX_
167 #include "adodatalinks.hxx"
169 #endif //_ADO_DATALINK_BROWSE_
171 #ifndef _COM_SUN_STAR_MOZILLA_XMOZILLABOOTSTRAP_HPP_
172 #include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
174 #include <unotools/processfactory.hxx>
178 //.........................................................................
181 //.........................................................................
182 using namespace ::com::sun::star::uno
;
183 using namespace ::com::sun::star::ucb
;
184 using namespace ::com::sun::star::ui::dialogs
;
185 using namespace ::com::sun::star::sdbc
;
186 using namespace ::com::sun::star::beans
;
187 using namespace ::com::sun::star::lang
;
188 using namespace ::com::sun::star::container
;
189 using namespace ::com::sun::star::mozilla
;
190 using namespace ::dbtools
;
191 using namespace ::svt
;
194 DBG_NAME(OConnectionHelper
)
196 OConnectionHelper::OConnectionHelper( Window
* pParent
, const ResId
& _rId
, const SfxItemSet
& _rCoreAttrs
)
197 :OGenericAdministrationPage(pParent
, _rId
, _rCoreAttrs
)
198 ,m_aFT_Connection ( this, ResId( FT_AUTOBROWSEURL
, *_rId
.GetResMgr() ) )
199 ,m_aConnectionURL ( this, ResId( ET_AUTOBROWSEURL
, *_rId
.GetResMgr() ) )
200 ,m_aPB_Connection ( this, ResId( PB_AUTOBROWSEURL
, *_rId
.GetResMgr() ) )
202 DBG_CTOR(OConnectionHelper
,NULL
);
204 // extract the datasource type collection from the item set
205 DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, _rCoreAttrs
.GetItem(DSID_TYPECOLLECTION
));
207 m_pCollection
= pCollectionItem
->getCollection();
208 m_aPB_Connection
.SetClickHdl(LINK(this, OConnectionHelper
, OnBrowseConnections
));
209 DBG_ASSERT(m_pCollection
, "OConnectionHelper::OConnectionHelper : really need a DSN type collection !");
210 m_aConnectionURL
.SetTypeCollection(m_pCollection
);
214 OConnectionHelper::~OConnectionHelper()
217 DBG_DTOR(OConnectionHelper
,NULL
);
221 // -----------------------------------------------------------------------
222 void OConnectionHelper::implInitControls(const SfxItemSet
& _rSet
, sal_Bool _bSaveValue
)
224 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
225 sal_Bool bValid
, bReadonly
;
226 getFlags(_rSet
, bValid
, bReadonly
);
228 m_aFT_Connection
.Show();
229 m_aConnectionURL
.Show();
230 m_aConnectionURL
.ShowPrefix( ::dbaccess::DST_JDBC
== m_pCollection
->determineType(m_eType
) );
232 BOOL bEnableBrowseButton
= m_pCollection
->supportsBrowsing( m_eType
);
233 m_aPB_Connection
.Show( bEnableBrowseButton
);
235 SFX_ITEMSET_GET(_rSet
, pUrlItem
, SfxStringItem
, DSID_CONNECTURL
, sal_True
);
237 // forward the values to the controls
240 String sUrl
= pUrlItem
->GetValue();
243 checkTestConnection();
244 m_aConnectionURL
.ClearModifyFlag();
247 OGenericAdministrationPage::implInitControls(_rSet
, _bSaveValue
);
250 // -----------------------------------------------------------------------
251 void OConnectionHelper::implUpdateURLDependentStates() const
253 OSL_PRECOND( m_pAdminDialog
, "OConnectionHelper::implUpdateURLDependentStates: no admin dialog!" );
254 if ( !m_pAdminDialog
)
257 if ( m_pCollection
->isFileSystemBased(m_eType
) )
258 m_pAdminDialog
->enableConfirmSettings( getURLNoPrefix().Len() > 0 );
261 // -----------------------------------------------------------------------
262 IMPL_LINK(OConnectionHelper
, OnBrowseConnections
, PushButton
*, /*_pButton*/)
264 OSL_ENSURE(m_pAdminDialog
,"No Admin dialog set! ->GPF");
265 const ::dbaccess::DATASOURCE_TYPE eType
= m_pCollection
->determineType(m_eType
);
268 case ::dbaccess::DST_DBASE
:
269 case ::dbaccess::DST_FLAT
:
273 ::rtl::OUString sFolderPickerService
= ::rtl::OUString::createFromAscii(SERVICE_UI_FOLDERPICKER
);
274 Reference
< XFolderPicker
> xFolderPicker(m_xORB
->createInstance(sFolderPickerService
), UNO_QUERY
);
275 if (!xFolderPicker
.is())
277 ShowServiceNotAvailableError(GetParent(), sFolderPickerService
, sal_True
);
281 sal_Bool bDoBrowse
= sal_False
;
282 String sOldPath
= getURLNoPrefix();
286 xFolderPicker
->setDisplayDirectory(sOldPath
);
287 if (0 == xFolderPicker
->execute())
288 // cancelled by the user
291 sOldPath
= xFolderPicker
->getDirectory();
292 switch (checkPathExistence(sOldPath
))
295 bDoBrowse
= sal_True
;
305 String sSelectedDirectory
= xFolderPicker
->getDirectory();
306 INetURLObject
aSelectedDirectory( sSelectedDirectory
, INetURLObject::WAS_ENCODED
, RTL_TEXTENCODING_UTF8
);
308 // for UI purpose, we don't want to have the path encoded
309 sSelectedDirectory
= aSelectedDirectory
.GetMainURL( INetURLObject::DECODE_WITH_CHARSET
, RTL_TEXTENCODING_UTF8
);
311 setURLNoPrefix( sSelectedDirectory
);
312 SetRoadmapStateValue(sal_True
);
315 catch( const Exception
& )
317 DBG_UNHANDLED_EXCEPTION();
321 case ::dbaccess::DST_CALC
:
323 SvtModuleOptions aModule
;
324 ::sfx2::FileDialogHelper
aFileDlg(WB_3DLOOK
| WB_STDMODAL
| WB_OPEN
325 ,aModule
.GetFactoryEmptyDocumentURL(SvtModuleOptions::E_CALC
)
327 askForFileName(aFileDlg
);
330 case ::dbaccess::DST_MSACCESS
:
332 const ::rtl::OUString
sExt(RTL_CONSTASCII_USTRINGPARAM("*.mdb"));
333 String
sFilterName(ModuleRes (STR_MSACCESS_FILTERNAME
));
334 ::sfx2::FileDialogHelper
aFileDlg(WB_3DLOOK
| WB_STDMODAL
| WB_OPEN
);
335 aFileDlg
.AddFilter(sFilterName
,sExt
);
336 aFileDlg
.SetCurrentFilter(sFilterName
);
337 askForFileName(aFileDlg
);
340 case ::dbaccess::DST_MSACCESS_2007
:
342 const ::rtl::OUString
sAccdb(RTL_CONSTASCII_USTRINGPARAM("*.accdb"));
343 String
sFilterName2(ModuleRes (STR_MSACCESS_2007_FILTERNAME
));
344 ::sfx2::FileDialogHelper
aFileDlg(WB_3DLOOK
| WB_STDMODAL
| WB_OPEN
);
345 aFileDlg
.AddFilter(sFilterName2
,sAccdb
);
346 aFileDlg
.SetCurrentFilter(sFilterName2
);
347 askForFileName(aFileDlg
);
350 case ::dbaccess::DST_ADABAS
:
352 // collect all names from the config dir
353 // and all dir's of the DBWORK/wrk or DBROOT/wrk dir
356 // collect the names of the installed databases
357 StringBag aInstalledDBs
;
358 ::rtl::OUString sAdabasConfigDir
,sAdabasWorkDir
,sRootDir
;
359 ::rtl::OUString
sEnvVarName(RTL_CONSTASCII_USTRINGPARAM("DBWORK"));
360 rtl_uString
* pDbVar
= NULL
;
361 if(osl_getEnvironment(sEnvVarName
.pData
,&pDbVar
) == osl_Process_E_None
&& pDbVar
)
363 sAdabasWorkDir
= pDbVar
;
365 utl::LocalFileHelper::ConvertPhysicalNameToURL(sAdabasWorkDir
,sURL
);
366 sAdabasWorkDir
= sURL
;
367 rtl_uString_release(pDbVar
);
371 sEnvVarName
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DBCONFIG"));
372 if(osl_getEnvironment(sEnvVarName
.pData
,&pDbVar
) == osl_Process_E_None
&& pDbVar
)
374 sAdabasConfigDir
= pDbVar
;
376 utl::LocalFileHelper::ConvertPhysicalNameToURL(sAdabasConfigDir
,sURL
);
377 sAdabasConfigDir
= sURL
;
378 rtl_uString_release(pDbVar
);
382 sEnvVarName
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DBROOT"));
383 if(osl_getEnvironment(sEnvVarName
.pData
,&pDbVar
) == osl_Process_E_None
&& pDbVar
)
387 utl::LocalFileHelper::ConvertPhysicalNameToURL(sRootDir
,sURL
);
389 rtl_uString_release(pDbVar
);
393 sal_Bool bOldFashion
= sAdabasConfigDir
.getLength() && sAdabasWorkDir
.getLength();
395 if(!bOldFashion
) // we have a normal adabas installation
396 { // so we check the local database names in $DBROOT/config
397 sAdabasConfigDir
= sRootDir
;
398 sAdabasWorkDir
= sRootDir
;
401 if(sAdabasConfigDir
.getLength() && sAdabasWorkDir
.getLength() && sRootDir
.getLength())
404 aInstalledDBs
= getInstalledAdabasDBs(sAdabasConfigDir
,sAdabasWorkDir
);
406 if(!aInstalledDBs
.size() && bOldFashion
)
408 sAdabasConfigDir
= sRootDir
;
409 sAdabasWorkDir
= sRootDir
;
410 aInstalledDBs
= getInstalledAdabasDBs(sAdabasConfigDir
,sAdabasWorkDir
);
413 ODatasourceSelectDialog
aSelector(GetParent(), aInstalledDBs
, true,m_pItemSetHelper
->getWriteOutputSet());
414 if (RET_OK
== aSelector
.Execute())
416 setURLNoPrefix(aSelector
.GetSelected());
417 // checkCreateDatabase( ::dbaccess::DST_ADABAS);
418 SetRoadmapStateValue(sal_True
);
424 LocalResourceAccess
aLocRes( PAGE_CONNECTION
, RSC_TABPAGE
);
425 String sError
= String(ModuleRes(STR_NO_ADABASE_DATASOURCES
));
426 ErrorBox
aBox(this, WB_OK
, sError
);
431 case ::dbaccess::DST_MYSQL_ODBC
:
432 case ::dbaccess::DST_ODBC
:
434 // collect all ODBC data source names
435 ::rtl::OUString sCurrDatasource
= getURLNoPrefix();
436 ::rtl::OUString sDataSource
;
437 if ( getSelectedDataSource(sDataSource
,sCurrDatasource
) && sDataSource
.getLength() )
439 setURLNoPrefix(sDataSource
);
440 SetRoadmapStateValue(sal_True
);
447 #ifdef _ADO_DATALINK_BROWSE_
448 case ::dbaccess::DST_ADO
:
450 ::rtl::OUString sOldDataSource
=getURLNoPrefix();
451 ::rtl::OUString sNewDataSource
;
452 HWND hWnd
= GetParent()->GetSystemData()->hWnd
;
453 sNewDataSource
= getAdoDatalink((long)hWnd
,sOldDataSource
);
454 if ( sNewDataSource
.getLength() )
456 setURLNoPrefix(sNewDataSource
);
457 SetRoadmapStateValue(sal_True
);
465 case ::dbaccess::DST_MOZILLA
:
466 case ::dbaccess::DST_THUNDERBIRD
:
468 MozillaProductType profileType
= MozillaProductType_Mozilla
;
469 if (eType
== ::dbaccess::DST_THUNDERBIRD
)
470 profileType
= MozillaProductType_Thunderbird
;
472 Reference
<XMultiServiceFactory
> xFactory
= ::comphelper::getProcessServiceFactory();
473 OSL_ENSURE( xFactory
.is(), "can't get service factory" );
475 Reference
<XInterface
> xInstance
= xFactory
->createInstance(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap")) );
476 OSL_ENSURE( xInstance
.is(), "failed to create instance" );
477 Reference
<XMozillaBootstrap
> xMozillaBootstrap
= Reference
<XMozillaBootstrap
>(xInstance
,UNO_QUERY
);
478 OSL_ENSURE( xMozillaBootstrap
.is(), "failed to create instance" );
480 if (xMozillaBootstrap
.is())
482 // collect all Mozilla Profiles
483 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> list
;
485 xMozillaBootstrap
->getProfileList( profileType
, list
);
486 const ::rtl::OUString
* pArray
= list
.getConstArray();
488 sal_Int32 count
= list
.getLength();
491 for (sal_Int32 index
=0; index
< count
; index
++)
492 aProfiles
.insert(pArray
[index
]);
495 // excute the select dialog
496 ODatasourceSelectDialog
aSelector(GetParent(), aProfiles
, eType
);
497 ::rtl::OUString sOldProfile
=getURLNoPrefix();
499 if (sOldProfile
.getLength())
500 aSelector
.Select(sOldProfile
);
502 aSelector
.Select(xMozillaBootstrap
->getDefaultProfile(profileType
));
504 if ( RET_OK
== aSelector
.Execute() )
505 setURLNoPrefix(aSelector
.GetSelected());
513 checkTestConnection();
518 //-------------------------------------------------------------------------
520 bool OConnectionHelper::checkTestConnection()
525 //-------------------------------------------------------------------------
526 void OConnectionHelper::impl_setURL( const String
& _rURL
, sal_Bool _bPrefix
)
528 String
sURL( _rURL
);
529 DBG_ASSERT( m_pCollection
, "OConnectionHelper::impl_setURL: have no interpreter for the URLs!" );
531 if ( m_pCollection
&& sURL
.Len() )
533 if ( m_pCollection
->isFileSystemBased( m_eType
) )
535 // get the tow parts: prefix and file URL
536 String sTypePrefix
, sFileURLEncoded
;
539 sTypePrefix
= m_pCollection
->getPrefix( m_eType
);
540 sFileURLEncoded
= m_pCollection
->cutPrefix( sURL
);
544 sFileURLEncoded
= sURL
;
547 // substitute any variables
548 sFileURLEncoded
= SvtPathOptions().SubstituteVariable( sFileURLEncoded
);
552 if ( sFileURLEncoded
.Len() )
554 OFileNotation
aFileNotation(sFileURLEncoded
);
555 // set this decoded URL as text
556 sURL
+= String(aFileNotation
.get(OFileNotation::N_SYSTEM
));
562 m_aConnectionURL
.SetText( sURL
);
564 m_aConnectionURL
.SetTextNoPrefix( sURL
);
566 implUpdateURLDependentStates();
569 //-------------------------------------------------------------------------
570 String
OConnectionHelper::impl_getURL( sal_Bool _bPrefix
) const
573 String sURL
= _bPrefix
? m_aConnectionURL
.GetText() : m_aConnectionURL
.GetTextNoPrefix();
575 DBG_ASSERT( m_pCollection
, "OConnectionHelper::impl_getURL: have no interpreter for the URLs!" );
577 if ( m_pCollection
&& sURL
.Len() )
579 if ( m_pCollection
->isFileSystemBased( m_eType
) )
581 // get the tow parts: prefix and file URL
582 String sTypePrefix
, sFileURLDecoded
;
585 sTypePrefix
= m_pCollection
->getPrefix( m_eType
);
586 sFileURLDecoded
= m_pCollection
->cutPrefix( sURL
);
590 sFileURLDecoded
= sURL
;
594 if ( sFileURLDecoded
.Len() )
596 OFileNotation
aFileNotation( sFileURLDecoded
, OFileNotation::N_SYSTEM
);
597 sURL
+= String( aFileNotation
.get( OFileNotation::N_URL
) );
601 INetURLObject
aFileURL( sFileURLDecoded
, INetURLObject::ENCODE_ALL
, RTL_TEXTENCODING_UTF8
);
602 sFileURLDecoded
= aFileURL
.GetMainURL( INetURLObject::NO_DECODE
);
608 //-------------------------------------------------------------------------
609 void OConnectionHelper::setURL( const String
& _rURL
)
611 impl_setURL( _rURL
, sal_True
);
614 //-------------------------------------------------------------------------
615 String
OConnectionHelper::getURLNoPrefix( ) const
617 return impl_getURL( sal_False
);
620 //-------------------------------------------------------------------------
621 void OConnectionHelper::setURLNoPrefix( const String
& _rURL
)
623 impl_setURL( _rURL
, sal_False
);
626 //-------------------------------------------------------------------------
627 sal_Int32
OConnectionHelper::checkPathExistence(const String
& _rURL
)
629 IS_PATH_EXIST e_exists
= pathExists(_rURL
, sal_False
);
630 if (( e_exists
== PATH_NOT_EXIST
) || ( e_exists
== PATH_NOT_KNOWN
))
632 String
sQuery(ModuleRes(STR_ASK_FOR_DIRECTORY_CREATION
));
633 OFileNotation
aTransformer(_rURL
);
634 sQuery
.SearchAndReplaceAscii("$path$", aTransformer
.get(OFileNotation::N_SYSTEM
));
636 m_bUserGrabFocus
= sal_False
;
637 QueryBox
aQuery(GetParent(), WB_YES_NO
| WB_DEF_YES
, sQuery
);
638 sal_Int32 nQueryResult
= aQuery
.Execute();
639 m_bUserGrabFocus
= sal_True
;
641 switch (nQueryResult
)
645 sal_Bool bTryCreate
= sal_False
;
648 if ( !createDirectoryDeep(_rURL
) )
649 { // could not create the directory
650 sQuery
= String(ModuleRes(STR_COULD_NOT_CREATE_DIRECTORY
));
651 sQuery
.SearchAndReplaceAscii("$name$", aTransformer
.get(OFileNotation::N_SYSTEM
));
653 m_bUserGrabFocus
= sal_False
;
654 QueryBox
aWhatToDo(GetParent(), WB_RETRY_CANCEL
| WB_DEF_RETRY
, sQuery
);
655 nQueryResult
= aWhatToDo
.Execute();
656 m_bUserGrabFocus
= sal_True
;
658 if (RET_RETRY
== nQueryResult
)
659 bTryCreate
= sal_True
;
662 SetRoadmapStateValue(sal_False
);
673 // SetRoadmapStateValue(sal_False);
679 SetRoadmapStateValue(sal_False
);
689 SetRoadmapStateValue(sal_True
);
695 //-------------------------------------------------------------------------
696 StringBag
OConnectionHelper::getInstalledAdabasDBDirs(const String
& _rPath
,const ::ucbhelper::ResultSetInclude
& _reResultSetInclude
)
698 INetURLObject aNormalizer
;
699 aNormalizer
.SetSmartProtocol(INET_PROT_FILE
);
700 aNormalizer
.SetSmartURL(_rPath
);
701 String sAdabasConfigDir
= aNormalizer
.GetMainURL(INetURLObject::NO_DECODE
);
703 ::ucbhelper::Content aAdabasConfigDir
;
706 aAdabasConfigDir
= ::ucbhelper::Content(sAdabasConfigDir
, Reference
< ::com::sun::star::ucb::XCommandEnvironment
>());
708 catch(::com::sun::star::ucb::ContentCreationException
&)
713 StringBag aInstalledDBs
;
714 sal_Bool bIsFolder
= sal_False
;
717 bIsFolder
= aAdabasConfigDir
.isFolder();
719 catch(Exception
&) // the exception is thrown when the path doesn't exists
722 if (bIsFolder
&& aAdabasConfigDir
.get().is())
723 { // we have a content for the directory, loop through all entries
724 Sequence
< ::rtl::OUString
> aProperties(1);
725 aProperties
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title"));
729 Reference
< XResultSet
> xFiles
= aAdabasConfigDir
.createCursor(aProperties
, _reResultSetInclude
);
730 Reference
< XRow
> xRow(xFiles
, UNO_QUERY
);
731 xFiles
->beforeFirst();
732 while (xFiles
->next())
735 ::rtl::OUString sName
= xRow
->getString(1);
737 aInstalledDBs
.insert(xRow
->getString(1));
742 DBG_ERROR("OConnectionHelper::getInstalledAdabasDBDirs: could not enumerate the adabas config files!");
747 return aInstalledDBs
;
749 // -----------------------------------------------------------------------------
750 StringBag
OConnectionHelper::getInstalledAdabasDBs(const String
&_rConfigDir
,const String
&_rWorkDir
)
752 String
sAdabasConfigDir(_rConfigDir
),sAdabasWorkDir(_rWorkDir
);
754 if (sAdabasConfigDir
.Len() && ('/' == sAdabasConfigDir
.GetBuffer()[sAdabasConfigDir
.Len() - 1]))
755 sAdabasConfigDir
.AppendAscii("config");
757 sAdabasConfigDir
.AppendAscii("/config");
759 if (sAdabasWorkDir
.Len() && ('/' == sAdabasWorkDir
.GetBuffer()[sAdabasWorkDir
.Len() - 1]))
760 sAdabasWorkDir
.AppendAscii("wrk");
762 sAdabasWorkDir
.AppendAscii("/wrk");
763 // collect the names of the installed databases
764 StringBag aInstalledDBs
;
765 // collect the names of the installed databases
766 StringBag aConfigDBs
,aWrkDBs
;
767 aConfigDBs
= getInstalledAdabasDBDirs(sAdabasConfigDir
,::ucbhelper::INCLUDE_DOCUMENTS_ONLY
);
768 aWrkDBs
= getInstalledAdabasDBDirs(sAdabasWorkDir
,::ucbhelper::INCLUDE_FOLDERS_ONLY
);
769 ConstStringBagIterator aOuter
= aConfigDBs
.begin();
770 ConstStringBagIterator aOuterEnd
= aConfigDBs
.end();
771 for(;aOuter
!= aOuterEnd
;++aOuter
)
773 ConstStringBagIterator aInner
= aWrkDBs
.begin();
774 ConstStringBagIterator aInnerEnd
= aWrkDBs
.end();
775 for (;aInner
!= aInnerEnd
; ++aInner
)
777 if (aInner
->equalsIgnoreAsciiCase(*aOuter
))
779 aInstalledDBs
.insert(*aInner
);
784 return aInstalledDBs
;
786 // #106016# -------------------------------------------------------------------
787 IS_PATH_EXIST
OConnectionHelper::pathExists(const ::rtl::OUString
& _rURL
, sal_Bool bIsFile
) const
789 ::ucbhelper::Content aCheckExistence
;
790 sal_Bool bExists
= sal_False
;
791 IS_PATH_EXIST eExists
= PATH_NOT_EXIST
;
792 Reference
< ::com::sun::star::task::XInteractionHandler
> xInteractionHandler
= Reference
< ::com::sun::star::task::XInteractionHandler
>(
793 m_xORB
->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY
);
794 OFilePickerInteractionHandler
* pHandler
= new OFilePickerInteractionHandler(xInteractionHandler
);
795 xInteractionHandler
= pHandler
;
797 Reference
< XCommandEnvironment
> xCmdEnv
= new ::ucbhelper::CommandEnvironment( xInteractionHandler
, Reference
< XProgressHandler
>() );
800 aCheckExistence
= ::ucbhelper::Content(_rURL
, xCmdEnv
);
801 bExists
= bIsFile
? aCheckExistence
.isDocument(): aCheckExistence
.isFolder();
802 eExists
= bExists
? PATH_EXIST
: PATH_NOT_EXIST
;
804 catch(const Exception
&)
806 eExists
= ( pHandler
&& pHandler
->isDoesNotExist() ) ? PATH_NOT_EXIST
: (bIsFile
? PATH_NOT_EXIST
: PATH_NOT_KNOWN
);
810 //-------------------------------------------------------------------------
811 long OConnectionHelper::PreNotify( NotifyEvent
& _rNEvt
)
813 if ( m_pCollection
->isFileSystemBased(m_eType
) )
815 switch (_rNEvt
.GetType())
818 if (m_aConnectionURL
.IsWindowOrChild(_rNEvt
.GetWindow()) && m_bUserGrabFocus
)
819 { // a descendant of the URL edit field got the focus
820 m_aConnectionURL
.SaveValueNoPrefix();
824 case EVENT_LOSEFOCUS
:
825 if (m_aConnectionURL
.IsWindowOrChild(_rNEvt
.GetWindow()) && m_bUserGrabFocus
)
826 { // a descendant of the URL edit field lost the focus
828 return 1L; // handled
831 } // switch (_rNEvt.GetType())
834 return OGenericAdministrationPage::PreNotify( _rNEvt
);
837 //-------------------------------------------------------------------------
839 sal_Bool
OConnectionHelper::createDirectoryDeep(const String
& _rPathURL
)
841 ::rtl::OUString
sPath(_rPathURL
);
843 // get an URL object analyzing the URL for us ...
844 INetURLObject aParser
;
845 aParser
.SetURL(_rPathURL
);
847 INetProtocol eProtocol
= aParser
.GetProtocol();
849 ::std::vector
< ::rtl::OUString
> aToBeCreated
; // the to-be-created levels
851 // search a level which exists
852 // #106016# ---------------------
853 IS_PATH_EXIST eParentExists
= PATH_NOT_EXIST
;
854 while ( eParentExists
== PATH_NOT_EXIST
&& aParser
.getSegmentCount())
856 aToBeCreated
.push_back(aParser
.getName()); // remember the local name for creation
857 aParser
.removeSegment(); // cut the local name
858 eParentExists
= pathExists(aParser
.GetMainURL(INetURLObject::NO_DECODE
), sal_False
);
861 if (!aParser
.getSegmentCount())
864 // create all the missing levels
867 // the parent content
868 Reference
< XCommandEnvironment
> xEmptyEnv
;
869 ::ucbhelper::Content
aParent(aParser
.GetMainURL(INetURLObject::NO_DECODE
), xEmptyEnv
);
871 ::rtl::OUString sContentType
;
872 if ( INET_PROT_FILE
== eProtocol
)
874 sContentType
= ::rtl::OUString::createFromAscii( "application/vnd.sun.staroffice.fsys-folder" );
875 // the file UCP currently does not support the ContentType property
879 Any aContentType
= aParent
.getPropertyValue( ::rtl::OUString::createFromAscii( "ContentType" ) );
880 aContentType
>>= sContentType
;
883 // the properties which need to be set on the new content
884 Sequence
< ::rtl::OUString
> aNewDirectoryProperties(1);
885 aNewDirectoryProperties
[0] = ::rtl::OUString::createFromAscii("Title");
887 // the values to be set
888 Sequence
< Any
> aNewDirectoryAttributes(1);
891 for ( ::std::vector
< ::rtl::OUString
>::reverse_iterator aLocalName
= aToBeCreated
.rbegin();
892 aLocalName
!= aToBeCreated
.rend();
896 aNewDirectoryAttributes
[0] <<= *aLocalName
;
897 if (!aParent
.insertNewContent(sContentType
, aNewDirectoryProperties
, aNewDirectoryAttributes
, aParent
))
901 catch ( const Exception
& )
903 DBG_UNHANDLED_EXCEPTION();
911 // -----------------------------------------------------------------------
912 void OConnectionHelper::fillWindows(::std::vector
< ISaveValueWrapper
* >& _rControlList
)
914 _rControlList
.push_back(new ODisableWrapper
<FixedText
>(&m_aFT_Connection
));
915 _rControlList
.push_back(new ODisableWrapper
<PushButton
>(&m_aPB_Connection
));
919 // -----------------------------------------------------------------------
920 void OConnectionHelper::fillControls(::std::vector
< ISaveValueWrapper
* >& _rControlList
)
922 _rControlList
.push_back( new OSaveValueWrapper
<Edit
>( &m_aConnectionURL
) );
925 //-------------------------------------------------------------------------
926 sal_Bool
OConnectionHelper::commitURL()
930 sOldPath
= m_aConnectionURL
.GetSavedValueNoPrefix();
931 sURL
= m_aConnectionURL
.GetTextNoPrefix();
933 if ( m_pCollection
->isFileSystemBased(m_eType
) )
935 if ( ( sURL
!= sOldPath
) && ( 0 != sURL
.Len() ) )
936 { // the text changed since entering the control
938 // the path may be in system notation ....
939 OFileNotation
aTransformer(sURL
);
940 sURL
= aTransformer
.get(OFileNotation::N_URL
);
942 const ::dbaccess::DATASOURCE_TYPE eType
= m_pCollection
->determineType(m_eType
);
944 if ( ( ::dbaccess::DST_CALC
== eType
) || ( ::dbaccess::DST_MSACCESS
== eType
) || ( ::dbaccess::DST_MSACCESS_2007
== eType
) )
945 { // #106016# --------------------------
946 if( pathExists(sURL
, sal_True
) == PATH_NOT_EXIST
)
948 String sFile
= String( ModuleRes( STR_FILE_DOES_NOT_EXIST
) );
949 sFile
.SearchAndReplaceAscii("$file$", aTransformer
.get(OFileNotation::N_SYSTEM
));
950 OSQLWarningBox( this, sFile
).Execute();
951 setURLNoPrefix(sOldPath
);
952 SetRoadmapStateValue(sal_False
);
959 switch (checkPathExistence(sURL
))
962 m_bUserGrabFocus
= sal_False
;
963 m_aConnectionURL
.GrabFocus();
964 m_bUserGrabFocus
= sal_True
;
968 setURLNoPrefix(sOldPath
);
975 setURLNoPrefix(sURL
);
976 m_aConnectionURL
.SaveValueNoPrefix();
979 //-------------------------------------------------------------------------
980 void OConnectionHelper::askForFileName(::sfx2::FileDialogHelper
& _aFileOpen
)
982 String sOldPath
= getURLNoPrefix();
983 if ( sOldPath
.Len() )
984 _aFileOpen
.SetDisplayDirectory(sOldPath
);
986 _aFileOpen
.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
987 if (0 == _aFileOpen
.Execute())
989 setURLNoPrefix(_aFileOpen
.GetPath());
990 SetRoadmapStateValue(checkTestConnection());
995 //.........................................................................
997 //.........................................................................