• Skip to content
  • Skip to link menu
KDE 4.1 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         load();
00101         emit( changed( false ));
00102     }
00103     QWidget::showEvent(ev);
00104 }
00105 
00106 KCModule::Buttons KCModule::buttons() const
00107 {
00108     return d->_buttons;
00109 }
00110 
00111 void KCModule::setButtons( Buttons buttons )
00112 {
00113     d->_buttons = buttons;
00114 }
00115 
00116 KConfigDialogManager* KCModule::addConfig( KConfigSkeleton *config, QWidget* widget )
00117 {
00118     KConfigDialogManager* manager = new KConfigDialogManager( widget, config );
00119     manager->setObjectName( objectName() );
00120     connect( manager, SIGNAL( widgetModified() ), SLOT( widgetChanged() ));
00121     d->managers.append( manager );
00122     return manager;
00123 }
00124 
00125 KCModule::~KCModule()
00126 {
00127     qDeleteAll(d->managers);
00128     d->managers.clear();
00129     delete d->_about;
00130     delete d;
00131 }
00132 
00133 void KCModule::load()
00134 {
00135     KConfigDialogManager* manager;
00136     Q_FOREACH( manager , d->managers )
00137         manager->updateWidgets();
00138     emit( changed( false ));
00139 }
00140 
00141 void KCModule::save()
00142 {
00143     KConfigDialogManager* manager;
00144     Q_FOREACH( manager , d->managers )
00145         manager->updateSettings();
00146     emit( changed( false ));
00147 }
00148 
00149 void KCModule::defaults()
00150 {
00151     KConfigDialogManager* manager;
00152     Q_FOREACH( manager , d->managers )
00153         manager->updateWidgetsDefault();
00154 }
00155 
00156 void KCModule::widgetChanged()
00157 {
00158     emit changed(d->_unmanagedWidgetChangeState || managedWidgetChangeState());
00159 }
00160 
00161 bool KCModule::managedWidgetChangeState() const
00162 {
00163     KConfigDialogManager* manager;
00164     Q_FOREACH( manager , d->managers )
00165     {
00166         if ( manager->hasChanged() )
00167             return true;
00168     }
00169 
00170     return false;
00171 }
00172 
00173 void KCModule::unmanagedWidgetChangeState(bool changed)
00174 {
00175     d->_unmanagedWidgetChangeState = changed;
00176     widgetChanged();
00177 }
00178 
00179 const KAboutData *KCModule::aboutData() const
00180 {
00181     return d->_about;
00182 }
00183 
00184 void KCModule::setAboutData( const KAboutData* about )
00185 {
00186     delete d->_about;
00187     d->_about = about;
00188 }
00189 
00190 void KCModule::setRootOnlyMessage(const QString& message)
00191 {
00192     d->_rootOnlyMessage = message;
00193 }
00194 
00195 QString KCModule::rootOnlyMessage() const
00196 {
00197     return d->_rootOnlyMessage;
00198 }
00199 
00200 void KCModule::setUseRootOnlyMessage(bool on)
00201 {
00202     d->_useRootOnlyMessage = on;
00203 }
00204 
00205 bool KCModule::useRootOnlyMessage() const
00206 {
00207     return d->_useRootOnlyMessage;
00208 }
00209 
00210 void KCModule::changed()
00211 {
00212     emit changed(true);
00213 }
00214 
00215 KComponentData KCModule::componentData() const
00216 {
00217     return d->_componentData;
00218 }
00219 
00220 void KCModule::setQuickHelp( const QString& help )
00221 {
00222     d->_quickHelp = help;
00223     emit( quickHelpChanged() );
00224 }
00225 
00226 QString KCModule::quickHelp() const
00227 {
00228     return d->_quickHelp;
00229 }
00230 
00231 QList<KConfigDialogManager*> KCModule::configs() const
00232 {
00233     return d->managers;
00234 }
00235 
00236 #include "kcmodule.moc"
00237 // 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
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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