[Deskbar] History Persistance



Of course i forgot the attachement..
Index: deskbar/applet.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/applet.py,v
retrieving revision 1.39
diff -u -p -r1.39 applet.py
--- deskbar/applet.py	27 Nov 2005 12:45:00 -0000	1.39
+++ deskbar/applet.py	26 Dec 2005 01:18:08 -0000
@@ -50,7 +50,7 @@ class DeskbarApplet:
 		self.loader.connect ("module-not-initialized", self.on_module_initialized)
 		self.loader.connect ("module-stopped", self.module_list.module_toggled_cb)
 		
-		self.entry = deskbar.deskbarentry.DeskbarEntry(self, self.module_list)
+		self.entry = deskbar.deskbarentry.DeskbarEntry(self, self.module_list, self.loader)
 		self.entry.get_evbox().connect("button-press-event", self.on_icon_button_press)
 		self.entry.get_entry().connect("button-press-event", self.on_entry_button_press)
 		self.loader.connect ("module-initialized", self.entry._connect_if_async)
Index: deskbar/deskbarentry.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/deskbarentry.py,v
retrieving revision 1.34
diff -u -p -r1.34 deskbarentry.py
--- deskbar/deskbarentry.py	12 Dec 2005 15:15:30 -0000	1.34
+++ deskbar/deskbarentry.py	26 Dec 2005 01:18:08 -0000
@@ -18,14 +18,12 @@ MATCH_COL = 4
 # The sort function ids
 SORT_BY_HANDLER_MATCH_ACTION = 1
 
-MAX_RESULTS_PER_HANDLER = 6
-
 #selection directions
 MOVE_UP   = -1
 MOVE_DOWN = +1
 
 class DeskbarEntry(deskbar.iconentry.IconEntry):
-	def __init__(self, applet, module_list):
+	def __init__(self, applet, module_list, loader):
 		deskbar.iconentry.IconEntry.__init__(self)
 		
 		# Set up the Handlers
@@ -33,7 +31,7 @@ class DeskbarEntry(deskbar.iconentry.Ico
 		
 		self._completion_model = None
 		self._selected_match_index = -1
-		self._history = DeskbarHistory(applet)
+		self._history = DeskbarHistory(applet, loader)
 		
 		# Connect to underlying entry signals		
 		entry = self.get_entry()
Index: deskbar/handler.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/handler.py,v
retrieving revision 1.19
diff -u -p -r1.19 handler.py
--- deskbar/handler.py	28 Nov 2005 20:16:27 -0000	1.19
+++ deskbar/handler.py	26 Dec 2005 01:18:08 -0000
@@ -16,6 +16,10 @@ HANDLER_IS_CONFIGURABLE   = 1
 HANDLER_HAS_REQUIREMENTS  = 2
 HANDLER_IS_NOT_APPLICABLE = 3
 
+
+MAX_RESULTS_PER_HANDLER = 6
+
+
 class Match:
 	def __init__(self, handler, name, icon=None):
 		self._priority = 0
Index: deskbar/history.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/history.py,v
retrieving revision 1.2
diff -u -p -r1.2 history.py
--- deskbar/history.py	3 Dec 2005 13:44:42 -0000	1.2
+++ deskbar/history.py	26 Dec 2005 01:18:08 -0000
@@ -1,24 +1,47 @@
 import cPickle, os
 from deskbar import MAX_HISTORY
 import deskbar.handler
+from deskbar.handler import *
 
 class DeskbarHistory:
-	def __init__(self, applet):
+	def __init__(self, applet, loader):
 		self.applet = applet
 		self._history = []
 		
-#		print 'Loading hitsory'
-#		try:
-#			save = cPickle.load(file(applet.prefs.HISTORY))
-#			print save
-#			for text, fun, data in save:
-#				match = fun(*data)
-#				self._history.append((text, match))
-#		except Exception, msg:
-#			print 'Error:History:', msg
-			
+		loader.connect ("module-initialized", self.on_module_initialized)
+		loader.connect ("module-initialized", self.connect_if_async)
+		
+		try:
+			self.saved_history = cPickle.load(file(applet.prefs.HISTORY))
+		except Exception, msg:
+			print 'Error:Loading history:', msg			
 			
 		self._index = -1
+	
+	def on_module_initialized(self, loader, modctx, matches=None):
+		for i, saved in enumerate(self.saved_history):
+			text, hsh, handler_class = saved
+			
+			# Checks wether it's the good handler
+			if not handler_class.endswith(modctx.handler):
+				continue
+			
+			if modctx.module.is_async() and matches == None:
+				modctx.module.query_async(text, MAX_RESULTS_PER_HANDLER)
+				matches = []
+			elif matches == None:
+				matches = modctx.module.query(text, MAX_RESULTS_PER_HANDLER)
+			
+			for match in matches:
+				self.add_saved_to_history(match, i, text, hsh)
+				
+	def connect_if_async (self, sender, context):
+		if context.module.is_async():
+			context.module.connect('query-ready', lambda sender, matches: self.on_module_initialized(sender, context, matches))
+	
+	def add_saved_to_history(self, match, i, text, hsh):
+		if match.get_hash(text) == hsh:
+			self._history.insert(i, (text, match))
 		
 	def add(self, text, match):
 		for htext, hmatch in self._history:
@@ -55,14 +78,15 @@ class DeskbarHistory:
 		return self._history[self._index]
 	
 	def save(self):
-#		save = []
-#		for text, match in self._history:
-#			fun, data = match.serialize()
-#			save.append((text, fun, data))
-#			
-#		try:
-#			cPickle.dump(save, file(self.applet.prefs.HISTORY, 'w'), cPickle.HIGHEST_PROTOCOL)
-#			print 'History saved:',  save
-#		except Exception, msg:
-#			print 'Error:History.save:%s', msg
+		save = []
+		for text, match in self._history:
+			hsh = match.get_hash(text)
+			if hsh != None:
+				save.append((text, hsh, str(match.get_handler().__class__) ))
+			
+		try:
+			cPickle.dump(save, file(self.applet.prefs.HISTORY, 'w'), cPickle.HIGHEST_PROTOCOL)
+			pass
+		except Exception, msg:
+			print 'Error:History.save:%s', msg
 		pass
Index: deskbar/handlers/beagle.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/handlers/beagle.py,v
retrieving revision 1.11
diff -u -p -r1.11 beagle.py
--- deskbar/handlers/beagle.py	18 Nov 2005 01:16:09 -0000	1.11
+++ deskbar/handlers/beagle.py	26 Dec 2005 01:18:08 -0000
@@ -31,6 +31,9 @@ class BeagleMatch(deskbar.handler.Match)
 	
 	def get_verb(self):
 		return _("Search for %s using Beagle") % "<b>%(name)s</b>"
+	
+	def get_hash(self, text=None):
+		return "BeagleMatch://" % text
 		
 				
 class BeagleHandler(deskbar.handler.Handler):


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