1*96de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*96de5490SAndrew Rist * distributed with this work for additional information 6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance 9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*96de5490SAndrew Rist * software distributed under the License is distributed on an 15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the 17*96de5490SAndrew Rist * specific language governing permissions and limitations 18*96de5490SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*96de5490SAndrew Rist *************************************************************/ 21*96de5490SAndrew Rist 22*96de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "dsnItem.hxx" 28cdf0e10cSrcweir #ifndef DBAUI_CONNECTIONHELPER_HXX 29cdf0e10cSrcweir #include "ConnectionHelper.hxx" 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir #ifndef _DBAUI_AUTOCONTROLS_HRC_ 32cdf0e10cSrcweir #include "AutoControls.hrc" 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_ 35cdf0e10cSrcweir #include "dbu_dlg.hrc" 36cdf0e10cSrcweir #endif 37cdf0e10cSrcweir #ifndef _DBU_MISC_HRC_ 38cdf0e10cSrcweir #include "dbu_misc.hrc" 39cdf0e10cSrcweir #endif 40cdf0e10cSrcweir #ifndef _SFXITEMSET_HXX 41cdf0e10cSrcweir #include <svl/itemset.hxx> 42cdf0e10cSrcweir #endif 43cdf0e10cSrcweir #ifndef INCLUDED_SVTOOLS_MODULEOPTIONS_HXX 44cdf0e10cSrcweir #include <unotools/moduleoptions.hxx> 45cdf0e10cSrcweir #endif 46cdf0e10cSrcweir #ifndef _SFX_FCONTNR_HXX 47cdf0e10cSrcweir #include <sfx2/fcontnr.hxx> 48cdf0e10cSrcweir #endif 49cdf0e10cSrcweir #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX 50cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 51cdf0e10cSrcweir #endif 52cdf0e10cSrcweir #ifndef _SFXSTRITEM_HXX 53cdf0e10cSrcweir #include <svl/stritem.hxx> 54cdf0e10cSrcweir #endif 55cdf0e10cSrcweir #ifndef _SFXENUMITEM_HXX 56cdf0e10cSrcweir #include <svl/eitem.hxx> 57cdf0e10cSrcweir #endif 58cdf0e10cSrcweir #ifndef _SFXINTITEM_HXX 59cdf0e10cSrcweir #include <svl/intitem.hxx> 60cdf0e10cSrcweir #endif 61cdf0e10cSrcweir #ifndef _DBAUI_DATASOURCEITEMS_HXX_ 62cdf0e10cSrcweir #include "dsitems.hxx" 63cdf0e10cSrcweir #endif 64cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_ 65cdf0e10cSrcweir #include "dbaccess_helpid.hrc" 66cdf0e10cSrcweir #endif 67cdf0e10cSrcweir #ifndef _DBAUI_LOCALRESACCESS_HXX_ 68cdf0e10cSrcweir #include "localresaccess.hxx" 69cdf0e10cSrcweir #endif 70cdf0e10cSrcweir #ifndef _OSL_PROCESS_H_ 71cdf0e10cSrcweir #include <osl/process.h> 72cdf0e10cSrcweir #endif 73cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX 74cdf0e10cSrcweir #include <vcl/msgbox.hxx> 75cdf0e10cSrcweir #endif 76cdf0e10cSrcweir #ifndef _FILEDLGHELPER_HXX 77cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx> 78cdf0e10cSrcweir #endif 79cdf0e10cSrcweir #ifndef _DBAUI_DBADMIN_HXX_ 80cdf0e10cSrcweir #include "dbadmin.hxx" 81cdf0e10cSrcweir #endif 82cdf0e10cSrcweir #ifndef _COMPHELPER_TYPES_HXX_ 83cdf0e10cSrcweir #include <comphelper/types.hxx> 84cdf0e10cSrcweir #endif 85cdf0e10cSrcweir #ifndef _VCL_STDTEXT_HXX 86cdf0e10cSrcweir #include <vcl/stdtext.hxx> 87cdf0e10cSrcweir #endif 88cdf0e10cSrcweir #ifndef _DBAUI_SQLMESSAGE_HXX_ 89cdf0e10cSrcweir #include "sqlmessage.hxx" 90cdf0e10cSrcweir #endif 91cdf0e10cSrcweir #ifndef _DBAUI_ODBC_CONFIG_HXX_ 92cdf0e10cSrcweir #include "odbcconfig.hxx" 93cdf0e10cSrcweir #endif 94cdf0e10cSrcweir #ifndef _DBAUI_DSSELECT_HXX_ 95cdf0e10cSrcweir #include "dsselect.hxx" 96cdf0e10cSrcweir #endif 97cdf0e10cSrcweir #ifndef SVTOOLS_FILENOTATION_HXX_ 98cdf0e10cSrcweir #include <svl/filenotation.hxx> 99cdf0e10cSrcweir #endif 100cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC 101cdf0e10cSrcweir #include "dbustrings.hrc" 102cdf0e10cSrcweir #endif 103cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_DIALOGS_XFOLDERPICKER_HPP_ 104cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFolderPicker.hpp> 105cdf0e10cSrcweir #endif 106cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ 107cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp> 108cdf0e10cSrcweir #endif 109cdf0e10cSrcweir #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_ 110cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 111cdf0e10cSrcweir #endif 112cdf0e10cSrcweir // #106016# ------------------------------------ 113cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_ 114cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 115cdf0e10cSrcweir #endif 116cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TASK_XPROGRESSHANDLER_HPP_ 117cdf0e10cSrcweir #include <com/sun/star/ucb/XProgressHandler.hpp> 118cdf0e10cSrcweir #endif 119cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX 120cdf0e10cSrcweir #include "UITools.hxx" 121cdf0e10cSrcweir #endif 122cdf0e10cSrcweir #ifndef _UNOTOOLS_LOCALFILEHELPER_HXX 123cdf0e10cSrcweir #include <unotools/localfilehelper.hxx> 124cdf0e10cSrcweir #endif 125cdf0e10cSrcweir #ifndef _UNOTOOLS_UCBHELPER_HXX 126cdf0e10cSrcweir #include <unotools/ucbhelper.hxx> 127cdf0e10cSrcweir #endif 128cdf0e10cSrcweir #ifndef _UCBHELPER_COMMANDENVIRONMENT_HXX 129cdf0e10cSrcweir #include <ucbhelper/commandenvironment.hxx> 130cdf0e10cSrcweir #endif 131cdf0e10cSrcweir #ifndef DBAUI_FILEPICKER_INTERACTION_HXX 132cdf0e10cSrcweir #include "finteraction.hxx" 133cdf0e10cSrcweir #endif 134cdf0e10cSrcweir #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ 135cdf0e10cSrcweir #include <connectivity/CommonTools.hxx> 136cdf0e10cSrcweir #endif 137cdf0e10cSrcweir #ifndef _URLOBJ_HXX 138cdf0e10cSrcweir #include <tools/urlobj.hxx> 139cdf0e10cSrcweir #endif 140cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H 141cdf0e10cSrcweir #include <tools/diagnose_ex.h> 142cdf0e10cSrcweir #endif 143cdf0e10cSrcweir #ifndef _SFX_DOCFILT_HACK_HXX 144cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 145cdf0e10cSrcweir #endif 146cdf0e10cSrcweir #if !defined(WINDOWS_VISTA_PSDK) && defined(WNT) 147cdf0e10cSrcweir #define _ADO_DATALINK_BROWSE_ 148cdf0e10cSrcweir #endif 149cdf0e10cSrcweir 150cdf0e10cSrcweir #ifdef _ADO_DATALINK_BROWSE_ 151cdf0e10cSrcweir #if defined( WNT ) 152cdf0e10cSrcweir #include <tools/prewin.h> 153cdf0e10cSrcweir #include <windows.h> 154cdf0e10cSrcweir #include <tools/postwin.h> 155cdf0e10cSrcweir #endif 156cdf0e10cSrcweir #ifndef _SV_SYSDATA_HXX 157cdf0e10cSrcweir #include <vcl/sysdata.hxx> 158cdf0e10cSrcweir #endif 159cdf0e10cSrcweir #ifndef _DBAUI_ADO_DATALINK_HXX_ 160cdf0e10cSrcweir #include "adodatalinks.hxx" 161cdf0e10cSrcweir #endif 162cdf0e10cSrcweir #endif //_ADO_DATALINK_BROWSE_ 163cdf0e10cSrcweir 164cdf0e10cSrcweir #ifndef _COM_SUN_STAR_MOZILLA_XMOZILLABOOTSTRAP_HPP_ 165cdf0e10cSrcweir #include <com/sun/star/mozilla/XMozillaBootstrap.hpp> 166cdf0e10cSrcweir #endif 167cdf0e10cSrcweir #include <unotools/processfactory.hxx> 168cdf0e10cSrcweir 169cdf0e10cSrcweir 170cdf0e10cSrcweir 171cdf0e10cSrcweir //......................................................................... 172cdf0e10cSrcweir namespace dbaui 173cdf0e10cSrcweir { 174cdf0e10cSrcweir //......................................................................... 175cdf0e10cSrcweir using namespace ::com::sun::star::uno; 176cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 177cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 178cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 179cdf0e10cSrcweir using namespace ::com::sun::star::beans; 180cdf0e10cSrcweir using namespace ::com::sun::star::lang; 181cdf0e10cSrcweir using namespace ::com::sun::star::container; 182cdf0e10cSrcweir using namespace ::com::sun::star::mozilla; 183cdf0e10cSrcweir using namespace ::dbtools; 184cdf0e10cSrcweir using namespace ::svt; 185cdf0e10cSrcweir 186cdf0e10cSrcweir 187cdf0e10cSrcweir DBG_NAME(OConnectionHelper) 188cdf0e10cSrcweir 189cdf0e10cSrcweir OConnectionHelper::OConnectionHelper( Window* pParent, const ResId& _rId, const SfxItemSet& _rCoreAttrs) 190cdf0e10cSrcweir :OGenericAdministrationPage(pParent, _rId, _rCoreAttrs) 191cdf0e10cSrcweir ,m_aFT_Connection ( this, ResId( FT_AUTOBROWSEURL, *_rId.GetResMgr() ) ) 192cdf0e10cSrcweir ,m_aConnectionURL ( this, ResId( ET_AUTOBROWSEURL, *_rId.GetResMgr() ) ) 193cdf0e10cSrcweir ,m_aPB_Connection ( this, ResId( PB_AUTOBROWSEURL, *_rId.GetResMgr() ) ) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir DBG_CTOR(OConnectionHelper,NULL); 196cdf0e10cSrcweir 197cdf0e10cSrcweir // extract the datasource type collection from the item set 198cdf0e10cSrcweir DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _rCoreAttrs.GetItem(DSID_TYPECOLLECTION)); 199cdf0e10cSrcweir if (pCollectionItem) 200cdf0e10cSrcweir m_pCollection = pCollectionItem->getCollection(); 201cdf0e10cSrcweir m_aPB_Connection.SetClickHdl(LINK(this, OConnectionHelper, OnBrowseConnections)); 202cdf0e10cSrcweir DBG_ASSERT(m_pCollection, "OConnectionHelper::OConnectionHelper : really need a DSN type collection !"); 203cdf0e10cSrcweir m_aConnectionURL.SetTypeCollection(m_pCollection); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir 207cdf0e10cSrcweir OConnectionHelper::~OConnectionHelper() 208cdf0e10cSrcweir { 209cdf0e10cSrcweir 210cdf0e10cSrcweir DBG_DTOR(OConnectionHelper,NULL); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir 214cdf0e10cSrcweir // ----------------------------------------------------------------------- 215cdf0e10cSrcweir void OConnectionHelper::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 218cdf0e10cSrcweir sal_Bool bValid, bReadonly; 219cdf0e10cSrcweir getFlags(_rSet, bValid, bReadonly); 220cdf0e10cSrcweir 221cdf0e10cSrcweir m_aFT_Connection.Show(); 222cdf0e10cSrcweir m_aConnectionURL.Show(); 223cdf0e10cSrcweir m_aConnectionURL.ShowPrefix( ::dbaccess::DST_JDBC == m_pCollection->determineType(m_eType) ); 224cdf0e10cSrcweir 225cdf0e10cSrcweir sal_Bool bEnableBrowseButton = m_pCollection->supportsBrowsing( m_eType ); 226cdf0e10cSrcweir m_aPB_Connection.Show( bEnableBrowseButton ); 227cdf0e10cSrcweir 228cdf0e10cSrcweir SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True); 229cdf0e10cSrcweir 230cdf0e10cSrcweir // forward the values to the controls 231cdf0e10cSrcweir if ( bValid ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir String sUrl = pUrlItem->GetValue(); 234cdf0e10cSrcweir setURL( sUrl ); 235cdf0e10cSrcweir 236cdf0e10cSrcweir checkTestConnection(); 237cdf0e10cSrcweir m_aConnectionURL.ClearModifyFlag(); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir // ----------------------------------------------------------------------- 244cdf0e10cSrcweir void OConnectionHelper::implUpdateURLDependentStates() const 245cdf0e10cSrcweir { 246cdf0e10cSrcweir OSL_PRECOND( m_pAdminDialog, "OConnectionHelper::implUpdateURLDependentStates: no admin dialog!" ); 247cdf0e10cSrcweir if ( !m_pAdminDialog ) 248cdf0e10cSrcweir return; 249cdf0e10cSrcweir 250cdf0e10cSrcweir if ( m_pCollection->isFileSystemBased(m_eType) ) 251cdf0e10cSrcweir m_pAdminDialog->enableConfirmSettings( getURLNoPrefix().Len() > 0 ); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir // ----------------------------------------------------------------------- 255cdf0e10cSrcweir IMPL_LINK(OConnectionHelper, OnBrowseConnections, PushButton*, /*_pButton*/) 256cdf0e10cSrcweir { 257cdf0e10cSrcweir OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF"); 258cdf0e10cSrcweir const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType); 259cdf0e10cSrcweir switch ( eType ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir case ::dbaccess::DST_DBASE: 262cdf0e10cSrcweir case ::dbaccess::DST_FLAT: 263cdf0e10cSrcweir { 264cdf0e10cSrcweir try 265cdf0e10cSrcweir { 266cdf0e10cSrcweir ::rtl::OUString sFolderPickerService = ::rtl::OUString::createFromAscii(SERVICE_UI_FOLDERPICKER); 267cdf0e10cSrcweir Reference< XFolderPicker > xFolderPicker(m_xORB->createInstance(sFolderPickerService), UNO_QUERY); 268cdf0e10cSrcweir if (!xFolderPicker.is()) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir ShowServiceNotAvailableError(GetParent(), sFolderPickerService, sal_True); 271cdf0e10cSrcweir break; 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir sal_Bool bDoBrowse = sal_False; 275cdf0e10cSrcweir String sOldPath = getURLNoPrefix(); 276cdf0e10cSrcweir do 277cdf0e10cSrcweir { 278cdf0e10cSrcweir if (sOldPath.Len()) 279cdf0e10cSrcweir xFolderPicker->setDisplayDirectory(sOldPath); 280cdf0e10cSrcweir if (0 == xFolderPicker->execute()) 281cdf0e10cSrcweir // cancelled by the user 282cdf0e10cSrcweir return 0L; 283cdf0e10cSrcweir 284cdf0e10cSrcweir sOldPath = xFolderPicker->getDirectory(); 285cdf0e10cSrcweir switch (checkPathExistence(sOldPath)) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir case RET_RETRY: 288cdf0e10cSrcweir bDoBrowse = sal_True; 289cdf0e10cSrcweir break; 290cdf0e10cSrcweir case RET_CANCEL: 291cdf0e10cSrcweir return 0L; 292cdf0e10cSrcweir default: 293cdf0e10cSrcweir break; 294cdf0e10cSrcweir } 295cdf0e10cSrcweir } 296cdf0e10cSrcweir while (bDoBrowse); 297cdf0e10cSrcweir 298cdf0e10cSrcweir String sSelectedDirectory = xFolderPicker->getDirectory(); 299cdf0e10cSrcweir INetURLObject aSelectedDirectory( sSelectedDirectory, INetURLObject::WAS_ENCODED, RTL_TEXTENCODING_UTF8 ); 300cdf0e10cSrcweir 301cdf0e10cSrcweir // for UI purpose, we don't want to have the path encoded 302cdf0e10cSrcweir sSelectedDirectory = aSelectedDirectory.GetMainURL( INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8 ); 303cdf0e10cSrcweir 304cdf0e10cSrcweir setURLNoPrefix( sSelectedDirectory ); 305cdf0e10cSrcweir SetRoadmapStateValue(sal_True); 306cdf0e10cSrcweir callModifiedHdl(); 307cdf0e10cSrcweir } 308cdf0e10cSrcweir catch( const Exception& ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 311cdf0e10cSrcweir } 312cdf0e10cSrcweir } 313cdf0e10cSrcweir break; 314cdf0e10cSrcweir case ::dbaccess::DST_CALC: 315cdf0e10cSrcweir { 316cdf0e10cSrcweir SvtModuleOptions aModule; 317cdf0e10cSrcweir ::sfx2::FileDialogHelper aFileDlg(WB_3DLOOK | WB_STDMODAL | WB_OPEN 318cdf0e10cSrcweir ,aModule.GetFactoryEmptyDocumentURL(SvtModuleOptions::E_CALC) 319cdf0e10cSrcweir ,SFX_FILTER_IMPORT); 320cdf0e10cSrcweir askForFileName(aFileDlg); 321cdf0e10cSrcweir } 322cdf0e10cSrcweir break; 323cdf0e10cSrcweir case ::dbaccess::DST_MSACCESS: 324cdf0e10cSrcweir { 325cdf0e10cSrcweir const ::rtl::OUString sExt(RTL_CONSTASCII_USTRINGPARAM("*.mdb")); 326cdf0e10cSrcweir String sFilterName(ModuleRes (STR_MSACCESS_FILTERNAME)); 327cdf0e10cSrcweir ::sfx2::FileDialogHelper aFileDlg(WB_3DLOOK | WB_STDMODAL | WB_OPEN); 328cdf0e10cSrcweir aFileDlg.AddFilter(sFilterName,sExt); 329cdf0e10cSrcweir aFileDlg.SetCurrentFilter(sFilterName); 330cdf0e10cSrcweir askForFileName(aFileDlg); 331cdf0e10cSrcweir } 332cdf0e10cSrcweir break; 333cdf0e10cSrcweir case ::dbaccess::DST_MSACCESS_2007: 334cdf0e10cSrcweir { 335cdf0e10cSrcweir const ::rtl::OUString sAccdb(RTL_CONSTASCII_USTRINGPARAM("*.accdb")); 336cdf0e10cSrcweir String sFilterName2(ModuleRes (STR_MSACCESS_2007_FILTERNAME)); 337cdf0e10cSrcweir ::sfx2::FileDialogHelper aFileDlg(WB_3DLOOK | WB_STDMODAL | WB_OPEN); 338cdf0e10cSrcweir aFileDlg.AddFilter(sFilterName2,sAccdb); 339cdf0e10cSrcweir aFileDlg.SetCurrentFilter(sFilterName2); 340cdf0e10cSrcweir askForFileName(aFileDlg); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir break; 343cdf0e10cSrcweir case ::dbaccess::DST_ADABAS: 344cdf0e10cSrcweir { 345cdf0e10cSrcweir // collect all names from the config dir 346cdf0e10cSrcweir // and all dir's of the DBWORK/wrk or DBROOT/wrk dir 347cdf0e10cSrcweir // compare the names 348cdf0e10cSrcweir 349cdf0e10cSrcweir // collect the names of the installed databases 350cdf0e10cSrcweir StringBag aInstalledDBs; 351cdf0e10cSrcweir ::rtl::OUString sAdabasConfigDir,sAdabasWorkDir,sRootDir; 352cdf0e10cSrcweir ::rtl::OUString sEnvVarName(RTL_CONSTASCII_USTRINGPARAM("DBWORK")); 353cdf0e10cSrcweir rtl_uString* pDbVar = NULL; 354cdf0e10cSrcweir if(osl_getEnvironment(sEnvVarName.pData,&pDbVar) == osl_Process_E_None && pDbVar) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir sAdabasWorkDir = pDbVar; 357cdf0e10cSrcweir String sURL; 358cdf0e10cSrcweir utl::LocalFileHelper::ConvertPhysicalNameToURL(sAdabasWorkDir,sURL); 359cdf0e10cSrcweir sAdabasWorkDir = sURL; 360cdf0e10cSrcweir rtl_uString_release(pDbVar); 361cdf0e10cSrcweir pDbVar = NULL; 362cdf0e10cSrcweir } 363cdf0e10cSrcweir 364cdf0e10cSrcweir sEnvVarName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DBCONFIG")); 365cdf0e10cSrcweir if(osl_getEnvironment(sEnvVarName.pData,&pDbVar) == osl_Process_E_None && pDbVar) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir sAdabasConfigDir = pDbVar; 368cdf0e10cSrcweir String sURL; 369cdf0e10cSrcweir utl::LocalFileHelper::ConvertPhysicalNameToURL(sAdabasConfigDir,sURL); 370cdf0e10cSrcweir sAdabasConfigDir = sURL; 371cdf0e10cSrcweir rtl_uString_release(pDbVar); 372cdf0e10cSrcweir pDbVar = NULL; 373cdf0e10cSrcweir } 374cdf0e10cSrcweir 375cdf0e10cSrcweir sEnvVarName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DBROOT")); 376cdf0e10cSrcweir if(osl_getEnvironment(sEnvVarName.pData,&pDbVar) == osl_Process_E_None && pDbVar) 377cdf0e10cSrcweir { 378cdf0e10cSrcweir sRootDir = pDbVar; 379cdf0e10cSrcweir String sURL; 380cdf0e10cSrcweir utl::LocalFileHelper::ConvertPhysicalNameToURL(sRootDir,sURL); 381cdf0e10cSrcweir sRootDir = sURL; 382cdf0e10cSrcweir rtl_uString_release(pDbVar); 383cdf0e10cSrcweir pDbVar = NULL; 384cdf0e10cSrcweir } 385cdf0e10cSrcweir 386cdf0e10cSrcweir sal_Bool bOldFashion = sAdabasConfigDir.getLength() && sAdabasWorkDir.getLength(); 387cdf0e10cSrcweir 388cdf0e10cSrcweir if(!bOldFashion) // we have a normal adabas installation 389cdf0e10cSrcweir { // so we check the local database names in $DBROOT/config 390cdf0e10cSrcweir sAdabasConfigDir = sRootDir; 391cdf0e10cSrcweir sAdabasWorkDir = sRootDir; 392cdf0e10cSrcweir } 393cdf0e10cSrcweir 394cdf0e10cSrcweir if(sAdabasConfigDir.getLength() && sAdabasWorkDir.getLength() && sRootDir.getLength()) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir 397cdf0e10cSrcweir aInstalledDBs = getInstalledAdabasDBs(sAdabasConfigDir,sAdabasWorkDir); 398cdf0e10cSrcweir 399cdf0e10cSrcweir if(!aInstalledDBs.size() && bOldFashion) 400cdf0e10cSrcweir { 401cdf0e10cSrcweir sAdabasConfigDir = sRootDir; 402cdf0e10cSrcweir sAdabasWorkDir = sRootDir; 403cdf0e10cSrcweir aInstalledDBs = getInstalledAdabasDBs(sAdabasConfigDir,sAdabasWorkDir); 404cdf0e10cSrcweir } 405cdf0e10cSrcweir 406cdf0e10cSrcweir ODatasourceSelectDialog aSelector(GetParent(), aInstalledDBs, true,m_pItemSetHelper->getWriteOutputSet()); 407cdf0e10cSrcweir if (RET_OK == aSelector.Execute()) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir setURLNoPrefix(aSelector.GetSelected()); 410cdf0e10cSrcweir // checkCreateDatabase( ::dbaccess::DST_ADABAS); 411cdf0e10cSrcweir SetRoadmapStateValue(sal_True); 412cdf0e10cSrcweir callModifiedHdl(); 413cdf0e10cSrcweir } 414cdf0e10cSrcweir } 415cdf0e10cSrcweir else 416cdf0e10cSrcweir { 417cdf0e10cSrcweir LocalResourceAccess aLocRes( PAGE_CONNECTION, RSC_TABPAGE ); 418cdf0e10cSrcweir String sError = String(ModuleRes(STR_NO_ADABASE_DATASOURCES)); 419cdf0e10cSrcweir ErrorBox aBox(this, WB_OK, sError); 420cdf0e10cSrcweir aBox.Execute(); 421cdf0e10cSrcweir } 422cdf0e10cSrcweir } 423cdf0e10cSrcweir break; 424cdf0e10cSrcweir case ::dbaccess::DST_MYSQL_ODBC: 425cdf0e10cSrcweir case ::dbaccess::DST_ODBC: 426cdf0e10cSrcweir { 427cdf0e10cSrcweir // collect all ODBC data source names 428cdf0e10cSrcweir ::rtl::OUString sCurrDatasource = getURLNoPrefix(); 429cdf0e10cSrcweir ::rtl::OUString sDataSource; 430cdf0e10cSrcweir if ( getSelectedDataSource(sDataSource,sCurrDatasource) && sDataSource.getLength() ) 431cdf0e10cSrcweir { 432cdf0e10cSrcweir setURLNoPrefix(sDataSource); 433cdf0e10cSrcweir SetRoadmapStateValue(sal_True); 434cdf0e10cSrcweir callModifiedHdl(); 435cdf0e10cSrcweir } 436cdf0e10cSrcweir else 437cdf0e10cSrcweir return 1L; 438cdf0e10cSrcweir } 439cdf0e10cSrcweir break; 440cdf0e10cSrcweir #ifdef _ADO_DATALINK_BROWSE_ 441cdf0e10cSrcweir case ::dbaccess::DST_ADO: 442cdf0e10cSrcweir { 443cdf0e10cSrcweir ::rtl::OUString sOldDataSource=getURLNoPrefix(); 444cdf0e10cSrcweir ::rtl::OUString sNewDataSource; 445cdf0e10cSrcweir HWND hWnd = GetParent()->GetSystemData()->hWnd; 446cdf0e10cSrcweir sNewDataSource = getAdoDatalink((long)hWnd,sOldDataSource); 447cdf0e10cSrcweir if ( sNewDataSource.getLength() ) 448cdf0e10cSrcweir { 449cdf0e10cSrcweir setURLNoPrefix(sNewDataSource); 450cdf0e10cSrcweir SetRoadmapStateValue(sal_True); 451cdf0e10cSrcweir callModifiedHdl(); 452cdf0e10cSrcweir } 453cdf0e10cSrcweir else 454cdf0e10cSrcweir return 1L; 455cdf0e10cSrcweir } 456cdf0e10cSrcweir break; 457cdf0e10cSrcweir #endif 458cdf0e10cSrcweir case ::dbaccess::DST_MOZILLA: 459cdf0e10cSrcweir case ::dbaccess::DST_THUNDERBIRD: 460cdf0e10cSrcweir { 461cdf0e10cSrcweir MozillaProductType profileType = MozillaProductType_Mozilla; 462cdf0e10cSrcweir if (eType == ::dbaccess::DST_THUNDERBIRD) 463cdf0e10cSrcweir profileType = MozillaProductType_Thunderbird; 464cdf0e10cSrcweir 465cdf0e10cSrcweir Reference<XMultiServiceFactory> xFactory = ::comphelper::getProcessServiceFactory(); 466cdf0e10cSrcweir OSL_ENSURE( xFactory.is(), "can't get service factory" ); 467cdf0e10cSrcweir 468cdf0e10cSrcweir Reference<XInterface> xInstance = xFactory->createInstance(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap")) ); 469cdf0e10cSrcweir OSL_ENSURE( xInstance.is(), "failed to create instance" ); 470cdf0e10cSrcweir Reference<XMozillaBootstrap> xMozillaBootstrap = Reference<XMozillaBootstrap>(xInstance,UNO_QUERY); 471cdf0e10cSrcweir OSL_ENSURE( xMozillaBootstrap.is(), "failed to create instance" ); 472cdf0e10cSrcweir 473cdf0e10cSrcweir if (xMozillaBootstrap.is()) 474cdf0e10cSrcweir { 475cdf0e10cSrcweir // collect all Mozilla Profiles 476cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > list; 477cdf0e10cSrcweir 478cdf0e10cSrcweir xMozillaBootstrap->getProfileList( profileType, list ); 479cdf0e10cSrcweir const ::rtl::OUString * pArray = list.getConstArray(); 480cdf0e10cSrcweir 481cdf0e10cSrcweir sal_Int32 count = list.getLength(); 482cdf0e10cSrcweir 483cdf0e10cSrcweir StringBag aProfiles; 484cdf0e10cSrcweir for (sal_Int32 index=0; index < count; index++) 485cdf0e10cSrcweir aProfiles.insert(pArray[index]); 486cdf0e10cSrcweir 487cdf0e10cSrcweir 488cdf0e10cSrcweir // excute the select dialog 489cdf0e10cSrcweir ODatasourceSelectDialog aSelector(GetParent(), aProfiles, eType); 490cdf0e10cSrcweir ::rtl::OUString sOldProfile=getURLNoPrefix(); 491cdf0e10cSrcweir 492cdf0e10cSrcweir if (sOldProfile.getLength()) 493cdf0e10cSrcweir aSelector.Select(sOldProfile); 494cdf0e10cSrcweir else 495cdf0e10cSrcweir aSelector.Select(xMozillaBootstrap->getDefaultProfile(profileType)); 496cdf0e10cSrcweir 497cdf0e10cSrcweir if ( RET_OK == aSelector.Execute() ) 498cdf0e10cSrcweir setURLNoPrefix(aSelector.GetSelected()); 499cdf0e10cSrcweir break; 500cdf0e10cSrcweir } 501cdf0e10cSrcweir } 502cdf0e10cSrcweir default: 503cdf0e10cSrcweir break; 504cdf0e10cSrcweir } 505cdf0e10cSrcweir 506cdf0e10cSrcweir checkTestConnection(); 507cdf0e10cSrcweir 508cdf0e10cSrcweir return 0L; 509cdf0e10cSrcweir } 510cdf0e10cSrcweir 511cdf0e10cSrcweir //------------------------------------------------------------------------- 512cdf0e10cSrcweir 513cdf0e10cSrcweir bool OConnectionHelper::checkTestConnection() 514cdf0e10cSrcweir { 515cdf0e10cSrcweir return true; 516cdf0e10cSrcweir } 517cdf0e10cSrcweir 518cdf0e10cSrcweir //------------------------------------------------------------------------- 519cdf0e10cSrcweir void OConnectionHelper::impl_setURL( const String& _rURL, sal_Bool _bPrefix ) 520cdf0e10cSrcweir { 521cdf0e10cSrcweir String sURL( _rURL ); 522cdf0e10cSrcweir DBG_ASSERT( m_pCollection, "OConnectionHelper::impl_setURL: have no interpreter for the URLs!" ); 523cdf0e10cSrcweir 524cdf0e10cSrcweir if ( m_pCollection && sURL.Len() ) 525cdf0e10cSrcweir { 526cdf0e10cSrcweir if ( m_pCollection->isFileSystemBased( m_eType ) ) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir // get the tow parts: prefix and file URL 529cdf0e10cSrcweir String sTypePrefix, sFileURLEncoded; 530cdf0e10cSrcweir if ( _bPrefix ) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir sTypePrefix = m_pCollection->getPrefix( m_eType ); 533cdf0e10cSrcweir sFileURLEncoded = m_pCollection->cutPrefix( sURL ); 534cdf0e10cSrcweir } 535cdf0e10cSrcweir else 536cdf0e10cSrcweir { 537cdf0e10cSrcweir sFileURLEncoded = sURL; 538cdf0e10cSrcweir } 539cdf0e10cSrcweir 540cdf0e10cSrcweir // substitute any variables 541cdf0e10cSrcweir sFileURLEncoded = SvtPathOptions().SubstituteVariable( sFileURLEncoded ); 542cdf0e10cSrcweir 543cdf0e10cSrcweir // decode the URL 544cdf0e10cSrcweir sURL = sTypePrefix; 545cdf0e10cSrcweir if ( sFileURLEncoded.Len() ) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir OFileNotation aFileNotation(sFileURLEncoded); 548cdf0e10cSrcweir // set this decoded URL as text 549cdf0e10cSrcweir sURL += String(aFileNotation.get(OFileNotation::N_SYSTEM)); 550cdf0e10cSrcweir } 551cdf0e10cSrcweir } 552cdf0e10cSrcweir } 553cdf0e10cSrcweir 554cdf0e10cSrcweir if ( _bPrefix ) 555cdf0e10cSrcweir m_aConnectionURL.SetText( sURL ); 556cdf0e10cSrcweir else 557cdf0e10cSrcweir m_aConnectionURL.SetTextNoPrefix( sURL ); 558cdf0e10cSrcweir 559cdf0e10cSrcweir implUpdateURLDependentStates(); 560cdf0e10cSrcweir } 561cdf0e10cSrcweir 562cdf0e10cSrcweir //------------------------------------------------------------------------- 563cdf0e10cSrcweir String OConnectionHelper::impl_getURL( sal_Bool _bPrefix ) const 564cdf0e10cSrcweir { 565cdf0e10cSrcweir // get the pure text 566cdf0e10cSrcweir String sURL = _bPrefix ? m_aConnectionURL.GetText() : m_aConnectionURL.GetTextNoPrefix(); 567cdf0e10cSrcweir 568cdf0e10cSrcweir DBG_ASSERT( m_pCollection, "OConnectionHelper::impl_getURL: have no interpreter for the URLs!" ); 569cdf0e10cSrcweir 570cdf0e10cSrcweir if ( m_pCollection && sURL.Len() ) 571cdf0e10cSrcweir { 572cdf0e10cSrcweir if ( m_pCollection->isFileSystemBased( m_eType ) ) 573cdf0e10cSrcweir { 574cdf0e10cSrcweir // get the tow parts: prefix and file URL 575cdf0e10cSrcweir String sTypePrefix, sFileURLDecoded; 576cdf0e10cSrcweir if ( _bPrefix ) 577cdf0e10cSrcweir { 578cdf0e10cSrcweir sTypePrefix = m_pCollection->getPrefix( m_eType ); 579cdf0e10cSrcweir sFileURLDecoded = m_pCollection->cutPrefix( sURL ); 580cdf0e10cSrcweir } 581cdf0e10cSrcweir else 582cdf0e10cSrcweir { 583cdf0e10cSrcweir sFileURLDecoded = sURL; 584cdf0e10cSrcweir } 585cdf0e10cSrcweir 586cdf0e10cSrcweir sURL = sTypePrefix; 587cdf0e10cSrcweir if ( sFileURLDecoded.Len() ) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir OFileNotation aFileNotation( sFileURLDecoded, OFileNotation::N_SYSTEM ); 590cdf0e10cSrcweir sURL += String( aFileNotation.get( OFileNotation::N_URL ) ); 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir // encode the URL 594cdf0e10cSrcweir INetURLObject aFileURL( sFileURLDecoded, INetURLObject::ENCODE_ALL, RTL_TEXTENCODING_UTF8 ); 595cdf0e10cSrcweir sFileURLDecoded = aFileURL.GetMainURL( INetURLObject::NO_DECODE ); 596cdf0e10cSrcweir } 597cdf0e10cSrcweir } 598cdf0e10cSrcweir return sURL; 599cdf0e10cSrcweir } 600cdf0e10cSrcweir 601cdf0e10cSrcweir //------------------------------------------------------------------------- 602cdf0e10cSrcweir void OConnectionHelper::setURL( const String& _rURL ) 603cdf0e10cSrcweir { 604cdf0e10cSrcweir impl_setURL( _rURL, sal_True ); 605cdf0e10cSrcweir } 606cdf0e10cSrcweir 607cdf0e10cSrcweir //------------------------------------------------------------------------- 608cdf0e10cSrcweir String OConnectionHelper::getURLNoPrefix( ) const 609cdf0e10cSrcweir { 610cdf0e10cSrcweir return impl_getURL( sal_False ); 611cdf0e10cSrcweir } 612cdf0e10cSrcweir 613cdf0e10cSrcweir //------------------------------------------------------------------------- 614cdf0e10cSrcweir void OConnectionHelper::setURLNoPrefix( const String& _rURL ) 615cdf0e10cSrcweir { 616cdf0e10cSrcweir impl_setURL( _rURL, sal_False ); 617cdf0e10cSrcweir } 618cdf0e10cSrcweir 619cdf0e10cSrcweir //------------------------------------------------------------------------- 620cdf0e10cSrcweir sal_Int32 OConnectionHelper::checkPathExistence(const String& _rURL) 621cdf0e10cSrcweir { 622cdf0e10cSrcweir IS_PATH_EXIST e_exists = pathExists(_rURL, sal_False); 623cdf0e10cSrcweir if (( e_exists == PATH_NOT_EXIST) || ( e_exists == PATH_NOT_KNOWN)) 624cdf0e10cSrcweir { 625cdf0e10cSrcweir String sQuery(ModuleRes(STR_ASK_FOR_DIRECTORY_CREATION)); 626cdf0e10cSrcweir OFileNotation aTransformer(_rURL); 627cdf0e10cSrcweir sQuery.SearchAndReplaceAscii("$path$", aTransformer.get(OFileNotation::N_SYSTEM)); 628cdf0e10cSrcweir 629cdf0e10cSrcweir m_bUserGrabFocus = sal_False; 630cdf0e10cSrcweir QueryBox aQuery(GetParent(), WB_YES_NO | WB_DEF_YES, sQuery); 631cdf0e10cSrcweir sal_Int32 nQueryResult = aQuery.Execute(); 632cdf0e10cSrcweir m_bUserGrabFocus = sal_True; 633cdf0e10cSrcweir 634cdf0e10cSrcweir switch (nQueryResult) 635cdf0e10cSrcweir { 636cdf0e10cSrcweir case RET_YES: 637cdf0e10cSrcweir { 638cdf0e10cSrcweir sal_Bool bTryCreate = sal_False; 639cdf0e10cSrcweir do 640cdf0e10cSrcweir { 641cdf0e10cSrcweir if ( !createDirectoryDeep(_rURL) ) 642cdf0e10cSrcweir { // could not create the directory 643cdf0e10cSrcweir sQuery = String(ModuleRes(STR_COULD_NOT_CREATE_DIRECTORY)); 644cdf0e10cSrcweir sQuery.SearchAndReplaceAscii("$name$", aTransformer.get(OFileNotation::N_SYSTEM)); 645cdf0e10cSrcweir 646cdf0e10cSrcweir m_bUserGrabFocus = sal_False; 647cdf0e10cSrcweir QueryBox aWhatToDo(GetParent(), WB_RETRY_CANCEL | WB_DEF_RETRY, sQuery); 648cdf0e10cSrcweir nQueryResult = aWhatToDo.Execute(); 649cdf0e10cSrcweir m_bUserGrabFocus = sal_True; 650cdf0e10cSrcweir 651cdf0e10cSrcweir if (RET_RETRY == nQueryResult) 652cdf0e10cSrcweir bTryCreate = sal_True; 653cdf0e10cSrcweir else 654cdf0e10cSrcweir { 655cdf0e10cSrcweir SetRoadmapStateValue(sal_False); 656cdf0e10cSrcweir callModifiedHdl(); 657cdf0e10cSrcweir return RET_RETRY; 658cdf0e10cSrcweir } 659cdf0e10cSrcweir } 660cdf0e10cSrcweir } 661cdf0e10cSrcweir while (bTryCreate); 662cdf0e10cSrcweir } 663cdf0e10cSrcweir break; 664cdf0e10cSrcweir 665cdf0e10cSrcweir case RET_NO: 666cdf0e10cSrcweir // SetRoadmapStateValue(sal_False); 667cdf0e10cSrcweir callModifiedHdl(); 668cdf0e10cSrcweir return RET_OK; 669cdf0e10cSrcweir 670cdf0e10cSrcweir default: 671cdf0e10cSrcweir // cancelled 672cdf0e10cSrcweir SetRoadmapStateValue(sal_False); 673cdf0e10cSrcweir callModifiedHdl(); 674cdf0e10cSrcweir return RET_CANCEL; 675cdf0e10cSrcweir } 676cdf0e10cSrcweir } 677cdf0e10cSrcweir /* else 678cdf0e10cSrcweir { 679cdf0e10cSrcweir // TODO: error msg 680cdf0e10cSrcweir return RET_CANCEL; 681cdf0e10cSrcweir } */ 682cdf0e10cSrcweir SetRoadmapStateValue(sal_True); 683cdf0e10cSrcweir callModifiedHdl(); 684cdf0e10cSrcweir return RET_OK; 685cdf0e10cSrcweir } 686cdf0e10cSrcweir 687cdf0e10cSrcweir 688cdf0e10cSrcweir //------------------------------------------------------------------------- 689cdf0e10cSrcweir StringBag OConnectionHelper::getInstalledAdabasDBDirs(const String& _rPath,const ::ucbhelper::ResultSetInclude& _reResultSetInclude) 690cdf0e10cSrcweir { 691cdf0e10cSrcweir INetURLObject aNormalizer; 692cdf0e10cSrcweir aNormalizer.SetSmartProtocol(INET_PROT_FILE); 693cdf0e10cSrcweir aNormalizer.SetSmartURL(_rPath); 694cdf0e10cSrcweir String sAdabasConfigDir = aNormalizer.GetMainURL(INetURLObject::NO_DECODE); 695cdf0e10cSrcweir 696cdf0e10cSrcweir ::ucbhelper::Content aAdabasConfigDir; 697cdf0e10cSrcweir try 698cdf0e10cSrcweir { 699cdf0e10cSrcweir aAdabasConfigDir = ::ucbhelper::Content(sAdabasConfigDir, Reference< ::com::sun::star::ucb::XCommandEnvironment >()); 700cdf0e10cSrcweir } 701cdf0e10cSrcweir catch(::com::sun::star::ucb::ContentCreationException&) 702cdf0e10cSrcweir { 703cdf0e10cSrcweir return StringBag(); 704cdf0e10cSrcweir } 705cdf0e10cSrcweir 706cdf0e10cSrcweir StringBag aInstalledDBs; 707cdf0e10cSrcweir sal_Bool bIsFolder = sal_False; 708cdf0e10cSrcweir try 709cdf0e10cSrcweir { 710cdf0e10cSrcweir bIsFolder = aAdabasConfigDir.isFolder(); 711cdf0e10cSrcweir } 712cdf0e10cSrcweir catch(Exception&) // the exception is thrown when the path doesn't exists 713cdf0e10cSrcweir { 714cdf0e10cSrcweir } 715cdf0e10cSrcweir if (bIsFolder && aAdabasConfigDir.get().is()) 716cdf0e10cSrcweir { // we have a content for the directory, loop through all entries 717cdf0e10cSrcweir Sequence< ::rtl::OUString > aProperties(1); 718cdf0e10cSrcweir aProperties[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title")); 719cdf0e10cSrcweir 720cdf0e10cSrcweir try 721cdf0e10cSrcweir { 722cdf0e10cSrcweir Reference< XResultSet > xFiles = aAdabasConfigDir.createCursor(aProperties, _reResultSetInclude); 723cdf0e10cSrcweir Reference< XRow > xRow(xFiles, UNO_QUERY); 724cdf0e10cSrcweir xFiles->beforeFirst(); 725cdf0e10cSrcweir while (xFiles->next()) 726cdf0e10cSrcweir { 727cdf0e10cSrcweir #ifdef DBG_UTIL 728cdf0e10cSrcweir ::rtl::OUString sName = xRow->getString(1); 729cdf0e10cSrcweir #endif 730cdf0e10cSrcweir aInstalledDBs.insert(xRow->getString(1)); 731cdf0e10cSrcweir } 732cdf0e10cSrcweir } 733cdf0e10cSrcweir catch(Exception&) 734cdf0e10cSrcweir { 735cdf0e10cSrcweir DBG_ERROR("OConnectionHelper::getInstalledAdabasDBDirs: could not enumerate the adabas config files!"); 736cdf0e10cSrcweir } 737cdf0e10cSrcweir } 738cdf0e10cSrcweir 739cdf0e10cSrcweir 740cdf0e10cSrcweir return aInstalledDBs; 741cdf0e10cSrcweir } 742cdf0e10cSrcweir // ----------------------------------------------------------------------------- 743cdf0e10cSrcweir StringBag OConnectionHelper::getInstalledAdabasDBs(const String &_rConfigDir,const String &_rWorkDir) 744cdf0e10cSrcweir { 745cdf0e10cSrcweir String sAdabasConfigDir(_rConfigDir),sAdabasWorkDir(_rWorkDir); 746cdf0e10cSrcweir 747cdf0e10cSrcweir if (sAdabasConfigDir.Len() && ('/' == sAdabasConfigDir.GetBuffer()[sAdabasConfigDir.Len() - 1])) 748cdf0e10cSrcweir sAdabasConfigDir.AppendAscii("config"); 749cdf0e10cSrcweir else 750cdf0e10cSrcweir sAdabasConfigDir.AppendAscii("/config"); 751cdf0e10cSrcweir 752cdf0e10cSrcweir if (sAdabasWorkDir.Len() && ('/' == sAdabasWorkDir.GetBuffer()[sAdabasWorkDir.Len() - 1])) 753cdf0e10cSrcweir sAdabasWorkDir.AppendAscii("wrk"); 754cdf0e10cSrcweir else 755cdf0e10cSrcweir sAdabasWorkDir.AppendAscii("/wrk"); 756cdf0e10cSrcweir // collect the names of the installed databases 757cdf0e10cSrcweir StringBag aInstalledDBs; 758cdf0e10cSrcweir // collect the names of the installed databases 759cdf0e10cSrcweir StringBag aConfigDBs,aWrkDBs; 760cdf0e10cSrcweir aConfigDBs = getInstalledAdabasDBDirs(sAdabasConfigDir,::ucbhelper::INCLUDE_DOCUMENTS_ONLY); 761cdf0e10cSrcweir aWrkDBs = getInstalledAdabasDBDirs(sAdabasWorkDir,::ucbhelper::INCLUDE_FOLDERS_ONLY); 762cdf0e10cSrcweir ConstStringBagIterator aOuter = aConfigDBs.begin(); 763cdf0e10cSrcweir ConstStringBagIterator aOuterEnd = aConfigDBs.end(); 764cdf0e10cSrcweir for(;aOuter != aOuterEnd;++aOuter) 765cdf0e10cSrcweir { 766cdf0e10cSrcweir ConstStringBagIterator aInner = aWrkDBs.begin(); 767cdf0e10cSrcweir ConstStringBagIterator aInnerEnd = aWrkDBs.end(); 768cdf0e10cSrcweir for (;aInner != aInnerEnd; ++aInner) 769cdf0e10cSrcweir { 770cdf0e10cSrcweir if (aInner->equalsIgnoreAsciiCase(*aOuter)) 771cdf0e10cSrcweir { 772cdf0e10cSrcweir aInstalledDBs.insert(*aInner); 773cdf0e10cSrcweir break; 774cdf0e10cSrcweir } 775cdf0e10cSrcweir } 776cdf0e10cSrcweir } 777cdf0e10cSrcweir return aInstalledDBs; 778cdf0e10cSrcweir } 779cdf0e10cSrcweir // #106016# ------------------------------------------------------------------- 780cdf0e10cSrcweir IS_PATH_EXIST OConnectionHelper::pathExists(const ::rtl::OUString& _rURL, sal_Bool bIsFile) const 781cdf0e10cSrcweir { 782cdf0e10cSrcweir ::ucbhelper::Content aCheckExistence; 783cdf0e10cSrcweir sal_Bool bExists = sal_False; 784cdf0e10cSrcweir IS_PATH_EXIST eExists = PATH_NOT_EXIST; 785cdf0e10cSrcweir Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = Reference< ::com::sun::star::task::XInteractionHandler >( 786cdf0e10cSrcweir m_xORB->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY ); 787cdf0e10cSrcweir OFilePickerInteractionHandler* pHandler = new OFilePickerInteractionHandler(xInteractionHandler); 788cdf0e10cSrcweir xInteractionHandler = pHandler; 789cdf0e10cSrcweir 790cdf0e10cSrcweir Reference< XCommandEnvironment > xCmdEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() ); 791cdf0e10cSrcweir try 792cdf0e10cSrcweir { 793cdf0e10cSrcweir aCheckExistence = ::ucbhelper::Content(_rURL, xCmdEnv ); 794cdf0e10cSrcweir bExists = bIsFile? aCheckExistence.isDocument(): aCheckExistence.isFolder(); 795cdf0e10cSrcweir eExists = bExists? PATH_EXIST: PATH_NOT_EXIST; 796cdf0e10cSrcweir } 797cdf0e10cSrcweir catch(const Exception&) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir eExists = ( pHandler && pHandler->isDoesNotExist() ) ? PATH_NOT_EXIST: (bIsFile ? PATH_NOT_EXIST : PATH_NOT_KNOWN); 800cdf0e10cSrcweir } 801cdf0e10cSrcweir return eExists; 802cdf0e10cSrcweir } 803cdf0e10cSrcweir //------------------------------------------------------------------------- 804cdf0e10cSrcweir long OConnectionHelper::PreNotify( NotifyEvent& _rNEvt ) 805cdf0e10cSrcweir { 806cdf0e10cSrcweir if ( m_pCollection->isFileSystemBased(m_eType) ) 807cdf0e10cSrcweir { 808cdf0e10cSrcweir switch (_rNEvt.GetType()) 809cdf0e10cSrcweir { 810cdf0e10cSrcweir case EVENT_GETFOCUS: 811cdf0e10cSrcweir if (m_aConnectionURL.IsWindowOrChild(_rNEvt.GetWindow()) && m_bUserGrabFocus) 812cdf0e10cSrcweir { // a descendant of the URL edit field got the focus 813cdf0e10cSrcweir m_aConnectionURL.SaveValueNoPrefix(); 814cdf0e10cSrcweir } 815cdf0e10cSrcweir break; 816cdf0e10cSrcweir 817cdf0e10cSrcweir case EVENT_LOSEFOCUS: 818cdf0e10cSrcweir if (m_aConnectionURL.IsWindowOrChild(_rNEvt.GetWindow()) && m_bUserGrabFocus) 819cdf0e10cSrcweir { // a descendant of the URL edit field lost the focus 820cdf0e10cSrcweir if (!commitURL()) 821cdf0e10cSrcweir return 1L; // handled 822cdf0e10cSrcweir } 823cdf0e10cSrcweir break; 824cdf0e10cSrcweir } // switch (_rNEvt.GetType()) 825cdf0e10cSrcweir } 826cdf0e10cSrcweir 827cdf0e10cSrcweir return OGenericAdministrationPage::PreNotify( _rNEvt ); 828cdf0e10cSrcweir } 829cdf0e10cSrcweir 830cdf0e10cSrcweir //------------------------------------------------------------------------- 831cdf0e10cSrcweir 832cdf0e10cSrcweir sal_Bool OConnectionHelper::createDirectoryDeep(const String& _rPathURL) 833cdf0e10cSrcweir { 834cdf0e10cSrcweir ::rtl::OUString sPath(_rPathURL); 835cdf0e10cSrcweir 836cdf0e10cSrcweir // get an URL object analyzing the URL for us ... 837cdf0e10cSrcweir INetURLObject aParser; 838cdf0e10cSrcweir aParser.SetURL(_rPathURL); 839cdf0e10cSrcweir 840cdf0e10cSrcweir INetProtocol eProtocol = aParser.GetProtocol(); 841cdf0e10cSrcweir 842cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aToBeCreated; // the to-be-created levels 843cdf0e10cSrcweir 844cdf0e10cSrcweir // search a level which exists 845cdf0e10cSrcweir // #106016# --------------------- 846cdf0e10cSrcweir IS_PATH_EXIST eParentExists = PATH_NOT_EXIST; 847cdf0e10cSrcweir while ( eParentExists == PATH_NOT_EXIST && aParser.getSegmentCount()) 848cdf0e10cSrcweir { 849cdf0e10cSrcweir aToBeCreated.push_back(aParser.getName()); // remember the local name for creation 850cdf0e10cSrcweir aParser.removeSegment(); // cut the local name 851cdf0e10cSrcweir eParentExists = pathExists(aParser.GetMainURL(INetURLObject::NO_DECODE), sal_False); 852cdf0e10cSrcweir } 853cdf0e10cSrcweir 854cdf0e10cSrcweir if (!aParser.getSegmentCount()) 855cdf0e10cSrcweir return sal_False; 856cdf0e10cSrcweir 857cdf0e10cSrcweir // create all the missing levels 858cdf0e10cSrcweir try 859cdf0e10cSrcweir { 860cdf0e10cSrcweir // the parent content 861cdf0e10cSrcweir Reference< XCommandEnvironment > xEmptyEnv; 862cdf0e10cSrcweir ::ucbhelper::Content aParent(aParser.GetMainURL(INetURLObject::NO_DECODE), xEmptyEnv); 863cdf0e10cSrcweir 864cdf0e10cSrcweir ::rtl::OUString sContentType; 865cdf0e10cSrcweir if ( INET_PROT_FILE == eProtocol ) 866cdf0e10cSrcweir { 867cdf0e10cSrcweir sContentType = ::rtl::OUString::createFromAscii( "application/vnd.sun.staroffice.fsys-folder" ); 868cdf0e10cSrcweir // the file UCP currently does not support the ContentType property 869cdf0e10cSrcweir } 870cdf0e10cSrcweir else 871cdf0e10cSrcweir { 872cdf0e10cSrcweir Any aContentType = aParent.getPropertyValue( ::rtl::OUString::createFromAscii( "ContentType" ) ); 873cdf0e10cSrcweir aContentType >>= sContentType; 874cdf0e10cSrcweir } 875cdf0e10cSrcweir 876cdf0e10cSrcweir // the properties which need to be set on the new content 877cdf0e10cSrcweir Sequence< ::rtl::OUString > aNewDirectoryProperties(1); 878cdf0e10cSrcweir aNewDirectoryProperties[0] = ::rtl::OUString::createFromAscii("Title"); 879cdf0e10cSrcweir 880cdf0e10cSrcweir // the values to be set 881cdf0e10cSrcweir Sequence< Any > aNewDirectoryAttributes(1); 882cdf0e10cSrcweir 883cdf0e10cSrcweir // loop 884cdf0e10cSrcweir for ( ::std::vector< ::rtl::OUString >::reverse_iterator aLocalName = aToBeCreated.rbegin(); 885cdf0e10cSrcweir aLocalName != aToBeCreated.rend(); 886cdf0e10cSrcweir ++aLocalName 887cdf0e10cSrcweir ) 888cdf0e10cSrcweir { 889cdf0e10cSrcweir aNewDirectoryAttributes[0] <<= *aLocalName; 890cdf0e10cSrcweir if (!aParent.insertNewContent(sContentType, aNewDirectoryProperties, aNewDirectoryAttributes, aParent)) 891cdf0e10cSrcweir return sal_False; 892cdf0e10cSrcweir } 893cdf0e10cSrcweir } 894cdf0e10cSrcweir catch ( const Exception& ) 895cdf0e10cSrcweir { 896cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 897cdf0e10cSrcweir return sal_False; 898cdf0e10cSrcweir } 899cdf0e10cSrcweir 900cdf0e10cSrcweir return sal_True; 901cdf0e10cSrcweir } 902cdf0e10cSrcweir 903cdf0e10cSrcweir 904cdf0e10cSrcweir // ----------------------------------------------------------------------- 905cdf0e10cSrcweir void OConnectionHelper::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList) 906cdf0e10cSrcweir { 907cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFT_Connection)); 908cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<PushButton>(&m_aPB_Connection)); 909cdf0e10cSrcweir } 910cdf0e10cSrcweir 911cdf0e10cSrcweir 912cdf0e10cSrcweir // ----------------------------------------------------------------------- 913cdf0e10cSrcweir void OConnectionHelper::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList) 914cdf0e10cSrcweir { 915cdf0e10cSrcweir _rControlList.push_back( new OSaveValueWrapper<Edit>( &m_aConnectionURL ) ); 916cdf0e10cSrcweir } 917cdf0e10cSrcweir 918cdf0e10cSrcweir //------------------------------------------------------------------------- 919cdf0e10cSrcweir sal_Bool OConnectionHelper::commitURL() 920cdf0e10cSrcweir { 921cdf0e10cSrcweir String sURL; 922cdf0e10cSrcweir String sOldPath; 923cdf0e10cSrcweir sOldPath = m_aConnectionURL.GetSavedValueNoPrefix(); 924cdf0e10cSrcweir sURL = m_aConnectionURL.GetTextNoPrefix(); 925cdf0e10cSrcweir 926cdf0e10cSrcweir if ( m_pCollection->isFileSystemBased(m_eType) ) 927cdf0e10cSrcweir { 928cdf0e10cSrcweir if ( ( sURL != sOldPath ) && ( 0 != sURL.Len() ) ) 929cdf0e10cSrcweir { // the text changed since entering the control 930cdf0e10cSrcweir 931cdf0e10cSrcweir // the path may be in system notation .... 932cdf0e10cSrcweir OFileNotation aTransformer(sURL); 933cdf0e10cSrcweir sURL = aTransformer.get(OFileNotation::N_URL); 934cdf0e10cSrcweir 935cdf0e10cSrcweir const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType); 936cdf0e10cSrcweir 937cdf0e10cSrcweir if ( ( ::dbaccess::DST_CALC == eType) || ( ::dbaccess::DST_MSACCESS == eType) || ( ::dbaccess::DST_MSACCESS_2007 == eType) ) 938cdf0e10cSrcweir { // #106016# -------------------------- 939cdf0e10cSrcweir if( pathExists(sURL, sal_True) == PATH_NOT_EXIST ) 940cdf0e10cSrcweir { 941cdf0e10cSrcweir String sFile = String( ModuleRes( STR_FILE_DOES_NOT_EXIST ) ); 942cdf0e10cSrcweir sFile.SearchAndReplaceAscii("$file$", aTransformer.get(OFileNotation::N_SYSTEM)); 943cdf0e10cSrcweir OSQLWarningBox( this, sFile ).Execute(); 944cdf0e10cSrcweir setURLNoPrefix(sOldPath); 945cdf0e10cSrcweir SetRoadmapStateValue(sal_False); 946cdf0e10cSrcweir callModifiedHdl(); 947cdf0e10cSrcweir return sal_False; 948cdf0e10cSrcweir } 949cdf0e10cSrcweir } 950cdf0e10cSrcweir else 951cdf0e10cSrcweir { 952cdf0e10cSrcweir switch (checkPathExistence(sURL)) 953cdf0e10cSrcweir { 954cdf0e10cSrcweir case RET_RETRY: 955cdf0e10cSrcweir m_bUserGrabFocus = sal_False; 956cdf0e10cSrcweir m_aConnectionURL.GrabFocus(); 957cdf0e10cSrcweir m_bUserGrabFocus = sal_True; 958cdf0e10cSrcweir return sal_False; 959cdf0e10cSrcweir 960cdf0e10cSrcweir case RET_CANCEL: 961cdf0e10cSrcweir setURLNoPrefix(sOldPath); 962cdf0e10cSrcweir return sal_False; 963cdf0e10cSrcweir } 964cdf0e10cSrcweir } 965cdf0e10cSrcweir } 966cdf0e10cSrcweir } 967cdf0e10cSrcweir 968cdf0e10cSrcweir setURLNoPrefix(sURL); 969cdf0e10cSrcweir m_aConnectionURL.SaveValueNoPrefix(); 970cdf0e10cSrcweir return sal_True; 971cdf0e10cSrcweir } 972cdf0e10cSrcweir //------------------------------------------------------------------------- 973cdf0e10cSrcweir void OConnectionHelper::askForFileName(::sfx2::FileDialogHelper& _aFileOpen) 974cdf0e10cSrcweir { 975cdf0e10cSrcweir String sOldPath = getURLNoPrefix(); 976cdf0e10cSrcweir if ( sOldPath.Len() ) 977cdf0e10cSrcweir _aFileOpen.SetDisplayDirectory(sOldPath); 978cdf0e10cSrcweir else 979cdf0e10cSrcweir _aFileOpen.SetDisplayDirectory( SvtPathOptions().GetWorkPath() ); 980cdf0e10cSrcweir if (0 == _aFileOpen.Execute()) 981cdf0e10cSrcweir { 982cdf0e10cSrcweir setURLNoPrefix(_aFileOpen.GetPath()); 983cdf0e10cSrcweir SetRoadmapStateValue(checkTestConnection()); 984cdf0e10cSrcweir callModifiedHdl(); 985cdf0e10cSrcweir } 986cdf0e10cSrcweir } 987cdf0e10cSrcweir 988cdf0e10cSrcweir //......................................................................... 989cdf0e10cSrcweir } // namespace dbaui 990cdf0e10cSrcweir //......................................................................... 991