[kupfer: 1/2] openoffice: support LibreOffice history



commit 2d5833f982e2c89faa7da9b0924a5e76093c33ee
Author: Karol BÄ?dkowski <karol bedkowski gmail com>
Date:   Wed Jan 26 18:01:41 2011 +0100

    openoffice: support LibreOffice history

 kupfer/plugin/openoffice.py |   41 ++++++++++++++++++++++++++---------------
 1 files changed, 26 insertions(+), 15 deletions(-)
---
diff --git a/kupfer/plugin/openoffice.py b/kupfer/plugin/openoffice.py
index 99bc0e0..10d4815 100644
--- a/kupfer/plugin/openoffice.py
+++ b/kupfer/plugin/openoffice.py
@@ -1,9 +1,9 @@
 # -*- coding: UTF-8 -*-
 
-__kupfer_name__ = _("OpenOffice")
+__kupfer_name__ = _("OpenOffice / LibreOffice")
 __kupfer_sources__ = ("RecentsSource", )
-__description__ = _("Recently used documents in OpenOffice")
-__version__ = "2009-11-24"
+__description__ = _("Recently used documents in OpenOffice/LibreOffice")
+__version__ = "2011-01-26"
 __author__ = "Karol BÄ?dkowski <karol bedkowski gmail com>"
 
 import os
@@ -14,8 +14,12 @@ from kupfer.objects import Source, FileLeaf, UrlLeaf, AppLeaf
 from kupfer.obj.helplib import PicklingHelperMixin
 
 
-_HISTORY_FILE = "~/.openoffice.org/3/user/registry/data/org/openoffice/Office/Histories.xcu"
-_NAME_ATTR="{http://openoffice.org/2001/registry}name";
+_HISTORY_FILE = [
+		"~/.openoffice.org/3/user/registrymodifications.xcu",
+		"~/.openoffice.org/3/user/registry/data/org/openoffice/Office/Histories.xcu",
+]
+_NAME_ATTR = "{http://openoffice.org/2001/registry}name";
+
 
 class MultiAppContentMixin (object):
 	"""
@@ -38,9 +42,11 @@ class MultiAppContentMixin (object):
 		else:
 			ids = (cls.appleaf_content_id, )
 		return ids
+
 	@classmethod
 	def decorates_type(cls):
 		return AppLeaf
+
 	@classmethod
 	def decorate_item(cls, leaf):
 		if leaf.get_id() in cls.__get_appleaf_id_iter():
@@ -56,9 +62,16 @@ class RecentsSource (MultiAppContentMixin, Source, PicklingHelperMixin):
 			"openoffice.org-impress",
 			"openoffice.org-math",
 			"openoffice.org-startcenter",
+			"libreoffice-writer",
+			"libreoffice-base",
+			"libreoffice-calc",
+			"libreoffice-draw",
+			"libreoffice-impress",
+			"libreoffice-math",
+			"libreoffice-startcenter",
 	]
 
-	def __init__(self, name=_("OpenOffice Recent Items")):
+	def __init__(self, name=_("OpenOffice/LibreOffice Recent Items")):
 		Source.__init__(self, name)
 
 	def pickle_prepare(self):
@@ -83,23 +96,20 @@ class RecentsSource (MultiAppContentMixin, Source, PicklingHelperMixin):
 		hist_file_path = _get_history_file_path()
 		if not hist_file_path:
 			return
-		
 		try:
 			tree = ElementTree.parse(hist_file_path)
 			node_histories = tree.find('node')
 			if (not node_histories \
 					or node_histories.attrib[_NAME_ATTR] != 'Histories'):
 				return
-			
 			for list_node in  node_histories.findall('node'):
 				if list_node.attrib[_NAME_ATTR] == 'PickList':
 					items_node = list_node.find('node')
 					if (not items_node \
 							or items_node.attrib[_NAME_ATTR] != 'ItemList'):
 						return
-
 					for node in items_node.findall('node'):
-						hfile = node.attrib[_NAME_ATTR] # file://.....
+						hfile = node.attrib[_NAME_ATTR]  # file://.....
 						if not hfile:
 							continue
 						gfile = gio.File(hfile)
@@ -111,12 +121,11 @@ class RecentsSource (MultiAppContentMixin, Source, PicklingHelperMixin):
 							leaf = UrlLeaf(hfile, gfile.get_basename())
 						yield leaf
 					break
-
 		except StandardError, err:
 			self.output_error(err)
 
 	def get_description(self):
-		return _("Recently used documents in OpenOffice")
+		return _("Recently used documents in OpenOffice/LibreOffice")
 
 	def get_icon_name(self):
 		return "document-open-recent"
@@ -127,6 +136,8 @@ class RecentsSource (MultiAppContentMixin, Source, PicklingHelperMixin):
 
 
 def _get_history_file_path():
-	path = os.path.expanduser(_HISTORY_FILE)
-	return path if os.path.isfile(path) else None
-
+	for file_path in _HISTORY_FILE:
+		path = os.path.expanduser(file_path)
+		if os.path.isfile(path):
+			return path
+	return None



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