[conduit] Remove VolumeMonitor abstraction, use gio directly



commit 98388dc0914913fee691295f50783cde93fffc7a
Author: John Stowers <john stowers gmail com>
Date:   Wed Sep 22 14:45:56 2010 +1200

    Remove VolumeMonitor abstraction, use gio directly

 conduit/modules/FileModule/FileModule.py |   30 +++++++++++++++----------
 conduit/vfs/Monitor.py                   |   35 ------------------------------
 2 files changed, 18 insertions(+), 47 deletions(-)
---
diff --git a/conduit/modules/FileModule/FileModule.py b/conduit/modules/FileModule/FileModule.py
index b6f7d42..854ed9c 100644
--- a/conduit/modules/FileModule/FileModule.py
+++ b/conduit/modules/FileModule/FileModule.py
@@ -3,6 +3,8 @@ from gettext import gettext as _
 import logging
 log = logging.getLogger("modules.File")
 
+import gio
+
 import conduit
 import conduit.dataproviders.DataProvider as DataProvider
 import conduit.dataproviders.DataProviderCategory as DataProviderCategory
@@ -12,7 +14,6 @@ import conduit.dataproviders.AutoSync as AutoSync
 import conduit.utils as Utils
 import conduit.vfs as Vfs
 import conduit.vfs.File as VfsFile
-import conduit.vfs.Monitor as VfsMonitor
 
 MODULES = {
     "FileSource" :              { "type": "dataprovider" },
@@ -159,17 +160,25 @@ class RemovableDeviceFactory(SimpleFactory.SimpleFactory):
         SimpleFactory.SimpleFactory.__init__(self, **kwargs)
         self._volumes = {}
         self._categories = {}
-        self._vm = VfsMonitor.VolumeMonitor()
-        self._vm.connect("volume-mounted",self._volume_mounted_cb)
-        self._vm.connect("volume-unmounted",self._volume_unmounted_cb)
+        self._vm = gio.volume_monitor_get()
+        self._vm.connect("mount-added",self._volume_mounted_cb)
+        self._vm.connect("mount-removed",self._volume_unmounted_cb)
+
+    def _get_mount_udi(self, gmount):
+        #The volume uuid is not always present, so use the mounted root URI instead
+        return gmount.get_root().get_uri()
 
-    def _volume_mounted_cb(self, monitor, device_udi, mount, label):
-        log.info("Volume mounted, %s : (%s : %s)" % (device_udi,mount,label))
+    def _volume_mounted_cb(self, monitor, gmount):
+        device_udi = self._get_mount_udi(gmount)
+        log.info("Volume mounted, %s" % device_udi)
         if device_udi:
+            mount = gmount.get_root().get_uri()
+            label = gmount.get_name()
             self._check_preconfigured(device_udi, mount, label)
             self.item_added(device_udi, mount=mount, label=label)
 
-    def _volume_unmounted_cb(self, monitor, device_udi):
+    def _volume_unmounted_cb(self, monitor, gmount):
+        device_udi = self._get_mount_udi(gmount)
         log.info("Volume unmounted, %s" % device_udi)
         if device_udi and device_udi in self._volumes:
             self.item_removed(device_udi)
@@ -218,15 +227,12 @@ class RemovableDeviceFactory(SimpleFactory.SimpleFactory):
         """
         Called after initialised to detect already connected volumes
         """
-        volumes = self._vm.get_mounted_volumes()
-        for device_udi in volumes:
+        for m in self._vm.get_mounts():
+            device_udi = self._get_mount_udi(mount)
             if device_udi:
                 mount,label = volumes[device_udi]
                 self._check_preconfigured(device_udi, mount, label)
                 self.item_added(device_udi, mount=mount, label=label)
-            if device_udi:
-                mount,label = volumes[device_udi]
-                self.item_added(device_udi, mount=mount, label=label)
 
     def emit_added(self, klass, initargs, category):
         """
diff --git a/conduit/vfs/Monitor.py b/conduit/vfs/Monitor.py
index 66cf649..0bb6507 100644
--- a/conduit/vfs/Monitor.py
+++ b/conduit/vfs/Monitor.py
@@ -41,39 +41,4 @@ class FileMonitor(gobject.GObject):
             except TypeError:
                 pass
 
-class VolumeMonitor(gobject.GObject):
-
-    __gsignals__ = {
-        "volume-mounted" :      (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
-            gobject.TYPE_STRING,        #udi/uuid
-            gobject.TYPE_STRING,        #mount point
-            gobject.TYPE_STRING]),      #label
-        "volume-unmounted" :    (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
-            gobject.TYPE_STRING])       #udi/uuid
-
-    }
-
-    def __init__(self):
-        gobject.GObject.__init__(self)
-        self._vm = gio.volume_monitor_get()
-        self._vm.connect("mount-added", self._mounted_cb)
-        self._vm.connect("mount-removed", self._unmounted_cb)
-
-    def _mounted_cb(self, sender, mount):
-        self.emit("volume-mounted", 
-            mount.get_uuid(),
-            mount.get_root().get_uri(),
-            mount.get_name())
-
-    def _unmounted_cb(self, sender, mount):
-        self.emit("volume-unmounted", mount.get_uuid())
-
-    def get_mounted_volumes(self):
-        """
-        @returs: Dict of mounted volumes, uuid : (mount, name) 
-        """
-        vols = {}
-        for m in self._vm.get_mounts():
-            vols[m.get_uuid()] = (m.get_root().get_uri(), m.get_name())
-        return vols
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]