• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.4 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • widgets
kcmodule.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE libraries
3 
4  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
5  Copyright (C) 2004 Frans Englich <frans.englich@telia.com>
6  Copyright (C) 2009 Dario Freddi <drf@kde.org>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 
23 */
24 
25 #define KDE3_SUPPORT
26 #include "kcmodule.h"
27 #undef KDE3_SUPPORT
28 
29 #include <QtGui/QLayout>
30 #include <QTimer>
31 
32 #include <kaboutdata.h>
33 #include <kconfigskeleton.h>
34 #include <kconfigdialogmanager.h>
35 #include <kdebug.h>
36 #include <kglobal.h>
37 #include <kcomponentdata.h>
38 #include <klocale.h>
39 #include "auth/kauthaction.h"
40 #include "auth/kauthactionwatcher.h"
41 
42 class KCModulePrivate
43 {
44 public:
45  KCModulePrivate():
46  _buttons( KCModule::Help | KCModule::Default | KCModule::Apply ),
47  _about( 0 ),
48  _useRootOnlyMessage( false ),
49  _firstshow(true),
50  _needsAuthorization(false),
51  _authAction(0),
52  _unmanagedWidgetChangeState( false )
53  { }
54 
55  void authStatusChanged(int status);
56 
57  KCModule::Buttons _buttons;
58  KComponentData _componentData;
59  const KAboutData *_about;
60  QString _rootOnlyMessage;
61  QList<KConfigDialogManager*> managers;
62  QString _quickHelp;
63  QString m_ExportText;
64  bool _useRootOnlyMessage : 1;
65  bool _firstshow : 1;
66 
67  bool _needsAuthorization : 1;
68  KAuth::Action *_authAction;
69 
70  // this member is used to record the state on non-automatically
71  // managed widgets, allowing for mixed KConfigXT-drive and manual
72  // widgets to coexist peacefully and do the correct thing with
73  // the changed(bool) signal
74  bool _unmanagedWidgetChangeState : 1;
75 };
76 
77 KCModule::KCModule( QWidget *parent, const char *name, const QStringList& )
78  : QWidget(parent), d(new KCModulePrivate)
79 {
80  if (name && strlen(name)) {
81  d->_componentData = KComponentData(name);
82  KGlobal::locale()->insertCatalog(name);
83  } else
84  d->_componentData = KComponentData("kcmunnamed");
85 }
86 
87 KCModule::KCModule(const KComponentData &componentData, QWidget *parent, const QStringList &)
88  : QWidget(parent), d(new KCModulePrivate)
89 {
90  Q_ASSERT(componentData.isValid());
91 
92  KGlobal::locale()->insertCatalog(componentData.componentName());
93 
94  d->_componentData = componentData;
95 }
96 
97 KCModule::KCModule(const KComponentData &componentData, QWidget *parent, const QVariantList &)
98  : QWidget( parent ), d(new KCModulePrivate)
99 {
100  Q_ASSERT(componentData.isValid());
101 
102  KGlobal::locale()->insertCatalog(componentData.componentName());
103 
104  d->_componentData = componentData;
105 }
106 
107 void KCModule::showEvent(QShowEvent *ev)
108 {
109  if (d->_firstshow) {
110  d->_firstshow = false;
111  QMetaObject::invokeMethod(this, "load", Qt::QueuedConnection);
112  QMetaObject::invokeMethod(this, "changed", Qt::QueuedConnection, Q_ARG(bool, false));
113  }
114 
115  QWidget::showEvent(ev);
116 }
117 
118 KCModule::Buttons KCModule::buttons() const
119 {
120  return d->_buttons;
121 }
122 
123 void KCModule::setButtons( Buttons buttons )
124 {
125  d->_buttons = buttons;
126 }
127 
128 KConfigDialogManager* KCModule::addConfig( KCoreConfigSkeleton *config, QWidget* widget )
129 {
130  KConfigDialogManager* manager = new KConfigDialogManager( widget, config );
131  manager->setObjectName( objectName() );
132  connect( manager, SIGNAL(widgetModified()), SLOT(widgetChanged()));
133  d->managers.append( manager );
134  return manager;
135 }
136 
137 KConfigDialogManager* KCModule::addConfig( KConfigSkeleton *config, QWidget* widget )
138 {
139  KConfigDialogManager* manager = new KConfigDialogManager( widget, config );
140  manager->setObjectName( objectName() );
141  connect( manager, SIGNAL(widgetModified()), SLOT(widgetChanged()));
142  d->managers.append( manager );
143  return manager;
144 }
145 
146 void KCModule::setNeedsAuthorization(bool needsAuth)
147 {
148  d->_needsAuthorization = needsAuth;
149  if (needsAuth && d->_about) {
150  d->_authAction = new KAuth::Action(QString("org.kde.kcontrol." + d->_about->appName() + ".save"));
151  d->_needsAuthorization = d->_authAction->isValid();
152  d->_authAction->setHelperID("org.kde.kcontrol." + d->_about->appName());
153  d->_authAction->setParentWidget(this);
154  connect(d->_authAction->watcher(), SIGNAL(statusChanged(int)),
155  this, SLOT(authStatusChanged(int)));
156  authStatusChanged(d->_authAction->status());
157  } else {
158  d->_authAction = 0;
159  }
160 }
161 
162 bool KCModule::needsAuthorization() const
163 {
164  return d->_needsAuthorization;
165 }
166 
167 KAuth::Action *KCModule::authAction() const
168 {
169  return d->_authAction;
170 }
171 
172 void KCModule::authStatusChanged(int status)
173 {
174  KAuth::Action::AuthStatus s = (KAuth::Action::AuthStatus)status;
175 
176  switch(s) {
177  case KAuth::Action::Authorized:
178  setUseRootOnlyMessage(false);
179  break;
180  case KAuth::Action::AuthRequired:
181  setUseRootOnlyMessage(true);
182  setRootOnlyMessage(i18n("You will be asked to authenticate before saving"));
183  break;
184  default:
185  setUseRootOnlyMessage(true);
186  setRootOnlyMessage(i18n("You are not allowed to save the configuration"));
187  break;
188  }
189 
190  qDebug() << useRootOnlyMessage();
191 }
192 
193 KCModule::~KCModule()
194 {
195  qDeleteAll(d->managers);
196  d->managers.clear();
197  delete d->_about;
198  delete d;
199 }
200 
201 void KCModule::load()
202 {
203  KConfigDialogManager* manager;
204  Q_FOREACH( manager , d->managers )
205  manager->updateWidgets();
206  emit( changed( false ));
207 }
208 
209 void KCModule::save()
210 {
211  KConfigDialogManager* manager;
212  Q_FOREACH( manager , d->managers )
213  manager->updateSettings();
214  emit( changed( false ));
215 }
216 
217 void KCModule::defaults()
218 {
219  KConfigDialogManager* manager;
220  Q_FOREACH( manager , d->managers )
221  manager->updateWidgetsDefault();
222 }
223 
224 void KCModule::widgetChanged()
225 {
226  emit changed(d->_unmanagedWidgetChangeState || managedWidgetChangeState());
227 }
228 
229 bool KCModule::managedWidgetChangeState() const
230 {
231  KConfigDialogManager* manager;
232  Q_FOREACH( manager , d->managers )
233  {
234  if ( manager->hasChanged() )
235  return true;
236  }
237 
238  return false;
239 }
240 
241 void KCModule::unmanagedWidgetChangeState(bool changed)
242 {
243  d->_unmanagedWidgetChangeState = changed;
244  widgetChanged();
245 }
246 
247 const KAboutData *KCModule::aboutData() const
248 {
249  return d->_about;
250 }
251 
252 void KCModule::setAboutData( const KAboutData* about )
253 {
254  delete d->_about;
255  d->_about = about;
256 }
257 
258 void KCModule::setRootOnlyMessage(const QString& message)
259 {
260  d->_rootOnlyMessage = message;
261  emit rootOnlyMessageChanged(d->_useRootOnlyMessage, d->_rootOnlyMessage);
262 }
263 
264 QString KCModule::rootOnlyMessage() const
265 {
266  return d->_rootOnlyMessage;
267 }
268 
269 void KCModule::setUseRootOnlyMessage(bool on)
270 {
271  d->_useRootOnlyMessage = on;
272  emit rootOnlyMessageChanged(d->_useRootOnlyMessage, d->_rootOnlyMessage);
273 }
274 
275 bool KCModule::useRootOnlyMessage() const
276 {
277  return d->_useRootOnlyMessage;
278 }
279 
280 void KCModule::changed()
281 {
282  emit changed(true);
283 }
284 
285 KComponentData KCModule::componentData() const
286 {
287  return d->_componentData;
288 }
289 
290 QString KCModule::exportText() const
291 {
292  return d->m_ExportText;
293 }
294 
295 void KCModule::setExportText(const QString& text)
296 {
297  d->m_ExportText = text;
298 }
299 
300 void KCModule::setQuickHelp( const QString& help )
301 {
302  d->_quickHelp = help;
303  emit( quickHelpChanged() );
304 }
305 
306 QString KCModule::quickHelp() const
307 {
308  return d->_quickHelp;
309 }
310 
311 QList<KConfigDialogManager*> KCModule::configs() const
312 {
313  return d->managers;
314 }
315 
316 #include "kcmodule.moc"
317 // vim: sw=4 et sts=4
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Mon Jul 15 2013 05:10:32 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs-4.10.4 API Reference

Skip menu "kdelibs-4.10.4 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal