kdeui
kcmodule.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qlayout.h>
00025
00026 #include <kaboutdata.h>
00027 #include <kconfigskeleton.h>
00028 #include <kconfigdialogmanager.h>
00029 #include <kdebug.h>
00030 #include <kglobal.h>
00031 #include <kinstance.h>
00032 #include <klocale.h>
00033
00034 #include "kcmodule.h"
00035 #include "kcmodule.moc"
00036
00037 class KCModulePrivate
00038 {
00039 public:
00040 KCModulePrivate():
00041 _about( 0 ),
00042 _useRootOnlyMsg( false ),
00043 _hasOwnInstance( true ),
00044 _unmanagedWidgetChangeState( false )
00045 { }
00046
00047 KInstance *_instance;
00048 KAboutData *_about;
00049 QString _rootOnlyMsg;
00050 bool _useRootOnlyMsg;
00051 bool _hasOwnInstance;
00052 QPtrList<KConfigDialogManager> managers;
00053 QString _quickHelp;
00054
00055
00056
00057
00058
00059 bool _unmanagedWidgetChangeState;
00060 };
00061
00062 KCModule::KCModule(QWidget *parent, const char *name, const QStringList &)
00063 : QWidget(parent, name)
00064 {
00065 init();
00066 if (name && strlen(name)) {
00067 d->_instance = new KInstance(name);
00068 KGlobal::locale()->insertCatalogue(name);
00069 } else
00070 d->_instance = new KInstance("kcmunnamed");
00071 KGlobal::setActiveInstance(this->instance());
00072
00073 d->managers.setAutoDelete( true );
00074
00075 }
00076
00077 KCModule::KCModule(KInstance *instance, QWidget *parent, const QStringList & )
00078 : QWidget(parent, instance ? instance->instanceName().data() : 0)
00079 {
00080 init();
00081 d->_instance = instance;
00082
00083 if (instance)
00084 {
00085 KGlobal::locale()->insertCatalogue(instance->instanceName());
00086 }
00087
00088 d->_hasOwnInstance = false;
00089 KGlobal::setActiveInstance(this->instance());
00090 }
00091
00092 void KCModule::init()
00093 {
00094 d = new KCModulePrivate;
00095 _btn = Help|Default|Apply;
00096 }
00097
00098 KConfigDialogManager* KCModule::addConfig( KConfigSkeleton *config, QWidget* widget )
00099 {
00100 KConfigDialogManager* manager = new KConfigDialogManager( widget, config, name() );
00101 connect( manager, SIGNAL( widgetModified() ), SLOT( widgetChanged() ));
00102 d->managers.append( manager );
00103 return manager;
00104 }
00105
00106 KCModule::~KCModule()
00107 {
00108 if (d->_hasOwnInstance)
00109 delete d->_instance;
00110 delete d->_about;
00111 delete d;
00112 }
00113
00114 void KCModule::load()
00115 {
00116 KConfigDialogManager* manager;
00117 for( manager = d->managers.first(); manager; manager = d->managers.next() )
00118 manager->updateWidgets();
00119 }
00120
00121 void KCModule::save()
00122 {
00123 KConfigDialogManager* manager;
00124 for( manager = d->managers.first(); manager; manager = d->managers.next() )
00125 manager->updateSettings();
00126 emit( changed( false ));
00127 }
00128
00129 void KCModule::defaults()
00130 {
00131 KConfigDialogManager* manager;
00132 for( manager = d->managers.first(); manager; manager = d->managers.next() )
00133 manager->updateWidgetsDefault();
00134 }
00135
00136 void KCModule::widgetChanged()
00137 {
00138 emit changed(d->_unmanagedWidgetChangeState || managedWidgetChangeState());
00139 }
00140
00141 bool KCModule::managedWidgetChangeState() const
00142 {
00143 KConfigDialogManager* manager;
00144 for( manager = d->managers.first(); manager; manager = d->managers.next() )
00145 {
00146 if ( manager->hasChanged() )
00147 return true;
00148 }
00149
00150 return false;
00151 }
00152
00153 void KCModule::unmanagedWidgetChangeState(bool changed)
00154 {
00155 d->_unmanagedWidgetChangeState = changed;
00156 widgetChanged();
00157 }
00158
00159 const KAboutData *KCModule::aboutData() const
00160 {
00161 return d->_about;
00162 }
00163
00164 void KCModule::setAboutData( KAboutData* about )
00165 {
00166 delete d->_about;
00167 d->_about = about;
00168 }
00169
00170 void KCModule::setRootOnlyMsg(const QString& msg)
00171 {
00172 d->_rootOnlyMsg = msg;
00173 }
00174
00175 QString KCModule::rootOnlyMsg() const
00176 {
00177 return d->_rootOnlyMsg;
00178 }
00179
00180 void KCModule::setUseRootOnlyMsg(bool on)
00181 {
00182 d->_useRootOnlyMsg = on;
00183 }
00184
00185 bool KCModule::useRootOnlyMsg() const
00186 {
00187 return d->_useRootOnlyMsg;
00188 }
00189
00190 void KCModule::changed()
00191 {
00192 emit changed(true);
00193 }
00194
00195 KInstance *KCModule::instance() const
00196 {
00197 return d->_instance;
00198 }
00199
00200 void KCModule::setQuickHelp( const QString& help )
00201 {
00202 d->_quickHelp = help;
00203 emit( quickHelpChanged() );
00204 }
00205
00206 QString KCModule::quickHelp() const
00207 {
00208 return d->_quickHelp;
00209 }
00210
00211
00212 const QPtrList<KConfigDialogManager>& KCModule::configs() const
00213 {
00214 return d->managers;
00215 }
00216
00217 void KCModule::virtual_hook( int, void* )
00218 { }
00219
00220