• Skip to content
  • Skip to link menu
KDE 4.3 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 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 
00022 */
00023 
00024 #define KDE3_SUPPORT
00025 #include "kcmodule.h"
00026 #undef KDE3_SUPPORT
00027 
00028 #include <QtGui/QLayout>
00029 #include <QTimer>
00030 
00031 #include <kaboutdata.h>
00032 #include <kconfigskeleton.h>
00033 #include <kconfigdialogmanager.h>
00034 #include <kdebug.h>
00035 #include <kglobal.h>
00036 #include <kcomponentdata.h>
00037 #include <klocale.h>
00038 
00039 class KCModulePrivate
00040 {
00041 public:
00042     KCModulePrivate():
00043         _buttons( KCModule::Help | KCModule::Default | KCModule::Apply ),
00044         _about( 0 ),
00045         _useRootOnlyMessage( false ),
00046         _firstshow(true),
00047         _unmanagedWidgetChangeState( false )
00048         { }
00049 
00050     KCModule::Buttons _buttons;
00051     KComponentData _componentData;
00052     const KAboutData *_about;
00053     QString _rootOnlyMessage;
00054     QList<KConfigDialogManager*> managers;
00055     QString _quickHelp;
00056     bool _useRootOnlyMessage : 1;
00057     bool _firstshow : 1;
00058 
00059     // this member is used to record the state on non-automatically
00060     // managed widgets, allowing for mixed KConfigXT-drive and manual
00061     // widgets to coexist peacefully and do the correct thing with
00062     // the changed(bool) signal
00063     bool _unmanagedWidgetChangeState : 1;
00064 };
00065 
00066 KCModule::KCModule( QWidget *parent, const char *name, const QStringList& )
00067     : QWidget(parent), d(new KCModulePrivate)
00068 {
00069     if (name && strlen(name)) {
00070         d->_componentData = KComponentData(name);
00071         KGlobal::locale()->insertCatalog(name);
00072     } else
00073         d->_componentData = KComponentData("kcmunnamed");
00074 }
00075 
00076 KCModule::KCModule(const KComponentData &componentData, QWidget *parent, const QStringList &)
00077     : QWidget(parent), d(new KCModulePrivate)
00078 {
00079     Q_ASSERT(componentData.isValid());
00080 
00081     KGlobal::locale()->insertCatalog(componentData.componentName());
00082 
00083     d->_componentData = componentData;
00084 }
00085 
00086 KCModule::KCModule(const KComponentData &componentData, QWidget *parent, const QVariantList &)
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 void KCModule::showEvent(QShowEvent *ev)
00097 {
00098     if (d->_firstshow) {
00099         d->_firstshow = false;
00100         QMetaObject::invokeMethod(this, "load", Qt::QueuedConnection);
00101         QMetaObject::invokeMethod(this, "changed", Qt::QueuedConnection, Q_ARG(bool, false));
00102     }
00103 
00104     QWidget::showEvent(ev);
00105 }
00106 
00107 KCModule::Buttons KCModule::buttons() const
00108 {
00109     return d->_buttons;
00110 }
00111 
00112 void KCModule::setButtons( Buttons buttons )
00113 {
00114     d->_buttons = buttons;
00115 }
00116 
00117 KConfigDialogManager* KCModule::addConfig( KConfigSkeleton *config, QWidget* widget )
00118 {
00119     KConfigDialogManager* manager = new KConfigDialogManager( widget, config );
00120     manager->setObjectName( objectName() );
00121     connect( manager, SIGNAL( widgetModified() ), SLOT( widgetChanged() ));
00122     d->managers.append( manager );
00123     return manager;
00124 }
00125 
00126 KCModule::~KCModule()
00127 {
00128     qDeleteAll(d->managers);
00129     d->managers.clear();
00130     delete d->_about;
00131     delete d;
00132 }
00133 
00134 void KCModule::load()
00135 {
00136     KConfigDialogManager* manager;
00137     Q_FOREACH( manager , d->managers )
00138         manager->updateWidgets();
00139     emit( changed( false ));
00140 }
00141 
00142 void KCModule::save()
00143 {
00144     KConfigDialogManager* manager;
00145     Q_FOREACH( manager , d->managers )
00146         manager->updateSettings();
00147     emit( changed( false ));
00148 }
00149 
00150 void KCModule::defaults()
00151 {
00152     KConfigDialogManager* manager;
00153     Q_FOREACH( manager , d->managers )
00154         manager->updateWidgetsDefault();
00155 }
00156 
00157 void KCModule::widgetChanged()
00158 {
00159     emit changed(d->_unmanagedWidgetChangeState || managedWidgetChangeState());
00160 }
00161 
00162 bool KCModule::managedWidgetChangeState() const
00163 {
00164     KConfigDialogManager* manager;
00165     Q_FOREACH( manager , d->managers )
00166     {
00167         if ( manager->hasChanged() )
00168             return true;
00169     }
00170 
00171     return false;
00172 }
00173 
00174 void KCModule::unmanagedWidgetChangeState(bool changed)
00175 {
00176     d->_unmanagedWidgetChangeState = changed;
00177     widgetChanged();
00178 }
00179 
00180 const KAboutData *KCModule::aboutData() const
00181 {
00182     return d->_about;
00183 }
00184 
00185 void KCModule::setAboutData( const KAboutData* about )
00186 {
00187     delete d->_about;
00188     d->_about = about;
00189 }
00190 
00191 void KCModule::setRootOnlyMessage(const QString& message)
00192 {
00193     d->_rootOnlyMessage = message;
00194 }
00195 
00196 QString KCModule::rootOnlyMessage() const
00197 {
00198     return d->_rootOnlyMessage;
00199 }
00200 
00201 void KCModule::setUseRootOnlyMessage(bool on)
00202 {
00203     d->_useRootOnlyMessage = on;
00204 }
00205 
00206 bool KCModule::useRootOnlyMessage() const
00207 {
00208     return d->_useRootOnlyMessage;
00209 }
00210 
00211 void KCModule::changed()
00212 {
00213     emit changed(true);
00214 }
00215 
00216 KComponentData KCModule::componentData() const
00217 {
00218     return d->_componentData;
00219 }
00220 
00221 void KCModule::setQuickHelp( const QString& help )
00222 {
00223     d->_quickHelp = help;
00224     emit( quickHelpChanged() );
00225 }
00226 
00227 QString KCModule::quickHelp() const
00228 {
00229     return d->_quickHelp;
00230 }
00231 
00232 QList<KConfigDialogManager*> KCModule::configs() const
00233 {
00234     return d->managers;
00235 }
00236 
00237 #include "kcmodule.moc"
00238 // 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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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