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