1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbui.hxx"
26
27 #include "dbwizsetup.hxx"
28 #include "dsmeta.hxx"
29 #include "DBSetupConnectionPages.hxx"
30 #include "dbadminsetup.hrc"
31 #include "dbu_dlg.hrc"
32 #include "dsitems.hxx"
33 #include "dsnItem.hxx"
34
35 #include <unotools/pathoptions.hxx>
36 #include <svl/stritem.hxx>
37 #include <svl/eitem.hxx>
38 #include <svl/intitem.hxx>
39 #include <vcl/msgbox.hxx>
40 #include "dbustrings.hrc"
41 #include "adminpages.hxx"
42 #include <sfx2/docfilt.hxx>
43 #include <unotools/ucbhelper.hxx>
44 #include "generalpage.hxx"
45 #include "localresaccess.hxx"
46 #include "stringlistitem.hxx"
47 #include "propertysetitem.hxx"
48 #include <unotools/confignode.hxx>
49 #include "DbAdminImpl.hxx"
50 #include "dbaccess_helpid.hrc"
51 #include "ConnectionPageSetup.hxx"
52 #include "UITools.hxx"
53 #include "dbadmin.hrc"
54 #include "AsyncronousLink.hxx"
55 #include <sfx2/filedlghelper.hxx>
56 #include <cppuhelper/exc_hlp.hxx>
57
58 /** === begin UNO includes === **/
59 #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
60 #include <com/sun/star/frame/XStorable.hpp>
61 #endif
62 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
63 #include <com/sun/star/uno/XNamingService.hpp>
64 #endif
65 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
66 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
67 #endif
68 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
69 #include <com/sun/star/sdbc/XDataSource.hpp>
70 #endif
71 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
72 #include <com/sun/star/container/XNameAccess.hpp>
73 #endif
74 #ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_
75 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
76 #endif
77 #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
78 #include <com/sun/star/frame/FrameSearchFlag.hpp>
79 #endif
80 #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
81 #include <com/sun/star/frame/XComponentLoader.hpp>
82 #endif
83 #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
84 #include <com/sun/star/frame/XModel.hpp>
85 #endif
86 #ifndef _COM_SUN_STAR_UCB_XSIMPLEFILEACCESS_HPP_
87 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
88 #endif
89 #ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_
90 #include <com/sun/star/task/XJobExecutor.hpp>
91 #endif
92 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
93 #include <com/sun/star/lang/XInitialization.hpp>
94 #endif
95 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
96 #include <com/sun/star/sdb/CommandType.hpp>
97 #endif
98 #ifndef _COM_SUN_STAR_UCB_INTERACTIVEIOEXCEPTION_HPP_
99 #include <com/sun/star/ucb/InteractiveIOException.hpp>
100 #endif
101 #ifndef _COM_SUN_STAR_IO_IOEXCEPTION_HPP_
102 #include <com/sun/star/io/IOException.hpp>
103 #endif
104 #ifndef _COM_SUN_STAR_FRAME_XTERMINATELISTENER_HPP_
105 #include <com/sun/star/frame/XTerminateListener.hpp>
106 #endif
107 #ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_
108 #include <com/sun/star/frame/XDesktop.hpp>
109 #endif
110 #ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_
111 #include <com/sun/star/sdbc/XDriverAccess.hpp>
112 #endif
113 #ifndef _COM_SUN_STAR_DOCUMENT_MACROEXECMODE_HPP_
114 #include <com/sun/star/document/MacroExecMode.hpp>
115 #endif
116 #include <com/sun/star/ucb/IOErrorCode.hpp>
117 #include <com/sun/star/task/XInteractionHandler2.hpp>
118 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
119
120
121 /** === end UNO includes === **/
122
123 #include <svl/filenotation.hxx>
124 #include <comphelper/interaction.hxx>
125 #include <comphelper/namedvaluecollection.hxx>
126 #include <comphelper/sequenceashashmap.hxx>
127 #include <tools/diagnose_ex.h>
128 #include <connectivity/DriversConfig.hxx>
129
130 #include <memory>
131
132
133 //.........................................................................
134 namespace dbaui
135 {
136 //.........................................................................
137 using namespace dbtools;
138 using namespace svt;
139 using namespace com::sun::star;
140 using namespace com::sun::star::uno;
141 using namespace com::sun::star::sdbc;
142 using namespace com::sun::star::sdbcx;
143 using namespace com::sun::star::task;
144 using namespace com::sun::star::lang;
145 using namespace com::sun::star::io;
146 using namespace com::sun::star::util;
147 using namespace com::sun::star::beans;
148 using namespace com::sun::star::container;
149 using namespace com::sun::star::frame;
150 using namespace com::sun::star::ucb;
151 using namespace ::com::sun::star::sdb;
152 using namespace ::com::sun::star::document;
153 using namespace ::comphelper;
154 using namespace ::cppu;
155
156 #define START_PAGE 0
157 #define CONNECTION_PAGE 1
158
159
160
161
162 //#define DBASE_PATH 1
163 //#define TEXT_PATH 2
164 //#define MSACCESS_PATH 3
165 //#define LDAP_PATH 4
166 //#define ADABAS_PATH 5
167 //#define ADO_PATH 6
168 //#define JDBC_PATH 7
169 //#define ORACLE_PATH 8
170 //#define MYSQL_JDBC_PATH 9
171 //#define MYSQL_ODBC_PATH 10
172 //#define ODBC_PATH 11
173 //#define SPREADSHEET_PATH 12
174 //#define OUTLOOKEXP_PATH 13
175 //#define OUTLOOK_PATH 14
176 //#define MOZILLA_PATH 15
177 //#define EVOLUTION_PATH 16
178 //#define EVOLUTION_PATH_GROUPWISE 17
179 //#define EVOLUTION_PATH_LDAP 18
180 //#define KAB_PATH 19
181 //#define MACAB_PATH 20
182 //#define THUNDERBIRD_PATH 21
183 //#define CREATENEW_PATH 22
184 //#define USERDEFINED_PATH 23
185 //#define OPEN_DOC_PATH 24
186 //#define MSACCESS2007_PATH 25
187 //#define MYSQL_NATIVE_PATH 26
188
189 OFinalDBPageSetup* pFinalPage;
190
191
192
DBG_NAME(ODbTypeWizDialogSetup)193 DBG_NAME(ODbTypeWizDialogSetup)
194 //=========================================================================
195 //= ODbTypeWizDialogSetup
196 //=========================================================================
197 //-------------------------------------------------------------------------
198 ODbTypeWizDialogSetup::ODbTypeWizDialogSetup(Window* _pParent
199 ,SfxItemSet* _pItems
200 ,const Reference< XMultiServiceFactory >& _rxORB
201 ,const ::com::sun::star::uno::Any& _aDataSourceName
202 )
203 :svt::RoadmapWizard( _pParent, ModuleRes(DLG_DATABASE_WIZARD),
204 WZB_NEXT | WZB_PREVIOUS | WZB_FINISH | WZB_CANCEL | WZB_HELP )
205
206 , m_pOutSet(NULL)
207 , m_bResetting(sal_False)
208 , m_bApplied(sal_False)
209 , m_bUIEnabled( sal_True )
210 , m_bIsConnectable( sal_False)
211 , m_sRM_IntroText(ModuleRes(STR_PAGETITLE_INTROPAGE))
212 , m_sRM_dBaseText(ModuleRes(STR_PAGETITLE_DBASE))
213 , m_sRM_TextText(ModuleRes(STR_PAGETITLE_TEXT))
214 , m_sRM_MSAccessText(ModuleRes(STR_PAGETITLE_MSACCESS))
215 , m_sRM_LDAPText(ModuleRes(STR_PAGETITLE_LDAP))
216 , m_sRM_ADABASText(ModuleRes(STR_PAGETITLE_ADABAS))
217 , m_sRM_ADOText(ModuleRes(STR_PAGETITLE_ADO))
218 , m_sRM_JDBCText(ModuleRes(STR_PAGETITLE_JDBC))
219 , m_sRM_MySQLNativePageTitle(ModuleRes(STR_PAGETITLE_MYSQL_NATIVE))
220 , m_pGeneralPage( NULL )
221 , m_pMySQLIntroPage(NULL)
222 , m_pCollection( NULL )
223 {
224 DBG_CTOR(ODbTypeWizDialogSetup,NULL);
225 // no local resources needed anymore
226 m_sRM_MySQLText = String(ModuleRes(STR_PAGETITLE_MYSQL));
227 m_sRM_OracleText = String(ModuleRes(STR_PAGETITLE_ORACLE));
228 m_sRM_ODBCText = String(ModuleRes(STR_PAGETITLE_ODBC));
229 m_sRM_SpreadSheetText = String(ModuleRes(STR_PAGETITLE_SPREADSHEET));
230 m_sRM_AuthentificationText = String(ModuleRes(STR_PAGETITLE_AUTHENTIFICATION));
231 m_sRM_FinalText = String(ModuleRes(STR_PAGETITLE_FINAL));
232 m_sWorkPath = SvtPathOptions().GetWorkPath();
233 pFinalPage = NULL;
234 // extract the datasource type collection from the item set
235 DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _pItems->GetItem(DSID_TYPECOLLECTION));
236 if (pCollectionItem)
237 m_pCollection = pCollectionItem->getCollection();
238
239 DBG_ASSERT(m_pCollection, "ODbTypeWizDialogSetup::ODbTypeWizDialogSetup : really need a DSN type collection !");
240
241 FreeResource();
242
243 m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,this,this));
244 m_pImpl->setDataSourceOrName(_aDataSourceName);
245 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
246 m_pOutSet = new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() );
247
248 m_pImpl->translateProperties(xDatasource, *m_pOutSet);
249 // eType = m_pImpl->getDatasourceType(*m_pOutSet);
250
251 SetPageSizePixel(LogicToPixel(::Size(WIZARD_PAGE_X, WIZARD_PAGE_Y), MAP_APPFONT));
252 ShowButtonFixedLine(sal_True);
253 defaultButton(WZB_NEXT);
254 enableButtons(WZB_FINISH, sal_True);
255 enableAutomaticNextButtonState();
256
257 ::dbaccess::ODsnTypeCollection::TypeIterator aIter = m_pCollection->begin();
258 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
259 for(PathId i = 1;aIter != aEnd;++aIter,++i)
260 {
261 const ::rtl::OUString sURLPrefix = aIter.getURLPrefix();
262 svt::RoadmapWizardTypes::WizardPath aPath;
263 aPath.push_back(PAGE_DBSETUPWIZARD_INTRO);
264 m_pCollection->fillPageIds(sURLPrefix,aPath);
265 aPath.push_back(PAGE_DBSETUPWIZARD_AUTHENTIFICATION);
266 aPath.push_back(PAGE_DBSETUPWIZARD_FINAL);
267
268 declareAuthDepPath(sURLPrefix,i,aPath);
269 }
270
271 svt::RoadmapWizardTypes::WizardPath aPath;
272 aPath.push_back(PAGE_DBSETUPWIZARD_INTRO);
273 declarePath( static_cast<PathId>(m_pCollection->size()+1), aPath);
274
275 m_pPrevPage->SetHelpId(HID_DBWIZ_PREVIOUS);
276 m_pNextPage->SetHelpId(HID_DBWIZ_NEXT);
277 m_pCancel->SetHelpId(HID_DBWIZ_CANCEL);
278 m_pFinish->SetHelpId(HID_DBWIZ_FINISH);
279 m_pHelp->SetUniqueId(UID_DBWIZ_HELP);
280 SetRoadmapInteractive( sal_True );
281 ActivatePage();
282 }
283
declareAuthDepPath(const::rtl::OUString & _sURL,PathId _nPathId,const svt::RoadmapWizardTypes::WizardPath & _rPaths)284 void ODbTypeWizDialogSetup::declareAuthDepPath( const ::rtl::OUString& _sURL, PathId _nPathId, const svt::RoadmapWizardTypes::WizardPath& _rPaths)
285 {
286 bool bHasAuthentication = DataSourceMetaData::getAuthentication( _sURL ) != AuthNone;
287
288 // collect the elements of the path
289 WizardPath aPath;
290
291 svt::RoadmapWizardTypes::WizardPath::const_iterator aIter = _rPaths.begin();
292 svt::RoadmapWizardTypes::WizardPath::const_iterator aEnd = _rPaths.end();
293 for(;aIter != aEnd;++aIter)
294 {
295 if ( bHasAuthentication || ( *aIter != PAGE_DBSETUPWIZARD_AUTHENTIFICATION ) )
296 aPath.push_back( *aIter );
297 } // for(;aIter != aEnd;++aIter)
298
299 // call base method
300 ::svt::RoadmapWizard::declarePath( _nPathId, aPath );
301 }
302
getStateDisplayName(WizardState _nState) const303 String ODbTypeWizDialogSetup::getStateDisplayName( WizardState _nState ) const
304 {
305 String sRoadmapItem;
306 switch( _nState )
307 {
308 case PAGE_DBSETUPWIZARD_INTRO:
309 sRoadmapItem = m_sRM_IntroText;
310 break;
311
312 case PAGE_DBSETUPWIZARD_DBASE:
313 sRoadmapItem = m_sRM_dBaseText;
314 break;
315 case PAGE_DBSETUPWIZARD_ADO:
316 sRoadmapItem = m_sRM_ADOText;
317 break;
318 case PAGE_DBSETUPWIZARD_TEXT:
319 sRoadmapItem = m_sRM_TextText;
320 break;
321 case PAGE_DBSETUPWIZARD_MSACCESS:
322 sRoadmapItem = m_sRM_MSAccessText;
323 break;
324 case PAGE_DBSETUPWIZARD_LDAP:
325 sRoadmapItem = m_sRM_LDAPText;
326 break;
327 case PAGE_DBSETUPWIZARD_ADABAS:
328 sRoadmapItem = m_sRM_ADABASText;
329 break;
330 case PAGE_DBSETUPWIZARD_JDBC:
331 sRoadmapItem = m_sRM_JDBCText;
332 break;
333 case PAGE_DBSETUPWIZARD_ORACLE:
334 sRoadmapItem = m_sRM_OracleText;
335 break;
336 case PAGE_DBSETUPWIZARD_MYSQL_INTRO:
337 sRoadmapItem = m_sRM_MySQLText;
338 break;
339 case PAGE_DBSETUPWIZARD_MYSQL_JDBC:
340 sRoadmapItem = m_sRM_JDBCText;
341 break;
342 case PAGE_DBSETUPWIZARD_MYSQL_NATIVE:
343 sRoadmapItem = m_sRM_MySQLNativePageTitle;
344 break;
345 case PAGE_DBSETUPWIZARD_MYSQL_ODBC:
346 sRoadmapItem = m_sRM_ODBCText;
347 break;
348 case PAGE_DBSETUPWIZARD_ODBC:
349 sRoadmapItem = m_sRM_ODBCText;
350 break;
351 case PAGE_DBSETUPWIZARD_SPREADSHEET:
352 sRoadmapItem = m_sRM_SpreadSheetText;
353 break;
354 case PAGE_DBSETUPWIZARD_AUTHENTIFICATION:
355 sRoadmapItem = m_sRM_AuthentificationText;
356 break;
357 case PAGE_DBSETUPWIZARD_USERDEFINED:
358 {
359 LocalResourceAccess aDummy(DLG_DATABASE_ADMINISTRATION, RSC_TABDIALOG);
360 sRoadmapItem = String(ModuleRes(STR_PAGETITLE_CONNECTION));
361 }
362 break;
363 case PAGE_DBSETUPWIZARD_FINAL:
364 sRoadmapItem = m_sRM_FinalText;
365 break;
366 default:
367 break;
368 }
369 return sRoadmapItem;
370 }
371
372 //-------------------------------------------------------------------------
~ODbTypeWizDialogSetup()373 ODbTypeWizDialogSetup::~ODbTypeWizDialogSetup()
374 {
375 delete m_pOutSet;
376 DBG_DTOR(ODbTypeWizDialogSetup,NULL);
377 }
378
379 //-------------------------------------------------------------------------
380 IMPL_LINK(ODbTypeWizDialogSetup, OnTypeSelected, OGeneralPage*, /*_pTabPage*/)
381 {
382 activateDatabasePath();
383 return 1L;
384 }
385
lcl_removeUnused(const::comphelper::NamedValueCollection & _aOld,const::comphelper::NamedValueCollection & _aNew,::comphelper::NamedValueCollection & _rDSInfo)386 void lcl_removeUnused(const ::comphelper::NamedValueCollection& _aOld,const ::comphelper::NamedValueCollection& _aNew,::comphelper::NamedValueCollection& _rDSInfo)
387 {
388 _rDSInfo.merge(_aNew,true);
389 uno::Sequence< beans::NamedValue > aOldValues = _aOld.getNamedValues();
390 const beans::NamedValue* pIter = aOldValues.getConstArray();
391 const beans::NamedValue* pEnd = pIter + aOldValues.getLength();
392 for(;pIter != pEnd;++pIter)
393 {
394 if ( !_aNew.has(pIter->Name) )
395 {
396 _rDSInfo.remove(pIter->Name);
397 }
398 }
399 }
400 // -----------------------------------------------------------------------------
convert(const::dbaccess::ODsnTypeCollection * _pCollection,const::rtl::OUString & _sOldURLPrefix,const::rtl::OUString & _sNewURLPrefix,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> & _xDatasource)401 void DataSourceInfoConverter::convert(const ::dbaccess::ODsnTypeCollection* _pCollection,const ::rtl::OUString& _sOldURLPrefix,const ::rtl::OUString& _sNewURLPrefix,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xDatasource)
402 {
403 if ( _pCollection->getPrefix(_sOldURLPrefix) == _pCollection->getPrefix(_sNewURLPrefix) )
404 return ;
405 uno::Sequence< beans::PropertyValue> aInfo;
406 _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
407 ::comphelper::NamedValueCollection aDS(aInfo);
408
409 ::connectivity::DriversConfig aDriverConfig(m_xFactory);
410
411 const ::comphelper::NamedValueCollection& aOldProperties = aDriverConfig.getProperties(_sOldURLPrefix);
412 const ::comphelper::NamedValueCollection& aNewProperties = aDriverConfig.getProperties(_sNewURLPrefix);
413 lcl_removeUnused(aOldProperties,aNewProperties,aDS);
414
415 aDS >>= aInfo;
416 _xDatasource->setPropertyValue(PROPERTY_INFO,uno::makeAny(aInfo));
417 }
418 //-------------------------------------------------------------------------
activateDatabasePath()419 void ODbTypeWizDialogSetup::activateDatabasePath()
420 {
421 switch ( m_pGeneralPage->GetDatabaseCreationMode() )
422 {
423 case OGeneralPage::eCreateNew:
424 {
425 sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( m_pCollection->getEmbeddedDatabase() );
426 if ( nCreateNewDBIndex == -1 )
427 nCreateNewDBIndex = m_pCollection->getIndexOf( ::rtl::OUString::createFromAscii( "sdbc:dbase:" ) );
428 OSL_ENSURE( nCreateNewDBIndex != -1, "ODbTypeWizDialogSetup::activateDatabasePath: the GeneralPage should have prevented this!" );
429 activatePath( static_cast< PathId >( nCreateNewDBIndex + 1 ), sal_True );
430
431 enableState(PAGE_DBSETUPWIZARD_FINAL, sal_True );
432 enableButtons( WZB_FINISH, sal_True);
433 }
434 break;
435 case OGeneralPage::eConnectExternal:
436 {
437 ::rtl::OUString sOld = m_sURL;
438 DataSourceInfoConverter aConverter(getORB());
439 m_sURL = m_pGeneralPage->GetSelectedType();
440 aConverter.convert(m_pCollection,sOld,m_sURL,m_pImpl->getCurrentDataSource());
441 ::dbaccess::DATASOURCE_TYPE eType = VerifyDataSourceType(m_pCollection->determineType(m_sURL));
442 if (eType == ::dbaccess::DST_UNKNOWN)
443 eType = m_pCollection->determineType(m_sOldURL);
444
445 activatePath( static_cast<PathId>(m_pCollection->getIndexOf(m_sURL) + 1), sal_True);
446 updateTypeDependentStates();
447 }
448 break;
449 case OGeneralPage::eOpenExisting:
450 {
451 activatePath( static_cast<PathId>(m_pCollection->size() + 1), sal_True );
452 enableButtons( WZB_FINISH, m_pGeneralPage->GetSelectedDocument().sURL.Len() != 0 );
453 }
454 break;
455 default:
456 DBG_ERROR( "ODbTypeWizDialogSetup::activateDatabasePath: unknown creation mode!" );
457 }
458
459 enableButtons( WZB_NEXT, m_pGeneralPage->GetDatabaseCreationMode() != OGeneralPage::eOpenExisting );
460 // TODO: this should go into the base class. Point is, we activate a path whose *last*
461 // step is also the current one. The base class should automatically disable
462 // the Next button in such a case. However, not for this patch ...
463 }
464
465 //-------------------------------------------------------------------------
updateTypeDependentStates()466 void ODbTypeWizDialogSetup::updateTypeDependentStates()
467 {
468 sal_Bool bDoEnable = sal_False;
469 sal_Bool bIsConnectionRequired = IsConnectionUrlRequired();
470 if (!bIsConnectionRequired)
471 {
472 bDoEnable = sal_True;
473 }
474 else if ( m_sURL == m_sOldURL )
475 {
476 bDoEnable = m_bIsConnectable;
477 }
478 enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, bDoEnable);
479 enableState(PAGE_DBSETUPWIZARD_FINAL, bDoEnable );
480 enableButtons( WZB_FINISH, bDoEnable);
481 }
482
483
484 //-------------------------------------------------------------------------
IsConnectionUrlRequired()485 sal_Bool ODbTypeWizDialogSetup::IsConnectionUrlRequired()
486 {
487 return m_pCollection->isConnectionUrlRequired(m_sURL);
488 }
489
490 //-------------------------------------------------------------------------
resetPages(const Reference<XPropertySet> & _rxDatasource)491 void ODbTypeWizDialogSetup::resetPages(const Reference< XPropertySet >& _rxDatasource)
492 {
493 // remove all items which relate to indirect properties from the input set
494 // (without this, the following may happen: select an arbitrary data source where some indirect properties
495 // are set. Select another data source of the same type, where the indirect props are not set (yet). Then,
496 // the indirect property values of the first ds are shown in the second ds ...)
497 const ODbDataSourceAdministrationHelper::MapInt2String& rMap = m_pImpl->getIndirectProperties();
498 for ( ODbDataSourceAdministrationHelper::ConstMapInt2StringIterator aIndirect = rMap.begin();
499 aIndirect != rMap.end();
500 ++aIndirect
501 )
502 getWriteOutputSet()->ClearItem( (sal_uInt16)aIndirect->first );
503
504 // extract all relevant data from the property set of the data source
505 m_pImpl->translateProperties(_rxDatasource, *getWriteOutputSet());
506 }
507 // -----------------------------------------------------------------------------
getOutputSet() const508 const SfxItemSet* ODbTypeWizDialogSetup::getOutputSet() const
509 {
510 return m_pOutSet;
511 }
512 // -----------------------------------------------------------------------------
getWriteOutputSet()513 SfxItemSet* ODbTypeWizDialogSetup::getWriteOutputSet()
514 {
515 return m_pOutSet;
516 }
517 // -----------------------------------------------------------------------------
createConnection()518 ::std::pair< Reference<XConnection>,sal_Bool> ODbTypeWizDialogSetup::createConnection()
519 {
520 return m_pImpl->createConnection();
521 }
522 // -----------------------------------------------------------------------------
getORB() const523 Reference< XMultiServiceFactory > ODbTypeWizDialogSetup::getORB() const
524 {
525 return m_pImpl->getORB();
526 }
527 // -----------------------------------------------------------------------------
getDriver()528 Reference< XDriver > ODbTypeWizDialogSetup::getDriver()
529 {
530 return m_pImpl->getDriver();
531 }
532
533
VerifyDataSourceType(const::dbaccess::DATASOURCE_TYPE _DatabaseType) const534 ::dbaccess::DATASOURCE_TYPE ODbTypeWizDialogSetup::VerifyDataSourceType(const ::dbaccess::DATASOURCE_TYPE _DatabaseType) const
535 {
536 ::dbaccess::DATASOURCE_TYPE LocDatabaseType = _DatabaseType;
537 if ((LocDatabaseType == ::dbaccess::DST_MYSQL_JDBC) || (LocDatabaseType == ::dbaccess::DST_MYSQL_ODBC) || (LocDatabaseType == ::dbaccess::DST_MYSQL_NATIVE))
538 {
539 if (m_pMySQLIntroPage != NULL)
540 {
541 switch( m_pMySQLIntroPage->getMySQLMode() )
542 {
543 case OMySQLIntroPageSetup::VIA_JDBC:
544 return ::dbaccess::DST_MYSQL_JDBC;
545 case OMySQLIntroPageSetup::VIA_NATIVE:
546 return ::dbaccess::DST_MYSQL_NATIVE;
547 case OMySQLIntroPageSetup::VIA_ODBC:
548 return ::dbaccess::DST_MYSQL_ODBC;
549 }
550 }
551 }
552 return LocDatabaseType;
553 }
554
555
556
557 // -----------------------------------------------------------------------------
getDatasourceType(const SfxItemSet & _rSet) const558 ::rtl::OUString ODbTypeWizDialogSetup::getDatasourceType(const SfxItemSet& _rSet) const
559 {
560 ::rtl::OUString sRet = m_pImpl->getDatasourceType(_rSet);
561 if (m_pMySQLIntroPage != NULL && m_pMySQLIntroPage->IsVisible() )
562 {
563 switch( m_pMySQLIntroPage->getMySQLMode() )
564 {
565 case OMySQLIntroPageSetup::VIA_JDBC:
566 sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:"));
567 break;
568 case OMySQLIntroPageSetup::VIA_NATIVE:
569 sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:"));
570 break;
571 case OMySQLIntroPageSetup::VIA_ODBC:
572 sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:"));
573 break;
574 }
575 }
576 return sRet;
577 }
578
579 // -----------------------------------------------------------------------------
clearPassword()580 void ODbTypeWizDialogSetup::clearPassword()
581 {
582 m_pImpl->clearPassword();
583 }
584
585 // -----------------------------------------------------------------------------
createPage(WizardState _nState)586 TabPage* ODbTypeWizDialogSetup::createPage(WizardState _nState)
587 {
588 SfxTabPage* pFirstPage;
589 OGenericAdministrationPage* pPage = NULL;
590 switch(_nState)
591 {
592 case PAGE_DBSETUPWIZARD_INTRO:
593 pFirstPage = OGeneralPage::Create(this,*m_pOutSet, sal_True);
594 pPage = static_cast<OGenericAdministrationPage*> (pFirstPage);
595 m_pGeneralPage = static_cast<OGeneralPage*>(pFirstPage);
596 m_pGeneralPage->SetTypeSelectHandler(LINK(this, ODbTypeWizDialogSetup, OnTypeSelected));
597 m_pGeneralPage->SetCreationModeHandler(LINK( this, ODbTypeWizDialogSetup, OnChangeCreationMode ) );
598 m_pGeneralPage->SetDocumentSelectionHandler(LINK( this, ODbTypeWizDialogSetup, OnRecentDocumentSelected ) );
599 m_pGeneralPage->SetChooseDocumentHandler(LINK( this, ODbTypeWizDialogSetup, OnSingleDocumentChosen ) );
600 break;
601
602 case PAGE_DBSETUPWIZARD_DBASE:
603 pPage = OConnectionTabPageSetup::CreateDbaseTabPage(this,*m_pOutSet);
604 break;
605
606 case PAGE_DBSETUPWIZARD_ADO:
607 pPage = OConnectionTabPageSetup::CreateADOTabPage( this, *m_pOutSet);
608 break;
609
610 case PAGE_DBSETUPWIZARD_TEXT:
611 pPage = OTextConnectionPageSetup::CreateTextTabPage(this,*m_pOutSet);
612 break;
613
614 case PAGE_DBSETUPWIZARD_ODBC:
615 pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet);
616 break;
617
618 case PAGE_DBSETUPWIZARD_JDBC:
619 pPage = OJDBCConnectionPageSetup::CreateJDBCTabPage( this, *m_pOutSet);
620 break;
621
622 case PAGE_DBSETUPWIZARD_MYSQL_ODBC:
623 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:")))));
624 pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet);
625 break;
626
627 case PAGE_DBSETUPWIZARD_MYSQL_JDBC:
628 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:")))));
629 pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateMySQLJDBCTabPage( this, *m_pOutSet);
630 break;
631 case PAGE_DBSETUPWIZARD_MYSQL_NATIVE:
632 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:")))));
633 pPage = MySQLNativeSetupPage::Create( this, *m_pOutSet);
634 break;
635
636 case PAGE_DBSETUPWIZARD_ORACLE:
637 pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateOracleJDBCTabPage( this, *m_pOutSet);
638 break;
639
640 case PAGE_DBSETUPWIZARD_ADABAS:
641 pPage = OConnectionTabPageSetup::CreateAdabasTabPage( this, *m_pOutSet);
642 break;
643
644 case PAGE_DBSETUPWIZARD_LDAP :
645 pPage = OLDAPConnectionPageSetup::CreateLDAPTabPage(this,*m_pOutSet);
646 break;
647
648 case PAGE_DBSETUPWIZARD_SPREADSHEET: /// first user defined driver
649 pPage = OSpreadSheetConnectionPageSetup::CreateSpreadSheetTabPage(this,*m_pOutSet);
650 break;
651
652 case PAGE_DBSETUPWIZARD_MSACCESS:
653 pPage = OConnectionTabPageSetup::CreateMSAccessTabPage(this,*m_pOutSet);
654 break;
655 case PAGE_DBSETUPWIZARD_MYSQL_INTRO:
656 m_pMySQLIntroPage = OMySQLIntroPageSetup::CreateMySQLIntroTabPage(this,*m_pOutSet);
657 m_pMySQLIntroPage->SetClickHdl(LINK( this, ODbTypeWizDialogSetup, ImplClickHdl ) );
658 pPage = m_pMySQLIntroPage;
659 break;
660
661 case PAGE_DBSETUPWIZARD_AUTHENTIFICATION:
662 pPage = OAuthentificationPageSetup::CreateAuthentificationTabPage(this,*m_pOutSet);
663 break;
664
665 case PAGE_DBSETUPWIZARD_USERDEFINED:
666 pPage = OConnectionTabPageSetup::CreateUserDefinedTabPage(this,*m_pOutSet);
667 break;
668
669 case PAGE_DBSETUPWIZARD_FINAL:
670 pPage = OFinalDBPageSetup::CreateFinalDBTabPageSetup(this,*m_pOutSet);
671 pFinalPage = static_cast<OFinalDBPageSetup*> (pPage);
672 break;
673 }
674
675 if ((_nState != PAGE_DBSETUPWIZARD_INTRO) && (_nState != PAGE_DBSETUPWIZARD_AUTHENTIFICATION))
676 {
677 pPage->SetModifiedHandler(LINK( this, ODbTypeWizDialogSetup, ImplModifiedHdl ) );
678 }
679
680 if ( pPage )
681 {
682 pPage->SetServiceFactory(m_pImpl->getORB());
683 pPage->SetAdminDialog(this, this);
684
685 defaultButton( _nState == PAGE_DBSETUPWIZARD_FINAL ? WZB_FINISH : WZB_NEXT );
686 enableButtons( WZB_FINISH, _nState == PAGE_DBSETUPWIZARD_FINAL );
687 enableButtons( WZB_NEXT, _nState == PAGE_DBSETUPWIZARD_FINAL ? sal_False : sal_True);
688 pPage->Show();
689 }
690 return pPage;
691 }
692
693
IMPL_LINK(ODbTypeWizDialogSetup,ImplModifiedHdl,OGenericAdministrationPage *,_pConnectionPageSetup)694 IMPL_LINK(ODbTypeWizDialogSetup, ImplModifiedHdl, OGenericAdministrationPage*, _pConnectionPageSetup)
695 {
696 m_bIsConnectable = _pConnectionPageSetup->GetRoadmapStateValue( );
697 enableState(PAGE_DBSETUPWIZARD_FINAL, m_bIsConnectable);
698 enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, m_bIsConnectable);
699 if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL)
700 enableButtons( WZB_FINISH, sal_True);
701 else
702 enableButtons( WZB_FINISH, m_bIsConnectable);
703 enableButtons( WZB_NEXT, m_bIsConnectable && (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL));
704 return sal_True;
705 }
706
707
708 // -----------------------------------------------------------------------------
IMPL_LINK(ODbTypeWizDialogSetup,ImplClickHdl,OMySQLIntroPageSetup *,_pMySQLIntroPageSetup)709 IMPL_LINK(ODbTypeWizDialogSetup, ImplClickHdl, OMySQLIntroPageSetup*, _pMySQLIntroPageSetup)
710 {
711 ::rtl::OUString sURLPrefix;
712 switch( _pMySQLIntroPageSetup->getMySQLMode() )
713 {
714 case OMySQLIntroPageSetup::VIA_ODBC:
715 sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:"));
716 break;
717 case OMySQLIntroPageSetup::VIA_JDBC:
718 sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:"));
719 break;
720 case OMySQLIntroPageSetup::VIA_NATIVE:
721 sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:"));
722 break;
723 } // switch( _pMySQLIntroPageSetup->getMySQLMode() )
724 activatePath( static_cast<PathId>(m_pCollection->getIndexOf(sURLPrefix) + 1), sal_True);
725 return sal_True;
726 }
727
728 // -----------------------------------------------------------------------------
729 IMPL_LINK(ODbTypeWizDialogSetup, OnChangeCreationMode, OGeneralPage*, /*_pGeneralPage*/)
730 {
731 activateDatabasePath();
732 return sal_True;
733 }
734
735 // -----------------------------------------------------------------------------
736 IMPL_LINK(ODbTypeWizDialogSetup, OnRecentDocumentSelected, OGeneralPage*, /*_pGeneralPage*/)
737 {
738 enableButtons( WZB_FINISH, m_pGeneralPage->GetSelectedDocument().sURL.Len() != 0 );
739 return 0L;
740 }
741
742 // -----------------------------------------------------------------------------
743 IMPL_LINK(ODbTypeWizDialogSetup, OnSingleDocumentChosen, OGeneralPage*, /*_pGeneralPage*/)
744 {
745 if ( prepareLeaveCurrentState( eFinish ) )
746 onFinish();
747 return 0L;
748 }
749
750 // -----------------------------------------------------------------------------
enterState(WizardState _nState)751 void ODbTypeWizDialogSetup::enterState(WizardState _nState)
752 {
753 m_sURL = m_pImpl->getDatasourceType(*m_pOutSet);
754 RoadmapWizard::enterState(_nState);
755 switch(_nState)
756 {
757 case PAGE_DBSETUPWIZARD_INTRO:
758 m_sOldURL = m_sURL;
759 break;
760 case PAGE_DBSETUPWIZARD_FINAL:
761 enableButtons( WZB_FINISH, sal_True);
762 if ( pFinalPage )
763 pFinalPage->enableTableWizardCheckBox(m_pCollection->supportsTableCreation(m_sURL));
764 break;
765 }
766 }
767
768 //-------------------------------------------------------------------------
saveDatasource()769 sal_Bool ODbTypeWizDialogSetup::saveDatasource()
770 {
771 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(getCurrentState()));
772 if ( pPage )
773 pPage->FillItemSet(*m_pOutSet);
774 return sal_True;
775 }
776
777
778 // -----------------------------------------------------------------------------
leaveState(WizardState _nState)779 sal_Bool ODbTypeWizDialogSetup::leaveState(WizardState _nState)
780 {
781 if (_nState == PAGE_DBSETUPWIZARD_MYSQL_INTRO)
782 return sal_True;
783 if ( _nState == PAGE_DBSETUPWIZARD_INTRO && m_sURL != m_sOldURL )
784 {
785 resetPages(m_pImpl->getCurrentDataSource());
786 }
787 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState));
788 return pPage && pPage->DeactivatePage(m_pOutSet) != 0;
789 }
790
791 // -----------------------------------------------------------------------------
setTitle(const::rtl::OUString &)792 void ODbTypeWizDialogSetup::setTitle(const ::rtl::OUString& /*_sTitle*/)
793 {
794 DBG_ERROR( "ODbTypeWizDialogSetup::setTitle: not implemented!" );
795 // why?
796 }
797
798 //-------------------------------------------------------------------------
enableConfirmSettings(bool _bEnable)799 void ODbTypeWizDialogSetup::enableConfirmSettings( bool _bEnable )
800 {
801 (void)_bEnable;
802 }
803
804 //-------------------------------------------------------------------------
805 namespace
806 {
lcl_handle(const Reference<XInteractionHandler2> & _rxHandler,const Any & _rRequest)807 bool lcl_handle( const Reference< XInteractionHandler2 >& _rxHandler, const Any& _rRequest )
808 {
809 OInteractionRequest* pRequest = new OInteractionRequest( _rRequest );
810 Reference < XInteractionRequest > xRequest( pRequest );
811 OInteractionAbort* pAbort = new OInteractionAbort;
812 pRequest->addContinuation( pAbort );
813
814 return _rxHandler->handleInteractionRequest( xRequest );
815 }
816 }
817
818 //-------------------------------------------------------------------------
SaveDatabaseDocument()819 sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument()
820 {
821 Reference< XInteractionHandler2 > xHandler( getORB()->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY );
822 try
823 {
824 if (callSaveAsDialog() == sal_True)
825 {
826 m_pImpl->saveChanges(*m_pOutSet);
827 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
828 Reference< XModel > xModel( getDataSourceOrModel( xDatasource ), UNO_QUERY_THROW );
829 Reference< XStorable > xStore( xModel, UNO_QUERY_THROW );
830
831 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eCreateNew )
832 CreateDatabase();
833
834 ::comphelper::NamedValueCollection aArgs( xModel->getArgs() );
835 aArgs.put( "Overwrite", sal_Bool( sal_True ) );
836 aArgs.put( "InteractionHandler", xHandler );
837 aArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
838
839 ::rtl::OUString sPath = m_pImpl->getDocumentUrl( *m_pOutSet );
840 xStore->storeAsURL( sPath, aArgs.getPropertyValues() );
841
842 if ( !pFinalPage || pFinalPage->IsDatabaseDocumentToBeRegistered() )
843 RegisterDataSourceByLocation( sPath );
844
845 return sal_True;
846 }
847 }
848 catch ( const Exception& e )
849 {
850 Any aError = ::cppu::getCaughtException();
851 if ( xHandler.is() )
852 {
853 if ( !lcl_handle( xHandler, aError ) )
854 {
855 InteractiveIOException aRequest;
856 aRequest.Classification = InteractionClassification_ERROR;
857 if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) )
858 // assume savint the document faile
859 aRequest.Code = IOErrorCode_CANT_WRITE;
860 else
861 aRequest.Code = IOErrorCode_GENERAL;
862 aRequest.Message = e.Message;
863 aRequest.Context = e.Context;
864 lcl_handle( xHandler, makeAny( aRequest ) );
865 }
866 }
867 }
868 return sal_False;
869 }
870 // ------------------------------------------------------------------------
IsDatabaseDocumentToBeOpened() const871 sal_Bool ODbTypeWizDialogSetup::IsDatabaseDocumentToBeOpened() const
872 {
873 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
874 return sal_True;
875
876 if ( pFinalPage != NULL )
877 return pFinalPage->IsDatabaseDocumentToBeOpened();
878
879 return sal_True;
880 }
881
882 // ------------------------------------------------------------------------
IsTableWizardToBeStarted() const883 sal_Bool ODbTypeWizDialogSetup::IsTableWizardToBeStarted() const
884 {
885 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
886 return sal_False;
887
888 if ( pFinalPage != NULL )
889 return pFinalPage->IsTableWizardToBeStarted();
890
891 return sal_False;
892 }
893
894 //-------------------------------------------------------------------------
getDefaultDatabaseType() const895 ::rtl::OUString ODbTypeWizDialogSetup::getDefaultDatabaseType() const
896 {
897 ::rtl::OUString sEmbeddedURL = m_pCollection->getEmbeddedDatabase();
898 ::connectivity::DriversConfig aDriverConfig(getORB());
899 try
900 {
901 if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() || !m_pImpl->getDriver(sEmbeddedURL).is() )
902 sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:"));
903 }
904 catch(const Exception&)
905 {
906 sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:"));
907 }
908
909 return sEmbeddedURL;
910 }
911
912 //-------------------------------------------------------------------------
CreateDatabase()913 void ODbTypeWizDialogSetup::CreateDatabase()
914 {
915 ::rtl::OUString sUrl;
916 ::rtl::OUString eType = getDefaultDatabaseType();
917 if ( m_pCollection->isEmbeddedDatabase(eType) )
918 {
919 sUrl = eType;
920 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
921 OSL_ENSURE(xDatasource.is(),"DataSource is null!");
922 if ( xDatasource.is() )
923 xDatasource->setPropertyValue( PROPERTY_INFO, makeAny( m_pCollection->getDefaultDBSettings( eType ) ) );
924 m_pImpl->translateProperties(xDatasource,*m_pOutSet);
925 }
926 else if ( m_pCollection->isFileSystemBased(eType) )
927 {
928 Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
929 INetURLObject aDBPathURL(m_sWorkPath);
930 aDBPathURL.Append(m_aDocURL.getBase());
931 createUniqueFolderName(&aDBPathURL);
932 ::rtl::OUString sPrefix = eType;
933 sUrl = aDBPathURL.GetMainURL( INetURLObject::NO_DECODE);
934 xSimpleFileAccess->createFolder(sUrl);
935 //OFileNotation aFileNotation(sUrl);
936 //sUrl = aFileNotation.get(OFileNotation::N_SYSTEM);
937 sUrl = sPrefix.concat(sUrl);
938 }
939 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, sUrl));
940 m_pImpl->saveChanges(*m_pOutSet);
941 }
942
943 //-------------------------------------------------------------------------
RegisterDataSourceByLocation(const::rtl::OUString & _sPath)944 void ODbTypeWizDialogSetup::RegisterDataSourceByLocation(const ::rtl::OUString& _sPath)
945 {
946 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
947 Reference< XNamingService > xDatabaseContext(getORB()->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
948 Reference< XNameAccess > xNameAccessDatabaseContext(xDatabaseContext, UNO_QUERY);
949 INetURLObject aURL( _sPath );
950 ::rtl::OUString sFilename = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
951 ::rtl::OUString sDatabaseName = ::dbtools::createUniqueName(xNameAccessDatabaseContext, sFilename,sal_False);
952 xDatabaseContext->registerObject(sDatabaseName, xDatasource);
953 }
954
955
956 //-------------------------------------------------------------------------
callSaveAsDialog()957 sal_Bool ODbTypeWizDialogSetup::callSaveAsDialog()
958 {
959 sal_Bool bRet = sal_False;
960 WinBits nBits(WB_STDMODAL|WB_SAVEAS);
961 ::sfx2::FileDialogHelper aFileDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION, static_cast<sal_uInt32>(nBits), this);
962 const SfxFilter* pFilter = getStandardDatabaseFilter();
963 if ( pFilter )
964 {
965 INetURLObject aWorkURL( m_sWorkPath );
966 aFileDlg.SetDisplayFolder( aWorkURL.GetMainURL( INetURLObject::NO_DECODE ));
967
968 ::rtl::OUString sDefaultName = String( ModuleRes( STR_DATABASEDEFAULTNAME ) );
969 ::rtl::OUString sExtension = pFilter->GetDefaultExtension();
970 sDefaultName += sExtension.replaceAt( 0, 1, ::rtl::OUString() );
971 aWorkURL.Append( sDefaultName );
972 sDefaultName = createUniqueFileName( aWorkURL );
973 aFileDlg.SetFileName( sDefaultName );
974
975 aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
976 aFileDlg.SetCurrentFilter(pFilter->GetUIName());
977 }
978 if ( aFileDlg.Execute() == ERRCODE_NONE )
979 {
980 m_aDocURL = INetURLObject(aFileDlg.GetPath());
981
982 if( m_aDocURL.GetProtocol() != INET_PROT_NOT_VALID )
983 {
984 ::rtl::OUString sFileName = m_aDocURL.GetMainURL( INetURLObject::NO_DECODE );
985 if ( ::utl::UCBContentHelper::IsDocument(sFileName) )
986 ::utl::UCBContentHelper::Kill(sFileName);
987 m_pOutSet->Put(SfxStringItem(DSID_DOCUMENT_URL, sFileName));
988 bRet = sal_True;
989 }
990 }
991 return bRet;
992 }
993
994 //-------------------------------------------------------------------------
createUniqueFolderName(INetURLObject * pURL)995 void ODbTypeWizDialogSetup::createUniqueFolderName(INetURLObject* pURL)
996 {
997 Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
998 :: rtl::OUString sLastSegmentName = pURL->getName();
999 sal_Bool bFolderExists = sal_True;
1000 sal_Int32 i = 1;
1001 while (bFolderExists == sal_True)
1002 {
1003 bFolderExists = xSimpleFileAccess->isFolder(pURL->GetMainURL( INetURLObject::NO_DECODE ));
1004 if (bFolderExists == sal_True)
1005 {
1006 i++;
1007 pURL->setName(sLastSegmentName.concat(::rtl::OUString::valueOf(i)));
1008 }
1009 }
1010 }
1011
1012 //-------------------------------------------------------------------------
createUniqueFileName(const INetURLObject & _rURL)1013 String ODbTypeWizDialogSetup::createUniqueFileName(const INetURLObject& _rURL)
1014 {
1015 Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
1016 :: rtl::OUString sFilename = _rURL.getName();
1017 ::rtl::OUString BaseName = _rURL.getBase();
1018 ::rtl::OUString sExtension = _rURL.getExtension();
1019
1020 sal_Bool bElementExists = sal_True;
1021
1022 INetURLObject aExistenceCheck( _rURL );
1023 for ( sal_Int32 i = 1; bElementExists; )
1024 {
1025 bElementExists = xSimpleFileAccess->exists( aExistenceCheck.GetMainURL( INetURLObject::NO_DECODE ) );
1026 if ( bElementExists )
1027 {
1028 aExistenceCheck.setBase( BaseName.concat( ::rtl::OUString::valueOf( i ) ) );
1029 ++i;
1030 }
1031 }
1032 return aExistenceCheck.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1033 }
1034 // -----------------------------------------------------------------------------
getPageController(TabPage * _pCurrentPage) const1035 IWizardPageController* ODbTypeWizDialogSetup::getPageController( TabPage* _pCurrentPage ) const
1036 {
1037 OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage);
1038 return pPage;
1039 }
1040
1041 // -----------------------------------------------------------------------------
1042 namespace
1043 {
1044 // .............................................................................
1045 typedef ::cppu::WeakImplHelper1 < XTerminateListener
1046 > AsyncLoader_Base;
1047 class AsyncLoader : public AsyncLoader_Base
1048 {
1049 private:
1050 Reference< XComponentLoader > m_xFrameLoader;
1051 Reference< XDesktop > m_xDesktop;
1052 Reference< XInteractionHandler > m_xInteractionHandler;
1053 ::rtl::OUString m_sURL;
1054 OAsyncronousLink m_aAsyncCaller;
1055
1056 public:
1057 AsyncLoader( const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rURL );
1058
1059 void doLoadAsync();
1060
1061 // XTerminateListener
1062 virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (TerminationVetoException, RuntimeException);
1063 virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (RuntimeException);
1064 // XEventListener
1065 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
1066
1067 private:
1068 DECL_LINK( OnOpenDocument, void* );
1069 };
1070
1071 // .............................................................................
AsyncLoader(const Reference<XMultiServiceFactory> & _rxORB,const::rtl::OUString & _rURL)1072 AsyncLoader::AsyncLoader( const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rURL )
1073 :m_sURL( _rURL )
1074 ,m_aAsyncCaller( LINK( this, AsyncLoader, OnOpenDocument ) )
1075 {
1076 try
1077 {
1078 m_xDesktop.set( _rxORB->createInstance( SERVICE_FRAME_DESKTOP ), UNO_QUERY_THROW );
1079 m_xFrameLoader.set( m_xDesktop, UNO_QUERY_THROW );
1080 m_xInteractionHandler.set(
1081 _rxORB->createInstance(
1082 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) )
1083 ),
1084 UNO_QUERY_THROW );
1085 }
1086 catch( const Exception& )
1087 {
1088 DBG_UNHANDLED_EXCEPTION();
1089 }
1090 }
1091
1092 // .............................................................................
doLoadAsync()1093 void AsyncLoader::doLoadAsync()
1094 {
1095 OSL_ENSURE( !m_aAsyncCaller.IsRunning(), "AsyncLoader:doLoadAsync: already running!" );
1096
1097 acquire();
1098 try
1099 {
1100 if ( m_xDesktop.is() )
1101 m_xDesktop->addTerminateListener( this );
1102 }
1103 catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
1104
1105 m_aAsyncCaller.Call( NULL );
1106 }
1107
1108 // .............................................................................
1109 IMPL_LINK( AsyncLoader, OnOpenDocument, void*, /*_pEmptyArg*/ )
1110 {
1111 try
1112 {
1113 if ( m_xFrameLoader.is() )
1114 {
1115 ::comphelper::NamedValueCollection aLoadArgs;
1116 aLoadArgs.put( "InteractionHandler", m_xInteractionHandler );
1117 aLoadArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
1118
1119 Sequence< PropertyValue > aLoadArgPV;
1120 aLoadArgs >>= aLoadArgPV;
1121
1122 m_xFrameLoader->loadComponentFromURL( m_sURL,
1123 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ),
1124 FrameSearchFlag::ALL,
1125 aLoadArgPV
1126 );
1127 }
1128 }
1129 catch( const Exception& )
1130 {
1131 // do not assert.
1132 // Such an exception happens for instance of the to-be-loaded document does not exist anymore.
1133 }
1134
1135 try
1136 {
1137 if ( m_xDesktop.is() )
1138 m_xDesktop->removeTerminateListener( this );
1139 }
1140 catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
1141
1142 release();
1143 return 0L;
1144 }
1145
1146 // .............................................................................
queryTermination(const::com::sun::star::lang::EventObject &)1147 void SAL_CALL AsyncLoader::queryTermination( const ::com::sun::star::lang::EventObject& /*Event*/ ) throw (TerminationVetoException, RuntimeException)
1148 {
1149 throw TerminationVetoException();
1150 }
1151
1152 // .............................................................................
notifyTermination(const::com::sun::star::lang::EventObject &)1153 void SAL_CALL AsyncLoader::notifyTermination( const ::com::sun::star::lang::EventObject& /*Event*/ ) throw (RuntimeException)
1154 {
1155 }
1156 // .............................................................................
disposing(const::com::sun::star::lang::EventObject &)1157 void SAL_CALL AsyncLoader::disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw (RuntimeException)
1158 {
1159 }
1160 }
1161
1162 // -----------------------------------------------------------------------------
onFinish()1163 sal_Bool ODbTypeWizDialogSetup::onFinish()
1164 {
1165 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
1166 {
1167 // we're not going to re-use the XModel we have - since the document the user
1168 // wants us to load could be a non-database document. Instead, we asynchronously
1169 // open the selected document. Thus, the wizard's return value is RET_CANCEL,
1170 // which means to not continue loading the database document
1171 if ( !OWizardMachine::Finnish( RET_CANCEL ) )
1172 return sal_False;
1173
1174 Reference< XComponentLoader > xFrameLoader;
1175 try
1176 {
1177 AsyncLoader* pAsyncLoader = new AsyncLoader( getORB(), m_pGeneralPage->GetSelectedDocument().sURL );
1178 ::rtl::Reference< AsyncLoader > xKeepAlive( pAsyncLoader );
1179 pAsyncLoader->doLoadAsync();
1180 }
1181 catch( const Exception& )
1182 {
1183 DBG_UNHANDLED_EXCEPTION();
1184 }
1185
1186 return sal_True;
1187 }
1188
1189 if (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL)
1190 {
1191 skipUntil(PAGE_DBSETUPWIZARD_FINAL);
1192 }
1193 if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL)
1194 return SaveDatabaseDocument() ? OWizardMachine::onFinish() : sal_False;
1195 else
1196 {
1197 enableButtons( WZB_FINISH, sal_False );
1198 return sal_False;
1199 }
1200 }
1201
1202 //.........................................................................
1203 } // namespace dbaui
1204 //.........................................................................
1205
1206