KDE/kdelibs/plasma

Marco Martin notmart at gmail.com
Fri Jul 30 14:12:31 CEST 2010


SVN commit 1157180 by mart:

support load by plugin from AbstractToolBox

what stinks is the both support direct creation -and- plugin loading,
but has to be BC
could be the case to add it to PluginLoader? don't see big use cases
CCMAIL:plasma-devel at kde.org



 M  +1 -0      CMakeLists.txt  
 M  +33 -0     abstracttoolbox.cpp  
 M  +20 -0     abstracttoolbox.h  
 A             data/servicetypes/plasma-toolbox.desktop  


--- trunk/KDE/kdelibs/plasma/CMakeLists.txt #1157179:1157180
@@ -408,6 +408,7 @@
    data/servicetypes/plasma-packagestructure.desktop
    data/servicetypes/plasma-runner.desktop
    data/servicetypes/plasma-scriptengine.desktop
+   data/servicetypes/plasma-toolbox.desktop
    data/servicetypes/plasma-wallpaper.desktop
    DESTINATION ${SERVICETYPES_INSTALL_DIR})
 
--- trunk/KDE/kdelibs/plasma/abstracttoolbox.cpp #1157179:1157180
@@ -21,6 +21,8 @@
 
 #include "containment.h"
 
+#include <kservicetypetrader.h>
+
 namespace Plasma
 {
 
@@ -40,11 +42,42 @@
 {
 }
 
+AbstractToolBox::AbstractToolBox(QObject *parent, const QVariantList &args)
+   : QGraphicsWidget(0),
+     d(new AbstractToolBoxPrivate(qobject_cast<Containment *>(parent)))
+{
+    Containment *cont = qobject_cast<Containment *>(parent);
+
+    if (cont) {
+        setParentItem(cont);
+    }
+}
+
 AbstractToolBox::~AbstractToolBox()
 {
     delete d;
 }
 
+AbstractToolBox *AbstractToolBox::load(const QString &name, const QVariantList &args, Plasma::Containment *containment)
+{
+    const QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(name);
+    KService::List offers = KServiceTypeTrader::self()->query("Plasma/ToolBox", constraint);
+
+    if (!offers.isEmpty()) {
+        KService::Ptr offer = offers.first();
+
+        KPluginLoader plugin(*offer);
+
+        if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
+            return 0;
+        }
+
+        return offer->createInstance<AbstractToolBox>(containment, args);
+    } else {
+        return 0;
+    }
+}
+
 Containment *AbstractToolBox::containment() const
 {
     return d->containment;
--- trunk/KDE/kdelibs/plasma/abstracttoolbox.h #1157179:1157180
@@ -51,9 +51,20 @@
     Q_ENUMS(ToolType)
 
     explicit AbstractToolBox(Containment *parent);
+    explicit AbstractToolBox(QObject *parent = 0,
+                    const QVariantList &args = QVariantList());
     ~AbstractToolBox();
 
     /**
+     * Create a new AbstractToolBox, loading the proper plugin
+     * @param name the plugin name
+     * @param args the plugin arguments
+     * @param containment the containment parent of the toolbox
+     * @since 4.6
+     */
+    static AbstractToolBox *load(const QString &name, const QVariantList &args=QVariantList(), Plasma::Containment *containment=0);
+
+    /**
      * create a toolbox tool from the given action
      * @p action the action to associate the tool with
      */
@@ -79,5 +90,14 @@
 };
 
 } // Plasma namespace
+
+/**
+ * Register an applet when it is contained in a loadable module
+ */
+#define K_EXPORT_PLASMA_TOOLBOX(libname, classname) \
+K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
+K_EXPORT_PLUGIN(factory("plasma_toolbox_" #libname)) \
+K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
+
 #endif // multiple inclusion guard
 


More information about the Plasma-devel mailing list