• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeutils
 

tdeutils

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

tdeutils

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

tdeutils

Skip menu "tdeutils"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeutils by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.