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