1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "adminpages.hxx"
21 #include <core_resource.hxx>
22 #include <dbu_dlg.hxx>
23 #include <IItemSetHelper.hxx>
24 #include <strings.hrc>
25 #include <svl/stritem.hxx>
26 #include <svl/eitem.hxx>
27 #include <svl/intitem.hxx>
28 #include <dsitems.hxx>
29 #include "dsselect.hxx"
30 #include "odbcconfig.hxx"
31 #include "optionalboolitem.hxx"
32 #include <sqlmessage.hxx>
33 #include <com/sun/star/sdbc/XConnection.hpp>
34 #include <comphelper/types.hxx>
35 #include <vcl/svapp.hxx>
36 #include <vcl/weld.hxx>
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::sdbc
;
43 using namespace ::com::sun::star::beans
;
44 using namespace ::com::sun::star::lang
;
45 using namespace ::dbtools
;
47 ISaveValueWrapper::~ISaveValueWrapper()
51 OGenericAdministrationPage::OGenericAdministrationPage(weld::Container
* pPage
, weld::DialogController
* pController
, const OUString
& rUIXMLDescription
, const OUString
& rId
, const SfxItemSet
& rAttrSet
)
52 : SfxTabPage(pPage
, pController
, rUIXMLDescription
, rId
, &rAttrSet
)
53 , m_abEnableRoadmap(false)
54 , m_pAdminDialog(nullptr)
55 , m_pItemSetHelper(nullptr)
59 m_xContainer
->set_size_request(m_xContainer
->get_approximate_digit_width() * WIZARD_PAGE_X
,
60 m_xContainer
->get_text_height() * WIZARD_PAGE_Y
);
63 DeactivateRC
OGenericAdministrationPage::DeactivatePage(SfxItemSet
* _pSet
)
68 return DeactivateRC::KeepPage
;
72 return DeactivateRC::LeavePage
;
75 void OGenericAdministrationPage::Reset(const SfxItemSet
* _rCoreAttrs
)
77 implInitControls(*_rCoreAttrs
, false);
80 void OGenericAdministrationPage::Activate()
82 BuilderPage::Activate();
83 OSL_ENSURE(m_pItemSetHelper
,"NO ItemSetHelper set!");
84 if ( m_pItemSetHelper
)
85 ActivatePage(*m_pItemSetHelper
->getOutputSet());
88 void OGenericAdministrationPage::ActivatePage(const SfxItemSet
& _rSet
)
90 implInitControls(_rSet
, true);
93 void OGenericAdministrationPage::getFlags(const SfxItemSet
& _rSet
, bool& _rValid
, bool& _rReadonly
)
95 const SfxBoolItem
* pInvalid
= _rSet
.GetItem
<SfxBoolItem
>(DSID_INVALID_SELECTION
);
96 _rValid
= !pInvalid
|| !pInvalid
->GetValue();
97 const SfxBoolItem
* pReadonly
= _rSet
.GetItem
<SfxBoolItem
>(DSID_READONLY
);
98 _rReadonly
= !_rValid
|| (pReadonly
&& pReadonly
->GetValue());
101 IMPL_LINK(OGenericAdministrationPage
, OnControlModified
, weld::Widget
*, pCtrl
, void)
103 callModifiedHdl(pCtrl
);
106 IMPL_LINK(OGenericAdministrationPage
, OnControlModifiedButtonClick
, weld::Toggleable
&, rCtrl
, void)
108 callModifiedHdl(&rCtrl
);
111 IMPL_LINK(OGenericAdministrationPage
, OnControlEntryModifyHdl
, weld::Entry
&, rCtrl
, void)
113 callModifiedHdl(&rCtrl
);
116 IMPL_LINK(OGenericAdministrationPage
, OnControlSpinButtonModifyHdl
, weld::SpinButton
&, rCtrl
, void)
118 callModifiedHdl(&rCtrl
);
121 bool OGenericAdministrationPage::getSelectedDataSource(OUString
& _sReturn
, OUString
const & _sCurr
)
123 // collect all ODBC data source names
124 std::set
<OUString
> aOdbcDatasources
;
125 OOdbcEnumeration aEnumeration
;
126 if (!aEnumeration
.isLoaded())
128 // show an error message
129 OUString
sError(DBA_RES(STR_COULD_NOT_LOAD_ODBC_LIB
));
130 sError
= sError
.replaceFirst("#lib#", aEnumeration
.getLibraryName());
131 std::unique_ptr
<weld::MessageDialog
> xDialog(Application::CreateMessageDialog(GetFrameWeld(),
132 VclMessageType::Warning
, VclButtonsType::Ok
,
139 aEnumeration
.getDatasourceNames(aOdbcDatasources
);
140 // execute the select dialog
141 ODatasourceSelectDialog
aSelector(GetFrameWeld(), aOdbcDatasources
);
142 if (!_sCurr
.isEmpty())
143 aSelector
.Select(_sCurr
);
144 if (RET_OK
== aSelector
.run())
145 _sReturn
= aSelector
.GetSelected();
150 void OGenericAdministrationPage::implInitControls(const SfxItemSet
& _rSet
, bool _bSaveValue
)
152 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
153 bool bValid
, bReadonly
;
154 getFlags(_rSet
, bValid
, bReadonly
);
156 std::vector
< std::unique_ptr
<ISaveValueWrapper
> > aControlList
;
159 fillControls(aControlList
);
160 for( const auto& pValueWrapper
: aControlList
)
162 pValueWrapper
->SaveValue();
168 fillWindows(aControlList
);
169 for( const auto& pValueWrapper
: aControlList
)
171 pValueWrapper
->Disable();
176 void OGenericAdministrationPage::initializePage()
178 OSL_ENSURE(m_pItemSetHelper
,"NO ItemSetHelper set!");
179 if ( m_pItemSetHelper
)
180 Reset(m_pItemSetHelper
->getOutputSet());
182 bool OGenericAdministrationPage::commitPage( ::vcl::WizardTypes::CommitPageReason
)
186 bool OGenericAdministrationPage::canAdvance() const
190 void OGenericAdministrationPage::fillBool( SfxItemSet
& _rSet
, const weld::CheckButton
* pCheckBox
, sal_uInt16 _nID
, bool bOptionalBool
, bool& _bChangedSomething
, bool _bRevertValue
)
192 if (!(pCheckBox
&& pCheckBox
->get_state_changed_from_saved()))
195 bool bValue
= pCheckBox
->get_active();
201 OptionalBoolItem
aValue( _nID
);
202 if ( pCheckBox
->get_state() != TRISTATE_INDET
)
203 aValue
.SetValue( bValue
);
207 _rSet
.Put( SfxBoolItem( _nID
, bValue
) );
209 _bChangedSomething
= true;
211 void OGenericAdministrationPage::fillInt32(SfxItemSet
& _rSet
, const weld::SpinButton
* pEdit
, TypedWhichId
<SfxInt32Item
> _nID
, bool& _bChangedSomething
)
213 if (pEdit
&& pEdit
->get_value_changed_from_saved())
215 _rSet
.Put(SfxInt32Item(_nID
, pEdit
->get_value()));
216 _bChangedSomething
= true;
219 void OGenericAdministrationPage::fillString(SfxItemSet
& _rSet
, const weld::Entry
* pEdit
, TypedWhichId
<SfxStringItem
> _nID
, bool& _bChangedSomething
)
221 if (pEdit
&& pEdit
->get_value_changed_from_saved())
223 _rSet
.Put(SfxStringItem(_nID
, pEdit
->get_text().trim()));
224 _bChangedSomething
= true;
227 void OGenericAdministrationPage::fillString(SfxItemSet
& _rSet
, const dbaui::OConnectionURLEdit
* pEdit
, TypedWhichId
<SfxStringItem
> _nID
, bool& _bChangedSomething
)
229 if (pEdit
&& pEdit
->get_value_changed_from_saved())
231 _rSet
.Put(SfxStringItem(_nID
, pEdit
->GetText().trim()));
232 _bChangedSomething
= true;
236 IMPL_LINK_NOARG(OGenericAdministrationPage
, OnTestConnectionButtonClickHdl
, weld::Button
&, void)
238 OSL_ENSURE(m_pAdminDialog
,"No Admin dialog set! ->GPF");
239 bool bSuccess
= false;
240 if ( !m_pAdminDialog
)
243 m_pAdminDialog
->saveDatasource();
244 OGenericAdministrationPage::implInitControls(*m_pItemSetHelper
->getOutputSet(), true);
245 bool bShowMessage
= true;
248 std::pair
< Reference
<XConnection
>,bool> aConnectionPair
= m_pAdminDialog
->createConnection();
249 bShowMessage
= aConnectionPair
.second
;
250 bSuccess
= aConnectionPair
.first
.is();
251 ::comphelper::disposeComponent(aConnectionPair
.first
);
258 MessageType eImage
= MessageType::Info
;
259 OUString aMessage
,sTitle
;
260 sTitle
= DBA_RES(STR_CONNECTION_TEST
);
263 aMessage
= DBA_RES(STR_CONNECTION_SUCCESS
);
267 eImage
= MessageType::Error
;
268 aMessage
= DBA_RES(STR_CONNECTION_NO_SUCCESS
);
270 OSQLMessageBox
aMsg(GetFrameWeld(), sTitle
, aMessage
, MessBoxStyle::Ok
, eImage
);
274 m_pAdminDialog
->clearPassword();
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */