[kupfer: 1/24] plugins: +openoffice - recent documents in OpenOffice3
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer: 1/24] plugins: +openoffice - recent documents in OpenOffice3
- Date: Fri, 27 Nov 2009 13:38:36 +0000 (UTC)
commit ce3ca1b1a1b1f30818d252fda21e16da4d0ed79d
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date: Fri Nov 13 19:06:32 2009 +0100
plugins: +openoffice - recent documents in OpenOffice3
Plugin based on abiword plugin.
kupfer/plugin/openoffice.py | 103 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 103 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/plugin/openoffice.py b/kupfer/plugin/openoffice.py
new file mode 100644
index 0000000..07a4ad0
--- /dev/null
+++ b/kupfer/plugin/openoffice.py
@@ -0,0 +1,103 @@
+# -*- coding: UTF-8 -*-
+
+import os
+from xml.etree import ElementTree
+import gio
+
+from kupfer.objects import (Source, FileLeaf, UrlLeaf, PicklingHelperMixin,
+ AppLeafContentMixin)
+
+__kupfer_name__ = _("OpenOffice")
+__kupfer_sources__ = ("RecentsSource", )
+__description__ = _("Recently used documents in OpenOffice")
+__version__ = "1.0"
+__author__ = "Karol BÄ?dkowski <karol bedkowski gmail com>"
+
+
+_HISTORY_FILE = "~/.openoffice.org/3/user/registry/data/org/openoffice/Office/Histories.xcu"
+_NAME_ATTR="{http://openoffice.org/2001/registry}name"
+
+
+class RecentsSource (AppLeafContentMixin, Source, PicklingHelperMixin):
+ appleaf_content_id = [
+ "openoffice.org-writer",
+ "openoffice.org-base",
+ "openoffice.org-calc",
+ "openoffice.org-draw",
+ "openoffice.org-impress",
+ "openoffice.org-math",
+ ]
+
+ def __init__(self, name=_("OpenOffice Recent Items")):
+ Source.__init__(self, name)
+ self.unpickle_finish()
+
+ def pickle_prepare(self):
+ self.monitor = None
+
+ def unpickle_finish(self):
+ hist_file_path = _get_history_file_path()
+ if not hist_file_path:
+ return
+ gfile = gio.File(hist_file_path)
+ self.monitor = gfile.monitor_file(gio.FILE_MONITOR_NONE, None)
+ if self.monitor:
+ self.monitor.connect("changed", self._on_history_changed)
+
+ def _on_history_changed(self, monitor, file1, file2, evt_type):
+ if evt_type in (gio.FILE_MONITOR_EVENT_CREATED,
+ gio.FILE_MONITOR_EVENT_DELETED,
+ gio.FILE_MONITOR_EVENT_CHANGED):
+ self.mark_for_update()
+
+ def get_items(self):
+ 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://.....
+ 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())
+ yield leaf
+ break
+
+ except StandardError, err:
+ self.output_error(err)
+
+ def get_description(self):
+ return _("Recently used documents in OpenOffice")
+
+ def get_icon_name(self):
+ return "document-open-recent"
+
+ def provides(self):
+ yield FileLeaf
+ yield UrlLeaf
+
+
+def _get_history_file_path():
+ path = os.path.expanduser(_HISTORY_FILE)
+ return path if os.path.isfile(path) else None
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]