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

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
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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