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