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

KDEUI

kcmodule.cpp

Go to the documentation of this file.
00001 /*
00002    This file is part of the KDE libraries
00003 
00004    Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
00005    Copyright (C) 2004 Frans Englich <frans.englich@telia.com>
00006    Copyright (C) 2009 Dario Freddi <drf@kde.org>
00007    
00008    This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public
00010    License as published by the Free Software Foundation; either
00011    version 2 of the License, or (at your option) any later version.
00012 
00013    This library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public License
00019    along with this library; see the file COPYING.LIB.  If not, write to
00020    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021    Boston, MA 02110-1301, USA.
00022 
00023 */
00024 
00025 #define KDE3_SUPPORT
00026 #include "kcmodule.h"
00027 #undef KDE3_SUPPORT
00028 
00029 #include <QtGui/QLayout>
00030 #include <QTimer>
00031 
00032 #include <kaboutdata.h>
00033 #include <kconfigskeleton.h>
00034 #include <kconfigdialogmanager.h>
00035 #include <kdebug.h>
00036 #include <kglobal.h>
00037 #include <kcomponentdata.h>
00038 #include <klocale.h>
00039 #include "auth/kauthaction.h"
00040 #include "auth/kauthactionwatcher.h"
00041 
00042 class KCModulePrivate
00043 {
00044 public:
00045     KCModulePrivate():
00046         _buttons( KCModule::Help | KCModule::Default | KCModule::Apply ),
00047         _about( 0 ),
00048         _useRootOnlyMessage( false ),
00049         _firstshow(true),
00050         _needsAuthorization(false),
00051         _authAction(0),
00052         _unmanagedWidgetChangeState( false )
00053         { }
00054 
00055     void authStatusChanged(int status);
00056 
00057     KCModule::Buttons _buttons;
00058     KComponentData _componentData;
00059     const KAboutData *_about;
00060     QString _rootOnlyMessage;
00061     QList<KConfigDialogManager*> managers;
00062     QString _quickHelp;
00063     bool _useRootOnlyMessage : 1;
00064     bool _firstshow : 1;
00065 
00066     bool  _needsAuthorization : 1;
00067     KAuth::Action *_authAction;
00068     
00069     // this member is used to record the state on non-automatically
00070     // managed widgets, allowing for mixed KConfigXT-drive and manual
00071     // widgets to coexist peacefully and do the correct thing with
00072     // the changed(bool) signal
00073     bool _unmanagedWidgetChangeState : 1;
00074 };
00075 
00076 KCModule::KCModule( QWidget *parent, const char *name, const QStringList& )
00077     : QWidget(parent), d(new KCModulePrivate)
00078 {
00079     if (name && strlen(name)) {
00080         d->_componentData = KComponentData(name);
00081         KGlobal::locale()->insertCatalog(name);
00082     } else
00083         d->_componentData = KComponentData("kcmunnamed");
00084 }
00085 
00086 KCModule::KCModule(const KComponentData &componentData, QWidget *parent, const QStringList &)
00087     : QWidget(parent), d(new KCModulePrivate)
00088 {
00089     Q_ASSERT(componentData.isValid());
00090 
00091     KGlobal::locale()->insertCatalog(componentData.componentName());
00092 
00093     d->_componentData = componentData;
00094 }
00095 
00096 KCModule::KCModule(const KComponentData &componentData, QWidget *parent, const QVariantList &)
00097     : QWidget( parent ), d(new KCModulePrivate)
00098 {
00099     Q_ASSERT(componentData.isValid());
00100 
00101     KGlobal::locale()->insertCatalog(componentData.componentName());
00102 
00103     d->_componentData = componentData;
00104 }
00105 
00106 void KCModule::showEvent(QShowEvent *ev)
00107 {
00108     if (d->_firstshow) {
00109         d->_firstshow = false;
00110         QMetaObject::invokeMethod(this, "load", Qt::QueuedConnection);
00111         QMetaObject::invokeMethod(this, "changed", Qt::QueuedConnection, Q_ARG(bool, false));
00112     }
00113 
00114     QWidget::showEvent(ev);
00115 }
00116 
00117 KCModule::Buttons KCModule::buttons() const
00118 {
00119     return d->_buttons;
00120 }
00121 
00122 void KCModule::setButtons( Buttons buttons )
00123 {
00124     d->_buttons = buttons;
00125 }
00126 
00127 KConfigDialogManager* KCModule::addConfig( KConfigSkeleton *config, QWidget* widget )
00128 {
00129     KConfigDialogManager* manager = new KConfigDialogManager( widget, config );
00130     manager->setObjectName( objectName() );
00131     connect( manager, SIGNAL( widgetModified() ), SLOT( widgetChanged() ));
00132     d->managers.append( manager );
00133     return manager;
00134 }
00135 
00136 void KCModule::setNeedsAuthorization(bool needsAuth)
00137 {
00138     d->_needsAuthorization = needsAuth;
00139     if (needsAuth && d->_about) {
00140         d->_authAction = new KAuth::Action(QString("org.kde.kcontrol." + d->_about->appName() + ".save"));
00141         d->_needsAuthorization = d->_authAction->isValid();
00142         d->_authAction->setHelperID("org.kde.kcontrol." + d->_about->appName());
00143         connect(d->_authAction->watcher(), SIGNAL(statusChanged(int)),
00144                 this, SLOT(authStatusChanged(int)));
00145         authStatusChanged(d->_authAction->status());
00146     } else {
00147         d->_authAction = 0;
00148     }
00149 }
00150 
00151 bool KCModule::needsAuthorization() const
00152 {
00153     return d->_needsAuthorization;
00154 }
00155 
00156 KAuth::Action *KCModule::authAction() const
00157 {
00158     return d->_authAction;
00159 }
00160 
00161 void KCModule::authStatusChanged(int status)
00162 {
00163     KAuth::Action::AuthStatus s = (KAuth::Action::AuthStatus)status;
00164 
00165     switch(s) {
00166         case KAuth::Action::Authorized:
00167             setUseRootOnlyMessage(false);
00168             break;
00169         case KAuth::Action::AuthRequired:
00170             setUseRootOnlyMessage(true);
00171             setRootOnlyMessage(i18n("You will be asked to authenticate before saving"));
00172             break;
00173         default:
00174             setUseRootOnlyMessage(true);
00175             setRootOnlyMessage(i18n("You are not allowed to save the configuration"));
00176             break;
00177     }
00178 
00179     qDebug() << useRootOnlyMessage();
00180 }
00181 
00182 KCModule::~KCModule()
00183 {
00184     qDeleteAll(d->managers);
00185     d->managers.clear();
00186     delete d->_about;
00187     delete d;
00188 }
00189 
00190 void KCModule::load()
00191 {
00192     KConfigDialogManager* manager;
00193     Q_FOREACH( manager , d->managers )
00194         manager->updateWidgets();
00195     emit( changed( false ));
00196 }
00197 
00198 void KCModule::save()
00199 {
00200     KConfigDialogManager* manager;
00201     Q_FOREACH( manager , d->managers )
00202         manager->updateSettings();
00203     emit( changed( false ));
00204 }
00205 
00206 void KCModule::defaults()
00207 {
00208     KConfigDialogManager* manager;
00209     Q_FOREACH( manager , d->managers )
00210         manager->updateWidgetsDefault();
00211 }
00212 
00213 void KCModule::widgetChanged()
00214 {
00215     emit changed(d->_unmanagedWidgetChangeState || managedWidgetChangeState());
00216 }
00217 
00218 bool KCModule::managedWidgetChangeState() const
00219 {
00220     KConfigDialogManager* manager;
00221     Q_FOREACH( manager , d->managers )
00222     {
00223         if ( manager->hasChanged() )
00224             return true;
00225     }
00226 
00227     return false;
00228 }
00229 
00230 void KCModule::unmanagedWidgetChangeState(bool changed)
00231 {
00232     d->_unmanagedWidgetChangeState = changed;
00233     widgetChanged();
00234 }
00235 
00236 const KAboutData *KCModule::aboutData() const
00237 {
00238     return d->_about;
00239 }
00240 
00241 void KCModule::setAboutData( const KAboutData* about )
00242 {
00243     delete d->_about;
00244     d->_about = about;
00245 }
00246 
00247 void KCModule::setRootOnlyMessage(const QString& message)
00248 {
00249     d->_rootOnlyMessage = message;
00250     emit rootOnlyMessageChanged(d->_useRootOnlyMessage, d->_rootOnlyMessage);
00251 }
00252 
00253 QString KCModule::rootOnlyMessage() const
00254 {
00255     return d->_rootOnlyMessage;
00256 }
00257 
00258 void KCModule::setUseRootOnlyMessage(bool on)
00259 {
00260     d->_useRootOnlyMessage = on;
00261     emit rootOnlyMessageChanged(d->_useRootOnlyMessage, d->_rootOnlyMessage);
00262 }
00263 
00264 bool KCModule::useRootOnlyMessage() const
00265 {
00266     return d->_useRootOnlyMessage;
00267 }
00268 
00269 void KCModule::changed()
00270 {
00271     emit changed(true);
00272 }
00273 
00274 KComponentData KCModule::componentData() const
00275 {
00276     return d->_componentData;
00277 }
00278 
00279 void KCModule::setQuickHelp( const QString& help )
00280 {
00281     d->_quickHelp = help;
00282     emit( quickHelpChanged() );
00283 }
00284 
00285 QString KCModule::quickHelp() const
00286 {
00287     return d->_quickHelp;
00288 }
00289 
00290 QList<KConfigDialogManager*> KCModule::configs() const
00291 {
00292     return d->managers;
00293 }
00294 
00295 #include "kcmodule.moc"
00296 // vim: sw=4 et sts=4

KDEUI

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
  • KUtils
  • Nepomuk
  • Plasma
  •     Sodep
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal