Extending KSettings::Dialog to allow to specify excludes

Andreas Pakulat apaku at gmx.de
Wed Jun 20 18:54:31 BST 2007


On 20.06.07 11:16:34, Aaron J. Seigo wrote:
> On Wednesday 20 June 2007, Andreas Pakulat wrote:
> > Ok, here's the updated patch, 
> 
> looks good ... some nitpicks (sorry *eek*):

Thanks, I don't mind nitpicks :)

> - i'd probably just call it "set*" rather than "initialize*". yes, it's only 
> an initializer right now, but the apidox can note that implementation detail 
> right now and if it does change in the future (mkretz seemed to note that 
> this was on his radar to eventually do) we won't be left with 
> innappropriately named methods ...

Oswald already said so. Will do.

> - after blacklisted = true you could probably put a break; to avoid further 
> looping when we already know the result

Oops, that got lost along the way.

> - could you adjust the code to follow the kdelibs style guide? =)
> 	 http://techbase.kde.org/Policies/Kdelibs_Coding_Style

Done.

Update attached, just in case I overlooked something (also removed the
kDebug() messages).

Andreas

-- 
Best of all is never to have been born.  Second best is to die soon.
-------------- next part --------------
Index: dialog.cpp
===================================================================
--- dialog.cpp	(Revision 677983)
+++ dialog.cpp	(Arbeitskopie)
@@ -36,8 +36,8 @@
 namespace KSettings
 {
 
-Dialog::Dialog(ContentInListView content, QWidget *parent, const QStringList &arguments)
-    : KCMultiDialog(parent), d_ptr(new DialogPrivate(this, parent, (content == Static), arguments))
+Dialog::Dialog(ContentInListView content, QWidget *parent)
+    : KCMultiDialog(parent), d_ptr(new DialogPrivate(this, parent, (content == Static)))
 {
     Q_D(Dialog);
     d->q_ptr = this;
@@ -45,8 +45,8 @@ Dialog::Dialog(ContentInListView content
     d->removeDuplicateServices();
 }
 
-Dialog::Dialog(const QStringList &components, QWidget *parent, const QStringList &arguments)
-    : KCMultiDialog(parent), d_ptr(new DialogPrivate(this, parent, true, arguments))
+Dialog::Dialog(const QStringList &components, QWidget *parent)
+    : KCMultiDialog(parent), d_ptr(new DialogPrivate(this, parent, true))
 {
     Q_D(Dialog);
     d->q_ptr = this;
@@ -54,8 +54,8 @@ Dialog::Dialog(const QStringList &compon
     d->removeDuplicateServices();
 }
 
-Dialog::Dialog(const QStringList &components, ContentInListView content, QWidget *parent, const QStringList &arguments)
-    : KCMultiDialog(parent), d_ptr(new DialogPrivate(this, parent, (content == Static), arguments))
+Dialog::Dialog(const QStringList &components, ContentInListView content, QWidget *parent)
+    : KCMultiDialog(parent), d_ptr(new DialogPrivate(this, parent, (content == Static)))
 {
     Q_D(Dialog);
     d->q_ptr = this;
@@ -68,6 +68,19 @@ Dialog::~Dialog()
     delete d_ptr;
 }
 
+
+void Dialog::setKCMArguments( const QStringList& arguments )
+{
+    Q_D(Dialog);
+    d->arguments = arguments;
+}
+
+void Dialog::setComponentBlacklist( const QStringList& blacklist )
+{
+    Q_D(Dialog);
+    d->componentBlacklist = blacklist;
+}
+
 void Dialog::addPluginInfos( const QList<KPluginInfo*> & plugininfos )
 {
     Q_D(Dialog);
@@ -90,8 +103,8 @@ void Dialog::show()
 	return d->dlg->show();
 }
 
-DialogPrivate::DialogPrivate(Dialog *d, QWidget *p, bool s, const QStringList &a)
-    : pagetree(d), arguments(a), dlg(0), parentwidget(p), staticlistview(s)
+DialogPrivate::DialogPrivate(Dialog *d, QWidget *p, bool s)
+    : pagetree(d), dlg(0), parentwidget(p), staticlistview(s)
 {
 }
 
@@ -216,6 +229,17 @@ void DialogPrivate::createDialogFromServ
     for (QList<KService::Ptr>::ConstIterator it = services.begin(); it != services.end(); ++it) {
 		// we create the KCModuleInfo
 		KCModuleInfo * info = new KCModuleInfo( *it );
+        bool blacklisted = false;
+        foreach( QString comp, (*it)->property( "X-KDE-ParentComponents" ).toStringList() )
+        {
+            if( componentBlacklist.contains(comp) ) {
+                blacklisted = true;
+                break;
+            }
+        }
+        if( blacklisted ) {
+            continue;
+        }
 		QString parentid;
 		QVariant tmp = info->service()->property( "X-KDE-CfgDlgHierarchy",
 			QVariant::String );
Index: dialog_p.h
===================================================================
--- dialog_p.h	(Revision 677983)
+++ dialog_p.h	(Arbeitskopie)
@@ -313,11 +313,12 @@ class DialogPrivate
     friend class PageNode;
     Q_DECLARE_PUBLIC(Dialog)
     protected:
-        DialogPrivate(Dialog *d, QWidget *p, bool s, const QStringList &a);
+        DialogPrivate(Dialog *d, QWidget *p, bool s);
 
         PageNode pagetree;
 
         QStringList registeredComponents;
+        QStringList componentBlacklist;
         QList<KService::Ptr> services;
         QMap<QString, KPluginInfo*> plugininfomap;
         QStringList arguments;
Index: dialog.h
===================================================================
--- dialog.h	(Revision 677983)
+++ dialog.h	(Arbeitskopie)
@@ -102,11 +102,8 @@ class KUTILS_EXPORT Dialog : public KCMu
          * @param parent       The parent is only used as the parent for the
          *                     dialog - centering the dialog over the parent
          *                     widget.
-         * @param arguments    A list of arguments that are passed to all
-         *                     KCModules when adding them to the dialog
          */
-        explicit Dialog( ContentInListView content = Static, QWidget * parent = 0,
-                         const QStringList& arguments = QStringList() );
+        explicit Dialog( ContentInListView content = Static, QWidget * parent = 0 );
 
         /**
          * Construct a new Preferences Dialog with the pages for the selected
@@ -119,11 +116,8 @@ class KUTILS_EXPORT Dialog : public KCMu
          * @param parent       The parent is only used as the parent for the
          *                     dialog - centering the dialog over the parent
          *                     widget.
-         * @param arguments    A list of arguments that are passed to all
-         *                     KCModules when adding them to the dialog
          */
-         explicit Dialog( const QStringList & components, QWidget * parent = 0,
-                          const QStringList& arguments = QStringList() );
+         explicit Dialog( const QStringList & components, QWidget * parent = 0 );
 
         /**
          * Construct a new Preferences Dialog with the pages for the selected
@@ -138,12 +132,9 @@ class KUTILS_EXPORT Dialog : public KCMu
          * @param parent       The parent is only used as the parent for the
          *                     dialog - centering the dialog over the parent
          *                     widget.
-         * @param arguments    A list of arguments that are passed to all
-         *                     KCModules when adding them to the dialog
          */
         Dialog( const QStringList & components, ContentInListView
-                content, QWidget * parent = 0,
-                const QStringList& arguments = QStringList() );
+                content, QWidget * parent = 0 );
 
         ~Dialog();
 
@@ -153,6 +144,30 @@ class KUTILS_EXPORT Dialog : public KCMu
          */
         void addPluginInfos( const QList<KPluginInfo*> & plugininfos );
 
+        /**
+         * sets the argument list that is given to all the KControlModule's when
+         * they are created.
+         * Use this if you have KControlModule's that need special arguments to
+         * work
+         *
+         * Note that this function only works before showing the
+         * KSettings::Dialog for the first time.
+         * @param arguments The list of arguments passed to each KCM
+         */
+        void setKCMArguments( const QStringList& arguments );
+
+        /**
+         * Initializes the blacklisted component list. Any KCM that lists one
+         * of the components in the given blacklist is not loaded even if it
+         * would fit otherwise. This is a way to explicitly prevent loading of
+         * certain KControlModules.
+         *
+         * Note that this function only works before showing the
+         * KSettings::Dialog for the first time.
+         * @param blacklist the list of components that prevent a KCM from being
+         * loaded
+         */
+        void setComponentBlacklist( const QStringList& blacklist );
     public Q_SLOTS:
         /**
          * Show the config dialog. The slot immediately returns since the dialog


More information about the kde-core-devel mailing list