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 "dbwiz.hxx"
22 : #include "dbadmin.hrc"
23 : #include "dbu_dlg.hrc"
24 : #include "dsitems.hxx"
25 : #include "dsnItem.hxx"
26 : #include <svl/stritem.hxx>
27 : #include <svl/eitem.hxx>
28 : #include <svl/intitem.hxx>
29 : #include <vcl/msgbox.hxx>
30 : #include "dbustrings.hrc"
31 : #include "adminpages.hxx"
32 : #include "generalpage.hxx"
33 : #include "localresaccess.hxx"
34 : #include "stringlistitem.hxx"
35 : #include "propertysetitem.hxx"
36 : #include <unotools/confignode.hxx>
37 : #include "ConnectionPage.hxx"
38 : #include "DriverSettings.hxx"
39 : #include "DbAdminImpl.hxx"
40 : #include "dbaccess_helpid.hrc"
41 :
42 : //.........................................................................
43 : namespace dbaui
44 : {
45 : //.........................................................................
46 : using namespace svt;
47 : using namespace com::sun::star::uno;
48 : using namespace com::sun::star::sdbc;
49 : using namespace com::sun::star::lang;
50 : using namespace com::sun::star::util;
51 : using namespace com::sun::star::beans;
52 : using namespace com::sun::star::container;
53 :
54 : #define START_PAGE 0
55 : #define CONNECTION_PAGE 1
56 : #define ADDITIONAL_PAGE_DBASE 2
57 : #define ADDITIONAL_PAGE_FLAT 3
58 : #define ADDITIONAL_PAGE_LDAP 4
59 : //5 was ADDITIONAL_PAGE_ADABAS
60 : #define ADDITIONAL_PAGE_MYSQL_JDBC 6
61 : #define ADDITIONAL_PAGE_MYSQL_ODBC 7
62 : #define ADDITIONAL_PAGE_ORACLE_JDBC 8
63 : #define ADDITIONAL_PAGE_ADO 9
64 : #define ADDITIONAL_PAGE_ODBC 10
65 : #define ADDITIONAL_USERDEFINED 11
66 : #define ADDITIONAL_PAGE_MYSQL_NATIVE 12
67 :
68 :
69 : DBG_NAME(ODbTypeWizDialog)
70 : //=========================================================================
71 : //= ODbTypeWizDialog
72 : //=========================================================================
73 : //-------------------------------------------------------------------------
74 0 : ODbTypeWizDialog::ODbTypeWizDialog(Window* _pParent
75 : ,SfxItemSet* _pItems
76 : ,const Reference< XMultiServiceFactory >& _rxORB
77 : ,const ::com::sun::star::uno::Any& _aDataSourceName
78 : )
79 : :OWizardMachine(_pParent, ModuleRes(DLG_DATABASE_TYPE_CHANGE), WZB_NEXT | WZB_PREVIOUS | WZB_FINISH | WZB_CANCEL | WZB_HELP )
80 : ,m_pOutSet(NULL)
81 : ,m_bResetting(sal_False)
82 : ,m_bApplied(sal_False)
83 0 : ,m_bUIEnabled( sal_True )
84 : {
85 : DBG_CTOR(ODbTypeWizDialog,NULL);
86 0 : m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,this,this));
87 0 : m_pImpl->setDataSourceOrName(_aDataSourceName);
88 0 : Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
89 0 : m_pOutSet = new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() );
90 :
91 0 : m_pImpl->translateProperties(xDatasource, *m_pOutSet);
92 0 : m_eType = m_pImpl->getDatasourceType(*m_pOutSet);
93 :
94 0 : SetPageSizePixel(LogicToPixel(::Size(PAGE_X, PAGE_Y), MAP_APPFONT));
95 0 : ShowButtonFixedLine(sal_True);
96 0 : defaultButton(WZB_NEXT);
97 0 : enableButtons(WZB_FINISH, sal_False);
98 0 : enableAutomaticNextButtonState( true );
99 :
100 0 : m_pPrevPage->SetHelpId(HID_DBWIZ_PREVIOUS);
101 0 : m_pNextPage->SetHelpId(HID_DBWIZ_NEXT);
102 0 : m_pCancel->SetHelpId(HID_DBWIZ_CANCEL);
103 0 : m_pFinish->SetHelpId(HID_DBWIZ_FINISH);
104 0 : m_pHelp->SetUniqueId(UID_DBWIZ_HELP);
105 : // no local resources needed anymore
106 :
107 0 : DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _pItems->GetItem(DSID_TYPECOLLECTION));
108 0 : m_pCollection = pCollectionItem->getCollection();
109 :
110 0 : FreeResource();
111 0 : ActivatePage();
112 0 : }
113 :
114 : //-------------------------------------------------------------------------
115 0 : ODbTypeWizDialog::~ODbTypeWizDialog()
116 : {
117 : DBG_DTOR(ODbTypeWizDialog,NULL);
118 0 : delete m_pOutSet;
119 0 : }
120 : //-------------------------------------------------------------------------
121 0 : IMPL_LINK(ODbTypeWizDialog, OnTypeSelected, OGeneralPage*, _pTabPage)
122 : {
123 0 : m_eType = _pTabPage->GetSelectedType();
124 0 : const bool bURLRequired = m_pCollection->isConnectionUrlRequired(m_eType);
125 0 : enableButtons(WZB_NEXT,bURLRequired);
126 0 : enableButtons(WZB_FINISH,!bURLRequired);
127 0 : return 1L;
128 : }
129 : //-------------------------------------------------------------------------
130 0 : WizardTypes::WizardState ODbTypeWizDialog::determineNextState( WizardState _nCurrentState ) const
131 : {
132 0 : WizardTypes::WizardState nNextState = WZS_INVALID_STATE;
133 0 : switch(_nCurrentState)
134 : {
135 : case START_PAGE:
136 0 : switch(m_pCollection->determineType(m_eType))
137 : {
138 : case ::dbaccess::DST_MOZILLA:
139 : case ::dbaccess::DST_OUTLOOK:
140 : case ::dbaccess::DST_OUTLOOKEXP:
141 : case ::dbaccess::DST_EVOLUTION:
142 : case ::dbaccess::DST_EVOLUTION_GROUPWISE:
143 : case ::dbaccess::DST_EVOLUTION_LDAP:
144 : case ::dbaccess::DST_KAB:
145 : case ::dbaccess::DST_MACAB:
146 0 : nNextState = WZS_INVALID_STATE;
147 0 : break;
148 : case ::dbaccess::DST_MYSQL_NATIVE:
149 0 : nNextState = ADDITIONAL_PAGE_MYSQL_NATIVE;
150 0 : break;
151 : default:
152 0 : nNextState = CONNECTION_PAGE;
153 0 : break;
154 : }
155 0 : break;
156 : case CONNECTION_PAGE:
157 0 : switch(m_pCollection->determineType(m_eType))
158 : {
159 : case ::dbaccess::DST_MOZILLA:
160 : case ::dbaccess::DST_THUNDERBIRD:
161 : case ::dbaccess::DST_OUTLOOK:
162 : case ::dbaccess::DST_OUTLOOKEXP:
163 : case ::dbaccess::DST_EVOLUTION:
164 : case ::dbaccess::DST_EVOLUTION_GROUPWISE:
165 : case ::dbaccess::DST_EVOLUTION_LDAP:
166 : case ::dbaccess::DST_KAB:
167 : case ::dbaccess::DST_MACAB:
168 : case ::dbaccess::DST_MSACCESS:
169 : case ::dbaccess::DST_MSACCESS_2007:
170 : case ::dbaccess::DST_JDBC:
171 : case ::dbaccess::DST_CALC:
172 0 : nNextState = WZS_INVALID_STATE;
173 0 : break;
174 : case ::dbaccess::DST_DBASE:
175 0 : nNextState = ADDITIONAL_PAGE_DBASE;
176 0 : break;
177 : case ::dbaccess::DST_FLAT:
178 0 : nNextState = ADDITIONAL_PAGE_FLAT;
179 0 : break;
180 : case ::dbaccess::DST_LDAP:
181 0 : nNextState = ADDITIONAL_PAGE_LDAP;
182 0 : break;
183 : case ::dbaccess::DST_MYSQL_JDBC:
184 0 : nNextState = ADDITIONAL_PAGE_MYSQL_JDBC;
185 0 : break;
186 : case ::dbaccess::DST_MYSQL_ODBC:
187 0 : nNextState = ADDITIONAL_PAGE_MYSQL_ODBC;
188 0 : break;
189 : case ::dbaccess::DST_ORACLE_JDBC:
190 0 : nNextState = ADDITIONAL_PAGE_ORACLE_JDBC;
191 0 : break;
192 : case ::dbaccess::DST_ADO:
193 0 : nNextState = ADDITIONAL_PAGE_ADO;
194 0 : break;
195 : case ::dbaccess::DST_ODBC:
196 0 : nNextState = ADDITIONAL_PAGE_ODBC;
197 0 : break;
198 : default:
199 0 : nNextState = WZS_INVALID_STATE;
200 0 : break;
201 : }
202 0 : break;
203 : }
204 :
205 0 : return nNextState;
206 : }
207 :
208 : // -----------------------------------------------------------------------------
209 0 : const SfxItemSet* ODbTypeWizDialog::getOutputSet() const
210 : {
211 0 : return m_pOutSet;
212 : }
213 : // -----------------------------------------------------------------------------
214 0 : SfxItemSet* ODbTypeWizDialog::getWriteOutputSet()
215 : {
216 0 : return m_pOutSet;
217 : }
218 : // -----------------------------------------------------------------------------
219 0 : ::std::pair< Reference<XConnection>,sal_Bool> ODbTypeWizDialog::createConnection()
220 : {
221 0 : return m_pImpl->createConnection();
222 : }
223 : // -----------------------------------------------------------------------------
224 0 : Reference< XMultiServiceFactory > ODbTypeWizDialog::getORB() const
225 : {
226 0 : return m_pImpl->getORB();
227 : }
228 : // -----------------------------------------------------------------------------
229 0 : Reference< XDriver > ODbTypeWizDialog::getDriver()
230 : {
231 0 : return m_pImpl->getDriver();
232 : }
233 : // -----------------------------------------------------------------------------
234 0 : ::rtl::OUString ODbTypeWizDialog::getDatasourceType(const SfxItemSet& _rSet) const
235 : {
236 0 : return m_pImpl->getDatasourceType(_rSet);
237 : }
238 : // -----------------------------------------------------------------------------
239 0 : void ODbTypeWizDialog::clearPassword()
240 : {
241 0 : m_pImpl->clearPassword();
242 0 : }
243 :
244 : // -----------------------------------------------------------------------------
245 0 : TabPage* ODbTypeWizDialog::createPage(WizardState _nState)
246 : {
247 0 : sal_uInt16 nStringId = STR_PAGETITLE_ADVANCED;
248 0 : TabPage* pPage = NULL;
249 0 : switch(_nState)
250 : {
251 : case START_PAGE: // start state
252 : {
253 0 : pPage = OGeneralPage::Create(this,*m_pOutSet);
254 0 : OGeneralPage* pGeneralPage = static_cast< OGeneralPage* >( pPage );
255 0 : pGeneralPage->SetTypeSelectHandler( LINK( this, ODbTypeWizDialog, OnTypeSelected));
256 : // pGeneralPage->SetCreationModeHandler( LINK( this, ODbTypeWizDialog, TODO ) );
257 0 : nStringId = STR_PAGETITLE_GENERAL;
258 : }
259 0 : break;
260 : case CONNECTION_PAGE:
261 0 : pPage = OConnectionTabPage::Create(this,*m_pOutSet);
262 0 : nStringId = STR_PAGETITLE_CONNECTION;
263 0 : break;
264 :
265 : case ADDITIONAL_PAGE_DBASE:
266 0 : pPage = ODriversSettings::CreateDbase(this,*m_pOutSet);
267 0 : break;
268 : case ADDITIONAL_PAGE_FLAT:
269 0 : pPage = ODriversSettings::CreateText(this,*m_pOutSet);
270 0 : break;
271 : case ADDITIONAL_PAGE_LDAP:
272 0 : pPage = ODriversSettings::CreateLDAP(this,*m_pOutSet);
273 0 : break;
274 : case ADDITIONAL_PAGE_MYSQL_JDBC:
275 0 : pPage = ODriversSettings::CreateMySQLJDBC(this,*m_pOutSet);
276 0 : break;
277 : case ADDITIONAL_PAGE_MYSQL_NATIVE:
278 0 : pPage = ODriversSettings::CreateMySQLNATIVE(this,*m_pOutSet);
279 0 : break;
280 : case ADDITIONAL_PAGE_MYSQL_ODBC:
281 0 : pPage = ODriversSettings::CreateMySQLODBC(this,*m_pOutSet);
282 0 : break;
283 : case ADDITIONAL_PAGE_ORACLE_JDBC:
284 0 : pPage = ODriversSettings::CreateOracleJDBC(this,*m_pOutSet);
285 0 : break;
286 : case ADDITIONAL_PAGE_ADO:
287 0 : pPage = ODriversSettings::CreateAdo(this,*m_pOutSet);
288 0 : break;
289 : case ADDITIONAL_PAGE_ODBC:
290 0 : pPage = ODriversSettings::CreateODBC(this,*m_pOutSet);
291 0 : break;
292 : case ADDITIONAL_USERDEFINED:
293 0 : pPage = ODriversSettings::CreateUser(this,*m_pOutSet);
294 0 : break;
295 : default:
296 : OSL_FAIL("Wrong state!");
297 0 : break;
298 : }
299 :
300 : // register ourself as modified listener
301 0 : if ( pPage )
302 : {
303 0 : static_cast<OGenericAdministrationPage*>(pPage)->SetServiceFactory(m_pImpl->getORB());
304 0 : static_cast<OGenericAdministrationPage*>(pPage)->SetAdminDialog(this,this);
305 : // open our own resource block, as the page titles are strings local to this block
306 0 : LocalResourceAccess aDummy(DLG_DATABASE_ADMINISTRATION, RSC_TABDIALOG);
307 :
308 0 : pPage->SetText(String(ModuleRes(nStringId)));
309 0 : defaultButton( _nState == START_PAGE ? WZB_NEXT : WZB_FINISH );
310 0 : enableButtons( WZB_FINISH, _nState == START_PAGE ? sal_False : sal_True);
311 0 : pPage->Show();
312 : }
313 0 : return pPage;
314 : }
315 : // -----------------------------------------------------------------------------
316 0 : sal_Bool ODbTypeWizDialog::leaveState(WizardState _nState)
317 : {
318 0 : SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState));
319 0 : if ( pPage )
320 0 : pPage->FillItemSet(*m_pOutSet);
321 0 : return sal_True;
322 : }
323 : // -----------------------------------------------------------------------------
324 0 : void ODbTypeWizDialog::setTitle(const ::rtl::OUString& _sTitle)
325 : {
326 0 : SetText(_sTitle);
327 0 : }
328 : //-------------------------------------------------------------------------
329 0 : void ODbTypeWizDialog::enableConfirmSettings( bool _bEnable )
330 : {
331 0 : enableButtons( WZB_FINISH, _bEnable );
332 : // TODO:
333 : // this is hacky. At the moment, this method is used in only one case.
334 : // As soon as it is to be used more wide-spread, we should find a proper concept
335 : // for enabling both the Next and Finish buttons, depending on the current page state.
336 : // Plus, the concept must also care for the case where those pages are embedded into
337 : // anormal tab dialog.
338 0 : }
339 : //-------------------------------------------------------------------------
340 0 : sal_Bool ODbTypeWizDialog::saveDatasource()
341 : {
342 0 : SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(getCurrentState()));
343 0 : if ( pPage )
344 0 : pPage->FillItemSet(*m_pOutSet);
345 :
346 0 : DataSourceInfoConverter aConverter(getORB());
347 0 : ::rtl::OUString sOldURL;
348 0 : if ( m_pImpl->getCurrentDataSource().is() )
349 0 : m_pImpl->getCurrentDataSource()->getPropertyValue(PROPERTY_URL) >>= sOldURL;
350 0 : aConverter.convert(m_pCollection,sOldURL,m_eType,m_pImpl->getCurrentDataSource());
351 0 : return sal_True;
352 : }
353 : // -----------------------------------------------------------------------------
354 0 : IWizardPageController* ODbTypeWizDialog::getPageController( TabPage* _pCurrentPage ) const
355 : {
356 0 : OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage);
357 0 : return pPage;
358 : }
359 : // -----------------------------------------------------------------------------
360 0 : sal_Bool ODbTypeWizDialog::onFinish()
361 : {
362 0 : saveDatasource();
363 0 : return m_pImpl->saveChanges(*m_pOutSet) ? OWizardMachine::onFinish() : sal_False;
364 : }
365 : //.........................................................................
366 0 : } // namespace dbaui
367 : //.........................................................................
368 :
369 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|