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 <osl/diagnose.h>
21 #include "connpooloptions.hxx"
23 #include "connpoolsettings.hxx"
24 #include <svl/eitem.hxx>
26 #include <strings.hrc>
27 #include <dialmgr.hxx>
28 
29 using ::svt::EditBrowseBox;
30 
31 namespace offapp
32 {
34  {
36  return true;
37 
39  for (auto const& currentSetting : m_aSettings)
40  {
41  if (currentSetting != *aSaved)
42  return true;
43  ++aSaved;
44  }
45 
46  return false;
47  }
48 
50  : SfxTabPage(pPage, pController, "cui/ui/connpooloptions.ui", "ConnPoolPage", &_rAttrSet)
51  , m_sYes(CuiResId(RID_SVXSTR_YES))
52  , m_sNo(CuiResId(RID_SVXSTR_NO))
53  , m_xEnablePooling(m_xBuilder->weld_check_button("connectionpooling"))
54  , m_xDriversLabel(m_xBuilder->weld_label("driverslabel"))
55  , m_xDriverList(m_xBuilder->weld_tree_view("driverlist"))
56  , m_xDriverLabel(m_xBuilder->weld_label("driverlabel"))
57  , m_xDriver(m_xBuilder->weld_label("driver"))
58  , m_xDriverPoolingEnabled(m_xBuilder->weld_check_button("enablepooling"))
59  , m_xTimeoutLabel(m_xBuilder->weld_label("timeoutlabel"))
60  , m_xTimeout(m_xBuilder->weld_spin_button("timeout"))
61  {
62  m_xDriverList->set_size_request(m_xDriverList->get_approximate_digit_width() * 60,
63  m_xDriverList->get_height_rows(15));
64  m_xDriverList->show();
65 
66  std::vector<int> aWidths;
67  aWidths.push_back(m_xDriverList->get_approximate_digit_width() * 50);
68  aWidths.push_back(m_xDriverList->get_approximate_digit_width() * 8);
69  m_xDriverList->set_column_fixed_widths(aWidths);
70 
71  m_xEnablePooling->connect_clicked( LINK(this, ConnectionPoolOptionsPage, OnEnabledDisabled) );
72  m_xDriverPoolingEnabled->connect_clicked( 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  OSL_FAIL("ConnectionPoolOptionsPage::implInitControls: missing the DriverTimeouts item!");
150  }
151  saveDriverList();
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  {
170  _rSet->Put(SfxBoolItem(SID_SB_POOLING_ENABLED, m_xEnablePooling->get_active()));
171  bModified = true;
172  }
173 
174  // the settings for the single drivers
175  if (isModifiedDriverList())
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::Button&, 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
DriverSettings::const_iterator const_iterator
virtual ~ConnectionPoolOptionsPage() override
std::unique_ptr< weld::CheckButton > m_xDriverPoolingEnabled
virtual void Reset(const SfxItemSet *_rSet) override
#define SID_SB_POOLING_ENABLED
virtual void ActivatePage(const SfxItemSet &)
std::unique_ptr< weld::TreeView > m_xDriverList
#define SID_SB_DRIVER_TIMEOUTS
IMPL_LINK(ConnectionPoolOptionsPage, OnEnabledDisabled, weld::Button &, rCheckBox, void)
DriverPoolingSettings m_aSavedSettings
const DriverPoolingSettings & getSettings() const
std::unique_ptr< weld::CheckButton > m_xEnablePooling
void UpdateDriverList(const DriverPoolingSettings &_rSettings)
int i
ConnectionPoolOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &_rAttrSet)
IMPL_LINK_NOARG(ConnectionPoolOptionsPage, OnSpinValueChanged, weld::SpinButton &, void)
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
::comphelper::NamedValueCollection m_aSettings
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
std::unique_ptr< weld::SpinButton > m_xTimeout
virtual bool FillItemSet(SfxItemSet *_rSet) override
virtual void ActivatePage(const SfxItemSet &_rSet) override
void implInitControls(const SfxItemSet &_rSet)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
const_iterator begin() const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const