• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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 ),d(new KCModuleContainerPrivate( QString(mods).remove( ' ' ).split( ',' ) ))
00069 {
00070     init();
00071 }
00072 
00073 KCModuleContainer::KCModuleContainer( QWidget* parent, const QStringList& mods )
00074     : KCModule( KGlobal::mainComponent(), parent ), d( new KCModuleContainerPrivate( mods ) )
00075 {
00076     init();
00077 }
00078 
00079 void KCModuleContainer::init()
00080 {
00081     d->topLayout = new QVBoxLayout( this );
00082     d->topLayout->setMargin( 0 );
00083     d->topLayout->setObjectName( "topLayout" );
00084     d->tabWidget = new KTabWidget(this);
00085     d->tabWidget->setObjectName( "tabWidget");
00086     connect( d->tabWidget, SIGNAL( currentChanged( QWidget* ) ), SLOT( tabSwitched( QWidget* ) ));
00087     d->topLayout->addWidget( d->tabWidget );
00088 
00089     if ( !d->modules.isEmpty() )
00090     {
00091         /* Add our modules */
00092         for ( QStringList::const_iterator it = d->modules.constBegin(); it != d->modules.constEnd(); ++it )
00093             addModule( (*it) );
00094     }
00095 }
00096 
00097 void KCModuleContainer::addModule( const QString& module )
00098 {
00099     /* In case it doesn't exist we just silently drop it.
00100      * This allows people to easily extend containers.
00101      * For example, KCM monitor gamma can be in kdegraphics.
00102      */
00103     KService::Ptr service = KService::serviceByDesktopName( module );
00104     if ( !service )
00105     {
00106         kDebug(713) << "KCModuleContainer: module '" << 
00107             module << "' was not found and thus not loaded" << endl;
00108         return;
00109     }
00110 
00111     if ( service->noDisplay() )
00112         return;
00113 
00114     KCModuleProxy* proxy = new KCModuleProxy( service, d->tabWidget );
00115     allModules.append( proxy );
00116 
00117     proxy->setObjectName( module.toLatin1() );
00118 
00119     d->tabWidget->addTab( proxy, KIcon( proxy->moduleInfo().icon() ),
00120             /* Qt eats ampersands for dinner. But not this time. */
00121             proxy->moduleInfo().moduleName().replace( '&', "&&" ));
00122 
00123     d->tabWidget->setTabToolTip( d->tabWidget->indexOf( proxy ), proxy->moduleInfo().comment() );
00124 
00125     connect( proxy, SIGNAL(changed(KCModuleProxy *)), SLOT(moduleChanged(KCModuleProxy *)));
00126 
00127     /* Collect our buttons - we go for the common deliminator */
00128     setButtons( buttons() | proxy->realModule()->buttons() );
00129 }
00130 
00131 void KCModuleContainer::tabSwitched( QWidget * module )
00132 {
00133     KCModuleProxy* mod = (KCModuleProxy *) module;
00134     setQuickHelp( mod->quickHelp() );
00135     setAboutData( mod->aboutData() );
00136 }
00137 
00138 void KCModuleContainer::save()
00139 {
00140     ModuleList list = changedModules;
00141     ModuleList::iterator it;
00142     for ( it = list.begin() ; it !=list.end() ; ++it )
00143     {
00144         (*it)->save();
00145     }
00146 
00147     emit changed( false );
00148 
00149 }
00150 
00151 void KCModuleContainer::load()
00152 {
00153     ModuleList list = allModules;
00154     ModuleList::iterator it;
00155     for ( it = list.begin() ; it !=list.end() ; ++it )
00156     {
00157         (*it)->load();
00158     }
00159 
00160     emit changed( false );
00161 }
00162 
00163 void KCModuleContainer::defaults()
00164 {
00165     ModuleList list = allModules;
00166     ModuleList::iterator it;
00167     for ( it = list.begin() ; it !=list.end() ; ++it )
00168     {
00169         (*it)->defaults();
00170     }
00171 
00172     emit changed( true );
00173 }
00174 
00175 
00176 void KCModuleContainer::moduleChanged(KCModuleProxy * proxy)
00177 {
00178     changedModules.append( proxy );
00179     if( changedModules.isEmpty() )
00180         return;
00181 
00182     emit changed(true);
00183 }
00184 
00185 KCModuleContainer::~KCModuleContainer()
00186 {
00187     delete d;
00188 }
00189 
00190 /***********************************************************************/
00191 
00192 
00193 
00194 

KUtils

Skip menu "KUtils"
  • Main Page
  • 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