KUtils
kcmodulecontainer.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2004 Frans Englich <frans.englich@telia.com> 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 as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "kcmodulecontainer.h" 00021 #include "kcmodulecontainer.moc" 00022 00023 #include <QtGui/QLayout> 00024 #include <QtGui/QPixmap> 00025 #include <QtCore/QStringList> 00026 00027 #include <kcmodule.h> 00028 #include <kcmoduleinfo.h> 00029 #include <kcmoduleloader.h> 00030 #include <kcmoduleproxy.h> 00031 #include <kdebug.h> 00032 #include <kdialog.h> 00033 #include <kglobal.h> 00034 #include <kguiitem.h> 00035 #include <kicon.h> 00036 #include <kiconloader.h> 00037 #include <kpushbutton.h> 00038 #include <kservice.h> 00039 #include <kstandardguiitem.h> 00040 #include <ktabwidget.h> 00041 00042 /***********************************************************************/ 00043 class KCModuleContainer::KCModuleContainerPrivate 00044 { 00045 public: 00046 KCModuleContainerPrivate( const QStringList& mods ) 00047 : modules( mods ) 00048 , tabWidget( 0 ) 00049 , topLayout( 0 ) 00050 {} 00051 00052 QStringList modules; 00053 KTabWidget *tabWidget; 00054 KCModule::Buttons buttons; 00055 QVBoxLayout *topLayout; 00056 00057 00058 }; 00059 /***********************************************************************/ 00060 00061 00062 00063 // The KCModuleContainer is only a wrapper around real KCModules. Therefore it doesn't need a 00064 // special KComponentData and can just use the global instance. The contained KCModules create their own 00065 // KComponentData objects when needed. 00066 /***********************************************************************/ 00067 KCModuleContainer::KCModuleContainer( QWidget* parent, const QString& mods ) 00068 : KCModule( KGlobal::mainComponent(), parent ), 00069 d(new KCModuleContainerPrivate( QString(mods).remove( ' ' ).split( ',', QString::SkipEmptyParts ) )) 00070 { 00071 init(); 00072 } 00073 00074 KCModuleContainer::KCModuleContainer( QWidget* parent, const QStringList& mods ) 00075 : KCModule( KGlobal::mainComponent(), parent ), 00076 d( new KCModuleContainerPrivate( mods ) ) 00077 { 00078 init(); 00079 } 00080 00081 void KCModuleContainer::init() 00082 { 00083 d->topLayout = new QVBoxLayout( this ); 00084 d->topLayout->setMargin( 0 ); 00085 d->topLayout->setObjectName( "topLayout" ); 00086 d->tabWidget = new KTabWidget(this); 00087 d->tabWidget->setObjectName( "tabWidget"); 00088 connect( d->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabSwitched(int))); 00089 d->topLayout->addWidget( d->tabWidget ); 00090 00091 if ( !d->modules.isEmpty() ) 00092 { 00093 /* Add our modules */ 00094 for ( QStringList::const_iterator it = d->modules.constBegin(); it != d->modules.constEnd(); ++it ) 00095 addModule( (*it) ); 00096 } 00097 } 00098 00099 void KCModuleContainer::addModule( const QString& module ) 00100 { 00101 /* In case it doesn't exist we just silently drop it. 00102 * This allows people to easily extend containers. 00103 * For example, KCM monitor gamma can be in kdegraphics. 00104 */ 00105 KService::Ptr service = KService::serviceByDesktopName( module ); 00106 if ( !service ) 00107 { 00108 kDebug(713) << "KCModuleContainer: module '" << 00109 module << "' was not found and thus not loaded" << endl; 00110 return; 00111 } 00112 00113 if ( service->noDisplay() ) 00114 return; 00115 00116 KCModuleProxy* proxy = new KCModuleProxy( service, d->tabWidget ); 00117 allModules.append( proxy ); 00118 00119 proxy->setObjectName( module.toLatin1() ); 00120 00121 d->tabWidget->addTab( proxy, KIcon( proxy->moduleInfo().icon() ), 00122 /* Qt eats ampersands for dinner. But not this time. */ 00123 proxy->moduleInfo().moduleName().replace( '&', "&&" )); 00124 00125 d->tabWidget->setTabToolTip( d->tabWidget->indexOf( proxy ), proxy->moduleInfo().comment() ); 00126 00127 connect( proxy, SIGNAL(changed(KCModuleProxy *)), SLOT(moduleChanged(KCModuleProxy *))); 00128 00129 /* Collect our buttons - we go for the common deliminator */ 00130 setButtons( buttons() | proxy->realModule()->buttons() ); 00131 } 00132 00133 void KCModuleContainer::tabSwitched(int index) 00134 { 00135 KCModuleProxy* mod = static_cast<KCModuleProxy *>(d->tabWidget->widget(index)); 00136 setQuickHelp( mod->quickHelp() ); 00137 setAboutData( mod->aboutData() ); 00138 } 00139 00140 void KCModuleContainer::save() 00141 { 00142 ModuleList list = changedModules; 00143 ModuleList::iterator it; 00144 for ( it = list.begin() ; it !=list.end() ; ++it ) 00145 { 00146 (*it)->save(); 00147 } 00148 00149 emit changed( false ); 00150 00151 } 00152 00153 void KCModuleContainer::load() 00154 { 00155 ModuleList list = allModules; 00156 ModuleList::iterator it; 00157 for ( it = list.begin() ; it !=list.end() ; ++it ) 00158 { 00159 (*it)->load(); 00160 } 00161 00162 emit changed( false ); 00163 } 00164 00165 void KCModuleContainer::defaults() 00166 { 00167 ModuleList list = allModules; 00168 ModuleList::iterator it; 00169 for ( it = list.begin() ; it !=list.end() ; ++it ) 00170 { 00171 (*it)->defaults(); 00172 } 00173 00174 emit changed( true ); 00175 } 00176 00177 00178 void KCModuleContainer::moduleChanged(KCModuleProxy * proxy) 00179 { 00180 changedModules.append( proxy ); 00181 if( changedModules.isEmpty() ) 00182 return; 00183 00184 emit changed(true); 00185 } 00186 00187 KCModuleContainer::~KCModuleContainer() 00188 { 00189 delete d; 00190 } 00191 00192 /***********************************************************************/ 00193 00194 00195 00196
KDE 4.6 API Reference