[conduit] Move vfs.Monitor into vfs.File
- From: John Stowers <jstowers src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [conduit] Move vfs.Monitor into vfs.File
- Date: Wed, 22 Sep 2010 04:19:28 +0000 (UTC)
commit 50ae2fc9c137d95d90f0cfc6776401bd3cb55fec
Author: John Stowers <john stowers gmail com>
Date: Wed Sep 22 15:54:20 2010 +1200
Move vfs.Monitor into vfs.File
conduit/modules/FileModule/FileModule.py | 2 +-
conduit/vfs/File.py | 42 ++++++++++++++++++++++++++++
conduit/vfs/Makefile.am | 3 +-
conduit/vfs/Monitor.py | 44 ------------------------------
4 files changed, 44 insertions(+), 47 deletions(-)
---
diff --git a/conduit/modules/FileModule/FileModule.py b/conduit/modules/FileModule/FileModule.py
index 03446b5..9a2e1ea 100644
--- a/conduit/modules/FileModule/FileModule.py
+++ b/conduit/modules/FileModule/FileModule.py
@@ -108,7 +108,7 @@ class FolderTwoWay(FileDataProvider.FolderTwoWay, AutoSync.AutoSync):
)
AutoSync.AutoSync.__init__(self)
- self._monitor = VfsMonitor.FileMonitor()
+ self._monitor = VfsFile.MultipleFileMonitor()
self._monitor.connect("changed", self._monitor_folder_cb)
self.update_configuration(
diff --git a/conduit/vfs/File.py b/conduit/vfs/File.py
index ecebbdd..e0de2fd 100644
--- a/conduit/vfs/File.py
+++ b/conduit/vfs/File.py
@@ -444,4 +444,46 @@ class FolderScannerThreadManager:
thread.cancel()
thread.join() #May block
+class MultipleFileMonitor(gobject.GObject):
+ """
+ Abstraction which makes it easy to monitor multiple files
+ for changes
+ """
+
+ __gsignals__ = {
+ "changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [
+ gobject.TYPE_PYOBJECT, #uri that changed
+ gobject.TYPE_PYOBJECT]) #event type
+ }
+
+ MONITOR_EVENT_CREATED = gio.FILE_MONITOR_EVENT_CREATED
+ MONITOR_EVENT_CHANGED = gio.FILE_MONITOR_EVENT_CHANGED
+ MONITOR_EVENT_DELETED = gio.FILE_MONITOR_EVENT_DELETED
+ MONITOR_DIRECTORY = 255
+
+ def __init__(self):
+ gobject.GObject.__init__(self)
+ self._fm = None
+
+ def _on_change(self, monitor, f1, f2, event):
+ self.emit("changed", f1.get_uri(), event)
+
+ def add(self, URI, monitorType):
+ try:
+ if monitorType == self.MONITOR_DIRECTORY:
+ self._fm = gio.File(URI).monitor_directory()
+ else:
+ self._fm = gio.File(URI).monitor_file()
+
+ self._fm.connect("changed", self._on_change)
+ except gio.Error:
+ log.warn("Could not add monitor", exc_info=True)
+
+ def cancel(self):
+ if self._fm:
+ try:
+ self._fm.disconnect_by_func(self._on_change)
+ except TypeError:
+ pass
+
diff --git a/conduit/vfs/Makefile.am b/conduit/vfs/Makefile.am
index 05978e6..06c58ef 100644
--- a/conduit/vfs/Makefile.am
+++ b/conduit/vfs/Makefile.am
@@ -1,8 +1,7 @@
conduitdir = $(pythondir)/conduit/vfs
conduit_PYTHON = \
__init__.py \
- File.py \
- Monitor.py
+ File.py
clean-local:
rm -rf *.pyc *.pyo
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]