20 #include "ksettings/dialog.h"
23 #include <kcmultidialog.h>
25 #include <kservicegroup.h>
28 #include <kplugininfo.h>
29 #include "ksettings/dispatcher.h"
30 #include "ksettings/componentsdialog.h"
31 #include <ksimpleconfig.h>
32 #include <kstandarddirs.h>
33 #include <kiconloader.h>
36 #include "tdecmoduleinfo.h"
57 typedef TQValueList<PageNode*> List;
58 enum Type { KCM, Group, Root };
81 m_dialog = parent->m_dialog;
84 PageNode( GroupInfo & group, PageNode * parent )
90 m_value.group =
new GroupInfo( group );
91 m_value.group->page = 0;
92 m_dialog = parent->m_dialog;
95 void bubbleSort( List::Iterator begin, List::Iterator end )
99 List::Iterator lastswapped = begin;
102 while( begin != end )
115 }
while( j != begin );
124 PageNode( Dialog * dialog )
136 else if( Group == m_type )
137 delete m_value.group;
138 List::Iterator
end = m_children.end();
139 for( List::Iterator it = m_children.begin(); it != end; ++it )
145 int w = ( KCM == m_type ) ? m_value.kcm->weight()
146 : m_value.group->weight;
151 bool operator<(
const PageNode & rhs )
const
153 return weight() < rhs.weight();
161 m_visible = m_dialog->isPluginForKCMEnabled( m_value.kcm );
165 List::Iterator
end = m_children.end();
166 for( List::Iterator it = m_children.begin(); it != end;
168 if( ( *it )->isVisible() )
176 kdDebug( 700 ) << k_funcinfo <<
"returns " << m_visible <<
endl;
183 List::Iterator
end = m_children.end();
184 for( List::Iterator it = m_children.begin(); it != end; ++it )
185 ( *it )->makeDirty();
188 TQString
name()
const
191 return TQString::fromAscii(
"root node" );
192 return ( KCM == m_type ) ? m_value.kcm->moduleName()
193 : m_value.group->name;
196 TQStringList parentNames()
const
199 PageNode * node = m_parent;
200 while( node && node->m_type != Root )
202 ret.prepend( node->name() );
203 node = node->m_parent;
216 dlg->
addModule( *m_value.kcm, parentNames() );
219 if( Group == m_type && 0 == m_value.group->page )
222 if( ! m_value.group->icon.isNull() )
223 icon = SmallIcon( m_value.group->icon,
225 TQVBox * page = dlg->
addVBoxPage( m_value.group->name,
226 TQString::null, icon );
227 TQLabel * comment =
new TQLabel( m_value.group->comment, page );
228 comment->setTextFormat( TQt::RichText );
229 m_value.group->page = page;
231 List::Iterator
end = m_children.end();
232 for( List::Iterator it = m_children.begin(); it != end; ++it )
233 ( *it )->addToDialog( dlg );
243 List::Iterator
end = m_children.end();
244 for( List::Iterator it = m_children.begin(); it != end; ++it )
245 ( *it )->removeFromDialog( dlg );
246 if( Group == m_type )
248 delete m_value.group->page;
249 m_value.group->page = 0;
256 List::Iterator begin = m_children.begin();
257 List::Iterator
end = m_children.end();
258 bubbleSort( begin, end );
259 for( List::Iterator it = begin ; it !=
end; ++it )
263 bool insert( GroupInfo & group )
265 if( group.parentid.isNull() )
269 m_children.
append(
new PageNode( group,
this ) );
273 kdFatal( 700 ) <<
"wrong PageNode insertion"
276 if( Group == m_type && group.parentid == m_value.group->id )
278 m_children.append(
new PageNode( group,
this ) );
281 List::Iterator
end = m_children.end();
282 for( List::Iterator it = m_children.begin(); it != end; ++it )
283 if( ( *it )->insert( group ) )
288 m_children.
append(
new PageNode( group,
this ) );
296 if( parentid.isNull() )
300 m_children.
append(
new PageNode( info,
this ) );
304 kdFatal( 700 ) <<
"wrong PageNode insertion"
307 if( Group == m_type && parentid == m_value.group->id )
309 m_children.append(
new PageNode( info,
this ) );
312 List::Iterator
end = m_children.end();
313 for( List::Iterator it = m_children.begin(); it != end; ++it )
314 if( ( *it )->insert( info, parentid ) )
319 m_children.
append(
new PageNode( info,
this ) );
327 List::ConstIterator
end = m_children.end();
328 for( List::ConstIterator it = m_children.begin(); it != end; ++it )
329 if( ( *it )->m_children.count() > 0 )
336 return ( m_children.count() == 1 );
340 class Dialog::DialogPrivate
343 DialogPrivate(
Dialog * parent )
352 TQWidget * parentwidget;
353 TQStringList registeredComponents;
354 TQValueList<KService::Ptr> services;
355 TQMap<TQString, KPluginInfo*> plugininfomap;
359 : TQObject( parent, name )
360 , d( new DialogPrivate( this ) )
362 d->parentwidget = parent;
363 d->staticlistview =
true;
364 d->services = instanceServices();
368 TQWidget * parent,
const char * name )
369 : TQObject( parent, name )
370 , d( new DialogPrivate( this ) )
372 d->parentwidget = parent;
373 d->staticlistview = ( content ==
Static );
374 d->services = instanceServices();
378 TQWidget * parent,
const char * name )
379 : TQObject( parent, name )
380 , d( new DialogPrivate( this ) )
382 d->parentwidget = parent;
383 d->staticlistview =
true;
384 d->services = instanceServices() + parentComponentsServices( components );
389 : TQObject( parent, name )
390 , d( new DialogPrivate( this ) )
392 d->parentwidget = parent;
393 d->staticlistview = ( content ==
Static );
394 d->services = instanceServices() + parentComponentsServices( components );
404 for( TQValueList<KPluginInfo*>::ConstIterator it = plugininfos.begin();
405 it != plugininfos.end(); ++it )
407 d->registeredComponents.append( ( *it )->pluginName() );
408 d->services += ( *it )->kcmServices();
409 d->plugininfomap[ ( *it )->pluginName() ] = *it;
416 createDialogFromServices();
418 return d->dlg->show();
424 createDialogFromServices();
428 TQValueList<KService::Ptr> Dialog::instanceServices()
const
432 d->registeredComponents.append( instanceName );
433 kdDebug( 700 ) <<
"calling KServiceGroup::childGroup( " << instanceName
435 KServiceGroup::Ptr service = KServiceGroup::childGroup( instanceName );
437 TQValueList<KService::Ptr> ret;
439 if( service && service->isValid() )
442 KServiceGroup::List list = service->entries();
443 for( KServiceGroup::List::ConstIterator it = list.begin();
444 it != list.end(); ++it )
447 if( p->isType( KST_KService ) )
450 ret << static_cast<KService *>( p );
453 kdWarning( 700 ) <<
"KServiceGroup::childGroup returned"
454 " something else than a KService (kinda)" <<
endl;
461 TQValueList<KService::Ptr> Dialog::parentComponentsServices(
462 const TQStringList & kcdparents )
const
464 d->registeredComponents += kcdparents;
465 TQString constraint = kcdparents.join(
466 "' in [X-TDE-ParentComponents]) or ('" );
467 constraint =
"('" + constraint +
"' in [X-TDE-ParentComponents])";
469 kdDebug( 700 ) <<
"constraint = " << constraint <<
endl;
470 return TDETrader::self()->query(
"TDECModule", constraint );
473 bool Dialog::isPluginForKCMEnabled(
TDECModuleInfo * moduleinfo )
const
479 <<
" KCM should be shown" <<
endl;
481 TQStringList parentComponents = moduleinfo->
service()->property(
482 "X-TDE-ParentComponents" ).toStringList();
483 for( TQStringList::ConstIterator pcit = parentComponents.begin();
484 pcit != parentComponents.end(); ++pcit )
487 if( d->registeredComponents.find( *pcit ) ==
488 d->registeredComponents.end() )
492 if( ! d->plugininfomap.contains( *pcit ) )
503 kdDebug( 700 ) <<
"parent " << *pcit <<
" is "
504 << ( enabled ?
"enabled" :
"disabled" ) <<
endl;
512 void Dialog::parseGroupFile(
const TQString & filename )
515 TQStringList groups = file.groupList();
516 for( TQStringList::ConstIterator it = groups.begin(); it != groups.end();
521 file.setGroup(
id.utf8() );
523 group.name = file.readEntry(
"Name" );
524 group.comment = file.readEntry(
"Comment" );
525 group.weight = file.readNumEntry(
"Weight", 100 );
526 group.parentid = file.readEntry(
"Parent" );
527 group.icon = file.readEntry(
"Icon" );
528 d->pagetree.insert( group );
532 void Dialog::createDialogFromServices()
535 TQString setdlgpath =
locate(
"appdata",
538 "ksettingsdialog/*.setdlg" );
539 if( ! setdlgpath.isNull() )
540 parseGroupFile( setdlgpath );
541 if( setdlgaddon.size() > 0 )
542 for( TQStringList::ConstIterator it = setdlgaddon.begin();
543 it != setdlgaddon.end(); ++it )
544 parseGroupFile( *it );
547 for( TQValueList<KService::Ptr>::ConstIterator it = d->services.begin();
548 it != d->services.end(); ++it )
553 TQVariant tmp = info->
service()->property(
"X-TDE-CfgDlgHierarchy",
556 parentid = tmp.toString();
557 d->pagetree.insert( info, parentid );
565 if( d->pagetree.needTree() )
567 else if( d->pagetree.singleChild() )
570 kdDebug( 700 ) <<
"creating KCMultiDialog" <<
endl;
575 d->dlg->setShowIconsInTreeList(
true );
589 if( ! d->staticlistview )
590 d->dlg->addButtonBelowList( i18n(
"Select Components..." ),
this,
591 TQ_SLOT( configureTree() ) );
594 TQ_SLOT( syncConfiguration() ) );
596 TQ_SLOT( syncConfiguration() ) );
597 connect( d->dlg, TQ_SIGNAL( configCommitted(
const TQCString & ) ),
600 d->pagetree.addToDialog( d->dlg );
603 d->dlg->unfoldTreeList();
606 void Dialog::configureTree()
609 ComponentsDialog * subdlg =
new ComponentsDialog( d->dlg );
610 subdlg->setPluginInfos( d->plugininfomap );
612 connect( subdlg, TQ_SIGNAL( okClicked() ),
this, TQ_SLOT( updateTreeList() ) );
613 connect( subdlg, TQ_SIGNAL( applyClicked() ),
this, TQ_SLOT( updateTreeList() ) );
614 connect( subdlg, TQ_SIGNAL( okClicked() ),
this,
616 connect( subdlg, TQ_SIGNAL( applyClicked() ),
this,
618 connect( subdlg, TQ_SIGNAL( finished() ), subdlg, TQ_SLOT( delayedDestruct() ) );
621 void Dialog::updateTreeList()
625 d->pagetree.makeDirty();
631 d->pagetree.removeFromDialog( d->dlg );
632 d->pagetree.addToDialog( d->dlg );
634 if( d->pagetree.needTree() )
635 d->dlg->unfoldTreeList(
true );
640 #include "dialog.moc"
A method that offers a KDialogBase containing arbitrary KControl Modules.
void addModule(const TQString &module, bool withfallback=true, TQStringList args=TQStringList())
Add a module.
void removeAllModules()
Remove all modules from the dialog.
TQVBox * addVBoxPage(const TQString &itemName, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
Information about a plugin.
virtual bool isPluginEnabled() const
virtual void load(TDEConfigGroup *config=0)
Load the state of the plugin - enabled or not.
void pluginSelectionChanged()
If you use the dialog in Configurable mode and want to be notified when the user changes the plugin s...
ContentInListView
Tells the dialog whether the entries in the listview are all static or whether it should add a Config...
@ Static
Static listview, while running no entries are added or deleted.
Dialog(TQWidget *parent=0, const char *name=0)
Construct a new Preferences Dialog for the application.
void addPluginInfos(const TQValueList< KPluginInfo * > &plugininfos)
If you use a Configurable dialog you need to pass KPluginInfo objects that the dialog should configur...
void show()
Show the config dialog.
void syncConfiguration()
When this slot is called the TDEConfig objects of all the registered instances are sync()ed.
static Dispatcher * self()
Get a reference the the Dispatcher object.
A class that provides information about a TDECModule.
KService::Ptr service() const
TQString moduleName() const
static TDEStandardDirs * dirs()
static TDEInstance * instance()
TQCString instanceName() const
bool append(const KKeySequence &keySeq)
TQStringList findAllResources(const char *type, const TQString &filter=TQString::null, bool recursive=false, bool unique=false) const
kdbgstream kdFatal(int area=0)
kndbgstream & endl(kndbgstream &s)
TQString kdBacktrace(int levels=-1)
kdbgstream kdWarning(int area=0)
kdbgstream kdDebug(int area=0)
TQString locate(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())
A collection of classes to create configuration dialogs that work over component boundaries.
const TDEShortcut & insert()
TQString name(StdAccel id)
const TDEShortcut & end()