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

kutils

  • kutils
kcmodulecontainer.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2004 Frans Englich <frans.englich@telia.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <tqlayout.h>
21 #include <tqpixmap.h>
22 #include <tqstringlist.h>
23 #include <tqtabwidget.h>
24 #include <tqtooltip.h>
25 #include <tqvaluelist.h>
26 
27 #include <kcmodule.h>
28 #include <kcmoduleinfo.h>
29 #include <kcmoduleloader.h>
30 #include <kcmoduleproxy.h>
31 #include <kdebug.h>
32 #include <kdialog.h>
33 #include <kglobal.h>
34 #include <kiconloader.h>
35 #include <kpushbutton.h>
36 #include <kservice.h>
37 #include <kstdguiitem.h>
38 
39 #include "kcmodulecontainer.h"
40 #include "kcmodulecontainer.moc"
41 
42 /***********************************************************************/
43 class KCModuleContainer::KCModuleContainerPrivate
44 {
45  public:
46  KCModuleContainerPrivate( const TQStringList& mods )
47  : modules( mods )
48  , tabWidget( 0 )
49  , buttons( 0 )
50  , hasRootKCM( false )
51  , btnRootMode( 0 )
52  , btnLayout( 0 )
53  , topLayout( 0 )
54  {}
55 
56  TQStringList modules;
57  TQTabWidget *tabWidget;
58  int buttons;
59  bool hasRootKCM: 1;
60  KPushButton *btnRootMode;
61  TQHBoxLayout *btnLayout;
62  TQVBoxLayout *topLayout;
63 
64 
65 };
66 /***********************************************************************/
67 
68 
69 
70 
71 
72 /***********************************************************************/
73 KCModuleContainer::KCModuleContainer( TQWidget* parent, const char* name,
74  const TQString& mods )
75  : KCModule( parent, name )
76 {
77  d = new KCModuleContainerPrivate( TQStringList::split( ",", TQString(mods).remove( " " )) );
78  init();
79 }
80 
81 KCModuleContainer::KCModuleContainer( TQWidget* parent, const char* name,
82  const TQStringList& mods )
83  : KCModule( parent, name ), d( new KCModuleContainerPrivate( mods ) )
84 {
85  init();
86 }
87 
88 void KCModuleContainer::init()
89 {
90  d->topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint(), "topLayout" );
91  d->tabWidget = new TQTabWidget(this, "tabWidget");
92  d->tabWidget->setMargin(KDialog::marginHint());
93  connect( d->tabWidget, TQT_SIGNAL( currentChanged( TQWidget* ) ), TQT_SLOT( tabSwitched( TQWidget* ) ));
94  d->topLayout->addWidget( d->tabWidget );
95 
96  if ( !d->modules.isEmpty() )
97  {
98  /* Add our modules */
99  for ( TQStringList::Iterator it = d->modules.begin(); it != d->modules.end(); ++it )
100  addModule( (*it) );
101 
102  finalize();
103  }
104 
105 }
106 
107 void KCModuleContainer::finalize()
108 {
109  setButtons( d->buttons );
110  if ( d->hasRootKCM ) /* Add a root mode button */
111  {
112  if(!d->btnLayout) /* It could already be added */
113  {
114  d->btnLayout = new TQHBoxLayout(this, 0, 0, "btnLayout");
115  d->btnRootMode = new KPushButton(KStdGuiItem::adminMode(), this, "btnRootMode");
116 
117  d->btnLayout->addWidget( d->btnRootMode );
118  d->btnLayout->addStretch();
119  d->topLayout->addLayout( d->btnLayout );
120  }
121  }
122 }
123 
124 void KCModuleContainer::addModule( const TQString& module )
125 {
126  /* In case it doesn't exist we just silently drop it.
127  * This allows people to easily extend containers.
128  * For example, KCM monitor gamma can be in kdegraphics.
129  */
130  if ( !KService::serviceByDesktopName( module ) )
131  {
132  kdDebug(713) << "KCModuleContainer: module '" <<
133  module << "' was not found and thus not loaded" << endl;
134  return;
135  }
136 
137  if( !KCModuleLoader::testModule( module ))
138  return;
139 
140  KCModuleProxy* proxy = new KCModuleProxy( module, false, d->tabWidget, module.latin1());
141  allModules.append( proxy );
142 
143  d->tabWidget->addTab( proxy, TQIconSet(KGlobal::iconLoader()->loadIcon(
144  proxy->moduleInfo().icon(), KIcon::Desktop)),
145  /* QT eats ampersands for dinner. But not this time. */
146  proxy->moduleInfo().moduleName().replace( "&", "&&" ));
147 
148  d->tabWidget->setTabToolTip( proxy, proxy->moduleInfo().comment() );
149 
150  connect( proxy, TQT_SIGNAL(changed(KCModuleProxy *)), TQT_SLOT(moduleChanged(KCModuleProxy *)));
151 
152  /* Collect our buttons - we go for the common deliminator */
153  d->buttons = d->buttons | proxy->realModule()->buttons();
154 
155  /* If we should add an Administrator Mode button */
156  if ( proxy->moduleInfo().needsRootPrivileges() )
157  d->hasRootKCM=true;
158 
159 
160 }
161 
162 void KCModuleContainer::tabSwitched( TQWidget * module )
163 {
164  if ( !d->hasRootKCM )
165  return;
166 
167  /* Not like this. Not like this. */
168  disconnect( d->btnRootMode, 0, 0, 0 );
169  /* Welcome to the real world huh baby? */
170 
171  KCModuleProxy* mod = (KCModuleProxy *) module;
172 
173  if ( mod->moduleInfo().needsRootPrivileges() && !mod->rootMode() )
174  {
175  d->btnRootMode->setEnabled( true );
176  connect( d->btnRootMode, TQT_SIGNAL( clicked() ),
177  TQT_SLOT( runAsRoot() ));
178  connect( mod, TQT_SIGNAL( childClosed() ),
179  TQT_SLOT ( rootExited() ));
180  }
181  else
182  d->btnRootMode->setEnabled( false );
183 
184  setQuickHelp( mod->quickHelp() );
185  setAboutData( const_cast<KAboutData*>(mod->aboutData()) );
186 
187 }
188 
189 void KCModuleContainer::runAsRoot()
190 {
191  if ( d->tabWidget->currentPage() )
192  ( (KCModuleProxy *) d->tabWidget->currentPage() )->runAsRoot();
193  d->btnRootMode->setEnabled( false );
194 }
195 
196 void KCModuleContainer::rootExited()
197 {
198  connect( d->btnRootMode, TQT_SIGNAL( clicked() ), TQT_SLOT( runAsRoot() ));
199  d->btnRootMode->setEnabled( true );
200 }
201 
202 void KCModuleContainer::save()
203 {
204  ModuleList list = changedModules;
205  ModuleList::iterator it;
206  for ( it = list.begin() ; it !=list.end() ; ++it )
207  {
208  (*it)->save();
209  }
210 
211  emit changed( false );
212 
213 }
214 
215 void KCModuleContainer::load()
216 {
217  ModuleList list = allModules;
218  ModuleList::iterator it;
219  for ( it = list.begin() ; it !=list.end() ; ++it )
220  {
221  (*it)->load();
222  }
223 
224  emit changed( false );
225 }
226 
227 void KCModuleContainer::defaults()
228 {
229  ModuleList list = allModules;
230  ModuleList::iterator it;
231  for ( it = list.begin() ; it !=list.end() ; ++it )
232  {
233  (*it)->defaults();
234  }
235 
236  emit changed( true );
237 }
238 
239 
240 void KCModuleContainer::moduleChanged(KCModuleProxy * proxy)
241 {
242  changedModules.append( proxy );
243  if( changedModules.isEmpty() )
244  return;
245 
246  emit changed(true);
247 }
248 
249 KCModuleContainer::~KCModuleContainer()
250 {
251  delete d;
252 }
253 
254 /***********************************************************************/
255 
256 
257 
258 
KPushButton
KCModuleLoader::testModule
static bool testModule(const TQString &module)
Checks whether an KCModule should be shown by running its test function.
Definition: kcmoduleloader.cpp:230
KCModuleContainer::KCModuleContainer
KCModuleContainer(TQWidget *parent, const char *name, const TQStringList &mods)
Creates a KCModuleContainer with tabs, each one containing one of the specified modules in mods...
Definition: kcmodulecontainer.cpp:81
KCModuleContainer::changedModules
ModuleList changedModules
A list containing KCModuleProxy objects which have changed and must be saved.
Definition: kcmodulecontainer.h:137
KCModuleContainer::finalize
void finalize()
Sets this KCM's buttons and adds a AdminMode button if necessary.
Definition: kcmodulecontainer.cpp:107
KCModule::setButtons
void setButtons(int btn)
KCModuleProxy::moduleInfo
const KCModuleInfo & moduleInfo() const
Definition: kcmoduleproxy.cpp:626
KGlobal::iconLoader
static KIconLoader * iconLoader()
KCModuleContainer::save
void save()
Reimplemented for internal purposes.
Definition: kcmodulecontainer.cpp:202
KCModuleInfo::icon
TQString icon() const
Definition: kcmoduleinfo.h:147
KCModuleProxy::quickHelp
TQString quickHelp() const
Definition: kcmoduleproxy.cpp:559
kdDebug
kdbgstream kdDebug(int area=0)
KIcon::Desktop
KCModule::setAboutData
void setAboutData(KAboutData *about)
KCModule::setQuickHelp
void setQuickHelp(const TQString &help)
KCModuleContainer::load
void load()
Reimplemented for internal purposes.
Definition: kcmodulecontainer.cpp:215
KCModuleContainer::addModule
void addModule(const TQString &module)
Adds the specified module to the tab widget.
Definition: kcmodulecontainer.cpp:124
KCModuleProxy::aboutData
const KAboutData * aboutData() const
Definition: kcmoduleproxy.cpp:588
KCModuleInfo::needsRootPrivileges
bool needsRootPrivileges() const
Definition: kcmoduleinfo.cpp:213
KCModuleInfo::moduleName
TQString moduleName() const
Definition: kcmoduleinfo.h:131
KCModuleProxy
Encapsulates a KCModule for embedding.
Definition: kcmoduleproxy.h:68
KCModuleInfo::comment
TQString comment() const
Definition: kcmoduleinfo.h:142
KCModuleContainer::defaults
void defaults()
Reimplemented for internal purposes.
Definition: kcmodulecontainer.cpp:227
KCModuleContainer::~KCModuleContainer
virtual ~KCModuleContainer()
Default destructor.
Definition: kcmodulecontainer.cpp:249
KCModuleContainer::allModules
ModuleList allModules
A list of all modules which are encapsulated.
Definition: kcmodulecontainer.h:142
KStdGuiItem::adminMode
static KGuiItem adminMode()
KCModule::buttons
int buttons() const
endl
kndbgstream & endl(kndbgstream &s)
KCModuleProxy::rootMode
bool rootMode() const
Returns whether the module is running in root mode.
Definition: kcmoduleproxy.cpp:631
KCModuleProxy::realModule
KCModule * realModule() const
Access to the actual module.
Definition: kcmoduleproxy.cpp:140
KCModule
KCModule::changed
void changed()

kutils

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

kutils

Skip menu "kutils"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kutils by doxygen 1.8.8
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |