LibreOffice Module cui (master) 1
connpooloptions.cxx
Go to the documentation of this file.
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 <o3tl/safeint.hxx>
21#include <osl/diagnose.h>
22#include "connpooloptions.hxx"
23#include "connpoolsettings.hxx"
24#include <svl/eitem.hxx>
26#include <strings.hrc>
27#include <dialmgr.hxx>
28
29namespace offapp
30{
32 {
34 return true;
35
37 for (auto const& currentSetting : m_aSettings)
38 {
39 if (currentSetting != *aSaved)
40 return true;
41 ++aSaved;
42 }
43
44 return false;
45 }
46
48 : SfxTabPage(pPage, pController, "cui/ui/connpooloptions.ui", "ConnPoolPage", &_rAttrSet)
49 , m_sYes(CuiResId(RID_CUISTR_YES))
50 , m_sNo(CuiResId(RID_CUISTR_NO))
51 , m_xEnablePooling(m_xBuilder->weld_check_button("connectionpooling"))
52 , m_xDriversLabel(m_xBuilder->weld_label("driverslabel"))
53 , m_xDriverList(m_xBuilder->weld_tree_view("driverlist"))
54 , m_xDriverLabel(m_xBuilder->weld_label("driverlabel"))
55 , m_xDriver(m_xBuilder->weld_label("driver"))
56 , m_xDriverPoolingEnabled(m_xBuilder->weld_check_button("enablepooling"))
57 , m_xTimeoutLabel(m_xBuilder->weld_label("timeoutlabel"))
58 , m_xTimeout(m_xBuilder->weld_spin_button("timeout"))
59 {
60 m_xDriverList->set_size_request(m_xDriverList->get_approximate_digit_width() * 60,
61 m_xDriverList->get_height_rows(15));
62 m_xDriverList->show();
63
64 std::vector<int> aWidths
65 {
66 o3tl::narrowing<int>(m_xDriverList->get_approximate_digit_width() * 50),
67 o3tl::narrowing<int>(m_xDriverList->get_approximate_digit_width() * 8)
68 };
69 m_xDriverList->set_column_fixed_widths(aWidths);
70
71 m_xEnablePooling->connect_toggled( LINK(this, ConnectionPoolOptionsPage, OnEnabledDisabled) );
72 m_xDriverPoolingEnabled->connect_toggled( LINK(this, ConnectionPoolOptionsPage, OnEnabledDisabled) );
73
74 m_xDriverList->connect_changed(LINK(this, ConnectionPoolOptionsPage, OnDriverRowChanged));
75 m_xTimeout->connect_value_changed(LINK(this, ConnectionPoolOptionsPage, OnSpinValueChanged));
76 }
77
79 {
80 auto const& currentSetting = m_aSettings[nRow];
81 m_xDriverList->set_text(nRow, currentSetting.sName, 0);
82 if (currentSetting.bEnabled)
83 {
84 m_xDriverList->set_text(nRow, m_sYes, 1);
85 m_xDriverList->set_text(nRow, OUString::number(currentSetting.nTimeoutSeconds), 2);
86 }
87 else
88 {
89 m_xDriverList->set_text(nRow, m_sNo, 1);
90 m_xDriverList->set_text(nRow, "-", 2);
91 }
92 }
93
95 {
96 int nRow = m_xDriverList->get_selected_index();
97 if (nRow == -1)
98 return;
99 updateRow(nRow);
100 }
101
103 {
104 m_aSettings = _rSettings;
105
106 m_xDriverList->freeze();
107 m_xDriverList->clear();
108
109 for (size_t i = 0; i < m_aSettings.size(); ++i)
110 {
111 m_xDriverList->append();
112 updateRow(i);
113 }
114
115 m_xDriverList->thaw();
116
117 if (!m_aSettings.empty())
118 {
119 m_xDriverList->select(0);
120 OnDriverRowChanged(*m_xDriverList);
121 }
122 }
123
125 {
126 }
127
128 std::unique_ptr<SfxTabPage> ConnectionPoolOptionsPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* _rAttrSet)
129 {
130 return std::make_unique<ConnectionPoolOptionsPage>(pPage, pController, *_rAttrSet);
131 }
132
134 {
135 // the enabled flag
136 const SfxBoolItem* pEnabled = _rSet.GetItem<SfxBoolItem>(SID_SB_POOLING_ENABLED);
137 OSL_ENSURE(pEnabled, "ConnectionPoolOptionsPage::implInitControls: missing the Enabled item!");
138 m_xEnablePooling->set_active(pEnabled == nullptr || pEnabled->GetValue());
139
140 m_xEnablePooling->save_state();
141
142 // the settings for the single drivers
144 if (pDriverSettings)
145 UpdateDriverList(pDriverSettings->getSettings());
146 else
147 {
148 SAL_WARN("cui.options", "ConnectionPoolOptionsPage::implInitControls: missing the DriverTimeouts item!");
150 }
152
153 // reflect the new settings
154 OnEnabledDisabled(*m_xEnablePooling);
155 }
156
158 {
159 commitTimeoutField();
160 }
161
163 {
165
166 bool bModified = false;
167 // the enabled flag
168 if (m_xEnablePooling->get_state_changed_from_saved())
169 {
171 bModified = true;
172 }
173
174 // the settings for the single drivers
176 {
178 bModified = true;
179 }
180
181 return bModified;
182 }
183
185 {
187 implInitControls(_rSet);
188 }
189
191 {
192 implInitControls(*_rSet);
193 }
194
196 {
197 const int nDriverPos = m_xDriverList->get_selected_index();
198 bool bValidRow = (nDriverPos != -1);
199 m_xDriverPoolingEnabled->set_sensitive(bValidRow && m_xEnablePooling->get_active());
200 m_xTimeoutLabel->set_sensitive(bValidRow);
201 m_xTimeout->set_sensitive(bValidRow);
202
203 if (!bValidRow)
204 { // positioned on an invalid row
205 m_xDriver->set_label(OUString());
206 }
207 else
208 {
209 auto const& currentSetting = m_aSettings[nDriverPos];
210 m_xDriver->set_label(currentSetting.sName);
211 m_xDriverPoolingEnabled->set_active(currentSetting.bEnabled);
212 m_xTimeout->set_value(currentSetting.nTimeoutSeconds);
213
214 OnEnabledDisabled(*m_xDriverPoolingEnabled);
215 }
216 }
217
219 {
220 const int nDriverPos = m_xDriverList->get_selected_index();
221 if (nDriverPos == -1)
222 return;
223 m_aSettings[nDriverPos].nTimeoutSeconds = m_xTimeout->get_value();
225 }
226
227 IMPL_LINK( ConnectionPoolOptionsPage, OnEnabledDisabled, weld::Toggleable&, rCheckBox, void )
228 {
229 bool bGloballyEnabled = m_xEnablePooling->get_active();
230 bool bLocalDriverChanged = m_xDriverPoolingEnabled.get() == &rCheckBox;
231
232 if (m_xEnablePooling.get() == &rCheckBox)
233 {
234 m_xDriversLabel->set_sensitive(bGloballyEnabled);
235 m_xDriverList->set_sensitive(bGloballyEnabled);
236 if (!bGloballyEnabled)
237 m_xDriverList->select(-1);
238 m_xDriverLabel->set_sensitive(bGloballyEnabled);
239 m_xDriver->set_sensitive(bGloballyEnabled);
240 m_xDriverPoolingEnabled->set_sensitive(bGloballyEnabled);
241 }
242 else
243 OSL_ENSURE(bLocalDriverChanged, "ConnectionPoolOptionsPage::OnEnabledDisabled: where did this come from?");
244
245 m_xTimeoutLabel->set_sensitive(bGloballyEnabled && m_xDriverPoolingEnabled->get_active());
246 m_xTimeout->set_sensitive(bGloballyEnabled && m_xDriverPoolingEnabled->get_active());
247
248 if (bLocalDriverChanged)
249 {
250 // update the list
251 const int nDriverPos = m_xDriverList->get_selected_index();
252 if (nDriverPos == -1)
253 return;
254 m_aSettings[nDriverPos].bEnabled = m_xDriverPoolingEnabled->get_active();
255 updateCurrentRow();
256 }
257 }
258
259} // namespace offapp
260
261/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool GetValue() const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual void ActivatePage(const SfxItemSet &)
std::unique_ptr< weld::TreeView > m_xDriverList
void implInitControls(const SfxItemSet &_rSet)
std::unique_ptr< weld::SpinButton > m_xTimeout
virtual void Reset(const SfxItemSet *_rSet) override
virtual void ActivatePage(const SfxItemSet &_rSet) override
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
void UpdateDriverList(const DriverPoolingSettings &_rSettings)
virtual ~ConnectionPoolOptionsPage() override
std::unique_ptr< weld::CheckButton > m_xDriverPoolingEnabled
ConnectionPoolOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &_rAttrSet)
virtual bool FillItemSet(SfxItemSet *_rSet) override
DriverPoolingSettings m_aSavedSettings
std::unique_ptr< weld::CheckButton > m_xEnablePooling
const DriverPoolingSettings & getSettings() const
const_iterator begin() const
DriverSettings::const_iterator const_iterator
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
#define SID_SB_DRIVER_TIMEOUTS
#define SID_SB_POOLING_ENABLED
#define SAL_WARN(area, stream)
int i
IMPL_LINK(ConnectionPoolOptionsPage, OnEnabledDisabled, weld::Toggleable &, rCheckBox, void)
IMPL_LINK_NOARG(ConnectionPoolOptionsPage, OnSpinValueChanged, weld::SpinButton &, void)
::comphelper::NamedValueCollection m_aSettings