Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / dlg / ConnectionHelper.cxx
blob7fe55e702aa77b3a68aa4be4b6667edc4427ee50
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "dsnItem.hxx"
31 #include "ConnectionHelper.hxx"
32 #include "AutoControls.hrc"
33 #include "dbu_dlg.hrc"
34 #include "dbu_misc.hrc"
35 #include <svl/itemset.hxx>
36 #include <unotools/moduleoptions.hxx>
37 #include <sfx2/fcontnr.hxx>
38 #include <unotools/pathoptions.hxx>
39 #include <svl/stritem.hxx>
40 #include <svl/eitem.hxx>
41 #include <svl/intitem.hxx>
42 #include "dsitems.hxx"
43 #include "dbaccess_helpid.hrc"
44 #include "localresaccess.hxx"
45 #include <osl/process.h>
46 #include <osl/diagnose.h>
47 #include <vcl/msgbox.hxx>
48 #include <sfx2/filedlghelper.hxx>
49 #include "dbadmin.hxx"
50 #include <comphelper/types.hxx>
51 #include <vcl/stdtext.hxx>
52 #include "sqlmessage.hxx"
53 #include "odbcconfig.hxx"
54 #include "dsselect.hxx"
55 #include <svl/filenotation.hxx>
56 #include "dbustrings.hrc"
57 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
58 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
59 #include <com/sun/star/sdbc/XRow.hpp>
60 #include <com/sun/star/awt/XWindow.hpp>
61 #include <com/sun/star/task/XInteractionHandler.hpp>
62 #include <com/sun/star/ucb/XProgressHandler.hpp>
63 #include "UITools.hxx"
64 #include <unotools/localfilehelper.hxx>
65 #include <unotools/ucbhelper.hxx>
66 #include <ucbhelper/commandenvironment.hxx>
67 #include "finteraction.hxx"
68 #include <connectivity/CommonTools.hxx>
69 #include <tools/urlobj.hxx>
70 #include <tools/diagnose_ex.h>
71 #include <sfx2/docfilt.hxx>
73 #if defined(WNT)
74 #define _ADO_DATALINK_BROWSE_
75 #endif
77 #ifdef _ADO_DATALINK_BROWSE_
78 #include <vcl/sysdata.hxx>
79 #include "adodatalinks.hxx"
80 #endif //_ADO_DATALINK_BROWSE_
82 #include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
83 #include <comphelper/processfactory.hxx>
87 //.........................................................................
88 namespace dbaui
90 //.........................................................................
91 using namespace ::com::sun::star;
92 using namespace ::com::sun::star::uno;
93 using namespace ::com::sun::star::ucb;
94 using namespace ::com::sun::star::ui::dialogs;
95 using namespace ::com::sun::star::sdbc;
96 using namespace ::com::sun::star::beans;
97 using namespace ::com::sun::star::lang;
98 using namespace ::com::sun::star::container;
99 using namespace ::com::sun::star::mozilla;
100 using namespace ::dbtools;
101 using namespace ::svt;
104 DBG_NAME(OConnectionHelper)
106 OConnectionHelper::OConnectionHelper( Window* pParent, const ResId& _rId, const SfxItemSet& _rCoreAttrs)
107 :OGenericAdministrationPage(pParent, _rId, _rCoreAttrs)
108 ,m_aFT_Connection ( this, ResId( FT_AUTOBROWSEURL, *_rId.GetResMgr() ) )
109 ,m_aConnectionURL ( this, ResId( ET_AUTOBROWSEURL, *_rId.GetResMgr() ) )
110 ,m_aPB_Connection ( this, ResId( PB_AUTOBROWSEURL, *_rId.GetResMgr() ) )
112 DBG_CTOR(OConnectionHelper,NULL);
114 // extract the datasource type collection from the item set
115 DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _rCoreAttrs.GetItem(DSID_TYPECOLLECTION));
116 if (pCollectionItem)
117 m_pCollection = pCollectionItem->getCollection();
118 m_aPB_Connection.SetClickHdl(LINK(this, OConnectionHelper, OnBrowseConnections));
119 OSL_ENSURE(m_pCollection, "OConnectionHelper::OConnectionHelper : really need a DSN type collection !");
120 m_aConnectionURL.SetTypeCollection(m_pCollection);
124 OConnectionHelper::~OConnectionHelper()
127 DBG_DTOR(OConnectionHelper,NULL);
131 // -----------------------------------------------------------------------
132 void OConnectionHelper::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
134 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
135 sal_Bool bValid, bReadonly;
136 getFlags(_rSet, bValid, bReadonly);
138 m_aFT_Connection.Show();
139 m_aConnectionURL.Show();
140 m_aConnectionURL.ShowPrefix( ::dbaccess::DST_JDBC == m_pCollection->determineType(m_eType) );
142 sal_Bool bEnableBrowseButton = m_pCollection->supportsBrowsing( m_eType );
143 m_aPB_Connection.Show( bEnableBrowseButton );
145 SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True);
147 // forward the values to the controls
148 if ( bValid )
150 String sUrl = pUrlItem->GetValue();
151 setURL( sUrl );
153 checkTestConnection();
154 m_aConnectionURL.ClearModifyFlag();
157 OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
160 // -----------------------------------------------------------------------
161 void OConnectionHelper::implUpdateURLDependentStates() const
163 OSL_PRECOND( m_pAdminDialog, "OConnectionHelper::implUpdateURLDependentStates: no admin dialog!" );
164 if ( !m_pAdminDialog )
165 return;
167 if ( m_pCollection->isFileSystemBased(m_eType) )
168 m_pAdminDialog->enableConfirmSettings( getURLNoPrefix().Len() > 0 );
171 // -----------------------------------------------------------------------
172 IMPL_LINK(OConnectionHelper, OnBrowseConnections, PushButton*, /*_pButton*/)
174 OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
175 const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
176 switch ( eType )
178 case ::dbaccess::DST_DBASE:
179 case ::dbaccess::DST_FLAT:
183 ::rtl::OUString sFolderPickerService(SERVICE_UI_FOLDERPICKER);
184 Reference< XFolderPicker > xFolderPicker(m_xORB->createInstance(sFolderPickerService), UNO_QUERY);
185 if (!xFolderPicker.is())
187 ShowServiceNotAvailableError(GetParent(), sFolderPickerService, sal_True);
188 break;
191 sal_Bool bDoBrowse = sal_False;
192 String sOldPath = getURLNoPrefix();
195 if (sOldPath.Len())
196 xFolderPicker->setDisplayDirectory(sOldPath);
197 if (0 == xFolderPicker->execute())
198 // cancelled by the user
199 return 0L;
201 sOldPath = xFolderPicker->getDirectory();
202 switch (checkPathExistence(sOldPath))
204 case RET_RETRY:
205 bDoBrowse = sal_True;
206 break;
207 case RET_CANCEL:
208 return 0L;
209 default:
210 break;
213 while (bDoBrowse);
215 String sSelectedDirectory = xFolderPicker->getDirectory();
216 INetURLObject aSelectedDirectory( sSelectedDirectory, INetURLObject::WAS_ENCODED, RTL_TEXTENCODING_UTF8 );
218 // for UI purpose, we don't want to have the path encoded
219 sSelectedDirectory = aSelectedDirectory.GetMainURL( INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8 );
221 setURLNoPrefix( sSelectedDirectory );
222 SetRoadmapStateValue(sal_True);
223 callModifiedHdl();
225 catch( const Exception& )
227 DBG_UNHANDLED_EXCEPTION();
230 break;
231 case ::dbaccess::DST_CALC:
233 SvtModuleOptions aModule;
234 ::sfx2::FileDialogHelper aFileDlg(
235 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
237 aModule.GetFactoryEmptyDocumentURL(SvtModuleOptions::E_CALC)
238 ,SFX_FILTER_IMPORT);
239 askForFileName(aFileDlg);
241 break;
242 case ::dbaccess::DST_MSACCESS:
244 const ::rtl::OUString sExt(RTL_CONSTASCII_USTRINGPARAM("*.mdb"));
245 String sFilterName(ModuleRes (STR_MSACCESS_FILTERNAME));
246 ::sfx2::FileDialogHelper aFileDlg(
247 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
249 aFileDlg.AddFilter(sFilterName,sExt);
250 aFileDlg.SetCurrentFilter(sFilterName);
251 askForFileName(aFileDlg);
253 break;
254 case ::dbaccess::DST_MSACCESS_2007:
256 const ::rtl::OUString sAccdb(RTL_CONSTASCII_USTRINGPARAM("*.accdb"));
257 String sFilterName2(ModuleRes (STR_MSACCESS_2007_FILTERNAME));
258 ::sfx2::FileDialogHelper aFileDlg(
259 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
261 aFileDlg.AddFilter(sFilterName2,sAccdb);
262 aFileDlg.SetCurrentFilter(sFilterName2);
263 askForFileName(aFileDlg);
265 break;
266 case ::dbaccess::DST_MYSQL_ODBC:
267 case ::dbaccess::DST_ODBC:
269 // collect all ODBC data source names
270 ::rtl::OUString sCurrDatasource = getURLNoPrefix();
271 ::rtl::OUString sDataSource;
272 if ( getSelectedDataSource(sDataSource,sCurrDatasource) && !sDataSource.isEmpty() )
274 setURLNoPrefix(sDataSource);
275 SetRoadmapStateValue(sal_True);
276 callModifiedHdl();
278 else
279 return 1L;
281 break;
282 #ifdef _ADO_DATALINK_BROWSE_
283 case ::dbaccess::DST_ADO:
285 ::rtl::OUString sOldDataSource=getURLNoPrefix();
286 ::rtl::OUString sNewDataSource;
287 HWND hWnd = GetParent()->GetSystemData()->hWnd;
288 sNewDataSource = getAdoDatalink((long)hWnd,sOldDataSource);
289 if ( !sNewDataSource.isEmpty() )
291 setURLNoPrefix(sNewDataSource);
292 SetRoadmapStateValue(sal_True);
293 callModifiedHdl();
295 else
296 return 1L;
298 break;
299 #endif
300 case ::dbaccess::DST_MOZILLA:
301 case ::dbaccess::DST_THUNDERBIRD:
303 MozillaProductType profileType = MozillaProductType_Mozilla;
304 if (eType == ::dbaccess::DST_THUNDERBIRD)
305 profileType = MozillaProductType_Thunderbird;
307 Reference<XMultiServiceFactory> xFactory = ::comphelper::getProcessServiceFactory();
308 OSL_ENSURE( xFactory.is(), "can't get service factory" );
310 Reference<XInterface> xInstance = xFactory->createInstance(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap")) );
311 OSL_ENSURE( xInstance.is(), "failed to create instance" );
312 Reference<XMozillaBootstrap> xMozillaBootstrap = Reference<XMozillaBootstrap>(xInstance,UNO_QUERY);
313 OSL_ENSURE( xMozillaBootstrap.is(), "failed to create instance" );
315 if (xMozillaBootstrap.is())
317 // collect all Mozilla Profiles
318 ::com::sun::star::uno::Sequence< ::rtl::OUString > list;
320 xMozillaBootstrap->getProfileList( profileType, list );
321 const ::rtl::OUString * pArray = list.getConstArray();
323 sal_Int32 count = list.getLength();
325 StringBag aProfiles;
326 for (sal_Int32 index=0; index < count; index++)
327 aProfiles.insert(pArray[index]);
330 // execute the select dialog
331 ODatasourceSelectDialog aSelector(GetParent(), aProfiles);
332 ::rtl::OUString sOldProfile=getURLNoPrefix();
334 if (!sOldProfile.isEmpty())
335 aSelector.Select(sOldProfile);
336 else
337 aSelector.Select(xMozillaBootstrap->getDefaultProfile(profileType));
339 if ( RET_OK == aSelector.Execute() )
340 setURLNoPrefix(aSelector.GetSelected());
341 break;
344 default:
345 break;
348 checkTestConnection();
350 return 0L;
353 //-------------------------------------------------------------------------
355 bool OConnectionHelper::checkTestConnection()
357 return true;
360 //-------------------------------------------------------------------------
361 void OConnectionHelper::impl_setURL( const String& _rURL, sal_Bool _bPrefix )
363 String sURL( _rURL );
364 OSL_ENSURE( m_pCollection, "OConnectionHelper::impl_setURL: have no interpreter for the URLs!" );
366 if ( m_pCollection && sURL.Len() )
368 if ( m_pCollection->isFileSystemBased( m_eType ) )
370 // get the two parts: prefix and file URL
371 String sTypePrefix, sFileURLEncoded;
372 if ( _bPrefix )
374 sTypePrefix = m_pCollection->getPrefix( m_eType );
375 sFileURLEncoded = m_pCollection->cutPrefix( sURL );
377 else
379 sFileURLEncoded = sURL;
382 // substitute any variables
383 sFileURLEncoded = SvtPathOptions().SubstituteVariable( sFileURLEncoded );
385 // decode the URL
386 sURL = sTypePrefix;
387 if ( sFileURLEncoded.Len() )
389 OFileNotation aFileNotation(sFileURLEncoded);
390 // set this decoded URL as text
391 sURL += String(aFileNotation.get(OFileNotation::N_SYSTEM));
396 if ( _bPrefix )
397 m_aConnectionURL.SetText( sURL );
398 else
399 m_aConnectionURL.SetTextNoPrefix( sURL );
401 implUpdateURLDependentStates();
404 //-------------------------------------------------------------------------
405 String OConnectionHelper::impl_getURL( sal_Bool _bPrefix ) const
407 // get the pure text
408 String sURL = _bPrefix ? m_aConnectionURL.GetText() : m_aConnectionURL.GetTextNoPrefix();
410 OSL_ENSURE( m_pCollection, "OConnectionHelper::impl_getURL: have no interpreter for the URLs!" );
412 if ( m_pCollection && sURL.Len() )
414 if ( m_pCollection->isFileSystemBased( m_eType ) )
416 // get the two parts: prefix and file URL
417 String sTypePrefix, sFileURLDecoded;
418 if ( _bPrefix )
420 sTypePrefix = m_pCollection->getPrefix( m_eType );
421 sFileURLDecoded = m_pCollection->cutPrefix( sURL );
423 else
425 sFileURLDecoded = sURL;
428 sURL = sTypePrefix;
429 if ( sFileURLDecoded.Len() )
431 OFileNotation aFileNotation( sFileURLDecoded, OFileNotation::N_SYSTEM );
432 sURL += String( aFileNotation.get( OFileNotation::N_URL ) );
435 // encode the URL
436 INetURLObject aFileURL( sFileURLDecoded, INetURLObject::ENCODE_ALL, RTL_TEXTENCODING_UTF8 );
437 sFileURLDecoded = aFileURL.GetMainURL( INetURLObject::NO_DECODE );
440 return sURL;
443 //-------------------------------------------------------------------------
444 void OConnectionHelper::setURL( const String& _rURL )
446 impl_setURL( _rURL, sal_True );
449 //-------------------------------------------------------------------------
450 String OConnectionHelper::getURLNoPrefix( ) const
452 return impl_getURL( sal_False );
455 //-------------------------------------------------------------------------
456 void OConnectionHelper::setURLNoPrefix( const String& _rURL )
458 impl_setURL( _rURL, sal_False );
461 //-------------------------------------------------------------------------
462 sal_Int32 OConnectionHelper::checkPathExistence(const String& _rURL)
464 IS_PATH_EXIST e_exists = pathExists(_rURL, sal_False);
465 if (( e_exists == PATH_NOT_EXIST) || ( e_exists == PATH_NOT_KNOWN))
467 String sQuery(ModuleRes(STR_ASK_FOR_DIRECTORY_CREATION));
468 OFileNotation aTransformer(_rURL);
469 sQuery.SearchAndReplaceAscii("$path$", aTransformer.get(OFileNotation::N_SYSTEM));
471 m_bUserGrabFocus = sal_False;
472 QueryBox aQuery(GetParent(), WB_YES_NO | WB_DEF_YES, sQuery);
473 sal_Int32 nQueryResult = aQuery.Execute();
474 m_bUserGrabFocus = sal_True;
476 switch (nQueryResult)
478 case RET_YES:
480 sal_Bool bTryCreate = sal_False;
483 if ( !createDirectoryDeep(_rURL) )
484 { // could not create the directory
485 sQuery = String(ModuleRes(STR_COULD_NOT_CREATE_DIRECTORY));
486 sQuery.SearchAndReplaceAscii("$name$", aTransformer.get(OFileNotation::N_SYSTEM));
488 m_bUserGrabFocus = sal_False;
489 QueryBox aWhatToDo(GetParent(), WB_RETRY_CANCEL | WB_DEF_RETRY, sQuery);
490 nQueryResult = aWhatToDo.Execute();
491 m_bUserGrabFocus = sal_True;
493 if (RET_RETRY == nQueryResult)
494 bTryCreate = sal_True;
495 else
497 SetRoadmapStateValue(sal_False);
498 callModifiedHdl();
499 return RET_RETRY;
503 while (bTryCreate);
505 break;
507 case RET_NO:
508 callModifiedHdl();
509 return RET_OK;
511 default:
512 // cancelled
513 SetRoadmapStateValue(sal_False);
514 callModifiedHdl();
515 return RET_CANCEL;
518 /* else
520 // TODO: error msg
521 return RET_CANCEL;
522 } */
523 SetRoadmapStateValue(sal_True);
524 callModifiedHdl();
525 return RET_OK;
528 // -----------------------------------------------------------------------------
529 IS_PATH_EXIST OConnectionHelper::pathExists(const ::rtl::OUString& _rURL, sal_Bool bIsFile) const
531 ::ucbhelper::Content aCheckExistence;
532 sal_Bool bExists = sal_False;
533 IS_PATH_EXIST eExists = PATH_NOT_EXIST;
534 Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = Reference< ::com::sun::star::task::XInteractionHandler >(
535 m_xORB->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY );
536 OFilePickerInteractionHandler* pHandler = new OFilePickerInteractionHandler(xInteractionHandler);
537 xInteractionHandler = pHandler;
539 Reference< XCommandEnvironment > xCmdEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
542 aCheckExistence = ::ucbhelper::Content(_rURL, xCmdEnv );
543 bExists = bIsFile? aCheckExistence.isDocument(): aCheckExistence.isFolder();
544 eExists = bExists? PATH_EXIST: PATH_NOT_EXIST;
546 catch(const Exception&)
548 eExists = ( pHandler && pHandler->isDoesNotExist() ) ? PATH_NOT_EXIST: (bIsFile ? PATH_NOT_EXIST : PATH_NOT_KNOWN);
550 return eExists;
552 //-------------------------------------------------------------------------
553 long OConnectionHelper::PreNotify( NotifyEvent& _rNEvt )
555 if ( m_pCollection->isFileSystemBased(m_eType) )
557 switch (_rNEvt.GetType())
559 case EVENT_GETFOCUS:
560 if (m_aConnectionURL.IsWindowOrChild(_rNEvt.GetWindow()) && m_bUserGrabFocus)
561 { // a descendant of the URL edit field got the focus
562 m_aConnectionURL.SaveValueNoPrefix();
564 break;
566 case EVENT_LOSEFOCUS:
567 if (m_aConnectionURL.IsWindowOrChild(_rNEvt.GetWindow()) && m_bUserGrabFocus)
568 { // a descendant of the URL edit field lost the focus
569 if (!commitURL())
570 return 1L; // handled
572 break;
576 return OGenericAdministrationPage::PreNotify( _rNEvt );
579 //-------------------------------------------------------------------------
581 sal_Bool OConnectionHelper::createDirectoryDeep(const String& _rPathURL)
583 // get an URL object analyzing the URL for us ...
584 INetURLObject aParser;
585 aParser.SetURL(_rPathURL);
587 INetProtocol eProtocol = aParser.GetProtocol();
589 ::std::vector< ::rtl::OUString > aToBeCreated; // the to-be-created levels
591 // search a level which exists
592 IS_PATH_EXIST eParentExists = PATH_NOT_EXIST;
593 while ( eParentExists == PATH_NOT_EXIST && aParser.getSegmentCount())
595 aToBeCreated.push_back(aParser.getName()); // remember the local name for creation
596 aParser.removeSegment(); // cut the local name
597 eParentExists = pathExists(aParser.GetMainURL(INetURLObject::NO_DECODE), sal_False);
600 if (!aParser.getSegmentCount())
601 return sal_False;
603 // create all the missing levels
606 // the parent content
607 Reference< XCommandEnvironment > xEmptyEnv;
608 ::ucbhelper::Content aParent(aParser.GetMainURL(INetURLObject::NO_DECODE), xEmptyEnv);
610 ::rtl::OUString sContentType;
611 if ( INET_PROT_FILE == eProtocol )
613 sContentType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.staroffice.fsys-folder"));
614 // the file UCP currently does not support the ContentType property
616 else
618 Any aContentType = aParent.getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ContentType")) );
619 aContentType >>= sContentType;
622 // the properties which need to be set on the new content
623 Sequence< ::rtl::OUString > aNewDirectoryProperties(1);
624 aNewDirectoryProperties[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title"));
626 // the values to be set
627 Sequence< Any > aNewDirectoryAttributes(1);
629 // loop
630 for ( ::std::vector< ::rtl::OUString >::reverse_iterator aLocalName = aToBeCreated.rbegin();
631 aLocalName != aToBeCreated.rend();
632 ++aLocalName
635 aNewDirectoryAttributes[0] <<= *aLocalName;
636 if (!aParent.insertNewContent(sContentType, aNewDirectoryProperties, aNewDirectoryAttributes, aParent))
637 return sal_False;
640 catch ( const Exception& )
642 DBG_UNHANDLED_EXCEPTION();
643 return sal_False;
646 return sal_True;
650 // -----------------------------------------------------------------------
651 void OConnectionHelper::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
653 _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFT_Connection));
654 _rControlList.push_back(new ODisableWrapper<PushButton>(&m_aPB_Connection));
658 // -----------------------------------------------------------------------
659 void OConnectionHelper::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
661 _rControlList.push_back( new OSaveValueWrapper<Edit>( &m_aConnectionURL ) );
664 //-------------------------------------------------------------------------
665 sal_Bool OConnectionHelper::commitURL()
667 String sURL;
668 String sOldPath;
669 sOldPath = m_aConnectionURL.GetSavedValueNoPrefix();
670 sURL = m_aConnectionURL.GetTextNoPrefix();
672 if ( m_pCollection->isFileSystemBased(m_eType) )
674 if ( ( sURL != sOldPath ) && ( 0 != sURL.Len() ) )
675 { // the text changed since entering the control
677 // the path may be in system notation ....
678 OFileNotation aTransformer(sURL);
679 sURL = aTransformer.get(OFileNotation::N_URL);
681 const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
683 if ( ( ::dbaccess::DST_CALC == eType) || ( ::dbaccess::DST_MSACCESS == eType) || ( ::dbaccess::DST_MSACCESS_2007 == eType) )
685 if( pathExists(sURL, sal_True) == PATH_NOT_EXIST )
687 String sFile = String( ModuleRes( STR_FILE_DOES_NOT_EXIST ) );
688 sFile.SearchAndReplaceAscii("$file$", aTransformer.get(OFileNotation::N_SYSTEM));
689 OSQLWarningBox( this, sFile ).Execute();
690 setURLNoPrefix(sOldPath);
691 SetRoadmapStateValue(sal_False);
692 callModifiedHdl();
693 return sal_False;
696 else
698 switch (checkPathExistence(sURL))
700 case RET_RETRY:
701 m_bUserGrabFocus = sal_False;
702 m_aConnectionURL.GrabFocus();
703 m_bUserGrabFocus = sal_True;
704 return sal_False;
706 case RET_CANCEL:
707 setURLNoPrefix(sOldPath);
708 return sal_False;
714 setURLNoPrefix(sURL);
715 m_aConnectionURL.SaveValueNoPrefix();
716 return sal_True;
718 //-------------------------------------------------------------------------
719 void OConnectionHelper::askForFileName(::sfx2::FileDialogHelper& _aFileOpen)
721 String sOldPath = getURLNoPrefix();
722 if ( sOldPath.Len() )
723 _aFileOpen.SetDisplayDirectory(sOldPath);
724 else
725 _aFileOpen.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
726 if (0 == _aFileOpen.Execute())
728 setURLNoPrefix(_aFileOpen.GetPath());
729 SetRoadmapStateValue(checkTestConnection());
730 callModifiedHdl();
734 //.........................................................................
735 } // namespace dbaui
736 //.........................................................................
738 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */