kutils Library API Documentation

kcmoduleproxy.cpp

00001 /* This file is part of the KDE project 00002 Copyright (C) 2003 Matthias Kretz <kretz@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00016 Boston, MA 02111-1307, USA. 00017 00018 */ 00019 00020 #include "kcmoduleproxy.h" 00021 #include "kcmoduleloader.h" 00022 #include "kcmoduleinfo.h" 00023 #include <qlayout.h> 00024 #include <qapplication.h> 00025 #include <qcursor.h> 00026 00027 class KCModuleProxy::KCModuleProxyPrivate 00028 { 00029 public: 00030 KCModuleProxyPrivate( const KCModuleInfo & info ) 00031 : kcm( 0 ) 00032 , modinfo( info ) 00033 , changed( false ) 00034 , failed( false ) 00035 {} 00036 00037 ~KCModuleProxyPrivate() 00038 { 00039 delete kcm; 00040 } 00041 00042 QStringList args; 00043 KCModule * kcm; 00044 KCModuleInfo modinfo; 00045 bool withfallback; 00046 bool changed; 00047 bool failed; 00048 }; 00049 00050 KCModuleProxy::KCModuleProxy( const KCModuleInfo & info, bool fallback, 00051 QWidget * parent, const char * name, const QStringList & args ) 00052 : QWidget( parent, name ) 00053 , d( new KCModuleProxyPrivate( info ) ) 00054 { 00055 d->args = args; 00056 d->withfallback = fallback; 00057 } 00058 00059 KCModuleProxy::~KCModuleProxy() 00060 { 00061 KCModuleLoader::unloadModule( d->modinfo ); 00062 delete d; 00063 } 00064 00065 void KCModuleProxy::load() 00066 { 00067 if( d->kcm ) 00068 { 00069 d->kcm->load(); 00070 moduleChanged( false ); 00071 } 00072 } 00073 00074 void KCModuleProxy::save() 00075 { 00076 if( d->kcm ) 00077 { 00078 d->kcm->save(); 00079 moduleChanged( false ); 00080 } 00081 } 00082 00083 void KCModuleProxy::defaults() 00084 { 00085 if( d->kcm ) 00086 { 00087 d->kcm->defaults(); 00088 } 00089 } 00090 00091 QString KCModuleProxy::quickHelp() const 00092 { 00093 return realModule() ? realModule()->quickHelp() : QString::null; 00094 } 00095 00096 const KAboutData * KCModuleProxy::aboutData() const 00097 { 00098 return realModule() ? realModule()->aboutData() : 0; 00099 } 00100 00101 int KCModuleProxy::buttons() const 00102 { 00103 return realModule() ? realModule()->buttons() : 00104 KCModule::Help | KCModule::Default | KCModule::Apply ; 00105 } 00106 00107 QString KCModuleProxy::rootOnlyMsg() const 00108 { 00109 return realModule() ? realModule()->rootOnlyMsg() : QString::null; 00110 } 00111 00112 bool KCModuleProxy::useRootOnlyMsg() const 00113 { 00114 return realModule() ? realModule()->useRootOnlyMsg() : true; 00115 } 00116 00117 KInstance * KCModuleProxy::instance() const 00118 { 00119 return realModule() ? realModule()->instance() : 0; 00120 } 00121 00122 bool KCModuleProxy::changed() const 00123 { 00124 return d->changed; 00125 } 00126 00127 KCModule * KCModuleProxy::realModule() const 00128 { 00129 if( ! d->kcm && ! d->failed ) 00130 { 00131 QApplication::setOverrideCursor(Qt::WaitCursor); 00132 KCModuleProxy * that = const_cast<KCModuleProxy*>( this ); 00133 ( new QHBoxLayout( that, 0, 0 ) )->setAutoAdd( true ); 00134 d->kcm = KCModuleLoader::loadModule( d->modinfo, d->withfallback, 00135 that, name(), d->args ); 00136 if( ! d->kcm ) 00137 { 00138 QApplication::restoreOverrideCursor(); 00139 KCModuleLoader::showLastLoaderError( that ); 00140 d->failed = true; 00141 return 0; 00142 } 00143 connect( d->kcm, SIGNAL( changed( bool ) ), 00144 this, SLOT( moduleChanged( bool ) ) ); 00145 connect( d->kcm, SIGNAL( destroyed() ), 00146 this, SLOT( moduleDestroyed() ) ); 00147 QApplication::restoreOverrideCursor(); 00148 } 00149 return d->kcm; 00150 } 00151 00152 void KCModuleProxy::showEvent( QShowEvent * ev ) 00153 { 00154 ( void )realModule(); 00155 QWidget::showEvent( ev ); 00156 } 00157 00158 void KCModuleProxy::moduleChanged( bool c ) 00159 { 00160 if( d->changed != c ) 00161 { 00162 d->changed = c; 00163 emit changed( c ); 00164 } 00165 } 00166 00167 void KCModuleProxy::moduleDestroyed() 00168 { 00169 d->kcm = 0; 00170 } 00171 00172 #include "kcmoduleproxy.moc" 00173 00174 // vim: sw=4 ts=4 noet
KDE Logo
This file is part of the documentation for kutils Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Aug 30 22:55:24 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003