[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] Priority of Solid Actions
From:       Gökçen_Eraslan <gokcen () pardus ! org ! tr>
Date:       2009-05-22 9:22:33
Message-ID: 200905221222.41639.gokcen () pardus ! org ! tr
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hi,

I've hit a bug about action .desktop files of Solid and written a patch about 
this. When you install some applications with solid action desktop files (for 
example digikam), there is no mechanism for priority of those actions, I mean, 
when there are two desktop files with a matching predicate, the order of these 
actions in notification dialog is now undefined. Well actually, the order is 
defined like this:

KStandardDirs::findAllResources() -> lookupPrefix() -> lookupDictionary() -> 
readdir()

So, now, when hotplug data-engine determines the order of the action desktop 
files, it totally depends on readdir, which is different in different 
computers/disks.

Attached patch make comparisons based on InitialPreference key in desktop 
files, if it can't find any, it looks at the name of the desktop file (better 
than readdir order :) ). Maybe later, an option about ordering may be added to 
"Device Actions" kcm. 

Any ideas, comments?

-- 
Gökçen Eraslan
Pardus Developer

["solid-actions-priority.diff" (text/x-patch)]

diff -Naur ../kdebase-workspace-4.2.3-orig/plasma/applets/devicenotifier/test-predicate-openinwindow.desktop \
                plasma/applets/devicenotifier/test-predicate-openinwindow.desktop
--- ../kdebase-workspace-4.2.3-orig/plasma/applets/devicenotifier/test-predicate-openinwindow.desktop	2009-05-22 \
                00:22:15.860074457 +0300
+++ plasma/applets/devicenotifier/test-predicate-openinwindow.desktop	2009-05-22 \
11:19:14.782499046 +0300 @@ -2,6 +2,7 @@
 X-KDE-Solid-Predicate=[[ StorageVolume.ignored == false AND StorageVolume.usage == \
'FileSystem' ] OR [ IS StorageAccess AND StorageDrive.driveType == 'Floppy' ]]  \
Type=Service  Actions=open;
+InitialPreference=10
 
 [Desktop Action open]
 Name=Open with Dolphin
diff -Naur ../kdebase-workspace-4.2.3-orig/plasma/dataengines/hotplug/hotplugengine.cpp \
                plasma/dataengines/hotplug/hotplugengine.cpp
--- ../kdebase-workspace-4.2.3-orig/plasma/dataengines/hotplug/hotplugengine.cpp	2009-05-22 \
                11:22:37.398498124 +0300
+++ plasma/dataengines/hotplug/hotplugengine.cpp	2009-05-22 11:22:57.413620417 +0300
@@ -32,13 +32,13 @@
 #include <solid/deviceinterface.h>
 #include <solid/predicate.h>
 
-
-
 HotplugEngine::HotplugEngine(QObject* parent, const QVariantList& args)
     : Plasma::DataEngine(parent, args)
 {
     Q_UNUSED(args)
     files = KGlobal::dirs()->findAllResources("data", "solid/actions/");
+    if (files.count() > 1)
+        sortByPreference(files);
 
     foreach (const Solid::Device &dev, Solid::Device::allDevices()) {
         onDeviceAdded(dev.udi());
@@ -55,6 +55,27 @@
 
 }
 
+bool lessThan(const QString &s1, const QString &s2)
+{
+    KDesktopFile desktop1(s1);
+    KDesktopFile desktop2(s2);
+
+    QVariant initial1 = desktop1.desktopGroup().readEntry("InitialPreference", 0);
+    QVariant initial2 = desktop2.desktopGroup().readEntry("InitialPreference", 0);
+
+    // return "greater than" instead of "less than", we want list in decreasing \
order +    if (initial1.toInt() != 0 || initial2.toInt() != 0)
+        return initial1.toInt() > initial2.toInt();
+    else
+        return s1.toLower() > s2.toLower();
+
+}
+
+void HotplugEngine::sortByPreference(QStringList& desktops)
+{
+    qSort(desktops.begin(), desktops.end(), ::lessThan);
+}
+
 void HotplugEngine::onDeviceAdded(const QString &udi)
 {
     bool new_device = false;
@@ -62,6 +83,7 @@
 
     QStringList interestingDesktopFiles;
     //search in all desktop configuration file if the device inserted is a correct \
device +
     foreach (const QString &path, files) {
         KDesktopFile cfg(path);
         QString string_predicate = \
                cfg.desktopGroup().readEntry("X-KDE-Solid-Predicate");
diff -Naur ../kdebase-workspace-4.2.3-orig/plasma/dataengines/hotplug/hotplugengine.h \
                plasma/dataengines/hotplug/hotplugengine.h
--- ../kdebase-workspace-4.2.3-orig/plasma/dataengines/hotplug/hotplugengine.h	2009-05-22 \
                00:22:15.828075124 +0300
+++ plasma/dataengines/hotplug/hotplugengine.h	2009-05-22 10:52:55.917600252 +0300
@@ -42,6 +42,8 @@
         void onDeviceRemoved(const QString &udi);
     private :
         QStringList files;
+        void sortByPreference(QStringList& desktops);
+        bool lessThan(const QString &s1, const QString &s2);
 };
 
 K_EXPORT_PLASMA_DATAENGINE(hotplug, HotplugEngine)


["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic