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