[kupfer] notes: Watch Gnote and Tomboy directories for Updates



commit 28b85a4e334134e01ec5c947f975541d10a583a5
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Fri Aug 28 00:52:06 2009 +0200

    notes: Watch Gnote and Tomboy directories for Updates
    
    Watch the relevant directories for changes so that our notes source
    updates immediately with new and deleted notes. Important to be able
    to get to items just created etc.

 kupfer/plugin/notes.py |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/plugin/notes.py b/kupfer/plugin/notes.py
index 9d816fb..b5bb755 100644
--- a/kupfer/plugin/notes.py
+++ b/kupfer/plugin/notes.py
@@ -3,9 +3,13 @@ It *should* be possible to support Tomboy and Gnote equally since
 they support the same DBus protocol. This plugin takes this assumption.
 """
 
+import os
+
 import dbus
+import xdg.BaseDirectory as base
 
-from kupfer.objects import Action, Source, Leaf, AppLeafContentMixin, TextLeaf
+from kupfer.objects import (Action, Source, Leaf, AppLeafContentMixin, TextLeaf,
+		PicklingHelperMixin, FilesystemWatchMixin, )
 from kupfer import icons
 
 __kupfer_name__ = _("Notes")
@@ -112,11 +116,27 @@ class Note (Leaf):
 	def get_icon_name(self):
 		return "text-x-generic"
 
-class NotesSource (AppLeafContentMixin, Source):
+
+class NotesSource (AppLeafContentMixin, Source, PicklingHelperMixin,
+		FilesystemWatchMixin):
 	appleaf_content_id = PROGRAM_IDS
 	def __init__(self):
 		Source.__init__(self, _("Notes"))
 		self._notes = []
+		self.unpickle_finish()
+
+	def unpickle_finish(self):
+		"""Set up filesystem monitors to catch changes"""
+		# We monitor all directories that exist of a couple of candidates
+		dirs = []
+		for program in PROGRAM_IDS:
+			notedatapaths = (os.path.join(base.xdg_data_home, program),
+					os.path.expanduser("~/.%s" % program))
+			dirs.extend(notedatapaths)
+		self.monitor_token = self.monitor_directories(*dirs)
+
+	def pickle_prepare(self):
+		del self.monitor_token
 
 	def _update_cache(self, notes):
 		try:



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