Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "dsnItem.hxx"
22 : : #include "ConnectionHelper.hxx"
23 : : #include "AutoControls.hrc"
24 : : #include "dbu_dlg.hrc"
25 : : #include "dbu_misc.hrc"
26 : : #include <svl/itemset.hxx>
27 : : #include <unotools/moduleoptions.hxx>
28 : : #include <sfx2/fcontnr.hxx>
29 : : #include <unotools/pathoptions.hxx>
30 : : #include <svl/stritem.hxx>
31 : : #include <svl/eitem.hxx>
32 : : #include <svl/intitem.hxx>
33 : : #include "dsitems.hxx"
34 : : #include "dbaccess_helpid.hrc"
35 : : #include "localresaccess.hxx"
36 : : #include <osl/process.h>
37 : : #include <osl/diagnose.h>
38 : : #include <vcl/msgbox.hxx>
39 : : #include <sfx2/filedlghelper.hxx>
40 : : #include "dbadmin.hxx"
41 : : #include <comphelper/types.hxx>
42 : : #include <vcl/stdtext.hxx>
43 : : #include "sqlmessage.hxx"
44 : : #include "odbcconfig.hxx"
45 : : #include "dsselect.hxx"
46 : : #include <svl/filenotation.hxx>
47 : : #include "dbustrings.hrc"
48 : : #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
49 : : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
50 : : #include <com/sun/star/sdbc/XRow.hpp>
51 : : #include <com/sun/star/awt/XWindow.hpp>
52 : : #include <com/sun/star/task/XInteractionHandler.hpp>
53 : : #include <com/sun/star/ucb/XProgressHandler.hpp>
54 : : #include "UITools.hxx"
55 : : #include <unotools/localfilehelper.hxx>
56 : : #include <unotools/ucbhelper.hxx>
57 : : #include <ucbhelper/commandenvironment.hxx>
58 : : #include "finteraction.hxx"
59 : : #include <connectivity/CommonTools.hxx>
60 : : #include <tools/urlobj.hxx>
61 : : #include <tools/diagnose_ex.h>
62 : : #include <sfx2/docfilt.hxx>
63 : :
64 : : #if defined(WNT)
65 : : #define _ADO_DATALINK_BROWSE_
66 : : #endif
67 : :
68 : : #ifdef _ADO_DATALINK_BROWSE_
69 : : #include <vcl/sysdata.hxx>
70 : : #include "adodatalinks.hxx"
71 : : #endif //_ADO_DATALINK_BROWSE_
72 : :
73 : : #include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
74 : : #include <comphelper/processfactory.hxx>
75 : :
76 : :
77 : :
78 : : //.........................................................................
79 : : namespace dbaui
80 : : {
81 : : //.........................................................................
82 : : using namespace ::com::sun::star;
83 : : using namespace ::com::sun::star::uno;
84 : : using namespace ::com::sun::star::ucb;
85 : : using namespace ::com::sun::star::ui::dialogs;
86 : : using namespace ::com::sun::star::sdbc;
87 : : using namespace ::com::sun::star::beans;
88 : : using namespace ::com::sun::star::lang;
89 : : using namespace ::com::sun::star::container;
90 : : using namespace ::com::sun::star::mozilla;
91 : : using namespace ::dbtools;
92 : : using namespace ::svt;
93 : :
94 : :
95 : : DBG_NAME(OConnectionHelper)
96 : :
97 : 0 : OConnectionHelper::OConnectionHelper( Window* pParent, const ResId& _rId, const SfxItemSet& _rCoreAttrs)
98 : : :OGenericAdministrationPage(pParent, _rId, _rCoreAttrs)
99 : 0 : ,m_aFT_Connection ( this, ResId( FT_AUTOBROWSEURL, *_rId.GetResMgr() ) )
100 : 0 : ,m_aConnectionURL ( this, ResId( ET_AUTOBROWSEURL, *_rId.GetResMgr() ) )
101 [ # # # # ]: 0 : ,m_aPB_Connection ( this, ResId( PB_AUTOBROWSEURL, *_rId.GetResMgr() ) )
[ # # ]
102 : : {
103 : : DBG_CTOR(OConnectionHelper,NULL);
104 : :
105 : : // extract the datasource type collection from the item set
106 [ # # ][ # # ]: 0 : DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _rCoreAttrs.GetItem(DSID_TYPECOLLECTION));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
107 [ # # ]: 0 : if (pCollectionItem)
108 : 0 : m_pCollection = pCollectionItem->getCollection();
109 [ # # ]: 0 : m_aPB_Connection.SetClickHdl(LINK(this, OConnectionHelper, OnBrowseConnections));
110 : : OSL_ENSURE(m_pCollection, "OConnectionHelper::OConnectionHelper : really need a DSN type collection !");
111 : 0 : m_aConnectionURL.SetTypeCollection(m_pCollection);
112 : 0 : }
113 : :
114 : :
115 [ # # ][ # # ]: 0 : OConnectionHelper::~OConnectionHelper()
[ # # ]
116 : : {
117 : :
118 : : DBG_DTOR(OConnectionHelper,NULL);
119 [ # # ]: 0 : }
120 : :
121 : :
122 : : // -----------------------------------------------------------------------
123 : 0 : void OConnectionHelper::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
124 : : {
125 : : // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
126 : : sal_Bool bValid, bReadonly;
127 [ # # ]: 0 : getFlags(_rSet, bValid, bReadonly);
128 : :
129 [ # # ]: 0 : m_aFT_Connection.Show();
130 [ # # ]: 0 : m_aConnectionURL.Show();
131 [ # # ][ # # ]: 0 : m_aConnectionURL.ShowPrefix( ::dbaccess::DST_JDBC == m_pCollection->determineType(m_eType) );
[ # # ][ # # ]
132 : :
133 [ # # ]: 0 : sal_Bool bEnableBrowseButton = m_pCollection->supportsBrowsing( m_eType );
134 [ # # ]: 0 : m_aPB_Connection.Show( bEnableBrowseButton );
135 : :
136 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True);
137 : :
138 : : // forward the values to the controls
139 [ # # ]: 0 : if ( bValid )
140 : : {
141 [ # # ]: 0 : String sUrl = pUrlItem->GetValue();
142 [ # # ]: 0 : setURL( sUrl );
143 : :
144 [ # # ]: 0 : checkTestConnection();
145 [ # # ][ # # ]: 0 : m_aConnectionURL.ClearModifyFlag();
146 : : }
147 : :
148 [ # # ]: 0 : OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
149 : 0 : }
150 : :
151 : : // -----------------------------------------------------------------------
152 : 0 : void OConnectionHelper::implUpdateURLDependentStates() const
153 : : {
154 : : OSL_PRECOND( m_pAdminDialog, "OConnectionHelper::implUpdateURLDependentStates: no admin dialog!" );
155 [ # # ]: 0 : if ( !m_pAdminDialog )
156 : 0 : return;
157 : :
158 [ # # ]: 0 : if ( m_pCollection->isFileSystemBased(m_eType) )
159 [ # # ]: 0 : m_pAdminDialog->enableConfirmSettings( getURLNoPrefix().Len() > 0 );
160 : : }
161 : :
162 : : // -----------------------------------------------------------------------
163 : 0 : IMPL_LINK(OConnectionHelper, OnBrowseConnections, PushButton*, /*_pButton*/)
164 : : {
165 : : OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
166 [ # # ]: 0 : const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
167 [ # # # # : 0 : switch ( eType )
# # # ]
168 : : {
169 : : case ::dbaccess::DST_DBASE:
170 : : case ::dbaccess::DST_FLAT:
171 : : {
172 : : try
173 : : {
174 [ # # ]: 0 : ::rtl::OUString sFolderPickerService(SERVICE_UI_FOLDERPICKER);
175 [ # # ][ # # ]: 0 : Reference< XFolderPicker > xFolderPicker(m_xORB->createInstance(sFolderPickerService), UNO_QUERY);
[ # # ]
176 [ # # ]: 0 : if (!xFolderPicker.is())
177 : : {
178 [ # # ][ # # ]: 0 : ShowServiceNotAvailableError(GetParent(), sFolderPickerService, sal_True);
[ # # ][ # # ]
179 : : break;
180 : : }
181 : :
182 : 0 : sal_Bool bDoBrowse = sal_False;
183 [ # # ]: 0 : String sOldPath = getURLNoPrefix();
184 [ # # ]: 0 : do
185 : : {
186 [ # # ]: 0 : if (sOldPath.Len())
187 [ # # ][ # # ]: 0 : xFolderPicker->setDisplayDirectory(sOldPath);
[ # # ]
188 [ # # ][ # # ]: 0 : if (0 == xFolderPicker->execute())
[ # # ]
189 : : // cancelled by the user
190 : 0 : return 0L;
191 : :
192 [ # # ][ # # ]: 0 : sOldPath = xFolderPicker->getDirectory();
[ # # ]
193 [ # # # ]: 0 : switch (checkPathExistence(sOldPath))
[ # # ]
194 : : {
195 : : case RET_RETRY:
196 : 0 : bDoBrowse = sal_True;
197 : 0 : break;
198 : : case RET_CANCEL:
199 : 0 : return 0L;
200 : : default:
201 : 0 : break;
202 : : }
203 : : }
204 : : while (bDoBrowse);
205 : :
206 [ # # ][ # # ]: 0 : String sSelectedDirectory = xFolderPicker->getDirectory();
[ # # ]
207 [ # # ][ # # ]: 0 : INetURLObject aSelectedDirectory( sSelectedDirectory, INetURLObject::WAS_ENCODED, RTL_TEXTENCODING_UTF8 );
208 : :
209 : : // for UI purpose, we don't want to have the path encoded
210 [ # # ][ # # ]: 0 : sSelectedDirectory = aSelectedDirectory.GetMainURL( INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8 );
211 : :
212 [ # # ]: 0 : setURLNoPrefix( sSelectedDirectory );
213 : 0 : SetRoadmapStateValue(sal_True);
214 [ # # ][ # # ]: 0 : callModifiedHdl();
[ # # ][ # # ]
[ # # # ]
[ # # # ]
[ # # ][ # # ]
215 : : }
216 : 0 : catch( const Exception& )
217 : : {
218 : : DBG_UNHANDLED_EXCEPTION();
219 : : }
220 : : }
221 : 0 : break;
222 : : case ::dbaccess::DST_CALC:
223 : : {
224 [ # # ]: 0 : SvtModuleOptions aModule;
225 : : ::sfx2::FileDialogHelper aFileDlg(
226 : : ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
227 : : 0,
228 : : aModule.GetFactoryEmptyDocumentURL(SvtModuleOptions::E_CALC)
229 [ # # ][ # # ]: 0 : ,SFX_FILTER_IMPORT);
[ # # ][ # # ]
230 [ # # ][ # # ]: 0 : askForFileName(aFileDlg);
[ # # ]
231 : : }
232 : 0 : break;
233 : : case ::dbaccess::DST_MSACCESS:
234 : : {
235 [ # # ]: 0 : const ::rtl::OUString sExt(RTL_CONSTASCII_USTRINGPARAM("*.mdb"));
236 [ # # ][ # # ]: 0 : String sFilterName(ModuleRes (STR_MSACCESS_FILTERNAME));
237 : : ::sfx2::FileDialogHelper aFileDlg(
238 : : ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
239 [ # # ]: 0 : 0);
240 [ # # ][ # # ]: 0 : aFileDlg.AddFilter(sFilterName,sExt);
[ # # ]
241 [ # # ]: 0 : aFileDlg.SetCurrentFilter(sFilterName);
242 [ # # ][ # # ]: 0 : askForFileName(aFileDlg);
[ # # ]
243 : : }
244 : 0 : break;
245 : : case ::dbaccess::DST_MSACCESS_2007:
246 : : {
247 [ # # ]: 0 : const ::rtl::OUString sAccdb(RTL_CONSTASCII_USTRINGPARAM("*.accdb"));
248 [ # # ][ # # ]: 0 : String sFilterName2(ModuleRes (STR_MSACCESS_2007_FILTERNAME));
249 : : ::sfx2::FileDialogHelper aFileDlg(
250 : : ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
251 [ # # ]: 0 : 0);
252 [ # # ][ # # ]: 0 : aFileDlg.AddFilter(sFilterName2,sAccdb);
[ # # ]
253 [ # # ]: 0 : aFileDlg.SetCurrentFilter(sFilterName2);
254 [ # # ][ # # ]: 0 : askForFileName(aFileDlg);
[ # # ]
255 : : }
256 : 0 : break;
257 : : case ::dbaccess::DST_MYSQL_ODBC:
258 : : case ::dbaccess::DST_ODBC:
259 : : {
260 : : // collect all ODBC data source names
261 [ # # ][ # # ]: 0 : ::rtl::OUString sCurrDatasource = getURLNoPrefix();
[ # # ]
262 : 0 : ::rtl::OUString sDataSource;
263 [ # # ][ # # ]: 0 : if ( getSelectedDataSource(sDataSource,sCurrDatasource) && !sDataSource.isEmpty() )
[ # # ][ # # ]
264 : : {
265 [ # # ][ # # ]: 0 : setURLNoPrefix(sDataSource);
[ # # ]
266 : 0 : SetRoadmapStateValue(sal_True);
267 [ # # ]: 0 : callModifiedHdl();
268 : : }
269 : : else
270 [ # # ][ # # ]: 0 : return 1L;
271 : : }
272 : 0 : break;
273 : : #ifdef _ADO_DATALINK_BROWSE_
274 : : case ::dbaccess::DST_ADO:
275 : : {
276 : : ::rtl::OUString sOldDataSource=getURLNoPrefix();
277 : : ::rtl::OUString sNewDataSource;
278 : : HWND hWnd = GetParent()->GetSystemData()->hWnd;
279 : : sNewDataSource = getAdoDatalink((long)hWnd,sOldDataSource);
280 : : if ( !sNewDataSource.isEmpty() )
281 : : {
282 : : setURLNoPrefix(sNewDataSource);
283 : : SetRoadmapStateValue(sal_True);
284 : : callModifiedHdl();
285 : : }
286 : : else
287 : : return 1L;
288 : : }
289 : : break;
290 : : #endif
291 : : case ::dbaccess::DST_MOZILLA:
292 : : case ::dbaccess::DST_THUNDERBIRD:
293 : : {
294 : 0 : MozillaProductType profileType = MozillaProductType_Mozilla;
295 [ # # ]: 0 : if (eType == ::dbaccess::DST_THUNDERBIRD)
296 : 0 : profileType = MozillaProductType_Thunderbird;
297 : :
298 [ # # ]: 0 : Reference<XMultiServiceFactory> xFactory = ::comphelper::getProcessServiceFactory();
299 : : OSL_ENSURE( xFactory.is(), "can't get service factory" );
300 : :
301 [ # # ][ # # ]: 0 : Reference<XInterface> xInstance = xFactory->createInstance(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap")) );
[ # # ]
302 : : OSL_ENSURE( xInstance.is(), "failed to create instance" );
303 [ # # ]: 0 : Reference<XMozillaBootstrap> xMozillaBootstrap = Reference<XMozillaBootstrap>(xInstance,UNO_QUERY);
304 : : OSL_ENSURE( xMozillaBootstrap.is(), "failed to create instance" );
305 : :
306 [ # # ]: 0 : if (xMozillaBootstrap.is())
307 : : {
308 : : // collect all Mozilla Profiles
309 [ # # ]: 0 : ::com::sun::star::uno::Sequence< ::rtl::OUString > list;
310 : :
311 [ # # ][ # # ]: 0 : xMozillaBootstrap->getProfileList( profileType, list );
312 : 0 : const ::rtl::OUString * pArray = list.getConstArray();
313 : :
314 : 0 : sal_Int32 count = list.getLength();
315 : :
316 [ # # ]: 0 : StringBag aProfiles;
317 [ # # ]: 0 : for (sal_Int32 index=0; index < count; index++)
318 [ # # ]: 0 : aProfiles.insert(pArray[index]);
319 : :
320 : :
321 : : // execute the select dialog
322 [ # # ][ # # ]: 0 : ODatasourceSelectDialog aSelector(GetParent(), aProfiles);
323 [ # # ][ # # ]: 0 : ::rtl::OUString sOldProfile=getURLNoPrefix();
[ # # ]
324 : :
325 [ # # ]: 0 : if (!sOldProfile.isEmpty())
326 [ # # ][ # # ]: 0 : aSelector.Select(sOldProfile);
[ # # ]
327 : : else
328 [ # # ][ # # ]: 0 : aSelector.Select(xMozillaBootstrap->getDefaultProfile(profileType));
[ # # ][ # # ]
[ # # ]
329 : :
330 [ # # ][ # # ]: 0 : if ( RET_OK == aSelector.Execute() )
331 [ # # ][ # # ]: 0 : setURLNoPrefix(aSelector.GetSelected());
[ # # ]
332 [ # # ][ # # ]: 0 : break;
333 [ # # ][ # # ]: 0 : }
[ # # ]
334 : : }
335 : : default:
336 : 0 : break;
337 : : }
338 : :
339 : 0 : checkTestConnection();
340 : :
341 : 0 : return 0L;
342 : : }
343 : :
344 : : //-------------------------------------------------------------------------
345 : :
346 : 0 : bool OConnectionHelper::checkTestConnection()
347 : : {
348 : 0 : return true;
349 : : }
350 : :
351 : : //-------------------------------------------------------------------------
352 : 0 : void OConnectionHelper::impl_setURL( const String& _rURL, sal_Bool _bPrefix )
353 : : {
354 [ # # ]: 0 : String sURL( _rURL );
355 : : OSL_ENSURE( m_pCollection, "OConnectionHelper::impl_setURL: have no interpreter for the URLs!" );
356 : :
357 [ # # ][ # # ]: 0 : if ( m_pCollection && sURL.Len() )
[ # # ]
358 : : {
359 [ # # ][ # # ]: 0 : if ( m_pCollection->isFileSystemBased( m_eType ) )
360 : : {
361 : : // get the two parts: prefix and file URL
362 [ # # ][ # # ]: 0 : String sTypePrefix, sFileURLEncoded;
363 [ # # ]: 0 : if ( _bPrefix )
364 : : {
365 [ # # ][ # # ]: 0 : sTypePrefix = m_pCollection->getPrefix( m_eType );
[ # # ]
366 [ # # ][ # # ]: 0 : sFileURLEncoded = m_pCollection->cutPrefix( sURL );
[ # # ][ # # ]
367 : : }
368 : : else
369 : : {
370 [ # # ]: 0 : sFileURLEncoded = sURL;
371 : : }
372 : :
373 : : // substitute any variables
374 [ # # ][ # # ]: 0 : sFileURLEncoded = SvtPathOptions().SubstituteVariable( sFileURLEncoded );
[ # # ][ # # ]
[ # # ]
375 : :
376 : : // decode the URL
377 [ # # ]: 0 : sURL = sTypePrefix;
378 [ # # ]: 0 : if ( sFileURLEncoded.Len() )
379 : : {
380 [ # # ][ # # ]: 0 : OFileNotation aFileNotation(sFileURLEncoded);
381 : : // set this decoded URL as text
382 [ # # ][ # # ]: 0 : sURL += String(aFileNotation.get(OFileNotation::N_SYSTEM));
[ # # ][ # # ]
[ # # ]
383 [ # # ][ # # ]: 0 : }
384 : : }
385 : : }
386 : :
387 [ # # ]: 0 : if ( _bPrefix )
388 [ # # ]: 0 : m_aConnectionURL.SetText( sURL );
389 : : else
390 [ # # ]: 0 : m_aConnectionURL.SetTextNoPrefix( sURL );
391 : :
392 [ # # ][ # # ]: 0 : implUpdateURLDependentStates();
393 : 0 : }
394 : :
395 : : //-------------------------------------------------------------------------
396 : 0 : String OConnectionHelper::impl_getURL( sal_Bool _bPrefix ) const
397 : : {
398 : : // get the pure text
399 [ # # ]: 0 : String sURL = _bPrefix ? m_aConnectionURL.GetText() : m_aConnectionURL.GetTextNoPrefix();
400 : :
401 : : OSL_ENSURE( m_pCollection, "OConnectionHelper::impl_getURL: have no interpreter for the URLs!" );
402 : :
403 [ # # ][ # # ]: 0 : if ( m_pCollection && sURL.Len() )
[ # # ]
404 : : {
405 [ # # ][ # # ]: 0 : if ( m_pCollection->isFileSystemBased( m_eType ) )
406 : : {
407 : : // get the two parts: prefix and file URL
408 [ # # ][ # # ]: 0 : String sTypePrefix, sFileURLDecoded;
409 [ # # ]: 0 : if ( _bPrefix )
410 : : {
411 [ # # ][ # # ]: 0 : sTypePrefix = m_pCollection->getPrefix( m_eType );
[ # # ]
412 [ # # ][ # # ]: 0 : sFileURLDecoded = m_pCollection->cutPrefix( sURL );
[ # # ][ # # ]
413 : : }
414 : : else
415 : : {
416 [ # # ]: 0 : sFileURLDecoded = sURL;
417 : : }
418 : :
419 [ # # ]: 0 : sURL = sTypePrefix;
420 [ # # ]: 0 : if ( sFileURLDecoded.Len() )
421 : : {
422 [ # # ][ # # ]: 0 : OFileNotation aFileNotation( sFileURLDecoded, OFileNotation::N_SYSTEM );
423 [ # # ][ # # ]: 0 : sURL += String( aFileNotation.get( OFileNotation::N_URL ) );
[ # # ][ # # ]
[ # # ]
424 : : }
425 : :
426 : : // encode the URL
427 [ # # ][ # # ]: 0 : INetURLObject aFileURL( sFileURLDecoded, INetURLObject::ENCODE_ALL, RTL_TEXTENCODING_UTF8 );
428 [ # # ][ # # ]: 0 : sFileURLDecoded = aFileURL.GetMainURL( INetURLObject::NO_DECODE );
[ # # ][ # # ]
[ # # ]
429 : : }
430 : : }
431 : 0 : return sURL;
432 : : }
433 : :
434 : : //-------------------------------------------------------------------------
435 : 0 : void OConnectionHelper::setURL( const String& _rURL )
436 : : {
437 : 0 : impl_setURL( _rURL, sal_True );
438 : 0 : }
439 : :
440 : : //-------------------------------------------------------------------------
441 : 0 : String OConnectionHelper::getURLNoPrefix( ) const
442 : : {
443 : 0 : return impl_getURL( sal_False );
444 : : }
445 : :
446 : : //-------------------------------------------------------------------------
447 : 0 : void OConnectionHelper::setURLNoPrefix( const String& _rURL )
448 : : {
449 : 0 : impl_setURL( _rURL, sal_False );
450 : 0 : }
451 : :
452 : : //-------------------------------------------------------------------------
453 : 0 : sal_Int32 OConnectionHelper::checkPathExistence(const String& _rURL)
454 : : {
455 [ # # ]: 0 : IS_PATH_EXIST e_exists = pathExists(_rURL, sal_False);
456 [ # # ][ # # ]: 0 : if (( e_exists == PATH_NOT_EXIST) || ( e_exists == PATH_NOT_KNOWN))
457 : : {
458 [ # # ][ # # ]: 0 : String sQuery(ModuleRes(STR_ASK_FOR_DIRECTORY_CREATION));
459 [ # # ][ # # ]: 0 : OFileNotation aTransformer(_rURL);
460 [ # # ][ # # ]: 0 : sQuery.SearchAndReplaceAscii("$path$", aTransformer.get(OFileNotation::N_SYSTEM));
[ # # ][ # # ]
461 : :
462 : 0 : m_bUserGrabFocus = sal_False;
463 [ # # ][ # # ]: 0 : QueryBox aQuery(GetParent(), WB_YES_NO | WB_DEF_YES, sQuery);
464 [ # # ]: 0 : sal_Int32 nQueryResult = aQuery.Execute();
465 : 0 : m_bUserGrabFocus = sal_True;
466 : :
467 [ # # # ]: 0 : switch (nQueryResult)
468 : : {
469 : : case RET_YES:
470 : : {
471 : 0 : sal_Bool bTryCreate = sal_False;
472 [ # # ]: 0 : do
473 : : {
474 [ # # ][ # # ]: 0 : if ( !createDirectoryDeep(_rURL) )
475 : : { // could not create the directory
476 [ # # ][ # # ]: 0 : sQuery = String(ModuleRes(STR_COULD_NOT_CREATE_DIRECTORY));
[ # # ][ # # ]
477 [ # # ][ # # ]: 0 : sQuery.SearchAndReplaceAscii("$name$", aTransformer.get(OFileNotation::N_SYSTEM));
[ # # ][ # # ]
478 : :
479 : 0 : m_bUserGrabFocus = sal_False;
480 [ # # ][ # # ]: 0 : QueryBox aWhatToDo(GetParent(), WB_RETRY_CANCEL | WB_DEF_RETRY, sQuery);
481 [ # # ]: 0 : nQueryResult = aWhatToDo.Execute();
482 : 0 : m_bUserGrabFocus = sal_True;
483 : :
484 [ # # ]: 0 : if (RET_RETRY == nQueryResult)
485 : 0 : bTryCreate = sal_True;
486 : : else
487 : : {
488 : 0 : SetRoadmapStateValue(sal_False);
489 [ # # ]: 0 : callModifiedHdl();
490 : 0 : return RET_RETRY;
491 [ # # ][ # # ]: 0 : }
492 : : }
493 : : }
494 : : while (bTryCreate);
495 : : }
496 : 0 : break;
497 : :
498 : : case RET_NO:
499 [ # # ]: 0 : callModifiedHdl();
500 : 0 : return RET_OK;
501 : :
502 : : default:
503 : : // cancelled
504 : 0 : SetRoadmapStateValue(sal_False);
505 [ # # ]: 0 : callModifiedHdl();
506 : 0 : return RET_CANCEL;
507 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ][ # # ]
508 : : }
509 : : /* else
510 : : {
511 : : // TODO: error msg
512 : : return RET_CANCEL;
513 : : } */
514 : 0 : SetRoadmapStateValue(sal_True);
515 : 0 : callModifiedHdl();
516 : 0 : return RET_OK;
517 : : }
518 : :
519 : : // -----------------------------------------------------------------------------
520 : 0 : IS_PATH_EXIST OConnectionHelper::pathExists(const ::rtl::OUString& _rURL, sal_Bool bIsFile) const
521 : : {
522 [ # # ]: 0 : ::ucbhelper::Content aCheckExistence;
523 : 0 : sal_Bool bExists = sal_False;
524 : 0 : IS_PATH_EXIST eExists = PATH_NOT_EXIST;
525 : : Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = Reference< ::com::sun::star::task::XInteractionHandler >(
526 [ # # ][ # # ]: 0 : m_xORB->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY );
[ # # ][ # # ]
527 [ # # ]: 0 : OFilePickerInteractionHandler* pHandler = new OFilePickerInteractionHandler(xInteractionHandler);
528 [ # # ][ # # ]: 0 : xInteractionHandler = pHandler;
529 : :
530 [ # # ][ # # ]: 0 : Reference< XCommandEnvironment > xCmdEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
[ # # ]
531 : : try
532 : : {
533 [ # # ]: 0 : aCheckExistence = ::ucbhelper::Content(_rURL, xCmdEnv );
[ # # # # ]
[ # # ]
534 [ # # ][ # # ]: 0 : bExists = bIsFile? aCheckExistence.isDocument(): aCheckExistence.isFolder();
[ # # ]
535 [ # # ]: 0 : eExists = bExists? PATH_EXIST: PATH_NOT_EXIST;
536 : : }
537 [ # # ]: 0 : catch(const Exception&)
538 : : {
539 [ # # # # : 0 : eExists = ( pHandler && pHandler->isDoesNotExist() ) ? PATH_NOT_EXIST: (bIsFile ? PATH_NOT_EXIST : PATH_NOT_KNOWN);
# # ]
540 : : }
541 [ # # ]: 0 : return eExists;
542 : : }
543 : : //-------------------------------------------------------------------------
544 : 0 : long OConnectionHelper::PreNotify( NotifyEvent& _rNEvt )
545 : : {
546 [ # # ]: 0 : if ( m_pCollection->isFileSystemBased(m_eType) )
547 : : {
548 [ # # # ]: 0 : switch (_rNEvt.GetType())
549 : : {
550 : : case EVENT_GETFOCUS:
551 [ # # ][ # # ]: 0 : if (m_aConnectionURL.IsWindowOrChild(_rNEvt.GetWindow()) && m_bUserGrabFocus)
[ # # ]
552 : : { // a descendant of the URL edit field got the focus
553 : 0 : m_aConnectionURL.SaveValueNoPrefix();
554 : : }
555 : 0 : break;
556 : :
557 : : case EVENT_LOSEFOCUS:
558 [ # # ][ # # ]: 0 : if (m_aConnectionURL.IsWindowOrChild(_rNEvt.GetWindow()) && m_bUserGrabFocus)
[ # # ]
559 : : { // a descendant of the URL edit field lost the focus
560 [ # # ]: 0 : if (!commitURL())
561 : 0 : return 1L; // handled
562 : : }
563 : 0 : break;
564 : : }
565 : : }
566 : :
567 : 0 : return OGenericAdministrationPage::PreNotify( _rNEvt );
568 : : }
569 : :
570 : : //-------------------------------------------------------------------------
571 : :
572 : 0 : sal_Bool OConnectionHelper::createDirectoryDeep(const String& _rPathURL)
573 : : {
574 : : // get an URL object analyzing the URL for us ...
575 [ # # ]: 0 : INetURLObject aParser;
576 [ # # ][ # # ]: 0 : aParser.SetURL(_rPathURL);
577 : :
578 : 0 : INetProtocol eProtocol = aParser.GetProtocol();
579 : :
580 [ # # ]: 0 : ::std::vector< ::rtl::OUString > aToBeCreated; // the to-be-created levels
581 : :
582 : : // search a level which exists
583 : 0 : IS_PATH_EXIST eParentExists = PATH_NOT_EXIST;
584 [ # # ][ # # ]: 0 : while ( eParentExists == PATH_NOT_EXIST && aParser.getSegmentCount())
[ # # ][ # # ]
585 : : {
586 [ # # ][ # # ]: 0 : aToBeCreated.push_back(aParser.getName()); // remember the local name for creation
587 [ # # ]: 0 : aParser.removeSegment(); // cut the local name
588 [ # # ][ # # ]: 0 : eParentExists = pathExists(aParser.GetMainURL(INetURLObject::NO_DECODE), sal_False);
589 : : }
590 : :
591 [ # # ][ # # ]: 0 : if (!aParser.getSegmentCount())
592 : 0 : return sal_False;
593 : :
594 : : // create all the missing levels
595 : : try
596 : : {
597 : : // the parent content
598 : 0 : Reference< XCommandEnvironment > xEmptyEnv;
599 [ # # ][ # # ]: 0 : ::ucbhelper::Content aParent(aParser.GetMainURL(INetURLObject::NO_DECODE), xEmptyEnv);
600 : :
601 : 0 : ::rtl::OUString sContentType;
602 [ # # ]: 0 : if ( INET_PROT_FILE == eProtocol )
603 : : {
604 [ # # ]: 0 : sContentType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.staroffice.fsys-folder"));
605 : : // the file UCP currently does not support the ContentType property
606 : : }
607 : : else
608 : : {
609 [ # # ][ # # ]: 0 : Any aContentType = aParent.getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ContentType")) );
610 : 0 : aContentType >>= sContentType;
611 : : }
612 : :
613 : : // the properties which need to be set on the new content
614 [ # # ]: 0 : Sequence< ::rtl::OUString > aNewDirectoryProperties(1);
615 [ # # ][ # # ]: 0 : aNewDirectoryProperties[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title"));
616 : :
617 : : // the values to be set
618 [ # # ]: 0 : Sequence< Any > aNewDirectoryAttributes(1);
619 : :
620 : : // loop
621 [ # # # # ]: 0 : for ( ::std::vector< ::rtl::OUString >::reverse_iterator aLocalName = aToBeCreated.rbegin();
[ # # ]
622 : 0 : aLocalName != aToBeCreated.rend();
623 : : ++aLocalName
624 : : )
625 : : {
626 [ # # ][ # # ]: 0 : aNewDirectoryAttributes[0] <<= *aLocalName;
[ # # ]
627 [ # # ][ # # ]: 0 : if (!aParent.insertNewContent(sContentType, aNewDirectoryProperties, aNewDirectoryAttributes, aParent))
628 : 0 : return sal_False;
629 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
[ # # # # ]
630 : : }
631 [ # # ]: 0 : catch ( const Exception& )
632 : : {
633 : : DBG_UNHANDLED_EXCEPTION();
634 : 0 : return sal_False;
635 : : }
636 : :
637 [ # # ]: 0 : return sal_True;
638 : : }
639 : :
640 : :
641 : : // -----------------------------------------------------------------------
642 : 0 : void OConnectionHelper::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
643 : : {
644 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFT_Connection));
645 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<PushButton>(&m_aPB_Connection));
646 : 0 : }
647 : :
648 : :
649 : : // -----------------------------------------------------------------------
650 : 0 : void OConnectionHelper::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
651 : : {
652 [ # # ][ # # ]: 0 : _rControlList.push_back( new OSaveValueWrapper<Edit>( &m_aConnectionURL ) );
653 : 0 : }
654 : :
655 : : //-------------------------------------------------------------------------
656 : 0 : sal_Bool OConnectionHelper::commitURL()
657 : : {
658 [ # # ]: 0 : String sURL;
659 [ # # ]: 0 : String sOldPath;
660 [ # # ][ # # ]: 0 : sOldPath = m_aConnectionURL.GetSavedValueNoPrefix();
[ # # ]
661 [ # # ][ # # ]: 0 : sURL = m_aConnectionURL.GetTextNoPrefix();
[ # # ]
662 : :
663 [ # # ][ # # ]: 0 : if ( m_pCollection->isFileSystemBased(m_eType) )
664 : : {
665 [ # # ][ # # ]: 0 : if ( ( sURL != sOldPath ) && ( 0 != sURL.Len() ) )
[ # # ][ # # ]
666 : : { // the text changed since entering the control
667 : :
668 : : // the path may be in system notation ....
669 [ # # ][ # # ]: 0 : OFileNotation aTransformer(sURL);
670 [ # # ][ # # ]: 0 : sURL = aTransformer.get(OFileNotation::N_URL);
671 : :
672 [ # # ][ # # ]: 0 : const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
[ # # ]
673 : :
674 [ # # ][ # # ]: 0 : if ( ( ::dbaccess::DST_CALC == eType) || ( ::dbaccess::DST_MSACCESS == eType) || ( ::dbaccess::DST_MSACCESS_2007 == eType) )
[ # # ]
675 : : {
676 [ # # ][ # # ]: 0 : if( pathExists(sURL, sal_True) == PATH_NOT_EXIST )
[ # # ]
677 : : {
678 [ # # ][ # # ]: 0 : String sFile = String( ModuleRes( STR_FILE_DOES_NOT_EXIST ) );
679 [ # # ][ # # ]: 0 : sFile.SearchAndReplaceAscii("$file$", aTransformer.get(OFileNotation::N_SYSTEM));
[ # # ][ # # ]
680 [ # # ][ # # ]: 0 : OSQLWarningBox( this, sFile ).Execute();
[ # # ]
681 [ # # ]: 0 : setURLNoPrefix(sOldPath);
682 : 0 : SetRoadmapStateValue(sal_False);
683 [ # # ]: 0 : callModifiedHdl();
684 [ # # ]: 0 : return sal_False;
685 : 0 : }
686 : : }
687 : : else
688 : : {
689 [ # # ]: 0 : switch (checkPathExistence(sURL))
[ # # # ]
690 : : {
691 : : case RET_RETRY:
692 : 0 : m_bUserGrabFocus = sal_False;
693 [ # # ]: 0 : m_aConnectionURL.GrabFocus();
694 : 0 : m_bUserGrabFocus = sal_True;
695 : 0 : return sal_False;
696 : :
697 : : case RET_CANCEL:
698 [ # # ]: 0 : setURLNoPrefix(sOldPath);
699 : 0 : return sal_False;
700 : : }
701 [ # # ][ # # ]: 0 : }
702 : : }
703 : : }
704 : :
705 [ # # ]: 0 : setURLNoPrefix(sURL);
706 [ # # ]: 0 : m_aConnectionURL.SaveValueNoPrefix();
707 [ # # ][ # # ]: 0 : return sal_True;
708 : : }
709 : : //-------------------------------------------------------------------------
710 : 0 : void OConnectionHelper::askForFileName(::sfx2::FileDialogHelper& _aFileOpen)
711 : : {
712 [ # # ]: 0 : String sOldPath = getURLNoPrefix();
713 [ # # ]: 0 : if ( sOldPath.Len() )
714 [ # # ]: 0 : _aFileOpen.SetDisplayDirectory(sOldPath);
715 : : else
716 [ # # ][ # # ]: 0 : _aFileOpen.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
[ # # ][ # # ]
717 [ # # ][ # # ]: 0 : if (0 == _aFileOpen.Execute())
718 : : {
719 [ # # ][ # # ]: 0 : setURLNoPrefix(_aFileOpen.GetPath());
[ # # ]
720 [ # # ]: 0 : SetRoadmapStateValue(checkTestConnection());
721 [ # # ]: 0 : callModifiedHdl();
722 [ # # ]: 0 : }
723 : 0 : }
724 : :
725 : : //.........................................................................
726 : : } // namespace dbaui
727 : : //.........................................................................
728 : :
729 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|