LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File kdebase-udisks-loop-devices-916d1ea8da8cdabe604c6f9868d2559f2d73c062.patch of Package kdebase3 (Project openSUSE:Factory)

From 916d1ea8da8cdabe604c6f9868d2559f2d73c062 Mon Sep 17 00:00:00 2001
From: Serghei Amelian <serghei.amelian@gmail.com>
Date: Thu, 14 Jun 2012 00:05:34 +0300
Subject: [PATCH] [kioslave/media] added support for loop devices to udisks2
 backend

---
 kioslave/media/mediamanager/udisks2backend.cpp |   43 ++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/kioslave/media/mediamanager/udisks2backend.cpp b/kioslave/media/mediamanager/udisks2backend.cpp
index bb82f24..06fd6b2 100644
--- a/kioslave/media/mediamanager/udisks2backend.cpp
+++ b/kioslave/media/mediamanager/udisks2backend.cpp
@@ -77,6 +77,7 @@ class Object : public QDBusProxy {
     bool callMethod(const QString &interface, const QString &method, const QValueList<QDBusData> &params, QDBusData &response, QDBusError &error);
 
 private:
+    Medium *createLoopMedium();
     Medium *createMountableMedium();
     Medium *createBlankOrAudioMedium();
     bool checkMediaAvailability();
@@ -89,6 +90,9 @@ class Object : public QDBusProxy {
 
     bool m_mediaAvailable;
 
+    // loop interface
+    bool m_loop;
+
     // drive interface
     bool m_optical;
     bool m_opticalBlank;
@@ -236,6 +240,7 @@ QDBusObjectPath Property::toObjectPath() const
     setPath(objectPath);
 
     m_mediaAvailable = false;
+    m_loop = false;
     m_optical = false;
     m_opticalBlank = false;
     m_opticalAudio = false;
@@ -346,6 +351,34 @@ bool Object::callMethod(const QString &interface, const QString &method, const Q
 }
 
 
+Medium *Object::createLoopMedium()
+{
+    QString name = (m_label.isEmpty() ? QString(m_device).section('/', -1, -1) : m_label);
+    QString label = m_label;
+
+    QString mimeType;
+    QString iconName;
+
+    mimeType = ("iso9660" == m_fsType ? "media/cdrom" : "media/hdd");
+
+    if(label.isEmpty())
+        label = i18n("Loop Device");
+
+    mimeType += (m_mounted ? "_mounted" : "_unmounted");
+
+    if(m_label.isEmpty())
+        label = QString("%1 %2 (%3)").arg(qHumanReadableSize(m_size)).arg(label).arg(name);
+
+    Medium *medium = new Medium(path(), name);
+    medium->setLabel(label);
+    medium->mountableState(m_device, m_mountPoint, m_fsType, m_mounted);
+    medium->setMimeType(mimeType);
+    medium->setIconName(iconName);
+
+    return medium;
+}
+
+
 Medium *Object::createMountableMedium()
 {
     Object *drive =  m_objectManager->m_objects.find(m_drive);
@@ -460,7 +493,7 @@ bool Object::checkMediaAvailability()
 
     // media become available
     if(mediaAvailable) {
-        Medium *medium = (m_mountable && m_filesystem ? createMountableMedium() : createBlankOrAudioMedium());
+        Medium *medium = (m_mountable && m_filesystem ? (m_loop ? createLoopMedium() : createMountableMedium()) : createBlankOrAudioMedium());
         m_objectManager->m_mediaList.addMedium(medium, m_objectManager->allowNotification);
     }
 
@@ -504,8 +537,12 @@ void Object::propertiesChanged(const QString &interface, const QDBusDataMap<QStr
         else if("org.freedesktop.UDisks2.Block" == interface) {
             if("IdUsage" == propertyName)
                 m_mountable = ("filesystem" == propertyValue.toString());
-            else if("Drive" == propertyName)
+            else if("Drive" == propertyName) {
                 m_drive = propertyValue.toObjectPath();
+                // if the block device haven't a drive,
+                // we assume that is a loop device
+                m_loop = ("/" == m_drive);
+            }
             else if("PreferredDevice" == propertyName)
                 m_device = propertyValue.toString();
             else if("IdLabel" == propertyName) {
@@ -536,7 +573,7 @@ void Object::propertiesChanged(const QString &interface, const QDBusDataMap<QStr
         return;
 
     if(mediumNeedUpdate) {
-        Medium *medium = (m_mountable && m_filesystem ? createMountableMedium() : createBlankOrAudioMedium());
+        Medium *medium = (m_mountable && m_filesystem ? (m_loop ? createLoopMedium() : createMountableMedium()) : createBlankOrAudioMedium());
         m_objectManager->m_mediaList.changeMediumState(*medium, false);
         delete medium;
     }
-- 
1.7.10