fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / dlg / dbwiz.cxx
blobfe2b76f5fec7e3c7c5773bfbf19c8bf5ab2e3cbf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
40 namespace dbaui
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;
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
64 // ODbTypeWizDialog
65 ODbTypeWizDialog::ODbTypeWizDialog(vcl::Window* _pParent
66 ,SfxItemSet* _pItems
67 ,const Reference< XComponentContext >& _rxORB
68 ,const ::com::sun::star::uno::Any& _aDataSourceName
70 :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 ,m_bUIEnabled( true )
76 m_pImpl.reset(new ODbDataSourceAdministrationHelper(_rxORB,this,this));
77 m_pImpl->setDataSourceOrName(_aDataSourceName);
78 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
79 m_pOutSet = new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() );
81 m_pImpl->translateProperties(xDatasource, *m_pOutSet);
82 m_eType = dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(*m_pOutSet);
84 SetPageSizePixel(LogicToPixel(::Size(PAGE_X, PAGE_Y), MAP_APPFONT));
85 defaultButton(WizardButtonFlags::NEXT);
86 enableButtons(WizardButtonFlags::FINISH, false);
87 enableAutomaticNextButtonState( true );
89 m_pPrevPage->SetHelpId(HID_DBWIZ_PREVIOUS);
90 m_pNextPage->SetHelpId(HID_DBWIZ_NEXT);
91 m_pCancel->SetHelpId(HID_DBWIZ_CANCEL);
92 m_pFinish->SetHelpId(HID_DBWIZ_FINISH);
93 m_pHelp->SetUniqueId(UID_DBWIZ_HELP);
94 // no local resources needed anymore
96 const DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _pItems->GetItem(DSID_TYPECOLLECTION));
97 m_pCollection = pCollectionItem->getCollection();
99 ActivatePage();
100 setTitleBase(ModuleRes(STR_DATABASE_TYPE_CHANGE));
103 ODbTypeWizDialog::~ODbTypeWizDialog()
105 disposeOnce();
108 void ODbTypeWizDialog::dispose()
110 delete m_pOutSet;
111 svt::OWizardMachine::dispose();
114 IMPL_LINK(ODbTypeWizDialog, OnTypeSelected, OGeneralPage*, _pTabPage)
116 m_eType = _pTabPage->GetSelectedType();
117 const bool bURLRequired = m_pCollection->isConnectionUrlRequired(m_eType);
118 enableButtons(WizardButtonFlags::NEXT,bURLRequired);
119 enableButtons(WizardButtonFlags::FINISH,!bURLRequired);
120 return 1L;
123 WizardTypes::WizardState ODbTypeWizDialog::determineNextState( WizardState _nCurrentState ) const
125 WizardTypes::WizardState nNextState = WZS_INVALID_STATE;
126 switch(_nCurrentState)
128 case START_PAGE:
129 switch(m_pCollection->determineType(m_eType))
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 nNextState = WZS_INVALID_STATE;
140 break;
141 case ::dbaccess::DST_MYSQL_NATIVE:
142 nNextState = ADDITIONAL_PAGE_MYSQL_NATIVE;
143 break;
144 default:
145 nNextState = CONNECTION_PAGE;
146 break;
148 break;
149 case CONNECTION_PAGE:
150 switch(m_pCollection->determineType(m_eType))
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 nNextState = WZS_INVALID_STATE;
166 break;
167 case ::dbaccess::DST_DBASE:
168 nNextState = ADDITIONAL_PAGE_DBASE;
169 break;
170 case ::dbaccess::DST_FLAT:
171 nNextState = ADDITIONAL_PAGE_FLAT;
172 break;
173 case ::dbaccess::DST_LDAP:
174 nNextState = ADDITIONAL_PAGE_LDAP;
175 break;
176 case ::dbaccess::DST_MYSQL_JDBC:
177 nNextState = ADDITIONAL_PAGE_MYSQL_JDBC;
178 break;
179 case ::dbaccess::DST_MYSQL_ODBC:
180 nNextState = ADDITIONAL_PAGE_MYSQL_ODBC;
181 break;
182 case ::dbaccess::DST_ORACLE_JDBC:
183 nNextState = ADDITIONAL_PAGE_ORACLE_JDBC;
184 break;
185 case ::dbaccess::DST_ADO:
186 nNextState = ADDITIONAL_PAGE_ADO;
187 break;
188 case ::dbaccess::DST_ODBC:
189 nNextState = ADDITIONAL_PAGE_ODBC;
190 break;
191 default:
192 nNextState = WZS_INVALID_STATE;
193 break;
195 break;
198 return nNextState;
201 const SfxItemSet* ODbTypeWizDialog::getOutputSet() const
203 return m_pOutSet;
206 SfxItemSet* ODbTypeWizDialog::getWriteOutputSet()
208 return m_pOutSet;
211 ::std::pair< Reference<XConnection>,sal_Bool> ODbTypeWizDialog::createConnection()
213 return m_pImpl->createConnection();
216 Reference< XComponentContext > ODbTypeWizDialog::getORB() const
218 return m_pImpl->getORB();
221 Reference< XDriver > ODbTypeWizDialog::getDriver()
223 return m_pImpl->getDriver();
226 OUString ODbTypeWizDialog::getDatasourceType(const SfxItemSet& _rSet) const
228 return dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(_rSet);
231 void ODbTypeWizDialog::clearPassword()
233 m_pImpl->clearPassword();
236 VclPtr<TabPage> ODbTypeWizDialog::createPage(WizardState _nState)
238 sal_uInt16 nStringId = STR_PAGETITLE_ADVANCED;
239 VclPtr<TabPage> pPage;
240 switch(_nState)
242 case START_PAGE: // start state
244 pPage = VclPtr<OGeneralPageDialog>::Create(this,*m_pOutSet);
245 OGeneralPage* pGeneralPage = static_cast< OGeneralPage* >( pPage.get() );
246 pGeneralPage->SetTypeSelectHandler( LINK( this, ODbTypeWizDialog, OnTypeSelected));
247 nStringId = STR_PAGETITLE_GENERAL;
249 break;
250 case CONNECTION_PAGE:
251 pPage = OConnectionTabPage::Create(this,m_pOutSet);
252 nStringId = STR_PAGETITLE_CONNECTION;
253 break;
255 case ADDITIONAL_PAGE_DBASE:
256 pPage = ODriversSettings::CreateDbase(this,m_pOutSet);
257 break;
258 case ADDITIONAL_PAGE_FLAT:
259 pPage = ODriversSettings::CreateText(this,m_pOutSet);
260 break;
261 case ADDITIONAL_PAGE_LDAP:
262 pPage = ODriversSettings::CreateLDAP(this,m_pOutSet);
263 break;
264 case ADDITIONAL_PAGE_MYSQL_JDBC:
265 pPage = ODriversSettings::CreateMySQLJDBC(this,m_pOutSet);
266 break;
267 case ADDITIONAL_PAGE_MYSQL_NATIVE:
268 pPage = ODriversSettings::CreateMySQLNATIVE(this,m_pOutSet);
269 break;
270 case ADDITIONAL_PAGE_MYSQL_ODBC:
271 pPage = ODriversSettings::CreateMySQLODBC(this,m_pOutSet);
272 break;
273 case ADDITIONAL_PAGE_ORACLE_JDBC:
274 pPage = ODriversSettings::CreateOracleJDBC(this,m_pOutSet);
275 break;
276 case ADDITIONAL_PAGE_ADO:
277 pPage = ODriversSettings::CreateAdo(this,m_pOutSet);
278 break;
279 case ADDITIONAL_PAGE_ODBC:
280 pPage = ODriversSettings::CreateODBC(this,m_pOutSet);
281 break;
282 case ADDITIONAL_USERDEFINED:
283 pPage = ODriversSettings::CreateUser(this,m_pOutSet);
284 break;
285 default:
286 OSL_FAIL("Wrong state!");
287 break;
290 // register ourself as modified listener
291 if ( pPage )
293 static_cast<OGenericAdministrationPage*>(pPage.get())->SetServiceFactory( m_pImpl->getORB() );
294 static_cast<OGenericAdministrationPage*>(pPage.get())->SetAdminDialog(this,this);
295 pPage->SetText(ModuleRes(nStringId));
296 defaultButton( _nState == START_PAGE ? WizardButtonFlags::NEXT : WizardButtonFlags::FINISH );
297 enableButtons( WizardButtonFlags::FINISH, _nState != START_PAGE);
298 pPage->Show();
300 return pPage;
303 bool ODbTypeWizDialog::leaveState(WizardState _nState)
305 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState));
306 if ( pPage )
307 pPage->FillItemSet(m_pOutSet);
308 return true;
311 void ODbTypeWizDialog::setTitle(const OUString& _sTitle)
313 SetText(_sTitle);
316 void ODbTypeWizDialog::enableConfirmSettings( bool _bEnable )
318 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.
327 bool ODbTypeWizDialog::saveDatasource()
329 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(getCurrentState()));
330 if ( pPage )
331 pPage->FillItemSet(m_pOutSet);
333 OUString sOldURL;
334 if ( m_pImpl->getCurrentDataSource().is() )
335 m_pImpl->getCurrentDataSource()->getPropertyValue(PROPERTY_URL) >>= sOldURL;
336 DataSourceInfoConverter::convert( getORB(), m_pCollection,sOldURL,m_eType,m_pImpl->getCurrentDataSource());
337 return true;
340 IWizardPageController* ODbTypeWizDialog::getPageController( TabPage* _pCurrentPage ) const
342 OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage);
343 return pPage;
346 bool ODbTypeWizDialog::onFinish()
348 saveDatasource();
349 return m_pImpl->saveChanges(*m_pOutSet) && OWizardMachine::onFinish();
352 } // namespace dbaui
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */