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 QString m_ExportText; 00064 bool _useRootOnlyMessage : 1; 00065 bool _firstshow : 1; 00066 00067 bool _needsAuthorization : 1; 00068 KAuth::Action *_authAction; 00069 00070 // this member is used to record the state on non-automatically 00071 // managed widgets, allowing for mixed KConfigXT-drive and manual 00072 // widgets to coexist peacefully and do the correct thing with 00073 // the changed(bool) signal 00074 bool _unmanagedWidgetChangeState : 1; 00075 }; 00076 00077 KCModule::KCModule( QWidget *parent, const char *name, const QStringList& ) 00078 : QWidget(parent), d(new KCModulePrivate) 00079 { 00080 if (name && strlen(name)) { 00081 d->_componentData = KComponentData(name); 00082 KGlobal::locale()->insertCatalog(name); 00083 } else 00084 d->_componentData = KComponentData("kcmunnamed"); 00085 } 00086 00087 KCModule::KCModule(const KComponentData &componentData, QWidget *parent, const QStringList &) 00088 : QWidget(parent), d(new KCModulePrivate) 00089 { 00090 Q_ASSERT(componentData.isValid()); 00091 00092 KGlobal::locale()->insertCatalog(componentData.componentName()); 00093 00094 d->_componentData = componentData; 00095 } 00096 00097 KCModule::KCModule(const KComponentData &componentData, QWidget *parent, const QVariantList &) 00098 : QWidget( parent ), d(new KCModulePrivate) 00099 { 00100 Q_ASSERT(componentData.isValid()); 00101 00102 KGlobal::locale()->insertCatalog(componentData.componentName()); 00103 00104 d->_componentData = componentData; 00105 } 00106 00107 void KCModule::showEvent(QShowEvent *ev) 00108 { 00109 if (d->_firstshow) { 00110 d->_firstshow = false; 00111 QMetaObject::invokeMethod(this, "load", Qt::QueuedConnection); 00112 QMetaObject::invokeMethod(this, "changed", Qt::QueuedConnection, Q_ARG(bool, false)); 00113 } 00114 00115 QWidget::showEvent(ev); 00116 } 00117 00118 KCModule::Buttons KCModule::buttons() const 00119 { 00120 return d->_buttons; 00121 } 00122 00123 void KCModule::setButtons( Buttons buttons ) 00124 { 00125 d->_buttons = buttons; 00126 } 00127 00128 KConfigDialogManager* KCModule::addConfig( KCoreConfigSkeleton *config, QWidget* widget ) 00129 { 00130 KConfigDialogManager* manager = new KConfigDialogManager( widget, config ); 00131 manager->setObjectName( objectName() ); 00132 connect( manager, SIGNAL( widgetModified() ), SLOT( widgetChanged() )); 00133 d->managers.append( manager ); 00134 return manager; 00135 } 00136 00137 KConfigDialogManager* KCModule::addConfig( KConfigSkeleton *config, QWidget* widget ) 00138 { 00139 KConfigDialogManager* manager = new KConfigDialogManager( widget, config ); 00140 manager->setObjectName( objectName() ); 00141 connect( manager, SIGNAL( widgetModified() ), SLOT( widgetChanged() )); 00142 d->managers.append( manager ); 00143 return manager; 00144 } 00145 00146 void KCModule::setNeedsAuthorization(bool needsAuth) 00147 { 00148 d->_needsAuthorization = needsAuth; 00149 if (needsAuth && d->_about) { 00150 d->_authAction = new KAuth::Action(QString("org.kde.kcontrol." + d->_about->appName() + ".save")); 00151 d->_needsAuthorization = d->_authAction->isValid(); 00152 d->_authAction->setHelperID("org.kde.kcontrol." + d->_about->appName()); 00153 d->_authAction->setParentWidget(this); 00154 connect(d->_authAction->watcher(), SIGNAL(statusChanged(int)), 00155 this, SLOT(authStatusChanged(int))); 00156 authStatusChanged(d->_authAction->status()); 00157 } else { 00158 d->_authAction = 0; 00159 } 00160 } 00161 00162 bool KCModule::needsAuthorization() const 00163 { 00164 return d->_needsAuthorization; 00165 } 00166 00167 KAuth::Action *KCModule::authAction() const 00168 { 00169 return d->_authAction; 00170 } 00171 00172 void KCModule::authStatusChanged(int status) 00173 { 00174 KAuth::Action::AuthStatus s = (KAuth::Action::AuthStatus)status; 00175 00176 switch(s) { 00177 case KAuth::Action::Authorized: 00178 setUseRootOnlyMessage(false); 00179 break; 00180 case KAuth::Action::AuthRequired: 00181 setUseRootOnlyMessage(true); 00182 setRootOnlyMessage(i18n("You will be asked to authenticate before saving")); 00183 break; 00184 default: 00185 setUseRootOnlyMessage(true); 00186 setRootOnlyMessage(i18n("You are not allowed to save the configuration")); 00187 break; 00188 } 00189 00190 qDebug() << useRootOnlyMessage(); 00191 } 00192 00193 KCModule::~KCModule() 00194 { 00195 qDeleteAll(d->managers); 00196 d->managers.clear(); 00197 delete d->_about; 00198 delete d; 00199 } 00200 00201 void KCModule::load() 00202 { 00203 KConfigDialogManager* manager; 00204 Q_FOREACH( manager , d->managers ) 00205 manager->updateWidgets(); 00206 emit( changed( false )); 00207 } 00208 00209 void KCModule::save() 00210 { 00211 KConfigDialogManager* manager; 00212 Q_FOREACH( manager , d->managers ) 00213 manager->updateSettings(); 00214 emit( changed( false )); 00215 } 00216 00217 void KCModule::defaults() 00218 { 00219 KConfigDialogManager* manager; 00220 Q_FOREACH( manager , d->managers ) 00221 manager->updateWidgetsDefault(); 00222 } 00223 00224 void KCModule::widgetChanged() 00225 { 00226 emit changed(d->_unmanagedWidgetChangeState || managedWidgetChangeState()); 00227 } 00228 00229 bool KCModule::managedWidgetChangeState() const 00230 { 00231 KConfigDialogManager* manager; 00232 Q_FOREACH( manager , d->managers ) 00233 { 00234 if ( manager->hasChanged() ) 00235 return true; 00236 } 00237 00238 return false; 00239 } 00240 00241 void KCModule::unmanagedWidgetChangeState(bool changed) 00242 { 00243 d->_unmanagedWidgetChangeState = changed; 00244 widgetChanged(); 00245 } 00246 00247 const KAboutData *KCModule::aboutData() const 00248 { 00249 return d->_about; 00250 } 00251 00252 void KCModule::setAboutData( const KAboutData* about ) 00253 { 00254 delete d->_about; 00255 d->_about = about; 00256 } 00257 00258 void KCModule::setRootOnlyMessage(const QString& message) 00259 { 00260 d->_rootOnlyMessage = message; 00261 emit rootOnlyMessageChanged(d->_useRootOnlyMessage, d->_rootOnlyMessage); 00262 } 00263 00264 QString KCModule::rootOnlyMessage() const 00265 { 00266 return d->_rootOnlyMessage; 00267 } 00268 00269 void KCModule::setUseRootOnlyMessage(bool on) 00270 { 00271 d->_useRootOnlyMessage = on; 00272 emit rootOnlyMessageChanged(d->_useRootOnlyMessage, d->_rootOnlyMessage); 00273 } 00274 00275 bool KCModule::useRootOnlyMessage() const 00276 { 00277 return d->_useRootOnlyMessage; 00278 } 00279 00280 void KCModule::changed() 00281 { 00282 emit changed(true); 00283 } 00284 00285 KComponentData KCModule::componentData() const 00286 { 00287 return d->_componentData; 00288 } 00289 00290 QString KCModule::exportText() const 00291 { 00292 return d->m_ExportText; 00293 } 00294 00295 void KCModule::setExportText(const QString& text) 00296 { 00297 d->m_ExportText = text; 00298 } 00299 00300 void KCModule::setQuickHelp( const QString& help ) 00301 { 00302 d->_quickHelp = help; 00303 emit( quickHelpChanged() ); 00304 } 00305 00306 QString KCModule::quickHelp() const 00307 { 00308 return d->_quickHelp; 00309 } 00310 00311 QList<KConfigDialogManager*> KCModule::configs() const 00312 { 00313 return d->managers; 00314 } 00315 00316 #include "kcmodule.moc" 00317 // vim: sw=4 et sts=4
KDE 4.6 API Reference