27 #include <tqpushbutton.h>
29 #include <kaboutdata.h>
30 #include <kapplication.h>
32 #include <kiconloader.h>
33 #include <klibloader.h>
35 #include <kmessagebox.h>
38 #include <kstdguiitem.h>
41 #include "kcmoduleloader.h"
42 #include "kcmoduleproxy.h"
43 #include "kcmultidialog.h"
44 #include "kcmultidialog.moc"
46 class KCMultiDialog::KCMultiDialogPrivate
49 KCMultiDialogPrivate()
50 : hasRootKCM( false ), currentModule( 0 )
59 :
KDialogBase(IconList, i18n(
"Configure"), Help | Default |Cancel | Apply |
60 Ok | User1 | User2, Ok, parent, name, modal, true,
62 , dialogface( IconList ), d( new KCMultiDialogPrivate )
68 :
KDialogBase( dialogFace, caption, Help | Default | Cancel | Apply | Ok |
69 User1 | User2, Ok, parent, name, modal, true,
71 , dialogface( dialogFace ), d( new KCMultiDialogPrivate )
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,
82 , dialogface( dialogFace ), d( new KCMultiDialogPrivate )
84 kdDebug( 710 ) <<
"Root modules will not work with this constructor. See the API documentation." <<
endl;
86 if ( buttonMask & User2 )
87 showButton( User2,
true );
90 inline void KCMultiDialog::init()
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 );
104 OrphanMap::Iterator end2 = m_orphanModules.end();
105 for( OrphanMap::Iterator it = m_orphanModules.begin(); it != end2; ++it )
112 int curPageIndex = activePageIndex();
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 )
118 ( *it ).kcm->defaults();
119 clientChanged(
true );
126 int curPageIndex = activePageIndex();
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 )
133 clientChanged(
false );
138 void KCMultiDialog::apply()
140 TQStringList updatedModules;
141 ModuleList::Iterator end = m_modules.end();
142 for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
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 );
155 for( TQStringList::const_iterator it = updatedModules.begin(); it != updatedModules.end(); ++it )
157 kdDebug(710) << k_funcinfo << *it <<
" " << ( *it ).latin1() <<
endl;
165 TQPushButton *button = actionButton(Apply);
175 TQPushButton *button = actionButton(Ok);
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 )
192 docPath = ( *it ).kcm->moduleInfo().docPath();
196 KURL url(
KURL(
"help:/"), docPath );
200 process <<
"khelpcenter"
209 void KCMultiDialog::clientChanged(
bool state)
212 ModuleList::Iterator end = m_modules.end();
213 for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
214 if( ( *it ).kcm->changed() )
216 enableButton( Apply,
true );
219 enableButton( Apply,
false );
224 TQString complete = path;
226 if( !path.endsWith(
".desktop" ))
227 complete +=
".desktop";
229 KService::Ptr service = KService::serviceByStorageId( complete );
235 TQStringList parentmodulenames,
bool withfallback)
237 kdDebug(710) <<
"KCMultiDialog::addModule "
243 if ( !kapp->authorizeControlModule( moduleinfo.
service()->menuId() ))
250 if (!moduleinfo.
service()->noDisplay())
255 page = addHBoxPage( parentmodulenames, moduleinfo.
comment(),
256 SmallIcon( moduleinfo.
icon(),
261 moduleinfo.
comment(), DesktopIcon( moduleinfo.
icon(),
266 (
new TQHBoxLayout( page ) )->setAutoAdd(
true );
269 kdError( 710 ) <<
"unsupported dialog face for KCMultiDialog"
278 if( m_orphanModules.contains( moduleinfo.
service() ) )
282 module = m_orphanModules[ moduleinfo.
service() ];
283 m_orphanModules.remove( moduleinfo.
service() );
284 kdDebug( 710 ) <<
"Use KCModule from the list of orphans for " <<
287 module->reparent( page, 0, TQPoint( 0, 0 ),
true );
290 clientChanged(
true );
292 if( activePageIndex() == -1 )
293 showPage( pageIndex( page ) );
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 ) );
303 connect(module, TQT_SIGNAL(changed(
bool)),
this, TQT_SLOT(clientChanged(
bool)));
305 if( m_modules.count() == 0 )
306 aboutToShowPage( page );
310 cm.service = moduleinfo.
service();
311 m_modules.append( cm );
316 d->hasRootKCM =
true;
317 showButton( User2,
true );
319 slotAboutToShow( page );
326 ModuleList::Iterator end = m_modules.end();
327 for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
331 TQObject * page = TQT_TQOBJECT(kcm->parent());
336 kcm->reparent( 0, TQPoint( 0, 0 ),
false );
339 m_orphanModules[ ( *it ).service ] = kcm;
340 kdDebug( 710 ) <<
"added KCModule to the list of orphans: " <<
345 clientChanged(
false );
348 void KCMultiDialog::show()
353 void KCMultiDialog::slotAboutToShow(TQWidget *page)
357 TQObject * obj = page->child( 0,
"KCModuleProxy" );
364 d->currentModule = module;
366 enableButton( KDialogBase::Help,
367 d->currentModule->buttons() & KCModule::Help );
368 enableButton( KDialogBase::Default,
369 d->currentModule->buttons() & KCModule::Default );
371 disconnect(
this, TQT_SIGNAL(user2Clicked()), 0, 0 );
373 if (d->currentModule->moduleInfo().needsRootPrivileges())
375 if ( !d->currentModule->rootMode() )
377 enableButton( User2,
true );
378 connect(
this, TQT_SIGNAL(user2Clicked()), d->currentModule, TQT_SLOT( runAsRoot() ));
379 connect(
this, TQT_SIGNAL(user2Clicked()), TQT_SLOT( disableRModeButton() ));
382 enableButton( User2,
false);
386 void KCMultiDialog::rootExit()
388 enableButton( User2,
true);
391 void KCMultiDialog::disableRModeButton()
393 enableButton( User2,
false );
394 connect ( d->currentModule, TQT_SIGNAL( childClosed() ), TQT_SLOT( rootExit() ));
397 void KCMultiDialog::dialogClosed()
404 ModuleList::Iterator end = m_modules.end();
405 for( ModuleList::Iterator it = m_modules.begin(); it != end; ++it )
406 ( *it ).kcm->deleteClient();
void configCommitted()
Emitted after all KCModules have been told to save their configuration.
static bool testModule(const TQString &module)
Checks whether an KCModule should be shown by running its test function.
virtual void slotApply()
This slot is called when the user presses the "Apply" Button.
virtual void slotHelp()
This slot is called when the user presses the "Help" Button.
kdbgstream kdError(int area=0)
TQString protocol() const
virtual bool start(RunMode runmode=NotifyOnExit, Communication comm=NoCommunication)
kdbgstream kdDebug(int area=0)
virtual void slotUser1()
This slot is called when the user presses the "Reset" Button.
virtual void slotDefault()
This slot is called when the user presses the "Default" Button.
void removeAllModules()
Remove all modules from the dialog.
void addModule(const TQString &module, bool withfallback=true)
Add a module.
bool needsRootPrivileges() const
A class that provides information about a KCModule.
TQString moduleName() const
virtual ~KCMultiDialog()
Destructor.
Encapsulates a KCModule for embedding.
virtual void slotOk()
This slot is called when the user presses the "OK" Button.
KService::Ptr service() const
TQString url(int _trailing=0, int encoding_hint=0) const
KCMultiDialog(TQWidget *parent=0, const char *name=0, bool modal=false)
Constructs a new KCMultiDialog.
kndbgstream & endl(kndbgstream &s)
void save()
Calling it will cause the contained module to run its save() routine.
static void unloadModule(const KCModuleInfo &mod)
Unloads the module's library.