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

List:       kde-commits
Subject:    [kde-workspace/KDE/4.9] plasma/generic/dataengines/soliddevice: Fix Removable property in soliddevic
From:       Alberto Villa <avilla () FreeBSD ! org>
Date:       2012-10-06 1:53:06
Message-ID: 20121006015306.ACC4CA605D () git ! kde ! org
[Download RAW message or body]

Git commit ec9d4e418ca2327c1a098352ccf78247f1769c83 by Alberto Villa.
Committed on 06/10/2012 at 03:33.
Pushed by avilla into branch 'KDE/4.9'.

Fix Removable property in soliddevice engine (HAL)

Current hack to check for Removable property in StorageAccess devices
goes up only one level to search for the StorageDrive device. This
works fine with UDev, but not with HAL, which can have (at least on
FreeBSD) intermediate devices between the volume and its StorageDrive
ancestor, for example partition-type devices. A generic solution would
be to create a method in Solid::Device, but this cannot be done until
libsolid2 is ready; meanwhile, let's add a getAncestorAs() function to
the engine.
The patch was submitted by Andriy Gapon and modified by me to handle
other similar cases.

While here, add logic to really set Hotpluggable property.

The final version of the patch was reviewed by Aaron Seigo on IRC.

REVIEW: 105432
REVIEW: 106378
CCMAIL: avg@FreeBSD.org

M  +33   -10   plasma/generic/dataengines/soliddevice/soliddeviceengine.cpp

http://commits.kde.org/kde-workspace/ec9d4e418ca2327c1a098352ccf78247f1769c83

diff --git a/plasma/generic/dataengines/soliddevice/soliddeviceengine.cpp \
b/plasma/generic/dataengines/soliddevice/soliddeviceengine.cpp index ca9572c..d186843 \
                100644
--- a/plasma/generic/dataengines/soliddevice/soliddeviceengine.cpp
+++ b/plasma/generic/dataengines/soliddevice/soliddeviceengine.cpp
@@ -28,6 +28,22 @@
 
 #include <Plasma/DataContainer>
 
+//TODO: implement in libsolid2
+namespace
+{
+    template <class DevIface> DevIface *getAncestorAs(const Solid::Device &device)
+    {
+        for (Solid::Device parent = device.parent();
+             parent.isValid();
+             parent = parent.parent()) {
+            if (parent.is<DevIface>()) {
+                return parent.as<DevIface>();
+            }
+        }
+        return NULL;
+    }
+}
+
 SolidDeviceEngine::SolidDeviceEngine(QObject* parent, const QVariantList& args)
         : Plasma::DataEngine(parent, args),
           m_temperature(0),
@@ -184,10 +200,16 @@ bool SolidDeviceEngine::populateDeviceData(const QString &name)
         updateHardDiskTemperature(name);
     }
     else {
-        // Fixes removable property, needs better fix though
-        Solid::Device parentDevice = device.parent();
-        Solid::StorageDrive *drive = parentDevice.as<Solid::StorageDrive>();
-        setData(name, I18N_NOOP("Removable"), ( drive && (drive->isHotpluggable() || \
drive->isRemovable()) )); +        bool isRemovable = false;
+        bool isHotpluggable = false;
+        Solid::StorageDrive *drive = getAncestorAs<Solid::StorageDrive>(device);
+        if (drive) {
+            //remove check for isHotpluggable() when plasmoids are changed to check \
for both properties +            isRemovable = (drive->isRemovable() || \
drive->isHotpluggable()); +            isHotpluggable = drive->isHotpluggable();
+        }
+        setData(name, I18N_NOOP("Removable"), isRemovable);
+        setData(name, I18N_NOOP("Hotpluggable"), isHotpluggable);
     }
 
 
@@ -545,7 +567,7 @@ void SolidDeviceEngine::deviceAdded(const QString& udi)
     }
 
     if (device.is<Solid::OpticalDisc>()) {
-        Solid::OpticalDrive *drive = device.parent().as<Solid::OpticalDrive>();
+        Solid::OpticalDrive *drive = getAncestorAs<Solid::OpticalDrive>(device);
         if (drive) {
             connect(drive, SIGNAL(ejectRequested(QString)),
                     this, SLOT(setUnmountingState(QString)));
@@ -694,12 +716,13 @@ bool SolidDeviceEngine::updateInUse(const QString &udi)
         return false;
     }
 
-    Solid::Device parent = Solid::Device(udi).parent();
-
     if (storageaccess->isAccessible()) {
         setData(udi, I18N_NOOP("In Use"), true);
-    } else if (parent.is<Solid::StorageDrive>()) {
-        setData(udi, I18N_NOOP("In Use"), \
parent.as<Solid::StorageDrive>()->isInUse()); +    } else {
+        Solid::StorageDrive *drive = \
getAncestorAs<Solid::StorageDrive>(Solid::Device(udi)); +        if (drive) {
+            setData(udi, I18N_NOOP("In Use"), drive->isInUse());
+        }
     }
 
     return true;
@@ -739,7 +762,7 @@ void SolidDeviceEngine::deviceRemoved(const QString& udi)
         }
     }
     else if (device.is<Solid::OpticalDisc>()) {
-        Solid::OpticalDrive *drive = device.parent().as<Solid::OpticalDrive>();
+        Solid::OpticalDrive *drive = getAncestorAs<Solid::OpticalDrive>(device);
         if (drive) {
             disconnect(drive, 0, this, 0);
         }


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

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