• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
tdeconfigdialogmanager.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 2003 Benjamin C Meyer (ben+tdelibs at meyerhome dot net)
4  * Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #include "tdeconfigdialogmanager.h"
23 
24 #include <tqbuttongroup.h>
25 #include <tqcombobox.h>
26 #include <tqlabel.h>
27 #include <tqmetaobject.h>
28 #include <tqobjectlist.h>
29 #include <tqsqlpropertymap.h>
30 #include <tqtimer.h>
31 #include <tqwhatsthis.h>
32 
33 #include <tdeapplication.h>
34 #include <tdeconfigskeleton.h>
35 #include <kdebug.h>
36 #include <tdeglobal.h>
37 
38 #include <assert.h>
39 
40 class TDEConfigDialogManager::Private {
41 
42 public:
43  Private() : insideGroupBox(false) { }
44 
45 public:
46  TQDict<TQWidget> knownWidget;
47  TQDict<TQWidget> buddyWidget;
48  bool insideGroupBox;
49 };
50 
51 TDEConfigDialogManager::TDEConfigDialogManager(TQWidget *parent, TDEConfigSkeleton *conf, const char *name)
52  : TQObject(parent, name), m_conf(conf), m_dialog(parent)
53 {
54  d = new Private();
55 
56  kapp->installKDEPropertyMap();
57  propertyMap = TQSqlPropertyMap::defaultMap();
58 
59  init(true);
60 }
61 
62 TDEConfigDialogManager::~TDEConfigDialogManager()
63 {
64  delete d;
65 }
66 
67 void TDEConfigDialogManager::init(bool trackChanges)
68 {
69  if(trackChanges)
70  {
71  // QT
72  changedMap.insert("TQButton", TQ_SIGNAL(stateChanged(int)));
73  changedMap.insert("TQCheckBox", TQ_SIGNAL(stateChanged(int)));
74  changedMap.insert("TQPushButton", TQ_SIGNAL(stateChanged(int)));
75  changedMap.insert("TQRadioButton", TQ_SIGNAL(stateChanged(int)));
76  // We can only store one thing, so you can't have
77  // a ButtonGroup that is checkable.
78  changedMap.insert("TQButtonGroup", TQ_SIGNAL(clicked(int)));
79  changedMap.insert("TQGroupBox", TQ_SIGNAL(toggled(bool)));
80  changedMap.insert("TQComboBox", TQ_SIGNAL(activated (int)));
81  //qsqlproperty map doesn't store the text, but the value!
82  //changedMap.insert("TQComboBox", TQ_SIGNAL(textChanged(const TQString &)));
83  changedMap.insert("TQDateEdit", TQ_SIGNAL(valueChanged(const TQDate &)));
84  changedMap.insert("TQDateTimeEdit", TQ_SIGNAL(valueChanged(const TQDateTime &)));
85  changedMap.insert("TQDial", TQ_SIGNAL(valueChanged (int)));
86  changedMap.insert("TQLineEdit", TQ_SIGNAL(textChanged(const TQString &)));
87  changedMap.insert("TQSlider", TQ_SIGNAL(valueChanged(int)));
88  changedMap.insert("TQSpinBox", TQ_SIGNAL(valueChanged(int)));
89  changedMap.insert("TQTimeEdit", TQ_SIGNAL(valueChanged(const TQTime &)));
90  changedMap.insert("TQTextEdit", TQ_SIGNAL(textChanged()));
91  changedMap.insert("TQTextBrowser", TQ_SIGNAL(sourceChanged(const TQString &)));
92  changedMap.insert("TQMultiLineEdit", TQ_SIGNAL(textChanged()));
93  changedMap.insert("TQListBox", TQ_SIGNAL(selectionChanged()));
94  changedMap.insert("TQTabWidget", TQ_SIGNAL(currentChanged(TQWidget *)));
95 
96  // KDE
97  changedMap.insert( "KComboBox", TQ_SIGNAL(activated (int)));
98  changedMap.insert( "TDEFontCombo", TQ_SIGNAL(activated (int)));
99  changedMap.insert( "TDEFontRequester", TQ_SIGNAL(fontSelected(const TQFont &)));
100  changedMap.insert( "TDEFontChooser", TQ_SIGNAL(fontSelected(const TQFont &)));
101  changedMap.insert( "KHistoryCombo", TQ_SIGNAL(activated (int)));
102 
103  changedMap.insert( "KColorButton", TQ_SIGNAL(changed(const TQColor &)));
104  changedMap.insert( "KDatePicker", TQ_SIGNAL(dateSelected (TQDate)));
105  changedMap.insert( "KDateWidget", TQ_SIGNAL(changed (TQDate)));
106  changedMap.insert( "KDateTimeWidget", TQ_SIGNAL(valueChanged (const TQDateTime &)));
107  changedMap.insert( "KEditListBox", TQ_SIGNAL(changed()));
108  changedMap.insert( "TDEListBox", TQ_SIGNAL(selectionChanged()));
109  changedMap.insert( "KLineEdit", TQ_SIGNAL(textChanged(const TQString &)));
110  changedMap.insert( "KPasswordEdit", TQ_SIGNAL(textChanged(const TQString &)));
111  changedMap.insert( "KRestrictedLine", TQ_SIGNAL(textChanged(const TQString &)));
112  changedMap.insert( "KTextBrowser", TQ_SIGNAL(sourceChanged(const TQString &)));
113  changedMap.insert( "KTextEdit", TQ_SIGNAL(textChanged()));
114  changedMap.insert( "KURLRequester", TQ_SIGNAL(textChanged (const TQString& )));
115  changedMap.insert( "KIntNumInput", TQ_SIGNAL(valueChanged (int)));
116  changedMap.insert( "KIntSpinBox", TQ_SIGNAL(valueChanged (int)));
117  changedMap.insert( "KDoubleNumInput", TQ_SIGNAL(valueChanged (double)));
118  }
119 
120  // Go through all of the children of the widgets and find all known widgets
121  (void) parseChildren(m_dialog, trackChanges);
122 }
123 
124 void TDEConfigDialogManager::addWidget(TQWidget *widget)
125 {
126  (void) parseChildren(widget, true);
127 }
128 
129 void TDEConfigDialogManager::setupWidget(TQWidget *widget, TDEConfigSkeletonItem *item)
130 {
131  TQVariant minValue = item->minValue();
132  if (minValue.isValid())
133  {
134  if (widget->metaObject()->findProperty("minValue", true) != -1)
135  widget->setProperty("minValue", minValue);
136  }
137  TQVariant maxValue = item->maxValue();
138  if (maxValue.isValid())
139  {
140  if (widget->metaObject()->findProperty("maxValue", true) != -1)
141  widget->setProperty("maxValue", maxValue);
142  }
143  if (TQWhatsThis::textFor( widget ).isEmpty())
144  {
145  TQString whatsThis = item->whatsThis();
146  if ( !whatsThis.isEmpty() )
147  {
148  TQWhatsThis::add( widget, whatsThis );
149  }
150  }
151 }
152 
153 bool TDEConfigDialogManager::parseChildren(const TQWidget *widget, bool trackChanges)
154 {
155  bool valueChanged = false;
156  const TQObjectList listOfChildren = widget->childrenListObject();
157  if(listOfChildren.isEmpty())
158  return valueChanged;
159 
160  TQObject *object;
161  for( TQObjectListIterator it( listOfChildren );
162  (object = it.current()); ++it )
163  {
164  if(!object->isWidgetType())
165  continue; // Skip non-widgets
166 
167  TQWidget *childWidget = (TQWidget *)object;
168 
169  const char *widgetName = childWidget->name(0);
170  bool bParseChildren = true;
171  bool bSaveInsideGroupBox = d->insideGroupBox;
172 
173  if (widgetName && (strncmp(widgetName, "kcfg_", 5) == 0))
174  {
175  // This is one of our widgets!
176  TQString configId = widgetName+5;
177  TDEConfigSkeletonItem *item = m_conf->findItem(configId);
178  if (item)
179  {
180  d->knownWidget.insert(configId, childWidget);
181 
182  setupWidget(childWidget, item);
183 
184  TQMap<TQString, TQCString>::const_iterator changedIt = changedMap.find(childWidget->className());
185 
186  if (changedIt == changedMap.end())
187  {
188  // If the class name of the widget wasn't in the monitored widgets map, then look for
189  // it again using the super class name. This fixes a problem with using QtRuby/Korundum
190  // widgets with TDEConfigXT where 'TQt::Widget' wasn't being seen a the real deal, even
191  // though it was a 'TQWidget'.
192  changedIt = changedMap.find(childWidget->metaObject()->superClassName());
193  }
194 
195  if (changedIt == changedMap.end())
196  {
197  kdWarning(178) << "Don't know how to monitor widget '" << childWidget->className() << "' for changes!" << endl;
198  }
199  else
200  {
201  connect(childWidget, *changedIt,
202  this, TQ_SIGNAL(widgetModified()));
203 
204  TQGroupBox *gb = dynamic_cast<TQGroupBox *>(childWidget);
205  if (!gb)
206  bParseChildren = false;
207  else
208  d->insideGroupBox = true;
209 
210  TQComboBox *cb = dynamic_cast<TQComboBox *>(childWidget);
211  if (cb && cb->editable())
212  connect(cb, TQ_SIGNAL(textChanged(const TQString &)),
213  this, TQ_SIGNAL(widgetModified()));
214  }
215  }
216  else
217  {
218  kdWarning(178) << "A widget named '" << widgetName << "' was found but there is no setting named '" << configId << "'" << endl;
219  }
220  }
221  else if (childWidget->inherits("TQLabel"))
222  {
223  TQLabel *label = static_cast<TQLabel *>(childWidget);
224  TQWidget *buddy = label->buddy();
225  if (!buddy)
226  continue;
227  const char *buddyName = buddy->name(0);
228  if (buddyName && (strncmp(buddyName, "kcfg_", 5) == 0))
229  {
230  // This is one of our widgets!
231  TQString configId = buddyName+5;
232  d->buddyWidget.insert(configId, childWidget);
233  }
234  }
235 #ifndef NDEBUG
236  else if (widgetName)
237  {
238  TQMap<TQString, TQCString>::const_iterator changedIt = changedMap.find(childWidget->className());
239  if (changedIt != changedMap.end())
240  {
241  if ((!d->insideGroupBox || !childWidget->inherits("TQRadioButton")) &&
242  !childWidget->inherits("TQGroupBox"))
243  kdDebug(178) << "Widget '" << widgetName << "' (" << childWidget->className() << ") remains unmanaged." << endl;
244  }
245  }
246 #endif
247 
248  if(bParseChildren)
249  {
250  // this widget is not known as something we can store.
251  // Maybe we can store one of its children.
252  valueChanged |= parseChildren(childWidget, trackChanges);
253  }
254  d->insideGroupBox = bSaveInsideGroupBox;
255  }
256  return valueChanged;
257 }
258 
259 void TDEConfigDialogManager::updateWidgets()
260 {
261  bool changed = false;
262  bool bSignalsBlocked = signalsBlocked();
263  blockSignals(true);
264 
265  TQWidget *widget;
266  for( TQDictIterator<TQWidget> it( d->knownWidget );
267  (widget = it.current()); ++it )
268  {
269  TDEConfigSkeletonItem *item = m_conf->findItem(it.currentKey());
270  if (!item)
271  {
272  kdWarning(178) << "The setting '" << it.currentKey() << "' has disappeared!" << endl;
273  continue;
274  }
275 
276  TQVariant p = item->property();
277  if (p != property(widget))
278  {
279  setProperty(widget, p);
280 // kdDebug(178) << "The setting '" << it.currentKey() << "' [" << widget->className() << "] has changed" << endl;
281  changed = true;
282  }
283  if (item->isImmutable())
284  {
285  widget->setEnabled(false);
286  TQWidget *buddy = d->buddyWidget.find(it.currentKey());
287  if (buddy)
288  buddy->setEnabled(false);
289  }
290  }
291  blockSignals(bSignalsBlocked);
292 
293  if (changed)
294  TQTimer::singleShot(0, this, TQ_SIGNAL(widgetModified()));
295 }
296 
297 void TDEConfigDialogManager::updateWidgetsDefault()
298 {
299  bool bUseDefaults = m_conf->useDefaults(true);
300  updateWidgets();
301  m_conf->useDefaults(bUseDefaults);
302 }
303 
304 void TDEConfigDialogManager::updateSettings()
305 {
306  bool changed = false;
307 
308  TQWidget *widget;
309  for( TQDictIterator<TQWidget> it( d->knownWidget );
310  (widget = it.current()); ++it )
311  {
312  TDEConfigSkeletonItem *item = m_conf->findItem(it.currentKey());
313  if (!item)
314  {
315  kdWarning(178) << "The setting '" << it.currentKey() << "' has disappeared!" << endl;
316  continue;
317  }
318 
319  TQVariant p = property(widget);
320  if (p != item->property())
321  {
322  item->setProperty(p);
323  changed = true;
324  }
325  }
326  if (changed)
327  {
328  m_conf->writeConfig();
329  emit settingsChanged();
330  }
331 }
332 
333 void TDEConfigDialogManager::setProperty(TQWidget *w, const TQVariant &v)
334 {
335  TQButtonGroup *bg = dynamic_cast<TQButtonGroup *>(w);
336  if (bg)
337  {
338  bg->setButton(v.toInt());
339  return;
340  }
341 
342  TQComboBox *cb = dynamic_cast<TQComboBox *>(w);
343  if (cb && cb->editable())
344  {
345  cb->setCurrentText(v.toString());
346  return;
347  }
348 
349  propertyMap->setProperty(w, v);
350 }
351 
352 TQVariant TDEConfigDialogManager::property(TQWidget *w)
353 {
354  TQButtonGroup *bg = dynamic_cast<TQButtonGroup *>(w);
355  if (bg)
356  return TQVariant(bg->selectedId());
357 
358  TQComboBox *cb = dynamic_cast<TQComboBox *>(w);
359  if (cb && cb->editable())
360  return TQVariant(cb->currentText());
361 
362  return propertyMap->property(w);
363 }
364 
365 bool TDEConfigDialogManager::hasChanged()
366 {
367 
368  TQWidget *widget;
369  for( TQDictIterator<TQWidget> it( d->knownWidget );
370  (widget = it.current()); ++it )
371  {
372  TDEConfigSkeletonItem *item = m_conf->findItem(it.currentKey());
373  if (!item)
374  {
375  kdWarning(178) << "The setting '" << it.currentKey() << "' has disappeared!" << endl;
376  continue;
377  }
378 
379  TQVariant p = property(widget);
380  if (p != item->property())
381  {
382 // kdDebug(178) << "Widget for '" << it.currentKey() << "' has changed." << endl;
383  return true;
384  }
385  }
386  return false;
387 }
388 
389 bool TDEConfigDialogManager::isDefault()
390 {
391  bool bUseDefaults = m_conf->useDefaults(true);
392  bool result = !hasChanged();
393  m_conf->useDefaults(bUseDefaults);
394  return result;
395 }
396 
397 #include "tdeconfigdialogmanager.moc"
398 
TDEConfigDialogManager::updateWidgets
void updateWidgets()
Traverse the specified widgets, sets the state of all known widgets according to the state in the set...
Definition: tdeconfigdialogmanager.cpp:259
TDEConfigDialogManager::updateWidgetsDefault
void updateWidgetsDefault()
Traverse the specified widgets, sets the state of all known widgets according to the default state in...
Definition: tdeconfigdialogmanager.cpp:297
TDEConfigDialogManager::property
TQVariant property(TQWidget *w)
Retrieve a property.
Definition: tdeconfigdialogmanager.cpp:352
TDEConfigDialogManager::setProperty
void setProperty(TQWidget *w, const TQVariant &v)
Set a property.
Definition: tdeconfigdialogmanager.cpp:333
TDEConfigDialogManager::~TDEConfigDialogManager
~TDEConfigDialogManager()
Destructor.
Definition: tdeconfigdialogmanager.cpp:62
TDEConfigDialogManager::settingsChanged
void settingsChanged()
One or more of the settings have been saved (such as when the user clicks on the Apply button).
TDEConfigDialogManager::init
void init(bool trackChanges)
Definition: tdeconfigdialogmanager.cpp:67
TDEConfigDialogManager::TDEConfigDialogManager
TDEConfigDialogManager(TQWidget *parent, TDEConfigSkeleton *conf, const char *name=0)
Constructor.
Definition: tdeconfigdialogmanager.cpp:51
TDEConfigDialogManager::addWidget
void addWidget(TQWidget *widget)
Add additional widgets to manage.
Definition: tdeconfigdialogmanager.cpp:124
TDEConfigDialogManager::parseChildren
bool parseChildren(const TQWidget *widget, bool trackChanges)
Recursive function that finds all known children.
Definition: tdeconfigdialogmanager.cpp:153
TDEConfigDialogManager::changedMap
TQMap< TQString, TQCString > changedMap
Map of the classes and the signals that they emit when changed.
Definition: tdeconfigdialogmanager.h:224
TDEConfigDialogManager::widgetModified
void widgetModified()
If retrieveSettings() was told to track changes then if any known setting was changed this signal wil...
TDEConfigDialogManager::m_dialog
TQWidget * m_dialog
Dialog being managed.
Definition: tdeconfigdialogmanager.h:214
TDEConfigDialogManager::m_conf
TDEConfigSkeleton * m_conf
TDEConfigSkeleton object used to store settings.
Definition: tdeconfigdialogmanager.h:209
TDEConfigDialogManager::isDefault
bool isDefault()
Returns whether the current state of the known widgets are the same as the default state in the confi...
Definition: tdeconfigdialogmanager.cpp:389
TDEConfigDialogManager::hasChanged
bool hasChanged()
Returns whether the current state of the known widgets are different from the state in the config obj...
Definition: tdeconfigdialogmanager.cpp:365
TDEConfigDialogManager::updateSettings
void updateSettings()
Traverse the specified widgets, saving the settings of all known widgets in the settings object.
Definition: tdeconfigdialogmanager.cpp:304
TDEConfigDialogManager::setupWidget
void setupWidget(TQWidget *widget, TDEConfigSkeletonItem *item)
Setup secondary widget properties.
Definition: tdeconfigdialogmanager.cpp:129
TDEConfigDialogManager::propertyMap
TQSqlPropertyMap * propertyMap
Pointer to the property map for easy access.
Definition: tdeconfigdialogmanager.h:219
TDEConfigSkeletonItem
Class for storing a preferences setting.
Definition: tdeconfigskeleton.h:51
TDEConfigSkeletonItem::setProperty
virtual void setProperty(const TQVariant &p)=0
Set item to p.
TDEConfigSkeletonItem::maxValue
virtual TQVariant maxValue() const
Return maximum value of item or invalid if not specified.
Definition: tdeconfigskeleton.h:191
TDEConfigSkeletonItem::property
virtual TQVariant property() const =0
Return item as property.
TDEConfigSkeletonItem::whatsThis
TQString whatsThis() const
Return WhatsThis description of item.
Definition: tdeconfigskeleton.h:150
TDEConfigSkeletonItem::isImmutable
bool isImmutable() const
Return if the entry can be modified.
Definition: tdeconfigskeleton.h:207
TDEConfigSkeletonItem::minValue
virtual TQVariant minValue() const
Return minimum value of item or invalid if not specified.
Definition: tdeconfigskeleton.h:186
TDEConfigSkeleton
Class for handling preferences settings for an application.
Definition: tdeconfigskeleton.h:366
TDEConfigSkeleton::findItem
TDEConfigSkeletonItem * findItem(const TQString &name)
Lookup item by name.
Definition: tdeconfigskeleton.cpp:1204
TDEConfigSkeleton::useDefaults
bool useDefaults(bool b)
Indicate whether this object should reflect the actual values or the default values.
Definition: tdeconfigskeleton.cpp:923
TDEConfigSkeleton::writeConfig
void writeConfig()
Write preferences to config file.
Definition: tdeconfigskeleton.cpp:967
endl
kndbgstream & endl(kndbgstream &s)
Does nothing.
Definition: kdebug.h:583

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.1
This website is maintained by Timothy Pearson.