Greetings Plasma developers,

There is some code duplication in that some plasmoids share very much of
program logic but actually differ in just a setting. E.g. the recently
made ShowActivityManager plasmoid, which just is a DBus call launcher.
The Icon plasmoid is an example of this made right. I'd like to have
more generic plasmoids. Even better, I'd like to have an easy way to
configure them.

Let's see the code. config.patch shows a way to load a config metadata
file and fill a designated plasmoid with the configuration data
(metadata.desktop). We search for a X-Plasma-ConfigApplet property that
defines the plasmoid to configure and load. Additional properties define
the plasmoid settings. This allows us, for example, to easily provide
access to any webservice without code duplication.

Other uses include DBus call launchers, data visualizers.

What is missing in my code is a working way to fill/override the
plasmoid settings.

Do you like this idea? If so please help me in getting the configuration
part to work. Is the applet loading code in PluginLoader wrong? Please
tell me where I should work instead. I'm on #plasma-devel as dpalacio.

Kind regards,
David.

diff --git a/plasma/data/servicetypes/plasma-applet.desktop 
b/plasma/data/servicetypes/plasma-applet.desktop
index 8fabddb..5fbc986 100644
--- a/plasma/data/servicetypes/plasma-applet.desktop
+++ b/plasma/data/servicetypes/plasma-applet.desktop
@@ -79,6 +79,15 @@ Comment[zh_TW]=Plasma 小程式
 [PropertyDef::X-Plasma-API]
 Type=QString
 
+[PropertyDef::X-Plasma-ConfigApplet]
+Type=QString
+
+[PropertyDef::X-Plasma-ConfigUrl]
+Type=QString
+
+[PropertyDef::X-Plasma-ConfigIcon]
+Type=QString
+
 [PropertyDef::X-Plasma-DropMimeTypes]
 Type=QStringList
 
diff --git a/plasma/pluginloader.cpp b/plasma/pluginloader.cpp
index e57cac5..6fc4c6e 100644
--- a/plasma/pluginloader.cpp
+++ b/plasma/pluginloader.cpp
@@ -107,6 +107,26 @@ Applet *PluginLoader::loadApplet(const QString &name, uint 
appletId, const QVari
     }
 
     KService::Ptr offer = offers.first();
+    if(!offer->property("X-Plasma-ConfigApplet").toString().isEmpty()) {
+        QString appletName = 
offer->property("X-Plasma-ConfigApplet").toString();
+        kDebug() << "we have a configuration for applet" << appletName;
+        applet = loadApplet(appletName, appletId, args);
+        if(!applet) {
+            return 0;
+        }
+        KConfigGroup *config = applet->d->mainConfigGroup();
+        if(offer->property("X-Plasma-ConfigIcon").isValid()) {
+            config->writeEntry("Icon", offer->property("X-Plasma-ConfigIcon"));
+        }
+        kDebug() << "Check Url valid?" << 
offer->property("X-Plasma-ConfigUrl").isValid() << 
offer->property("X-Plasma-ConfigUrl");
+        if(offer->property("X-Plasma-ConfigUrl").isValid()) {
+            kDebug() << "write Url as" << 
offer->property("X-Plasma-ConfigUrl").toString();
+            config->writeEntry("Url", 
offer->property("X-Plasma-ConfigUrl").toString());
+        }
+        config->sync();
+        applet->restore(*config);
+        return applet;
+    }
  
     if (appletId == 0) {
         appletId = ++AppletPrivate::s_maxAppletId;
[Desktop Entry]
Name=KDE webview
Name[x-test]=xxGoogle Tasksxx
Comment=KDE EXample david
Comment[x-test]=xxGoogle Tasks widget. Works best if GMail autologins in 
Konqueror.xx
Type=Service
ServiceTypes=Plasma/Applet,Plasma/PopupApplet

X-Plasma-ConfigApplet=org.kde.configurable.webview
X-Plasma-ConfigIcon=konqueror
X-Plasma-ConfigUrl=http://kde.org/

X-KDE-PluginInfo-Author=David Palacio
X-KDE-PluginInfo-Email=dpala...@orbitalibre.org
X-KDE-PluginInfo-Name=org.example.kde
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=http://kde.example.org/
X-KDE-PluginInfo-Category=Online Services
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
X-Plasma-NotificationArea=true

_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to