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

tdeutils

  • tdeutils
tdecmodulecontainer.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 <tdecmodule.h>
28 #include <tdecmoduleinfo.h>
29 #include <tdecmoduleloader.h>
30 #include <tdecmoduleproxy.h>
31 #include <kdebug.h>
32 #include <kdialog.h>
33 #include <tdeglobal.h>
34 #include <kiconloader.h>
35 #include <kpushbutton.h>
36 #include <kservice.h>
37 #include <kstdguiitem.h>
38 
39 #include "tdecmodulecontainer.h"
40 #include "tdecmodulecontainer.moc"
41 
42 /***********************************************************************/
43 class TDECModuleContainer::TDECModuleContainerPrivate
44 {
45  public:
46  TDECModuleContainerPrivate( 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  TQString handbookSection;
64 
65 
66 };
67 /***********************************************************************/
68 
69 
70 
71 
72 
73 /***********************************************************************/
74 TDECModuleContainer::TDECModuleContainer( TQWidget* parent, const char* name,
75  const TQString& mods )
76  : TDECModule( parent, name )
77 {
78  d = new TDECModuleContainerPrivate( TQStringList::split( ",", TQString(mods).remove( " " )) );
79  init();
80 }
81 
82 TDECModuleContainer::TDECModuleContainer( TQWidget* parent, const char* name,
83  const TQStringList& mods )
84  : TDECModule( parent, name ), d( new TDECModuleContainerPrivate( mods ) )
85 {
86  init();
87 }
88 
89 void TDECModuleContainer::init()
90 {
91  d->topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint(), "topLayout" );
92  d->tabWidget = new TQTabWidget(this, "tabWidget");
93  d->tabWidget->setMargin(KDialog::marginHint());
94  connect( d->tabWidget, TQ_SIGNAL( currentChanged( TQWidget* ) ), TQ_SLOT( tabSwitched( TQWidget* ) ));
95  d->topLayout->addWidget( d->tabWidget );
96 
97  if ( !d->modules.isEmpty() )
98  {
99  /* Add our modules */
100  for ( TQStringList::Iterator it = d->modules.begin(); it != d->modules.end(); ++it )
101  addModule( (*it) );
102 
103  finalize();
104  }
105 
106 }
107 
108 void TDECModuleContainer::finalize()
109 {
110  setButtons( d->buttons );
111  if ( d->hasRootKCM ) /* Add a root mode button */
112  {
113  if(!d->btnLayout) /* It could already be added */
114  {
115  d->btnLayout = new TQHBoxLayout(this, 0, 0, "btnLayout");
116  d->btnRootMode = new KPushButton(KStdGuiItem::adminMode(), this, "btnRootMode");
117 
118  d->btnLayout->addWidget( d->btnRootMode );
119  d->btnLayout->addStretch();
120  d->topLayout->addLayout( d->btnLayout );
121  }
122  }
123 }
124 
125 void TDECModuleContainer::addModule( const TQString& module )
126 {
127  /* In case it doesn't exist we just silently drop it.
128  * This allows people to easily extend containers.
129  * For example, KCM monitor gamma can be in tdegraphics.
130  */
131  if ( !KService::serviceByDesktopName( module ) )
132  {
133  kdDebug(713) << "TDECModuleContainer: module '" <<
134  module << "' was not found and thus not loaded" << endl;
135  return;
136  }
137 
138  if( !TDECModuleLoader::testModule( module )) {
139  return;
140  }
141 
142  TDECModuleProxy* proxy = new TDECModuleProxy( module, false, d->tabWidget, module.latin1());
143  if (allModules.count() < 1) {
144  d->handbookSection = proxy->handbookSection();
145  }
146  allModules.append( proxy );
147 
148  d->tabWidget->addTab( proxy, TQIconSet(TDEGlobal::iconLoader()->loadIcon(
149  proxy->moduleInfo().icon(), TDEIcon::Desktop)),
150  /* QT eats ampersands for dinner. But not this time. */
151  proxy->moduleInfo().moduleName().replace( "&", "&&" ));
152 
153  d->tabWidget->setTabToolTip( proxy, proxy->moduleInfo().comment() );
154 
155  connect( proxy, TQ_SIGNAL(changed(TDECModuleProxy *)), TQ_SLOT(moduleChanged(TDECModuleProxy *)));
156 
157  /* Collect our buttons - we go for the common deliminator */
158  d->buttons = d->buttons | proxy->realModule()->buttons();
159 
160  /* If we should add an Administrator Mode button */
161  if ( proxy->moduleInfo().needsRootPrivileges() ) {
162  d->hasRootKCM=true;
163  }
164 }
165 
166 void TDECModuleContainer::tabSwitched( TQWidget * module )
167 {
168  TDECModuleProxy* mod = (TDECModuleProxy *) module;
169  d->handbookSection = mod->handbookSection();
170 
171  if ( !d->hasRootKCM ) {
172  return;
173  }
174 
175  /* Not like this. Not like this. */
176  disconnect( d->btnRootMode, 0, 0, 0 );
177  /* Welcome to the real world huh baby? */
178 
179  if ( mod->moduleInfo().needsRootPrivileges() && !mod->rootMode() ) {
180  d->btnRootMode->setEnabled( true );
181  connect( d->btnRootMode, TQ_SIGNAL( clicked() ),
182  TQ_SLOT( runAsRoot() ));
183  connect( mod, TQ_SIGNAL( childClosed() ),
184  TQ_SLOT ( rootExited() ));
185  }
186  else {
187  d->btnRootMode->setEnabled( false );
188  }
189 
190  setQuickHelp( mod->quickHelp() );
191  setAboutData( const_cast<TDEAboutData*>(mod->aboutData()) );
192 }
193 
194 TQString TDECModuleContainer::handbookSection() const
195 {
196  return d->handbookSection;
197 }
198 
199 void TDECModuleContainer::runAsRoot()
200 {
201  if ( d->tabWidget->currentPage() )
202  ( (TDECModuleProxy *) d->tabWidget->currentPage() )->runAsRoot();
203  d->btnRootMode->setEnabled( false );
204 }
205 
206 void TDECModuleContainer::rootExited()
207 {
208  connect( d->btnRootMode, TQ_SIGNAL( clicked() ), TQ_SLOT( runAsRoot() ));
209  d->btnRootMode->setEnabled( true );
210 }
211 
212 void TDECModuleContainer::save()
213 {
214  ModuleList list = changedModules;
215  ModuleList::iterator it;
216  for ( it = list.begin() ; it !=list.end() ; ++it )
217  {
218  (*it)->save();
219  }
220 
221  emit changed( false );
222 
223 }
224 
225 void TDECModuleContainer::load()
226 {
227  ModuleList list = allModules;
228  ModuleList::iterator it;
229  for ( it = list.begin() ; it !=list.end() ; ++it )
230  {
231  (*it)->load();
232  }
233 
234  emit changed( false );
235 }
236 
237 void TDECModuleContainer::defaults()
238 {
239  ModuleList list = allModules;
240  ModuleList::iterator it;
241  for ( it = list.begin() ; it !=list.end() ; ++it )
242  {
243  (*it)->defaults();
244  }
245 
246  emit changed( true );
247 }
248 
249 
250 void TDECModuleContainer::moduleChanged(TDECModuleProxy * proxy)
251 {
252  changedModules.append( proxy );
253  if( changedModules.isEmpty() )
254  return;
255 
256  emit changed(true);
257 }
258 
259 TDECModuleContainer::~TDECModuleContainer()
260 {
261  delete d;
262 }
263 
264 /***********************************************************************/
265 
266 
267 
268 
KDialog::marginHint
static int marginHint()
KDialog::spacingHint
static int spacingHint()
KPushButton
KStdGuiItem::adminMode
static KGuiItem adminMode()
TDEAboutData
TDECModuleContainer::defaults
void defaults()
Reimplemented for internal purposes.
Definition: tdecmodulecontainer.cpp:237
TDECModuleContainer::changedModules
ModuleList changedModules
A list containing TDECModuleProxy objects which have changed and must be saved.
Definition: tdecmodulecontainer.h:143
TDECModuleContainer::TDECModuleContainer
TDECModuleContainer(TQWidget *parent, const char *name, const TQStringList &mods)
Creates a TDECModuleContainer with tabs, each one containing one of the specified modules in mods.
Definition: tdecmodulecontainer.cpp:82
TDECModuleContainer::save
void save()
Reimplemented for internal purposes.
Definition: tdecmodulecontainer.cpp:212
TDECModuleContainer::~TDECModuleContainer
virtual ~TDECModuleContainer()
Default destructor.
Definition: tdecmodulecontainer.cpp:259
TDECModuleContainer::load
void load()
Reimplemented for internal purposes.
Definition: tdecmodulecontainer.cpp:225
TDECModuleContainer::handbookSection
virtual TQString handbookSection() const
Reimplemented for internal purposes.
Definition: tdecmodulecontainer.cpp:194
TDECModuleContainer::allModules
ModuleList allModules
A list of all modules which are encapsulated.
Definition: tdecmodulecontainer.h:148
TDECModuleContainer::addModule
void addModule(const TQString &module)
Adds the specified module to the tab widget.
Definition: tdecmodulecontainer.cpp:125
TDECModuleContainer::finalize
void finalize()
Sets this KCM's buttons and adds a AdminMode button if necessary.
Definition: tdecmodulecontainer.cpp:108
TDECModuleInfo::comment
TQString comment() const
Definition: tdecmoduleinfo.h:142
TDECModuleInfo::icon
TQString icon() const
Definition: tdecmoduleinfo.h:147
TDECModuleInfo::needsRootPrivileges
bool needsRootPrivileges() const
Definition: tdecmoduleinfo.cpp:213
TDECModuleInfo::moduleName
TQString moduleName() const
Definition: tdecmoduleinfo.h:131
TDECModuleLoader::testModule
static bool testModule(const TQString &module)
Checks whether an TDECModule should be shown by running its test function.
Definition: tdecmoduleloader.cpp:230
TDECModuleProxy
Encapsulates a TDECModule for embedding.
Definition: tdecmoduleproxy.h:69
TDECModuleProxy::aboutData
const TDEAboutData * aboutData() const
Definition: tdecmoduleproxy.cpp:589
TDECModuleProxy::realModule
TDECModule * realModule() const
Access to the actual module.
Definition: tdecmoduleproxy.cpp:140
TDECModuleProxy::handbookSection
TQString handbookSection() const
Definition: tdecmoduleproxy.cpp:613
TDECModuleProxy::rootMode
bool rootMode() const
Returns whether the module is running in root mode.
Definition: tdecmoduleproxy.cpp:656
TDECModuleProxy::moduleInfo
const TDECModuleInfo & moduleInfo() const
Definition: tdecmoduleproxy.cpp:651
TDECModuleProxy::quickHelp
TQString quickHelp() const
Definition: tdecmoduleproxy.cpp:560
TDECModule
TDECModule::setAboutData
void setAboutData(TDEAboutData *about)
TDECModule::buttons
int buttons() const
TDECModule::changed
void changed()
TDECModule::setButtons
void setButtons(int btn)
TDECModule::setQuickHelp
void setQuickHelp(const TQString &help)
TDEGlobal::iconLoader
static TDEIconLoader * iconLoader()
TDEIcon::Desktop
Desktop
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)

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.9.1
This website is maintained by Timothy Pearson.