• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • 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 <qlayout.h>
00021 #include <qpixmap.h>
00022 #include <qstringlist.h>
00023 #include <qtabwidget.h>
00024 #include <qtooltip.h>
00025 #include <qvaluelist.h>
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 <kiconloader.h>
00035 #include <kpushbutton.h>
00036 #include <kservice.h>
00037 #include <kstdguiitem.h>
00038 
00039 #include "kcmodulecontainer.h"
00040 #include "kcmodulecontainer.moc"
00041 
00042 /***********************************************************************/
00043 class KCModuleContainer::KCModuleContainerPrivate
00044 {
00045     public:
00046         KCModuleContainerPrivate( const QStringList& mods )
00047             : modules( mods )
00048             , tabWidget( 0 )
00049             , buttons( 0 )
00050             , hasRootKCM( false )
00051             , btnRootMode( 0 )
00052             , btnLayout( 0 )
00053             , topLayout( 0 )
00054             {}
00055 
00056         QStringList modules;
00057         QTabWidget *tabWidget;
00058         int buttons;
00059         bool hasRootKCM: 1;
00060         KPushButton *btnRootMode;
00061         QHBoxLayout *btnLayout;
00062         QVBoxLayout *topLayout;
00063 
00064 
00065 };
00066 /***********************************************************************/
00067 
00068 
00069 
00070 
00071 
00072 /***********************************************************************/
00073 KCModuleContainer::KCModuleContainer( QWidget* parent, const char* name, 
00074     const QString& mods )
00075     : KCModule( parent, name )
00076 {
00077     d = new KCModuleContainerPrivate( QStringList::split( ",", QString(mods).remove( " " )) );
00078     init();
00079 }
00080 
00081 KCModuleContainer::KCModuleContainer( QWidget* parent, const char* name, 
00082     const QStringList& mods )
00083     : KCModule( parent, name ), d( new KCModuleContainerPrivate( mods ) )
00084 {
00085     init();
00086 }
00087 
00088 void KCModuleContainer::init()
00089 {
00090     d->topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint(), "topLayout" );
00091     d->tabWidget = new QTabWidget(this, "tabWidget");
00092     d->tabWidget->setMargin(KDialog::marginHint());
00093     connect( d->tabWidget, SIGNAL( currentChanged( QWidget* ) ), SLOT( tabSwitched( QWidget* ) ));
00094     d->topLayout->addWidget( d->tabWidget );
00095 
00096     if ( !d->modules.isEmpty() )
00097     {
00098         /* Add our modules */
00099         for ( QStringList::Iterator it = d->modules.begin(); it != d->modules.end(); ++it )
00100             addModule( (*it) );
00101 
00102         finalize();
00103     }
00104 
00105 }
00106 
00107 void KCModuleContainer::finalize()
00108 {
00109     setButtons( d->buttons );
00110     if ( d->hasRootKCM ) /* Add a root mode button */
00111     {
00112         if(!d->btnLayout) /* It could already be added */
00113         {
00114             d->btnLayout = new QHBoxLayout(this, 0, 0, "btnLayout");
00115             d->btnRootMode = new KPushButton(KStdGuiItem::adminMode(), this, "btnRootMode");
00116                     
00117             d->btnLayout->addWidget( d->btnRootMode );
00118             d->btnLayout->addStretch();
00119             d->topLayout->addLayout( d->btnLayout );
00120         }
00121     }
00122 }
00123 
00124 void KCModuleContainer::addModule( const QString& module )
00125 {
00126     /* In case it doesn't exist we just silently drop it.
00127      * This allows people to easily extend containers.
00128      * For example, KCM monitor gamma can be in kdegraphics.
00129      */
00130     if ( !KService::serviceByDesktopName( module ) )
00131     {
00132         kdDebug(713) << "KCModuleContainer: module '" << 
00133             module << "' was not found and thus not loaded" << endl;
00134         return;
00135     }
00136 
00137     if( !KCModuleLoader::testModule( module ))
00138         return;
00139 
00140     KCModuleProxy* proxy = new KCModuleProxy( module, false, d->tabWidget, module.latin1());
00141     allModules.append( proxy );
00142 
00143     d->tabWidget->addTab( proxy, QIconSet(KGlobal::iconLoader()->loadIcon(
00144                     proxy->moduleInfo().icon(), KIcon::Desktop)),
00145             /* QT eats ampersands for dinner. But not this time. */
00146             proxy->moduleInfo().moduleName().replace( "&", "&&" ));
00147 
00148     d->tabWidget->setTabToolTip( proxy, proxy->moduleInfo().comment() );
00149 
00150     connect( proxy, SIGNAL(changed(KCModuleProxy *)), SLOT(moduleChanged(KCModuleProxy *)));
00151 
00152     /* Collect our buttons - we go for the common deliminator */
00153     d->buttons = d->buttons | proxy->realModule()->buttons();
00154 
00155     /* If we should add an Administrator Mode button */
00156     if ( proxy->moduleInfo().needsRootPrivileges() )
00157         d->hasRootKCM=true;
00158 
00159 
00160 }
00161 
00162 void KCModuleContainer::tabSwitched( QWidget * module )
00163 {
00164     if ( !d->hasRootKCM )
00165         return;
00166 
00167     /* Not like this. Not like this. */
00168     disconnect( d->btnRootMode, 0, 0, 0 );
00169     /* Welcome to the real world huh baby? */
00170     
00171     KCModuleProxy* mod = (KCModuleProxy *) module;
00172 
00173     if ( mod->moduleInfo().needsRootPrivileges() && !mod->rootMode() )
00174     {
00175         d->btnRootMode->setEnabled( true );
00176         connect( d->btnRootMode, SIGNAL( clicked() ), 
00177                 SLOT( runAsRoot() ));
00178         connect( mod, SIGNAL( childClosed() ), 
00179                 SLOT ( rootExited() ));
00180     }
00181     else
00182         d->btnRootMode->setEnabled( false );
00183 
00184     setQuickHelp( mod->quickHelp() );
00185     setAboutData( const_cast<KAboutData*>(mod->aboutData()) );
00186 
00187 }
00188 
00189 void KCModuleContainer::runAsRoot()
00190 {
00191     if ( d->tabWidget->currentPage() )
00192         ( (KCModuleProxy *) d->tabWidget->currentPage() )->runAsRoot();
00193     d->btnRootMode->setEnabled( false );
00194 }
00195 
00196 void KCModuleContainer::rootExited()
00197 {
00198     connect( d->btnRootMode, SIGNAL( clicked() ), SLOT( runAsRoot() ));
00199     d->btnRootMode->setEnabled( true );
00200 }
00201 
00202 void KCModuleContainer::save()
00203 {
00204     ModuleList list = changedModules;
00205     ModuleList::iterator it;
00206     for ( it = list.begin() ; it !=list.end() ; ++it )
00207     {
00208         (*it)->save();
00209     }
00210 
00211     emit changed( false );
00212 
00213 }
00214 
00215 void KCModuleContainer::load()
00216 {
00217     ModuleList list = allModules;
00218     ModuleList::iterator it;
00219     for ( it = list.begin() ; it !=list.end() ; ++it )
00220     {
00221         (*it)->load();
00222     }
00223 
00224     emit changed( false );
00225 }
00226 
00227 void KCModuleContainer::defaults()
00228 {
00229     ModuleList list = allModules;
00230     ModuleList::iterator it;
00231     for ( it = list.begin() ; it !=list.end() ; ++it )
00232     {
00233         (*it)->defaults();
00234     }
00235 
00236     emit changed( true );
00237 }
00238 
00239 
00240 void KCModuleContainer::moduleChanged(KCModuleProxy * proxy)
00241 {
00242     changedModules.append( proxy );
00243     if( changedModules.isEmpty() )
00244         return;
00245 
00246     emit changed(true);
00247 }
00248 
00249 KCModuleContainer::~KCModuleContainer()
00250 {
00251     delete d;
00252 }
00253 
00254 /***********************************************************************/
00255 
00256 
00257 
00258 

KUtils

Skip menu "KUtils"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
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