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