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

kutils

  • kutils
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 <kaboutdata.h>
30 #include <kapplication.h>
31 #include <kdebug.h>
32 #include <kiconloader.h>
33 #include <klibloader.h>
34 #include <klocale.h>
35 #include <kmessagebox.h>
36 #include <kprocess.h>
37 #include <krun.h>
38 #include <kstdguiitem.h>
39 #include <kuser.h>
40 
41 #include "kcmoduleloader.h"
42 #include "kcmoduleproxy.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  KCModuleProxy* 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, TQT_SIGNAL( finished()), TQT_SLOT( dialogClosed()));
93  showButton( User1, false );
94  showButton( User2, false );
95  enableButton(Apply, false);
96  connect(this, TQT_SIGNAL(aboutToShowPage(TQWidget *)), this, TQT_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  KCModuleProxy * 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  docPath = ( *it ).kcm->moduleInfo().docPath();
193  break;
194  }
195 
196  KURL url( KURL("help:/"), docPath );
197 
198  if (url.protocol() == "help" || url.protocol() == "man" || url.protocol() == "info") {
199  KProcess process;
200  process << "khelpcenter"
201  << url.url();
202  process.start(KProcess::DontCare);
203  process.detach();
204  } else {
205  new KRun(url);
206  }
207 }
208 
209 void KCMultiDialog::clientChanged(bool state)
210 {
211  kdDebug( 710 ) << k_funcinfo << state << endl;
212  ModuleList::Iterator end = m_modules.end();
213  for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
214  if( ( *it ).kcm->changed() )
215  {
216  enableButton( Apply, true );
217  return;
218  }
219  enableButton( Apply, false );
220 }
221 
222 void KCMultiDialog::addModule(const TQString& path, bool withfallback)
223 {
224  TQString complete = path;
225 
226  if( !path.endsWith( ".desktop" ))
227  complete += ".desktop";
228 
229  KService::Ptr service = KService::serviceByStorageId( complete );
230 
231  addModule( KCModuleInfo( service ), TQStringList(), withfallback);
232 }
233 
234 void KCMultiDialog::addModule(const KCModuleInfo& moduleinfo,
235  TQStringList parentmodulenames, bool withfallback)
236 {
237  kdDebug(710) << "KCMultiDialog::addModule "
238  << moduleinfo.moduleName() << endl;
239 
240  if( !moduleinfo.service() )
241  return;
242 
243  if ( !kapp->authorizeControlModule( moduleinfo.service()->menuId() ))
244  return;
245 
246  if( !KCModuleLoader::testModule( moduleinfo ))
247  return;
248 
249  TQFrame* page = 0;
250  if (!moduleinfo.service()->noDisplay())
251  switch( dialogface )
252  {
253  case TreeList:
254  parentmodulenames += moduleinfo.moduleName();
255  page = addHBoxPage( parentmodulenames, moduleinfo.comment(),
256  SmallIcon( moduleinfo.icon(),
257  IconSize( KIcon::Small ) ) );
258  break;
259  case IconList:
260  page = addHBoxPage( moduleinfo.moduleName(),
261  moduleinfo.comment(), DesktopIcon( moduleinfo.icon(),
262  KIcon::SizeMedium ) );
263  break;
264  case Plain:
265  page = plainPage();
266  ( new TQHBoxLayout( page ) )->setAutoAdd( true );
267  break;
268  default:
269  kdError( 710 ) << "unsupported dialog face for KCMultiDialog"
270  << endl;
271  break;
272  }
273  if(!page) {
274  KCModuleLoader::unloadModule(moduleinfo);
275  return;
276  }
277  KCModuleProxy * module;
278  if( m_orphanModules.contains( moduleinfo.service() ) )
279  {
280  // the KCModule already exists - it was removed from the dialog in
281  // removeAllModules
282  module = m_orphanModules[ moduleinfo.service() ];
283  m_orphanModules.remove( moduleinfo.service() );
284  kdDebug( 710 ) << "Use KCModule from the list of orphans for " <<
285  moduleinfo.moduleName() << ": " << module << endl;
286 
287  module->reparent( page, 0, TQPoint( 0, 0 ), true );
288 
289  if( module->changed() )
290  clientChanged( true );
291 
292  if( activePageIndex() == -1 )
293  showPage( pageIndex( page ) );
294  }
295  else
296  {
297  module = new KCModuleProxy( moduleinfo, withfallback, page );
298  TQStringList parentComponents = moduleinfo.service()->property(
299  "X-KDE-ParentComponents" ).toStringList();
300  moduleParentComponents.insert( module,
301  new TQStringList( parentComponents ) );
302 
303  connect(module, TQT_SIGNAL(changed(bool)), this, TQT_SLOT(clientChanged(bool)));
304 
305  if( m_modules.count() == 0 )
306  aboutToShowPage( page );
307  }
308  CreatedModule cm;
309  cm.kcm = module;
310  cm.service = moduleinfo.service();
311  m_modules.append( cm );
312  if ( moduleinfo.needsRootPrivileges() &&
313  !d->hasRootKCM &&
314  !KUser().isSuperUser() ) /* If we're embedded, it's true */
315  {
316  d->hasRootKCM = true;
317  showButton( User2, true );
318  if( plainPage() ) // returns 0 if we're not a Plain dialog
319  slotAboutToShow( page ); // Won't be called otherwise, necessary for adminMode button
320  }
321 }
322 
323 void KCMultiDialog::removeAllModules()
324 {
325  kdDebug( 710 ) << k_funcinfo << endl;
326  ModuleList::Iterator end = m_modules.end();
327  for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
328  {
329  kdDebug( 710 ) << "remove 2" << endl;
330  KCModuleProxy * kcm = ( *it ).kcm;
331  TQObject * page = TQT_TQOBJECT(kcm->parent());
332  kcm->hide();
333  if( page )
334  {
335  // I hate this
336  kcm->reparent( 0, TQPoint( 0, 0 ), false );
337  delete page;
338  }
339  m_orphanModules[ ( *it ).service ] = kcm;
340  kdDebug( 710 ) << "added KCModule to the list of orphans: " <<
341  kcm << endl;
342  }
343  m_modules.clear();
344  // all modules are gone, none can be changed
345  clientChanged( false );
346 }
347 
348 void KCMultiDialog::show()
349 { /* KDE 4 Remove..? */
350  KDialogBase::show();
351 }
352 
353 void KCMultiDialog::slotAboutToShow(TQWidget *page)
354 {
355  kdDebug(710) << k_funcinfo << endl;
356 
357  TQObject * obj = page->child( 0, "KCModuleProxy" );
358  if( ! obj )
359  return;
360 
361  KCModuleProxy * module = ::tqqt_cast<KCModuleProxy*>(obj);
362  if( ! module )
363  return;
364  d->currentModule = module;
365 
366  enableButton( KDialogBase::Help,
367  d->currentModule->buttons() & KCModule::Help );
368  enableButton( KDialogBase::Default,
369  d->currentModule->buttons() & KCModule::Default );
370 
371  disconnect( this, TQT_SIGNAL(user2Clicked()), 0, 0 );
372 
373  if (d->currentModule->moduleInfo().needsRootPrivileges())
374  {
375  if ( !d->currentModule->rootMode() )
376  { /* Enable the Admin Mode button */
377  enableButton( User2, true );
378  connect( this, TQT_SIGNAL(user2Clicked()), d->currentModule, TQT_SLOT( runAsRoot() ));
379  connect( this, TQT_SIGNAL(user2Clicked()), TQT_SLOT( disableRModeButton() ));
380  }
381  else
382  enableButton( User2, false);
383  }
384 }
385 
386 void KCMultiDialog::rootExit()
387 {
388  enableButton( User2, true);
389 }
390 
391 void KCMultiDialog::disableRModeButton()
392 {
393  enableButton( User2, false );
394  connect ( d->currentModule, TQT_SIGNAL( childClosed() ), TQT_SLOT( rootExit() ));
395 }
396 
397 void KCMultiDialog::dialogClosed()
398 {
399  kdDebug(710) << k_funcinfo << endl;
400 
401  /* If we don't delete them, the DCOP registration stays, and trying to load the KCMs
402  * in other situations will lead to "module already loaded in Foo," while to the user
403  * doesn't appear so(the dialog is hidden) */
404  ModuleList::Iterator end = m_modules.end();
405  for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
406  ( *it ).kcm->deleteClient();
407 }
408 
409 
410 // vim: sw=4 et sts=4
KURL
KCMultiDialog::configCommitted
void configCommitted()
Emitted after all KCModules have been told to save their configuration.
KDialogBase::applyClicked
void applyClicked()
KProcess
KCModuleLoader::testModule
static bool testModule(const TQString &module)
Checks whether an KCModule should be shown by running its test function.
Definition: kcmoduleloader.cpp:230
KDialogBase::Ok
Ok
KCModuleProxy::changed
bool changed() const
Definition: kcmoduleproxy.cpp:621
KCMultiDialog::slotApply
virtual void slotApply()
This slot is called when the user presses the "Apply" Button.
Definition: kcmultidialog.cpp:163
KIcon::Small
Small
KCMultiDialog::slotHelp
virtual void slotHelp()
This slot is called when the user presses the "Help" Button.
Definition: kcmultidialog.cpp:183
kdError
kdbgstream kdError(int area=0)
KCModuleInfo::icon
TQString icon() const
Definition: kcmoduleinfo.h:147
KURL::protocol
TQString protocol() const
KDialogBase::activePageIndex
int activePageIndex() const
KDialogBase::enableButton
void enableButton(ButtonCode id, bool state)
KProcess::start
virtual bool start(RunMode runmode=NotifyOnExit, Communication comm=NoCommunication)
kdDebug
kdbgstream kdDebug(int area=0)
KDialogBase::Apply
Apply
KDialogBase::Cancel
Cancel
klocale.h
KDialogBase
KCMultiDialog::slotUser1
virtual void slotUser1()
This slot is called when the user presses the "Reset" Button.
Definition: kcmultidialog.cpp:124
KCMultiDialog::slotDefault
virtual void slotDefault()
This slot is called when the user presses the "Default" Button.
Definition: kcmultidialog.cpp:110
KUser
KCMultiDialog::removeAllModules
void removeAllModules()
Remove all modules from the dialog.
Definition: kcmultidialog.cpp:323
KDialogBase::User1
User1
KIcon::SizeMedium
SizeMedium
KDialogBase::user2Clicked
void user2Clicked()
KDialogBase::addHBoxPage
TQHBox * addHBoxPage(const TQString &itemName, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
KDialogBase::Help
Help
KGuiItem
KProcess::detach
void detach()
KCMultiDialog::addModule
void addModule(const TQString &module, bool withfallback=true)
Add a module.
Definition: kcmultidialog.cpp:222
KDialogBase::User2
User2
KCModuleInfo::needsRootPrivileges
bool needsRootPrivileges() const
Definition: kcmoduleinfo.cpp:213
KDialogBase::aboutToShowPage
void aboutToShowPage(TQWidget *page)
KProcess::DontCare
DontCare
KDialogBase::actionButton
TQPushButton * actionButton(ButtonCode id)
KCModuleInfo
A class that provides information about a KCModule.
Definition: kcmoduleinfo.h:49
KDialogBase::plainPage
TQFrame * plainPage()
KDialogBase::showButton
void showButton(ButtonCode id, bool state)
KCModuleInfo::moduleName
TQString moduleName() const
Definition: kcmoduleinfo.h:131
KDialogBase::setInitialSize
void setInitialSize(const TQSize &s, bool noResize=false)
KDialogBase::okClicked
void okClicked()
KCMultiDialog::~KCMultiDialog
virtual ~KCMultiDialog()
Destructor.
Definition: kcmultidialog.cpp:102
KUser::isSuperUser
bool isSuperUser() const
KCModuleProxy
Encapsulates a KCModule for embedding.
Definition: kcmoduleproxy.h:68
KCMultiDialog::slotOk
virtual void slotOk()
This slot is called when the user presses the "OK" Button.
Definition: kcmultidialog.cpp:173
KCModuleInfo::service
KService::Ptr service() const
Definition: kcmoduleinfo.h:137
KCModuleInfo::comment
TQString comment() const
Definition: kcmoduleinfo.h:142
KURL::url
TQString url(int _trailing=0, int encoding_hint=0) const
KCMultiDialog::KCMultiDialog
KCMultiDialog(TQWidget *parent=0, const char *name=0, bool modal=false)
Constructs a new KCMultiDialog.
Definition: kcmultidialog.cpp:58
KDialogBase::Default
Default
endl
kndbgstream & endl(kndbgstream &s)
KStdGuiItem
KCModuleProxy::save
void save()
Calling it will cause the contained module to run its save() routine.
Definition: kcmoduleproxy.cpp:527
KDialogBase::showPage
bool showPage(int index)
KDialogBase::pageIndex
int pageIndex(TQWidget *widget) const
KCModuleLoader::unloadModule
static void unloadModule(const KCModuleInfo &mod)
Unloads the module&#39;s library.
Definition: kcmoduleloader.cpp:204
KDialogBase::finished
void finished()

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.11
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |