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

KDEUI

  • sources
  • kde-4.12
  • kdelibs
  • 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  if (about != d->_about) {
255  delete d->_about;
256  d->_about = about;
257  }
258 }
259 
260 void KCModule::setRootOnlyMessage(const QString& message)
261 {
262  d->_rootOnlyMessage = message;
263  emit rootOnlyMessageChanged(d->_useRootOnlyMessage, d->_rootOnlyMessage);
264 }
265 
266 QString KCModule::rootOnlyMessage() const
267 {
268  return d->_rootOnlyMessage;
269 }
270 
271 void KCModule::setUseRootOnlyMessage(bool on)
272 {
273  d->_useRootOnlyMessage = on;
274  emit rootOnlyMessageChanged(d->_useRootOnlyMessage, d->_rootOnlyMessage);
275 }
276 
277 bool KCModule::useRootOnlyMessage() const
278 {
279  return d->_useRootOnlyMessage;
280 }
281 
282 void KCModule::changed()
283 {
284  emit changed(true);
285 }
286 
287 KComponentData KCModule::componentData() const
288 {
289  return d->_componentData;
290 }
291 
292 QString KCModule::exportText() const
293 {
294  return d->m_ExportText;
295 }
296 
297 void KCModule::setExportText(const QString& text)
298 {
299  d->m_ExportText = text;
300 }
301 
302 void KCModule::setQuickHelp( const QString& help )
303 {
304  d->_quickHelp = help;
305  emit( quickHelpChanged() );
306 }
307 
308 QString KCModule::quickHelp() const
309 {
310  return d->_quickHelp;
311 }
312 
313 QList<KConfigDialogManager*> KCModule::configs() const
314 {
315  return d->managers;
316 }
317 
318 #include "kcmodule.moc"
319 // vim: sw=4 et sts=4
KStandardAction::help
KAction * help(const QObject *recvr, const char *slot, QObject *parent)
Display the help.
Definition: kstandardaction.cpp:596
i18n
QString i18n(const char *text)
KConfigDialogManager::updateWidgetsDefault
void updateWidgetsDefault()
Traverse the specified widgets, sets the state of all known widgets according to the default state in...
Definition: kconfigdialogmanager.cpp:371
KCModule::useRootOnlyMessage
bool useRootOnlyMessage() const
Tell if KControl should show a RootOnly message when run as a normal user.
Definition: kcmodule.cpp:277
KAuth::Action::AuthRequired
kdebug.h
KConfigDialogManager::updateWidgets
void updateWidgets()
Traverse the specified widgets, sets the state of all known widgets according to the state in the set...
Definition: kconfigdialogmanager.cpp:332
KCModule::setQuickHelp
void setQuickHelp(const QString &help)
Sets the quick help.
Definition: kcmodule.cpp:302
KCModule::unmanagedWidgetChangeState
void unmanagedWidgetChangeState(bool)
Call this method when your manually managed widgets change state between changed and not changed...
Definition: kcmodule.cpp:241
kcmodule.h
KCModule::quickHelpChanged
void quickHelpChanged()
Indicate that the module's quickhelp has changed.
KCModule::load
virtual void load()
Load the configuration data into the module.
Definition: kcmodule.cpp:201
QWidget
KConfigDialogManager::hasChanged
bool hasChanged() const
Returns whether the current state of the known widgets are different from the state in the config obj...
Definition: kconfigdialogmanager.cpp:517
KCModule::rootOnlyMessage
QString rootOnlyMessage() const
Get the RootOnly message for this module.
Definition: kcmodule.cpp:266
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
KConfigDialogManager
Provides a means of automatically retrieving, saving and resetting KConfigSkeleton based settings in ...
Definition: kconfigdialogmanager.h:85
KCModule::authStatusChanged
void authStatusChanged(int)
The status of the auth action, if one, has changed.
Definition: kcmodule.cpp:172
kauthactionwatcher.h
KConfigSkeleton
Class for handling preferences settings for an application.
Definition: kconfigskeleton.h:40
QString
KCModule::KCModule
KCModule(const KComponentData &componentData, QWidget *parent=0, const QVariantList &args=QVariantList())
Base class for all KControlModules.
Definition: kcmodule.cpp:77
KCModule::setExportText
void setExportText(const QString &)
Sets the export QString value, used for exporting data.
Definition: kcmodule.cpp:297
KCModule::componentData
KComponentData componentData() const
Definition: kcmodule.cpp:287
klocale.h
KCModule::widgetChanged
void widgetChanged()
A managed widget was changed, the widget settings and the current settings are compared and a corresp...
Definition: kcmodule.cpp:224
KCModule::Default
Definition: kcmodule.h:120
kglobal.h
KCModule::needsAuthorization
bool needsAuthorization() const
Returns the value previously set with setNeedsAuthorization().
Definition: kcmodule.cpp:162
KCModule::showEvent
virtual void showEvent(QShowEvent *ev)
Definition: kcmodule.cpp:107
KCoreConfigSkeleton
QStringList
KCModule::Help
Definition: kcmodule.h:120
KAboutData
KAuth::Action::Authorized
KCModule::addConfig
KConfigDialogManager * addConfig(KCoreConfigSkeleton *config, QWidget *widget)
Adds a KCoreConfigskeleton config to watch the widget widget.
Definition: kcmodule.cpp:128
KComponentData::componentName
QString componentName() const
kauthaction.h
KCModule::rootOnlyMessageChanged
void rootOnlyMessageChanged(bool use, QString message)
Indicate that the module's root message has changed.
KCModule::managedWidgetChangeState
bool managedWidgetChangeState() const
Returns the changed state of automatically managed widgets in this dialog.
Definition: kcmodule.cpp:229
KAuth::Action::AuthStatus
AuthStatus
KCModule::setUseRootOnlyMessage
void setUseRootOnlyMessage(bool on)
Change whether or not the RootOnly message should be shown.
Definition: kcmodule.cpp:271
KLocale::insertCatalog
void insertCatalog(const QString &catalog)
KCModule::setNeedsAuthorization
void setNeedsAuthorization(bool needsAuth)
Set if the module's save() method requires authorization to be executed.
Definition: kcmodule.cpp:146
KCModule::~KCModule
~KCModule()
Destroys the module.
Definition: kcmodule.cpp:193
KCModule::aboutData
virtual const KAboutData * aboutData() const
This is generally only called for the KBugReport.
Definition: kcmodule.cpp:247
KGlobal::locale
KLocale * locale()
KCModule::setRootOnlyMessage
void setRootOnlyMessage(const QString &message)
Sets the RootOnly message.
Definition: kcmodule.cpp:260
KCModule::exportText
QString exportText() const
Returns the value set by setExportText();.
Definition: kcmodule.cpp:292
KCModule::defaults
virtual void defaults()
Sets the configuration to sensible default values.
Definition: kcmodule.cpp:217
KCModule::buttons
Buttons buttons() const
Indicate which buttons will be used.
Definition: kcmodule.cpp:118
KCModule::setButtons
void setButtons(Buttons btn)
Sets the buttons to display.
Definition: kcmodule.cpp:123
KComponentData::isValid
bool isValid() const
KCModule::configs
QList< KConfigDialogManager * > configs() const
Definition: kcmodule.cpp:313
kaboutdata.h
KAuth::Action
kcomponentdata.h
KCModule::setAboutData
void setAboutData(const KAboutData *about)
This sets the KAboutData returned by aboutData()
Definition: kcmodule.cpp:252
KConfigDialogManager::updateSettings
void updateSettings()
Traverse the specified widgets, saving the settings of all known widgets in the settings object...
Definition: kconfigdialogmanager.cpp:378
KCModule::authAction
KAuth::Action * authAction() const
Returns the action previously set with setAuthAction().
Definition: kcmodule.cpp:167
KCModule::save
virtual void save()
Save the configuration data.
Definition: kcmodule.cpp:209
KComponentData
KCModule::quickHelp
virtual QString quickHelp() const
Return a quick-help text.
Definition: kcmodule.cpp:308
kconfigdialogmanager.h
QList< KConfigDialogManager * >
KCModule::changed
void changed()
Calling this slot is equivalent to emitting changed(true).
Definition: kcmodule.cpp:282
KCModule::Apply
Definition: kcmodule.h:120
kconfigskeleton.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:14 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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