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

tdeutils

  • tdeutils
kcmultidialog.cpp
1 /*
2  Copyright (c) 2000 Matthias Elter <elter@kde.org>
3  Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org>
4  Copyright (c) 2003 Matthias Kretz <kretz@kde.org>
5  Copyright (c) 2004 Frans Englich <frans.erglich.com>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 
22 */
23 
24 #include <tqcursor.h>
25 #include <tqhbox.h>
26 #include <tqlayout.h>
27 #include <tqpushbutton.h>
28 
29 #include <tdeaboutdata.h>
30 #include <tdeapplication.h>
31 #include <kdebug.h>
32 #include <kiconloader.h>
33 #include <klibloader.h>
34 #include <tdelocale.h>
35 #include <tdemessagebox.h>
36 #include <tdeprocess.h>
37 #include <krun.h>
38 #include <kstdguiitem.h>
39 #include <kuser.h>
40 
41 #include "tdecmoduleloader.h"
42 #include "tdecmoduleproxy.h"
43 #include "kcmultidialog.h"
44 #include "kcmultidialog.moc"
45 
46 class KCMultiDialog::KCMultiDialogPrivate
47 {
48  public:
49  KCMultiDialogPrivate()
50  : hasRootKCM( false ), currentModule( 0 )
51  {}
52 
53  bool hasRootKCM;
54  TDECModuleProxy* currentModule;
55 };
56 
57 
58 KCMultiDialog::KCMultiDialog(TQWidget *parent, const char *name, bool modal)
59  : KDialogBase(IconList, i18n("Configure"), Help | Default |Cancel | Apply |
60  Ok | User1 | User2, Ok, parent, name, modal, true,
61  KStdGuiItem::reset(), KStdGuiItem::adminMode())
62  , dialogface( IconList ), d( new KCMultiDialogPrivate )
63 {
64  init();
65 }
66 
67 KCMultiDialog::KCMultiDialog( int dialogFace, const TQString & caption, TQWidget * parent, const char * name, bool modal )
68  : KDialogBase( dialogFace, caption, Help | Default | Cancel | Apply | Ok |
69  User1 | User2, Ok, parent, name, modal, true,
70  KStdGuiItem::reset(), KStdGuiItem::adminMode())
71  , dialogface( dialogFace ), d( new KCMultiDialogPrivate )
72 {
73  init();
74 }
75 
76 KCMultiDialog::KCMultiDialog( int dialogFace, const KGuiItem &user2,
77  const KGuiItem &user3, int buttonMask, const TQString &caption,
78  TQWidget *parent, const char *name, bool modal )
79  : KDialogBase( dialogFace, caption, buttonMask | Help | Default | Cancel |
80  Apply | Ok | User1, Ok, parent, name, modal, true,
81  KStdGuiItem::reset(), user2, user3 )
82  , dialogface( dialogFace ), d( new KCMultiDialogPrivate )
83 {
84  kdDebug( 710 ) << "Root modules will not work with this constructor. See the API documentation." << endl;
85  init();
86  if ( buttonMask & User2 )
87  showButton( User2, true );
88 }
89 
90 inline void KCMultiDialog::init()
91 {
92  connect( this, TQ_SIGNAL( finished()), TQ_SLOT( dialogClosed()));
93  showButton( User1, false );
94  showButton( User2, false );
95  enableButton(Apply, false);
96  connect(this, TQ_SIGNAL(aboutToShowPage(TQWidget *)), this, TQ_SLOT(slotAboutToShow(TQWidget *)));
97  setInitialSize(TQSize(640,480));
98  moduleParentComponents.setAutoDelete( true );
99 
100 }
101 
102 KCMultiDialog::~KCMultiDialog()
103 {
104  OrphanMap::Iterator end2 = m_orphanModules.end();
105  for( OrphanMap::Iterator it = m_orphanModules.begin(); it != end2; ++it )
106  delete ( *it );
107  delete d;
108 }
109 
110 void KCMultiDialog::slotDefault()
111 {
112  int curPageIndex = activePageIndex();
113 
114  ModuleList::Iterator end = m_modules.end();
115  for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
116  if( pageIndex( ( TQWidget * )( *it ).kcm->parent() ) == curPageIndex )
117  {
118  ( *it ).kcm->defaults();
119  clientChanged( true );
120  return;
121  }
122 }
123 
124 void KCMultiDialog::slotUser1()
125 {
126  int curPageIndex = activePageIndex();
127 
128  ModuleList::Iterator end = m_modules.end();
129  for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
130  if( pageIndex( ( TQWidget * )( *it ).kcm->parent() ) == curPageIndex )
131  {
132  ( *it ).kcm->load();
133  clientChanged( false );
134  return;
135  }
136 }
137 
138 void KCMultiDialog::apply()
139 {
140  TQStringList updatedModules;
141  ModuleList::Iterator end = m_modules.end();
142  for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
143  {
144  TDECModuleProxy * m = ( *it ).kcm;
145  if( m->changed() )
146  {
147  m->save();
148  TQStringList * names = moduleParentComponents[ m ];
149  kdDebug(710) << k_funcinfo << *names << " saved and added to the list" << endl;
150  for( TQStringList::ConstIterator it = names->begin(); it != names->end(); ++it )
151  if( updatedModules.find( *it ) == updatedModules.end() )
152  updatedModules.append( *it );
153  }
154  }
155  for( TQStringList::const_iterator it = updatedModules.begin(); it != updatedModules.end(); ++it )
156  {
157  kdDebug(710) << k_funcinfo << *it << " " << ( *it ).latin1() << endl;
158  emit configCommitted( ( *it ).latin1() );
159  }
160  emit configCommitted();
161 }
162 
163 void KCMultiDialog::slotApply()
164 {
165  TQPushButton *button = actionButton(Apply);
166  if (button)
167  button->setFocus();
168  emit applyClicked();
169  apply();
170 }
171 
172 
173 void KCMultiDialog::slotOk()
174 {
175  TQPushButton *button = actionButton(Ok);
176  if (button)
177  button->setFocus();
178  emit okClicked();
179  apply();
180  accept();
181 }
182 
183 void KCMultiDialog::slotHelp()
184 {
185  TQString docPath;
186 
187  int curPageIndex = activePageIndex();
188  ModuleList::Iterator end = m_modules.end();
189  for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it ) {
190  if( pageIndex( ( TQWidget * )( *it ).kcm->parent() ) == curPageIndex )
191  {
192  TDECModuleProxy *m = (*it).kcm;
193 
194  docPath = m->handbookDocPath();
195  if (docPath == TQString::null)
196  docPath = m->moduleInfo().docPath();
197 
198  TQString section = m->handbookSection();
199  if (section != TQString::null) {
200  docPath = TQString( "%1#%2" ).arg( docPath ).arg( section );
201  }
202  break;
203  }
204  }
205 
206  KURL url( KURL("help:/"), docPath );
207 
208  if (url.protocol() == "help" || url.protocol() == "man" || url.protocol() == "info") {
209  TDEProcess process;
210  process << "khelpcenter"
211  << url.url();
212  process.start(TDEProcess::DontCare);
213  process.detach();
214  } else {
215  new KRun(url);
216  }
217 }
218 
219 void KCMultiDialog::clientChanged(bool state)
220 {
221  kdDebug( 710 ) << k_funcinfo << state << endl;
222  ModuleList::Iterator end = m_modules.end();
223  for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
224  if( ( *it ).kcm->changed() )
225  {
226  enableButton( Apply, true );
227  return;
228  }
229  enableButton( Apply, false );
230 }
231 
232 void KCMultiDialog::addModule(const TQString& path, bool withfallback, TQStringList args)
233 {
234  TQString complete = path;
235 
236  if( !path.endsWith( ".desktop" ))
237  complete += ".desktop";
238 
239  KService::Ptr service = KService::serviceByStorageId( complete );
240 
241  addModule( TDECModuleInfo( service ), TQStringList(), withfallback, args );
242 }
243 
244 void KCMultiDialog::addModule(const TDECModuleInfo& moduleinfo,
245  TQStringList parentmodulenames, bool withfallback, TQStringList args)
246 {
247  kdDebug(710) << "KCMultiDialog::addModule "
248  << moduleinfo.moduleName() << endl;
249 
250  if( !moduleinfo.service() )
251  return;
252 
253  if ( !kapp->authorizeControlModule( moduleinfo.service()->menuId() ))
254  return;
255 
256  if( !TDECModuleLoader::testModule( moduleinfo ))
257  return;
258 
259  TQFrame* page = 0;
260  if (!moduleinfo.service()->noDisplay())
261  switch( dialogface )
262  {
263  case TreeList:
264  parentmodulenames += moduleinfo.moduleName();
265  page = addHBoxPage( parentmodulenames, moduleinfo.comment(),
266  SmallIcon( moduleinfo.icon(),
267  IconSize( TDEIcon::Small ) ) );
268  break;
269  case IconList:
270  page = addHBoxPage( moduleinfo.moduleName(),
271  moduleinfo.comment(), DesktopIcon( moduleinfo.icon(),
272  TDEIcon::SizeMedium ) );
273  break;
274  case Plain:
275  page = plainPage();
276  ( new TQHBoxLayout( page ) )->setAutoAdd( true );
277  break;
278  default:
279  kdError( 710 ) << "unsupported dialog face for KCMultiDialog"
280  << endl;
281  break;
282  }
283  if(!page) {
284  TDECModuleLoader::unloadModule(moduleinfo);
285  return;
286  }
287  TDECModuleProxy * module;
288  if( m_orphanModules.contains( moduleinfo.service() ) )
289  {
290  // the TDECModule already exists - it was removed from the dialog in
291  // removeAllModules
292  module = m_orphanModules[ moduleinfo.service() ];
293  m_orphanModules.remove( moduleinfo.service() );
294  kdDebug( 710 ) << "Use TDECModule from the list of orphans for " <<
295  moduleinfo.moduleName() << ": " << module << endl;
296 
297  module->reparent( page, 0, TQPoint( 0, 0 ), true );
298 
299  if( module->changed() )
300  clientChanged( true );
301 
302  if( activePageIndex() == -1 )
303  showPage( pageIndex( page ) );
304  }
305  else
306  {
307  module = new TDECModuleProxy( moduleinfo, withfallback, page, 0, args );
308  TQStringList parentComponents = moduleinfo.service()->property(
309  "X-TDE-ParentComponents" ).toStringList();
310  moduleParentComponents.insert( module,
311  new TQStringList( parentComponents ) );
312 
313  connect(module, TQ_SIGNAL(changed(bool)), this, TQ_SLOT(clientChanged(bool)));
314 
315  if( m_modules.count() == 0 )
316  aboutToShowPage( page );
317  }
318  CreatedModule cm;
319  cm.kcm = module;
320  cm.service = moduleinfo.service();
321  m_modules.append( cm );
322  if ( moduleinfo.needsRootPrivileges() &&
323  !d->hasRootKCM &&
324  !KUser().isSuperUser() ) /* If we're embedded, it's true */
325  {
326  d->hasRootKCM = true;
327  showButton( User2, true );
328  if( plainPage() ) // returns 0 if we're not a Plain dialog
329  slotAboutToShow( page ); // Won't be called otherwise, necessary for adminMode button
330  }
331 }
332 
333 void KCMultiDialog::removeAllModules()
334 {
335  kdDebug( 710 ) << k_funcinfo << endl;
336  ModuleList::Iterator end = m_modules.end();
337  for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
338  {
339  kdDebug( 710 ) << "remove 2" << endl;
340  TDECModuleProxy * kcm = ( *it ).kcm;
341  TQObject * page = kcm->parent();
342  kcm->hide();
343  if( page )
344  {
345  // I hate this
346  kcm->reparent( 0, TQPoint( 0, 0 ), false );
347  delete page;
348  }
349  m_orphanModules[ ( *it ).service ] = kcm;
350  kdDebug( 710 ) << "added TDECModule to the list of orphans: " <<
351  kcm << endl;
352  }
353  m_modules.clear();
354  // all modules are gone, none can be changed
355  clientChanged( false );
356 }
357 
358 void KCMultiDialog::show()
359 { /* KDE 4 Remove..? */
360  KDialogBase::show();
361 }
362 
363 void KCMultiDialog::slotAboutToShow(TQWidget *page)
364 {
365  kdDebug(710) << k_funcinfo << endl;
366 
367  TQObject * obj = page->child( 0, "TDECModuleProxy" );
368  if( ! obj )
369  return;
370 
371  TDECModuleProxy * module = ::tqt_cast<TDECModuleProxy*>(obj);
372  if( ! module )
373  return;
374  d->currentModule = module;
375 
376  enableButton( KDialogBase::Help,
377  d->currentModule->buttons() & TDECModule::Help );
378  enableButton( KDialogBase::Default,
379  d->currentModule->buttons() & TDECModule::Default );
380 
381  disconnect( this, TQ_SIGNAL(user2Clicked()), 0, 0 );
382 
383  if (d->currentModule->moduleInfo().needsRootPrivileges())
384  {
385  if ( !d->currentModule->rootMode() )
386  { /* Enable the Admin Mode button */
387  enableButton( User2, true );
388  connect( this, TQ_SIGNAL(user2Clicked()), d->currentModule, TQ_SLOT( runAsRoot() ));
389  connect( this, TQ_SIGNAL(user2Clicked()), TQ_SLOT( disableRModeButton() ));
390  }
391  else
392  enableButton( User2, false);
393  }
394 }
395 
396 void KCMultiDialog::rootExit()
397 {
398  enableButton( User2, true);
399 }
400 
401 void KCMultiDialog::disableRModeButton()
402 {
403  enableButton( User2, false );
404  connect ( d->currentModule, TQ_SIGNAL( childClosed() ), TQ_SLOT( rootExit() ));
405 }
406 
407 void KCMultiDialog::dialogClosed()
408 {
409  kdDebug(710) << k_funcinfo << endl;
410 
411  /* If we don't delete them, the DCOP registration stays, and trying to load the KCMs
412  * in other situations will lead to "module already loaded in Foo," while to the user
413  * doesn't appear so(the dialog is hidden) */
414  ModuleList::Iterator end = m_modules.end();
415  for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
416  ( *it ).kcm->deleteClient();
417 }
KCMultiDialog::slotOk
virtual void slotOk()
This slot is called when the user presses the "OK" Button.
Definition: kcmultidialog.cpp:173
KCMultiDialog::addModule
void addModule(const TQString &module, bool withfallback=true, TQStringList args=TQStringList())
Add a module.
Definition: kcmultidialog.cpp:232
KCMultiDialog::~KCMultiDialog
virtual ~KCMultiDialog()
Destructor.
Definition: kcmultidialog.cpp:102
KCMultiDialog::KCMultiDialog
KCMultiDialog(TQWidget *parent=0, const char *name=0, bool modal=false)
Constructs a new KCMultiDialog.
Definition: kcmultidialog.cpp:58
KCMultiDialog::slotDefault
virtual void slotDefault()
This slot is called when the user presses the "Default" Button.
Definition: kcmultidialog.cpp:110
KCMultiDialog::slotHelp
virtual void slotHelp()
This slot is called when the user presses the "Help" Button.
Definition: kcmultidialog.cpp:183
KCMultiDialog::configCommitted
void configCommitted()
Emitted after all TDECModules have been told to save their configuration.
KCMultiDialog::slotUser1
virtual void slotUser1()
This slot is called when the user presses the "Reset" Button.
Definition: kcmultidialog.cpp:124
KCMultiDialog::removeAllModules
void removeAllModules()
Remove all modules from the dialog.
Definition: kcmultidialog.cpp:333
KCMultiDialog::slotApply
virtual void slotApply()
This slot is called when the user presses the "Apply" Button.
Definition: kcmultidialog.cpp:163
KDialogBase
KDialogBase::enableButton
void enableButton(ButtonCode id, bool state)
KDialogBase::showPage
bool showPage(int index)
KDialogBase::showButton
void showButton(ButtonCode id, bool state)
KDialogBase::applyClicked
void applyClicked()
KDialogBase::plainPage
TQFrame * plainPage()
KDialogBase::addHBoxPage
TQHBox * addHBoxPage(const TQString &itemName, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
KDialogBase::user2Clicked
void user2Clicked()
KDialogBase::actionButton
TQPushButton * actionButton(ButtonCode id)
KDialogBase::activePageIndex
int activePageIndex() const
KDialogBase::aboutToShowPage
void aboutToShowPage(TQWidget *page)
KDialogBase::setInitialSize
void setInitialSize(const TQSize &s, bool noResize=false)
KDialogBase::Default
Default
KDialogBase::User2
User2
KDialogBase::Apply
Apply
KDialogBase::User1
User1
KDialogBase::Help
Help
KDialogBase::Ok
Ok
KDialogBase::okClicked
void okClicked()
KDialogBase::finished
void finished()
KDialogBase::pageIndex
int pageIndex(TQWidget *widget) const
KGuiItem
KStdGuiItem
KURL
KURL::protocol
TQString protocol() const
KURL::url
TQString url(int _trailing=0, int encoding_hint=0) const
KUser
TDECModuleInfo
A class that provides information about a TDECModule.
Definition: tdecmoduleinfo.h:50
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::docPath
TQString docPath() const
Definition: tdecmoduleinfo.cpp:183
TDECModuleInfo::service
KService::Ptr service() const
Definition: tdecmoduleinfo.h:137
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
TDECModuleLoader::unloadModule
static void unloadModule(const TDECModuleInfo &mod)
Unloads the module's library.
Definition: tdecmoduleloader.cpp:204
TDECModuleProxy
Encapsulates a TDECModule for embedding.
Definition: tdecmoduleproxy.h:69
TDECModuleProxy::handbookSection
TQString handbookSection() const
Definition: tdecmoduleproxy.cpp:613
TDECModuleProxy::handbookDocPath
TQString handbookDocPath() const
Definition: tdecmoduleproxy.cpp:601
TDECModuleProxy::save
void save()
Calling it will cause the contained module to run its save() routine.
Definition: tdecmoduleproxy.cpp:528
TDECModuleProxy::moduleInfo
const TDECModuleInfo & moduleInfo() const
Definition: tdecmoduleproxy.cpp:651
TDECModuleProxy::changed
bool changed() const
Definition: tdecmoduleproxy.cpp:646
TDEIcon::Small
Small
TDEIcon::SizeMedium
SizeMedium
TDEProcess
TDEProcess::start
virtual bool start(RunMode runmode=NotifyOnExit, Communication comm=NoCommunication)
TDEProcess::DontCare
DontCare
TDEProcess::detach
void detach()
endl
kndbgstream & endl(kndbgstream &s)
kdError
kdbgstream kdError(int area=0)
kdDebug
kdbgstream kdDebug(int area=0)
TDEStdAccel::end
const TDEShortcut & end()
tdelocale.h

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.