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"
22 #include "connpoolsettings.hxx"
23 #include <svl/eitem.hxx>
25 #include <strings.hrc>
26 #include <dialmgr.hxx>
27 
28 namespace offapp
29 {
31  {
33  return true;
34 
36  for (auto const& currentSetting : m_aSettings)
37  {
38  if (currentSetting != *aSaved)
39  return true;
40  ++aSaved;
41  }
42 
43  return false;
44  }
45 
47  : SfxTabPage(pPage, pController, "cui/ui/connpooloptions.ui", "ConnPoolPage", &_rAttrSet)
48  , m_sYes(CuiResId(RID_SVXSTR_YES))
49  , m_sNo(CuiResId(RID_SVXSTR_NO))
50  , m_xEnablePooling(m_xBuilder->weld_check_button("connectionpooling"))
51  , m_xDriversLabel(m_xBuilder->weld_label("driverslabel"))
52  , m_xDriverList(m_xBuilder->weld_tree_view("driverlist"))
53  , m_xDriverLabel(m_xBuilder->weld_label("driverlabel"))
54  , m_xDriver(m_xBuilder->weld_label("driver"))
55  , m_xDriverPoolingEnabled(m_xBuilder->weld_check_button("enablepooling"))
56  , m_xTimeoutLabel(m_xBuilder->weld_label("timeoutlabel"))
57  , m_xTimeout(m_xBuilder->weld_spin_button("timeout"))
58  {
59  m_xDriverList->set_size_request(m_xDriverList->get_approximate_digit_width() * 60,
60  m_xDriverList->get_height_rows(15));
61  m_xDriverList->show();
62 
63  std::vector<int> aWidths;
64  aWidths.push_back(m_xDriverList->get_approximate_digit_width() * 50);
65  aWidths.push_back(m_xDriverList->get_approximate_digit_width() * 8);
66  m_xDriverList->set_column_fixed_widths(aWidths);
67 
68  m_xEnablePooling->connect_toggled( LINK(this, ConnectionPoolOptionsPage, OnEnabledDisabled) );
69  m_xDriverPoolingEnabled->connect_toggled( LINK(this, ConnectionPoolOptionsPage, OnEnabledDisabled) );
70 
71  m_xDriverList->connect_changed(LINK(this, ConnectionPoolOptionsPage, OnDriverRowChanged));
72  m_xTimeout->connect_value_changed(LINK(this, ConnectionPoolOptionsPage, OnSpinValueChanged));
73  }
74 
76  {
77  auto const& currentSetting = m_aSettings[nRow];
78  m_xDriverList->set_text(nRow, currentSetting.sName, 0);
79  if (currentSetting.bEnabled)
80  {
81  m_xDriverList->set_text(nRow, m_sYes, 1);
82  m_xDriverList->set_text(nRow, OUString::number(currentSetting.nTimeoutSeconds), 2);
83  }
84  else
85  {
86  m_xDriverList->set_text(nRow, m_sNo, 1);
87  m_xDriverList->set_text(nRow, "-", 2);
88  }
89  }
90 
92  {
93  int nRow = m_xDriverList->get_selected_index();
94  if (nRow == -1)
95  return;
96  updateRow(nRow);
97  }
98 
100  {
101  m_aSettings = _rSettings;
102 
103  m_xDriverList->freeze();
104  m_xDriverList->clear();
105 
106  for (size_t i = 0; i < m_aSettings.size(); ++i)
107  {
108  m_xDriverList->append();
109  updateRow(i);
110  }
111 
112  m_xDriverList->thaw();
113 
114  if (!m_aSettings.empty())
115  {
116  m_xDriverList->select(0);
117  OnDriverRowChanged(*m_xDriverList);
118  }
119  }
120 
122  {
123  }
124 
125  std::unique_ptr<SfxTabPage> ConnectionPoolOptionsPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* _rAttrSet)
126  {
127  return std::make_unique<ConnectionPoolOptionsPage>(pPage, pController, *_rAttrSet);
128  }
129 
131  {
132  // the enabled flag
133  const SfxBoolItem* pEnabled = _rSet.GetItem<SfxBoolItem>(SID_SB_POOLING_ENABLED);
134  OSL_ENSURE(pEnabled, "ConnectionPoolOptionsPage::implInitControls: missing the Enabled item!");
135  m_xEnablePooling->set_active(pEnabled == nullptr || pEnabled->GetValue());
136 
137  m_xEnablePooling->save_state();
138 
139  // the settings for the single drivers
141  if (pDriverSettings)
142  UpdateDriverList(pDriverSettings->getSettings());
143  else
144  {
145  OSL_FAIL("ConnectionPoolOptionsPage::implInitControls: missing the DriverTimeouts item!");
147  }
148  saveDriverList();
149 
150  // reflect the new settings
151  OnEnabledDisabled(*m_xEnablePooling);
152  }
153 
155  {
156  commitTimeoutField();
157  }
158 
160  {
162 
163  bool bModified = false;
164  // the enabled flag
165  if (m_xEnablePooling->get_state_changed_from_saved())
166  {
167  _rSet->Put(SfxBoolItem(SID_SB_POOLING_ENABLED, m_xEnablePooling->get_active()));
168  bModified = true;
169  }
170 
171  // the settings for the single drivers
172  if (isModifiedDriverList())
173  {
175  bModified = true;
176  }
177 
178  return bModified;
179  }
180 
182  {
184  implInitControls(_rSet);
185  }
186 
188  {
189  implInitControls(*_rSet);
190  }
191 
193  {
194  const int nDriverPos = m_xDriverList->get_selected_index();
195  bool bValidRow = (nDriverPos != -1);
196  m_xDriverPoolingEnabled->set_sensitive(bValidRow && m_xEnablePooling->get_active());
197  m_xTimeoutLabel->set_sensitive(bValidRow);
198  m_xTimeout->set_sensitive(bValidRow);
199 
200  if (!bValidRow)
201  { // positioned on an invalid row
202  m_xDriver->set_label(OUString());
203  }
204  else
205  {
206  auto const& currentSetting = m_aSettings[nDriverPos];
207  m_xDriver->set_label(currentSetting.sName);
208  m_xDriverPoolingEnabled->set_active(currentSetting.bEnabled);
209  m_xTimeout->set_value(currentSetting.nTimeoutSeconds);
210 
211  OnEnabledDisabled(*m_xDriverPoolingEnabled);
212  }
213  }
214 
216  {
217  const int nDriverPos = m_xDriverList->get_selected_index();
218  if (nDriverPos == -1)
219  return;
220  m_aSettings[nDriverPos].nTimeoutSeconds = m_xTimeout->get_value();
222  }
223 
224  IMPL_LINK( ConnectionPoolOptionsPage, OnEnabledDisabled, weld::Toggleable&, rCheckBox, void )
225  {
226  bool bGloballyEnabled = m_xEnablePooling->get_active();
227  bool bLocalDriverChanged = m_xDriverPoolingEnabled.get() == &rCheckBox;
228 
229  if (m_xEnablePooling.get() == &rCheckBox)
230  {
231  m_xDriversLabel->set_sensitive(bGloballyEnabled);
232  m_xDriverList->set_sensitive(bGloballyEnabled);
233  if (!bGloballyEnabled)
234  m_xDriverList->select(-1);
235  m_xDriverLabel->set_sensitive(bGloballyEnabled);
236  m_xDriver->set_sensitive(bGloballyEnabled);
237  m_xDriverPoolingEnabled->set_sensitive(bGloballyEnabled);
238  }
239  else
240  OSL_ENSURE(bLocalDriverChanged, "ConnectionPoolOptionsPage::OnEnabledDisabled: where did this come from?");
241 
242  m_xTimeoutLabel->set_sensitive(bGloballyEnabled && m_xDriverPoolingEnabled->get_active());
243  m_xTimeout->set_sensitive(bGloballyEnabled && m_xDriverPoolingEnabled->get_active());
244 
245  if (bLocalDriverChanged)
246  {
247  // update the list
248  const int nDriverPos = m_xDriverList->get_selected_index();
249  if (nDriverPos == -1)
250  return;
251  m_aSettings[nDriverPos].bEnabled = m_xDriverPoolingEnabled->get_active();
252  updateCurrentRow();
253  }
254  }
255 
256 } // namespace offapp
257 
258 /* 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
DriverPoolingSettings m_aSavedSettings
const DriverPoolingSettings & getSettings() const
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
int i
std::unique_ptr< weld::CheckButton > m_xEnablePooling
void UpdateDriverList(const DriverPoolingSettings &_rSettings)
ConnectionPoolOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &_rAttrSet)
IMPL_LINK_NOARG(ConnectionPoolOptionsPage, OnSpinValueChanged, weld::SpinButton &, void)
::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
IMPL_LINK(ConnectionPoolOptionsPage, OnEnabledDisabled, weld::Toggleable &, rCheckBox, void)
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