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