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

kdeui

  • kdeui
kconfigdialog.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 2003 Benjamin C Meyer (ben+kdelibs 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 "kconfigdialog.h"
23 
24 #include <kconfigskeleton.h>
25 #include <kconfigdialogmanager.h>
26 #include <klocale.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<KConfigDialog> KConfigDialog::openDialogs;
35 
36 // This class is here purly so we don't break binary compatibility down the road.
37 class KConfigDialog::KConfigDialogPrivate
38 {
39 public:
40  KConfigDialogPrivate(KDialogBase::DialogType t)
41  : shown(false), type(t), manager(0) { }
42 
43  bool shown;
44  KDialogBase::DialogType type;
45  KConfigDialogManager *manager;
46  TQMap<TQWidget *, KConfigDialogManager *> managerForPage;
47 };
48 
49 KConfigDialog::KConfigDialog( TQWidget *parent, const char *name,
50  KConfigSkeleton *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 KConfigDialogPrivate(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 KConfigDialogManager(this, config);
75  setupManagerConnections(d->manager);
76 
77  enableButton(Apply, false);
78 }
79 
80 KConfigDialog::~KConfigDialog()
81 {
82  openDialogs.remove(name());
83  delete d;
84 }
85 
86 void KConfigDialog::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 KConfigDialog::addPage(TQWidget *page,
98  KConfigSkeleton *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 KConfigDialogManager(page, config);
105  setupManagerConnections(d->managerForPage[page]);
106 }
107 
108 void KConfigDialog::addPageInternal(TQWidget *page,
109  const TQString &itemName,
110  const TQString &pixmapName,
111  const TQString &header)
112 {
113  if(d->shown)
114  {
115  kdDebug(240) << "KConfigDialog::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) << "KConfigDialog::addpage: unknown type.";
148  }
149 }
150 
151 void KConfigDialog::setupManagerConnections(KConfigDialogManager *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 KConfigDialog* KConfigDialog::exists(const char* name)
162 {
163  return openDialogs.find(name);
164 }
165 
166 bool KConfigDialog::showDialog(const char* name)
167 {
168  KConfigDialog *dialog = exists(name);
169  if(dialog)
170  dialog->show();
171  return (dialog != NULL);
172 }
173 
174 void KConfigDialog::updateButtons()
175 {
176  static bool only_once = false;
177  if (only_once) return;
178  only_once = true;
179 
180  TQMap<TQWidget *, KConfigDialogManager *>::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 KConfigDialog::settingsChangedSlot()
207 {
208  // Update the buttons
209  updateButtons();
210  emit settingsChanged();
211  emit settingsChanged(name());
212 }
213 
214 void KConfigDialog::show()
215 {
216  TQMap<TQWidget *, KConfigDialogManager *>::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 KConfigDialog::updateSettings()
247 {
248 }
249 
250 void KConfigDialog::updateWidgets()
251 {
252 }
253 
254 void KConfigDialog::updateWidgetsDefault()
255 {
256 }
257 
258 
259 #include "kconfigdialog.moc"

kdeui

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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |