[kupfer: 1/3] openoffice: support new configuration file from libreoffice



commit 0bdea326946035cd38d11807488b7a89439d7c07
Author: Karol BÄ?dkowski <karol bedkowski gmail com>
Date:   Sat Apr 2 23:26:56 2011 +0200

    openoffice: support new configuration file from libreoffice

 kupfer/plugin/openoffice.py |   74 ++++++++++++++++++++++++++++++-------------
 1 files changed, 52 insertions(+), 22 deletions(-)
---
diff --git a/kupfer/plugin/openoffice.py b/kupfer/plugin/openoffice.py
index 10d4815..61633d5 100644
--- a/kupfer/plugin/openoffice.py
+++ b/kupfer/plugin/openoffice.py
@@ -3,9 +3,14 @@
 __kupfer_name__ = _("OpenOffice / LibreOffice")
 __kupfer_sources__ = ("RecentsSource", )
 __description__ = _("Recently used documents in OpenOffice/LibreOffice")
-__version__ = "2011-01-26"
+__version__ = "2011-04-02"
 __author__ = "Karol BÄ?dkowski <karol bedkowski gmail com>"
 
+'''
+Changes:
+	2011-04-02: Support new cofiguration file format in LibreOffice.
+'''
+
 import os
 from xml.etree import cElementTree as ElementTree
 import gio
@@ -17,8 +22,12 @@ from kupfer.obj.helplib import PicklingHelperMixin
 _HISTORY_FILE = [
 		"~/.openoffice.org/3/user/registrymodifications.xcu",
 		"~/.openoffice.org/3/user/registry/data/org/openoffice/Office/Histories.xcu",
+		"~/.libreoffice/3/user/registrymodifications.xcu",
 ]
 _NAME_ATTR = "{http://openoffice.org/2001/registry}name";
+_PATH_ATTR = "{http://openoffice.org/2001/registry}path";
+_HISTORY_NODES = "/org.openoffice.Office.Histories/Histories/" \
+		"org.openoffice.Office.Histories:HistoryInfo['PickList']/OrderList"
 
 
 class MultiAppContentMixin (object):
@@ -94,33 +103,42 @@ class RecentsSource (MultiAppContentMixin, Source, PicklingHelperMixin):
 
 	def get_items(self):
 		hist_file_path = _get_history_file_path()
+		print hist_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://.....
-						if not hfile:
-							continue
-						gfile = gio.File(hfile)
-						if not gfile.query_exists():
-							continue
-						if gfile.get_path():
-							leaf = FileLeaf(gfile.get_path())
-						else:
-							leaf = UrlLeaf(hfile, gfile.get_basename())
+			if node_histories and node_histories.attrib[_NAME_ATTR] == 'Histories':
+				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://.....
+							leaf = _create_history_leaf(hfile)
+							if leaf:
+								yield leaf
+						break
+			# libreoffice new configuration file
+			for item in tree.getroot().findall('item'):
+				if item.get(_PATH_ATTR) != _HISTORY_NODES:
+					continue
+				node = item.find('node')
+				if not node:
+					continue
+				prop = node.find('prop')
+				if not prop:
+					continue
+				if prop.get(_NAME_ATTR) != 'HistoryItemRef':
+					continue
+				value = prop.find('value')
+				if value is not None:
+					leaf = _create_history_leaf(value.text)
+					if leaf:
 						yield leaf
-					break
 		except StandardError, err:
 			self.output_error(err)
 
@@ -141,3 +159,15 @@ def _get_history_file_path():
 		if os.path.isfile(path):
 			return path
 	return None
+
+
+def _create_history_leaf(path):
+	''' Create leaf from file url '''
+	if not path:
+		return None
+	gfile = gio.File(path)
+	if not gfile.query_exists():
+		None
+	if gfile.get_path():
+		return FileLeaf(gfile.get_path())
+	return UrlLeaf(path, gfile.get_basename())



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