tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / dbaccess / source / ui / dlg / dbwiz.cxx
blobf34e58c1717effdbf0a950e49f90f0345d8f4640
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 <core_resource.hxx>
21 #include <dbwiz.hxx>
22 #include <strings.hrc>
23 #include <strings.hxx>
24 #include <dsitems.hxx>
25 #include "dsnItem.hxx"
26 #include "adminpages.hxx"
27 #include "generalpage.hxx"
28 #include <unotools/confignode.hxx>
29 #include "ConnectionPage.hxx"
30 #include "DriverSettings.hxx"
31 #include "DbAdminImpl.hxx"
32 #include <helpids.h>
34 namespace dbaui
36 using namespace com::sun::star::uno;
37 using namespace com::sun::star::sdbc;
38 using namespace com::sun::star::util;
39 using namespace com::sun::star::beans;
40 using namespace com::sun::star::container;
42 #define START_PAGE 0
43 #define CONNECTION_PAGE 1
44 #define ADDITIONAL_PAGE_DBASE 2
45 #define ADDITIONAL_PAGE_FLAT 3
46 #define ADDITIONAL_PAGE_LDAP 4
47 //5 was ADDITIONAL_PAGE_ADABAS
48 #define ADDITIONAL_PAGE_MYSQL_JDBC 6
49 #define ADDITIONAL_PAGE_MYSQL_ODBC 7
50 #define ADDITIONAL_PAGE_ORACLE_JDBC 8
51 #define ADDITIONAL_PAGE_ADO 9
52 #define ADDITIONAL_PAGE_ODBC 10
53 #define ADDITIONAL_USERDEFINED 11
54 #define ADDITIONAL_PAGE_MYSQL_NATIVE 12
56 // ODbTypeWizDialog
57 ODbTypeWizDialog::ODbTypeWizDialog(weld::Window* _pParent, SfxItemSet const * _pItems,
58 const Reference< XComponentContext >& _rxORB, const css::uno::Any& _aDataSourceName)
59 : WizardMachine(_pParent, WizardButtonFlags::NEXT | WizardButtonFlags::PREVIOUS | WizardButtonFlags::FINISH | WizardButtonFlags::CANCEL | WizardButtonFlags::HELP )
61 m_pImpl.reset(new ODbDataSourceAdministrationHelper(_rxORB, m_xAssistant.get(), _pParent, this));
62 m_pImpl->setDataSourceOrName(_aDataSourceName);
63 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
64 m_pOutSet.reset(new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() ));
66 m_pImpl->translateProperties(xDatasource, *m_pOutSet);
67 m_eType = dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(*m_pOutSet);
69 defaultButton(WizardButtonFlags::NEXT);
70 enableButtons(WizardButtonFlags::FINISH, false);
71 enableAutomaticNextButtonState();
73 m_xPrevPage->set_help_id(HID_DBWIZ_PREVIOUS);
74 m_xNextPage->set_help_id(HID_DBWIZ_NEXT);
75 m_xCancel->set_help_id(HID_DBWIZ_CANCEL);
76 m_xFinish->set_help_id(HID_DBWIZ_FINISH);
77 // no local resources needed anymore
79 const DbuTypeCollectionItem* pCollectionItem = dynamic_cast<const DbuTypeCollectionItem*>(_pItems->GetItem(DSID_TYPECOLLECTION));
80 assert(pCollectionItem && "must exist");
81 m_pCollection = pCollectionItem->getCollection();
83 ActivatePage();
84 setTitleBase(DBA_RES(STR_DATABASE_TYPE_CHANGE));
86 m_xAssistant->set_current_page(0);
89 ODbTypeWizDialog::~ODbTypeWizDialog()
93 IMPL_LINK(ODbTypeWizDialog, OnTypeSelected, OGeneralPage&, _rTabPage, void)
95 m_eType = _rTabPage.GetSelectedType();
96 const bool bURLRequired = m_pCollection->isConnectionUrlRequired(m_eType);
97 enableButtons(WizardButtonFlags::NEXT,bURLRequired);
98 enableButtons(WizardButtonFlags::FINISH,!bURLRequired);
101 WizardState ODbTypeWizDialog::determineNextState( WizardState _nCurrentState ) const
103 WizardState nNextState = WZS_INVALID_STATE;
104 switch(_nCurrentState)
106 case START_PAGE:
107 switch(m_pCollection->determineType(m_eType))
109 case ::dbaccess::DST_MOZILLA:
110 case ::dbaccess::DST_OUTLOOK:
111 case ::dbaccess::DST_OUTLOOKEXP:
112 case ::dbaccess::DST_EVOLUTION:
113 case ::dbaccess::DST_EVOLUTION_GROUPWISE:
114 case ::dbaccess::DST_EVOLUTION_LDAP:
115 case ::dbaccess::DST_KAB:
116 case ::dbaccess::DST_MACAB:
117 nNextState = WZS_INVALID_STATE;
118 break;
119 case ::dbaccess::DST_MYSQL_NATIVE:
120 nNextState = ADDITIONAL_PAGE_MYSQL_NATIVE;
121 break;
122 default:
123 nNextState = CONNECTION_PAGE;
124 break;
126 break;
127 case CONNECTION_PAGE:
128 switch(m_pCollection->determineType(m_eType))
130 case ::dbaccess::DST_MOZILLA:
131 case ::dbaccess::DST_THUNDERBIRD:
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 case ::dbaccess::DST_MSACCESS:
140 case ::dbaccess::DST_JDBC:
141 case ::dbaccess::DST_CALC:
142 case ::dbaccess::DST_WRITER:
143 nNextState = WZS_INVALID_STATE;
144 break;
145 case ::dbaccess::DST_DBASE:
146 nNextState = ADDITIONAL_PAGE_DBASE;
147 break;
148 case ::dbaccess::DST_FLAT:
149 nNextState = ADDITIONAL_PAGE_FLAT;
150 break;
151 case ::dbaccess::DST_LDAP:
152 nNextState = ADDITIONAL_PAGE_LDAP;
153 break;
154 case ::dbaccess::DST_MYSQL_JDBC:
155 nNextState = ADDITIONAL_PAGE_MYSQL_JDBC;
156 break;
157 case ::dbaccess::DST_MYSQL_ODBC:
158 nNextState = ADDITIONAL_PAGE_MYSQL_ODBC;
159 break;
160 case ::dbaccess::DST_ORACLE_JDBC:
161 nNextState = ADDITIONAL_PAGE_ORACLE_JDBC;
162 break;
163 case ::dbaccess::DST_ADO:
164 nNextState = ADDITIONAL_PAGE_ADO;
165 break;
166 case ::dbaccess::DST_ODBC:
167 nNextState = ADDITIONAL_PAGE_ODBC;
168 break;
169 default:
170 nNextState = WZS_INVALID_STATE;
171 break;
173 break;
176 return nNextState;
179 const SfxItemSet* ODbTypeWizDialog::getOutputSet() const
181 return m_pOutSet.get();
184 SfxItemSet* ODbTypeWizDialog::getWriteOutputSet()
186 return m_pOutSet.get();
189 std::pair< Reference<XConnection>,bool> ODbTypeWizDialog::createConnection()
191 return m_pImpl->createConnection();
194 Reference< XComponentContext > ODbTypeWizDialog::getORB() const
196 return m_pImpl->getORB();
199 Reference< XDriver > ODbTypeWizDialog::getDriver()
201 return m_pImpl->getDriver();
204 OUString ODbTypeWizDialog::getDatasourceType(const SfxItemSet& _rSet) const
206 return dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(_rSet);
209 void ODbTypeWizDialog::clearPassword()
211 m_pImpl->clearPassword();
214 std::unique_ptr<BuilderPage> ODbTypeWizDialog::createPage(WizardState _nState)
216 TranslateId pStringId = STR_PAGETITLE_ADVANCED;
217 std::unique_ptr<BuilderPage> xPage;
219 OUString sIdent(OUString::number(_nState));
220 weld::Container* pPageContainer = m_xAssistant->append_page(sIdent);
222 switch(_nState)
224 case START_PAGE: // start state
226 xPage = std::make_unique<OGeneralPageDialog>(pPageContainer, this, *m_pOutSet);
227 OGeneralPage* pGeneralPage = static_cast<OGeneralPage*>(xPage.get());
228 pGeneralPage->SetTypeSelectHandler( LINK( this, ODbTypeWizDialog, OnTypeSelected));
229 pStringId = STR_PAGETITLE_GENERAL;
231 break;
232 case CONNECTION_PAGE:
233 xPage = OConnectionTabPage::Create(pPageContainer, this, m_pOutSet.get());
234 pStringId = STR_PAGETITLE_CONNECTION;
235 break;
237 case ADDITIONAL_PAGE_DBASE:
238 xPage = ODriversSettings::CreateDbase(pPageContainer, this, m_pOutSet.get());
239 break;
240 case ADDITIONAL_PAGE_FLAT:
241 xPage = ODriversSettings::CreateText(pPageContainer, this, m_pOutSet.get());
242 break;
243 case ADDITIONAL_PAGE_LDAP:
244 xPage = ODriversSettings::CreateLDAP(pPageContainer, this, m_pOutSet.get());
245 break;
246 case ADDITIONAL_PAGE_MYSQL_JDBC:
247 xPage = ODriversSettings::CreateMySQLJDBC(pPageContainer, this, m_pOutSet.get());
248 break;
249 case ADDITIONAL_PAGE_MYSQL_NATIVE:
250 xPage = ODriversSettings::CreateMySQLNATIVE(pPageContainer, this, m_pOutSet.get());
251 break;
252 case ADDITIONAL_PAGE_MYSQL_ODBC:
253 xPage = ODriversSettings::CreateMySQLODBC(pPageContainer, this, m_pOutSet.get());
254 break;
255 case ADDITIONAL_PAGE_ORACLE_JDBC:
256 xPage = ODriversSettings::CreateOracleJDBC(pPageContainer, this, m_pOutSet.get());
257 break;
258 case ADDITIONAL_PAGE_ADO:
259 xPage = ODriversSettings::CreateAdo(pPageContainer, this, m_pOutSet.get());
260 break;
261 case ADDITIONAL_PAGE_ODBC:
262 xPage = ODriversSettings::CreateODBC(pPageContainer, this, m_pOutSet.get());
263 break;
264 case ADDITIONAL_USERDEFINED:
265 xPage = ODriversSettings::CreateUser(pPageContainer, this, m_pOutSet.get());
266 break;
267 default:
268 OSL_FAIL("Wrong state!");
269 break;
272 // register ourself as modified listener
273 if ( xPage )
275 static_cast<OGenericAdministrationPage*>(xPage.get())->SetServiceFactory( m_pImpl->getORB() );
276 static_cast<OGenericAdministrationPage*>(xPage.get())->SetAdminDialog(this,this);
277 m_xAssistant->set_page_title(sIdent, DBA_RES(pStringId));
278 defaultButton( _nState == START_PAGE ? WizardButtonFlags::NEXT : WizardButtonFlags::FINISH );
279 enableButtons( WizardButtonFlags::FINISH, _nState != START_PAGE);
281 return xPage;
284 bool ODbTypeWizDialog::leaveState(WizardState _nState)
286 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardMachine::GetPage(_nState));
287 if ( pPage )
288 pPage->FillItemSet(m_pOutSet.get());
289 return true;
292 void ODbTypeWizDialog::setTitle(const OUString& _sTitle)
294 m_xAssistant->set_title(_sTitle);
297 void ODbTypeWizDialog::enableConfirmSettings( bool _bEnable )
299 enableButtons( WizardButtonFlags::FINISH, _bEnable );
300 // TODO:
301 // this is hacky. At the moment, this method is used in only one case.
302 // As soon as it is to be used more wide-spread, we should find a proper concept
303 // for enabling both the Next and Finish buttons, depending on the current page state.
304 // Plus, the concept must also care for the case where those pages are embedded into
305 // a normal tab dialog.
308 void ODbTypeWizDialog::saveDatasource()
310 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardMachine::GetPage(getCurrentState()));
311 if ( pPage )
312 pPage->FillItemSet(m_pOutSet.get());
314 OUString sOldURL;
315 if ( m_pImpl->getCurrentDataSource().is() )
316 m_pImpl->getCurrentDataSource()->getPropertyValue(PROPERTY_URL) >>= sOldURL;
317 DataSourceInfoConverter::convert( getORB(), m_pCollection,sOldURL,m_eType,m_pImpl->getCurrentDataSource());
320 vcl::IWizardPageController* ODbTypeWizDialog::getPageController(BuilderPage* pCurrentPage) const
322 OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(pCurrentPage);
323 return pPage;
326 bool ODbTypeWizDialog::onFinish()
328 saveDatasource();
329 return m_pImpl->saveChanges(*m_pOutSet) && WizardMachine::onFinish();
332 } // namespace dbaui
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */