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