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

tdeui

  • tdeui
tdeconfigdialog.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  * Copyright (C) 2004 Michael Brade <brade@kde.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 #include "tdeconfigdialog.h"
23 
24 #include <tdeconfigskeleton.h>
25 #include <tdeconfigdialogmanager.h>
26 #include <tdelocale.h>
27 #include <kiconloader.h>
28 #include <kdebug.h>
29 
30 #include <tqlayout.h>
31 #include <tqvbox.h>
32 #include <tqmap.h>
33 
34 TQAsciiDict<TDEConfigDialog> TDEConfigDialog::openDialogs;
35 
36 // This class is here purly so we don't break binary compatibility down the road.
37 class TDEConfigDialog::TDEConfigDialogPrivate
38 {
39 public:
40  TDEConfigDialogPrivate(KDialogBase::DialogType t)
41  : shown(false), type(t), manager(0) { }
42 
43  bool shown;
44  KDialogBase::DialogType type;
45  TDEConfigDialogManager *manager;
46  TQMap<TQWidget *, TDEConfigDialogManager *> managerForPage;
47 };
48 
49 TDEConfigDialog::TDEConfigDialog( TQWidget *parent, const char *name,
50  TDEConfigSkeleton *config,
51  DialogType dialogType,
52  int dialogButtons,
53  ButtonCode defaultButton,
54  bool modal ) :
55  KDialogBase( dialogType, (WFlags)TQt::WStyle_DialogBorder,
56  parent, name, modal, i18n("Configure"), dialogButtons, defaultButton ),
57  d(new TDEConfigDialogPrivate(dialogType))
58 {
59  if ( name ) {
60  openDialogs.insert(name, this);
61  } else {
62  TQCString genericName;
63  genericName.sprintf("SettingsDialog-%p", this);
64  openDialogs.insert(genericName, this);
65  setName(genericName);
66  }
67 
68  connect(this, TQT_SIGNAL(okClicked()), this, TQT_SLOT(updateSettings()));
69  connect(this, TQT_SIGNAL(applyClicked()), this, TQT_SLOT(updateSettings()));
70  connect(this, TQT_SIGNAL(applyClicked()), this, TQT_SLOT(updateButtons()));
71  connect(this, TQT_SIGNAL(defaultClicked()), this, TQT_SLOT(updateWidgetsDefault()));
72  connect(this, TQT_SIGNAL(defaultClicked()), this, TQT_SLOT(updateButtons()));
73 
74  d->manager = new TDEConfigDialogManager(this, config);
75  setupManagerConnections(d->manager);
76 
77  enableButton(Apply, false);
78 }
79 
80 TDEConfigDialog::~TDEConfigDialog()
81 {
82  openDialogs.remove(name());
83  delete d;
84 }
85 
86 void TDEConfigDialog::addPage(TQWidget *page,
87  const TQString &itemName,
88  const TQString &pixmapName,
89  const TQString &header,
90  bool manage)
91 {
92  addPageInternal(page, itemName, pixmapName, header);
93  if(manage)
94  d->manager->addWidget(page);
95 }
96 
97 void TDEConfigDialog::addPage(TQWidget *page,
98  TDEConfigSkeleton *config,
99  const TQString &itemName,
100  const TQString &pixmapName,
101  const TQString &header)
102 {
103  addPageInternal(page, itemName, pixmapName, header);
104  d->managerForPage[page] = new TDEConfigDialogManager(page, config);
105  setupManagerConnections(d->managerForPage[page]);
106 }
107 
108 void TDEConfigDialog::addPageInternal(TQWidget *page,
109  const TQString &itemName,
110  const TQString &pixmapName,
111  const TQString &header)
112 {
113  if(d->shown)
114  {
115  kdDebug(240) << "TDEConfigDialog::addPage: can not add a page after the dialog has been shown.";
116  return;
117  }
118  switch(d->type)
119  {
120  case TreeList:
121  case IconList:
122  case Tabbed: {
123  TQVBox *frame = addVBoxPage(itemName, header, SmallIcon(pixmapName, 32));
124  frame->setSpacing( 0 );
125  frame->setMargin( 0 );
126  page->reparent(((TQWidget*)frame), 0, TQPoint());
127  }
128  break;
129 
130  case Swallow:
131  {
132  page->reparent(this, 0, TQPoint());
133  setMainWidget(page);
134  }
135  break;
136 
137  case Plain:
138  {
139  TQFrame *main = plainPage();
140  TQVBoxLayout *topLayout = new TQVBoxLayout( main, 0, 0 );
141  page->reparent(((TQWidget*)main), 0, TQPoint());
142  topLayout->addWidget( page );
143  }
144  break;
145 
146  default:
147  kdDebug(240) << "TDEConfigDialog::addpage: unknown type.";
148  }
149 }
150 
151 void TDEConfigDialog::setupManagerConnections(TDEConfigDialogManager *manager)
152 {
153  connect(manager, TQT_SIGNAL(settingsChanged()), this, TQT_SLOT(settingsChangedSlot()));
154  connect(manager, TQT_SIGNAL(widgetModified()), this, TQT_SLOT(updateButtons()));
155 
156  connect(this, TQT_SIGNAL(okClicked()), manager, TQT_SLOT(updateSettings()));
157  connect(this, TQT_SIGNAL(applyClicked()), manager, TQT_SLOT(updateSettings()));
158  connect(this, TQT_SIGNAL(defaultClicked()), manager, TQT_SLOT(updateWidgetsDefault()));
159 }
160 
161 TDEConfigDialog* TDEConfigDialog::exists(const char* name)
162 {
163  return openDialogs.find(name);
164 }
165 
166 bool TDEConfigDialog::showDialog(const char* name)
167 {
168  TDEConfigDialog *dialog = exists(name);
169  if(dialog)
170  dialog->show();
171  return (dialog != NULL);
172 }
173 
174 void TDEConfigDialog::updateButtons()
175 {
176  static bool only_once = false;
177  if (only_once) return;
178  only_once = true;
179 
180  TQMap<TQWidget *, TDEConfigDialogManager *>::iterator it;
181 
182  bool has_changed = d->manager->hasChanged() || hasChanged();
183  for (it = d->managerForPage.begin();
184  it != d->managerForPage.end() && !has_changed;
185  ++it)
186  {
187  has_changed |= (*it)->hasChanged();
188  }
189 
190  enableButton(Apply, has_changed);
191 
192  bool is_default = d->manager->isDefault() && isDefault();
193  for (it = d->managerForPage.begin();
194  it != d->managerForPage.end() && is_default;
195  ++it)
196  {
197  is_default &= (*it)->isDefault();
198  }
199 
200  enableButton(Default, !is_default);
201 
202  emit widgetModified();
203  only_once = false;
204 }
205 
206 void TDEConfigDialog::settingsChangedSlot()
207 {
208  // Update the buttons
209  updateButtons();
210  emit settingsChanged();
211  emit settingsChanged(name());
212 }
213 
214 void TDEConfigDialog::show()
215 {
216  TQMap<TQWidget *, TDEConfigDialogManager *>::iterator it;
217 
218  updateWidgets();
219  d->manager->updateWidgets();
220  for (it = d->managerForPage.begin(); it != d->managerForPage.end(); ++it)
221  (*it)->updateWidgets();
222 
223  bool has_changed = d->manager->hasChanged() || hasChanged();
224  for (it = d->managerForPage.begin();
225  it != d->managerForPage.end() && !has_changed;
226  ++it)
227  {
228  has_changed |= (*it)->hasChanged();
229  }
230 
231  enableButton(Apply, has_changed);
232 
233  bool is_default = d->manager->isDefault() && isDefault();
234  for (it = d->managerForPage.begin();
235  it != d->managerForPage.end() && is_default;
236  ++it)
237  {
238  is_default &= (*it)->isDefault();
239  }
240 
241  enableButton(Default, !is_default);
242  d->shown = true;
243  KDialogBase::show();
244 }
245 
246 void TDEConfigDialog::updateSettings()
247 {
248 }
249 
250 void TDEConfigDialog::updateWidgets()
251 {
252 }
253 
254 void TDEConfigDialog::updateWidgetsDefault()
255 {
256 }
257 
258 
259 #include "tdeconfigdialog.moc"
KDialogBase::defaultClicked
void defaultClicked()
The Default button was pressed.
TDEConfigDialog::widgetModified
void widgetModified()
A widget in the dialog was modified.
TDEConfigDialog::show
virtual void show()
Show the dialog.
Definition: tdeconfigdialog.cpp:214
KDialogBase::applyClicked
void applyClicked()
The Apply button was pressed.
TDEConfigDialog::updateWidgets
virtual void updateWidgets()
Update the dialog based on the settings.
Definition: tdeconfigdialog.cpp:250
KDialogBase::addVBoxPage
TQVBox * addVBoxPage(const TQString &itemName, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
Add a page to the dialog when the class is used in TreeList, IconList or Tabbed mode.
Definition: kdialogbase.cpp:1309
TDEConfigDialog::settingsChangedSlot
void settingsChangedSlot()
Some setting was changed.
Definition: tdeconfigdialog.cpp:206
TDEConfigDialog::settingsChanged
void settingsChanged()
One or more of the settings have been permanently changed such as if the user clicked on the Apply or...
TDEConfigDialog::updateSettings
virtual void updateSettings()
Update the settings from the dialog.
Definition: tdeconfigdialog.cpp:246
TDEConfigSkeleton
KDialogBase::enableButton
void enableButton(ButtonCode id, bool state)
Enable or disable (gray out) a general action button.
Definition: kdialogbase.cpp:838
TDEConfigDialog::hasChanged
virtual bool hasChanged()
Returns whether the current state of the dialog is different from the current configutation.
Definition: tdeconfigdialog.h:233
kdDebug
kdbgstream kdDebug(int area=0)
KDialogBase::Apply
Show Apply button.
Definition: kdialogbase.h:202
KDialogBase::ButtonCode
ButtonCode
Definition: kdialogbase.h:197
TDEConfigDialog::showDialog
static bool showDialog(const char *name)
Attempts to show the dialog with the name 'name'.
Definition: tdeconfigdialog.cpp:166
KDialogBase
A dialog base class with standard buttons and predefined layouts.
Definition: kdialogbase.h:191
TDEConfigDialog
Standard KDE configuration dialog class.
Definition: tdeconfigdialog.h:72
KDialogBase::DialogType
DialogType
Definition: kdialogbase.h:237
TDEConfigDialog::updateWidgetsDefault
virtual void updateWidgetsDefault()
Update the dialog based on the default settings.
Definition: tdeconfigdialog.cpp:254
tdelocale.h
KDialogBase::setMainWidget
void setMainWidget(TQWidget *widget)
Sets the main user definable widget.
Definition: kdialogbase.cpp:1431
TDEConfigDialog::isDefault
virtual bool isDefault()
Returns whether the current state of the dialog is the same as the default configuration.
Definition: tdeconfigdialog.h:239
TDEConfigDialog::~TDEConfigDialog
~TDEConfigDialog()
Deconstructor, removes name from the list of open dialogs.
Definition: tdeconfigdialog.cpp:80
TDEConfigDialog::exists
static TDEConfigDialog * exists(const char *name)
See if a dialog with the name 'name' already exists.
Definition: tdeconfigdialog.cpp:161
KDialogBase::plainPage
TQFrame * plainPage()
Retrieve the empty page when the predefined layout is used in Plain mode.
Definition: kdialogbase.cpp:420
TDEConfigDialog::updateButtons
void updateButtons()
Updates the Apply and Default buttons.
Definition: tdeconfigdialog.cpp:174
TDEConfigDialog::addPage
void addPage(TQWidget *page, const TQString &itemName, const TQString &pixmapName, const TQString &header=TQString::null, bool manage=true)
Adds page to the dialog and to TDEConfigDialogManager.
Definition: tdeconfigdialog.cpp:86
KDialogBase::okClicked
void okClicked()
The OK button was pressed.
TDEConfigDialogManager
KDialogBase::Default
Show Default button.
Definition: kdialogbase.h:200
TDEConfigDialog::TDEConfigDialog
TDEConfigDialog(TQWidget *parent, const char *name, TDEConfigSkeleton *config, DialogType dialogType=IconList, int dialogButtons=Default|Ok|Apply|Cancel|Help, ButtonCode defaultButton=Ok, bool modal=false)
Definition: tdeconfigdialog.cpp:49

tdeui

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

tdeui

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