diff options
| author | Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com> | 2009-06-28 19:20:23 +0200 |
|---|---|---|
| committer | Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com> | 2009-06-28 19:20:23 +0200 |
| commit | 950e93186051cce9fcf8a661c42a28d462cbd4f5 (patch) | |
| tree | 2ec8dbdaa050974ace72e2150429dd43b58647d7 | |
| parent | 85568081c20130f516565d46a2d007d8dc376d57 (diff) | |
| parent | daebc25ba8357eec7e3d2f2271294bb1c367ca6a (diff) | |
| download | zeitgeist-950e93186051cce9fcf8a661c42a28d462cbd4f5.tar.gz | |
Merge
| -rw-r--r-- | zeitgeist/dbusutils.py | 2 | ||||
| -rw-r--r-- | zeitgeist/engine/engine.py | 13 | ||||
| -rw-r--r-- | zeitgeist/loggers/datasources/tomboy.py | 203 |
3 files changed, 13 insertions, 205 deletions
diff --git a/zeitgeist/dbusutils.py b/zeitgeist/dbusutils.py index cc8242b4..77e1ae2c 100644 --- a/zeitgeist/dbusutils.py +++ b/zeitgeist/dbusutils.py @@ -106,4 +106,4 @@ def plainify_dict(item_list): return tuple(item_list.get(name, DEFAULTS[type]) for name, type in ITEM_STRUCTURE) def dictify_data(item_list): - return dict((key[0], item_list[i]) for i, key in enumerate(ITEM_STRUCTURE)) + return dict((key[0], item_list[i]) for i, key in enumerate(ITEM_STRUCTURE)) diff --git a/zeitgeist/engine/engine.py b/zeitgeist/engine/engine.py index 385ca98e..1afb2b85 100644 --- a/zeitgeist/engine/engine.py +++ b/zeitgeist/engine/engine.py @@ -49,6 +49,7 @@ class ZeitgeistEngine(gobject.GObject): self._apps = set() self._bookmarks = [] self._last_time_from_app = {} + self._apps_id = {} ''' path = BaseDirectory.save_data_path("zeitgeist") @@ -57,6 +58,15 @@ class ZeitgeistEngine(gobject.GObject): self.cursor = self.connection.cursor() ''' + def _get_app(self, id): + if self._apps_id.has_key(id): + return self._apps_id[id] + + info = self.store.execute("SELECT info FROM app WHERE item_id=?",(id,)).get_one() + if info: + self._apps_id[id] = info[0] + return info[0] + def _set_bookmarks(self): self._bookmarks = self.store.find(Annotation.subject_id, Item.content_id == Content.BOOKMARK.id, @@ -107,6 +117,7 @@ class ZeitgeistEngine(gobject.GObject): result = self._get_tags_for_item(item) tags = ",".join(set(result)) if result else "" + return ( event.start if event else 0, # timestamp item.uri.value, # uri @@ -120,7 +131,7 @@ class ZeitgeistEngine(gobject.GObject): # FIXME: I guess event.item.content below should never be None event.item.content.value if (event and event.item.content) else "", # usage is determined by the event Content type item.icon or "", # icon - "", # app # FIXME! + self._get_app(event.app_id) or "", item.origin or "" # origin ) diff --git a/zeitgeist/loggers/datasources/tomboy.py b/zeitgeist/loggers/datasources/tomboy.py deleted file mode 100644 index f24cf3ec..00000000 --- a/zeitgeist/loggers/datasources/tomboy.py +++ /dev/null @@ -1,203 +0,0 @@ -# -.- encoding: utf-8 -.- - -# Zeitgeist -# -# Copyright © 2009 Seif Lotfy <seif@lotfy.com> -# Copyright © 2009 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com> -# Copyright © 2009 Natan Yellin <aantny@gmail.com> -# Copyright © 2009 Alex Graveley <alex.graveley@beatniksoftewarel.com> -# Copyright © 2009 Markus Korn <thekorn@gmx.de> -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -import gobject -import gio -import os.path -import logging -import time -import dbus -from xml.dom.minidom import parseString -from xml.parsers.expat import ExpatError - -from zeitgeist.loggers.zeitgeist_base import DataProvider -from zeitgeist.loggers.iso_strptime import iso_strptime - -_tomboy_logger = logging.getLogger("zeitgeist.logger.database.tomboy") - -# FIXME: This should really just use Beagle or Tracker. - -def flatten_text(node): - if node.nodeType == node.TEXT_NODE: - return node.data - else: - return "".join([flatten_text(x) for x in node.childNodes]) - - -class TomboyNote(object): - - @classmethod - def parse_content(cls, content, uri=None): - try: - content, length, tag = content - except ValueError: - pass - assert isinstance(content, (unicode, str)) - result = {"uri": uri} - try: - note = parseString(content) - except (IOError, ExpatError), err: - _tomboy_logger.error("could not parse note '%s'" %uri) - return None - else: - nodes = note.getElementsByTagName("title") - if nodes: - result["title"] = nodes[0].childNodes[0].data - nodes = note.getElementsByTagName("note-content") - if nodes: - result["content"] = flatten_text(nodes[0]) - nodes = note.getElementsByTagName("last-change-date") - if nodes: - result["date_changed"] = nodes[0].childNodes[0].data - nodes = note.getElementsByTagName("create-date") - if nodes: - result["date_created"] = nodes[0].childNodes[0].data - try: - note_obj = cls(**result) - except: - _tomboy_logger.exception("error initializing '%s'" %uri) - note_obj = None - note.unlink() - return note_obj - - def __init__(self, uri, date_created, title=None, content=None, - date_changed=None): - self.uri = uri - self.date_created = iso_strptime(date_created) - self.date_created = int(time.mktime(self.date_created.timetuple())) - self.title = title - self.content = content - if date_changed: - self.date_changed = iso_strptime(date_changed) - self.date_changed = int(time.mktime(self.date_changed.timetuple())) - - def __repr__(self): - return u"<%s %s>" %(self.__class__.__name__, self.uri) - -class TomboyNotes(gobject.GObject): - - PATH = os.path.expanduser("~/.tomboy") - - def __init__(self): - gobject.GObject.__init__(self) - _tomboy_logger.debug("watching '%s' for tomboy notes" %self.PATH) - path_object = gio.File(self.PATH) - self.notes_monitor = path_object.monitor_directory() - self.notes_monitor.connect("changed", self.notes_changed) - - def load_all(self): - for filename in os.listdir(self.PATH): - filename = os.path.join(self.PATH, filename) - if os.path.splitext(filename)[-1] == ".note": - with open(filename) as fileobj: - note = TomboyNote.parse_content(fileobj.read(), - u"file://%s" %filename) - if note is not None: - yield note - - def notes_changed(self, monitor, fileobj, _, event): - filename = fileobj.get_path() - if os.path.splitext(filename)[-1] == ".note": - if event in (gio.FILE_MONITOR_EVENT_CHANGED, - gio.FILE_MONITOR_EVENT_CREATED): - _tomboy_logger.debug("changed note '%s'" %filename) - note = TomboyNote.parse_content(fileobj.load_contents(), - fileobj.get_uri()) - if note is not None: - self.emit("note-changed", note) - elif event == gio.FILE_MONITOR_EVENT_DELETED: - _tomboy_logger.debug("deleted note '%s'" %filename) - # send one last item for this note to the engine :) - # this idea is not easy, as tomboy does not change a file, - # but delete a .note and recreates this file on changes - -gobject.signal_new("note-changed", TomboyNotes, - gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT,)) - - -class TomboySource(DataProvider): - - @staticmethod - def get_last_timestamp(): - # Connect to D-Bus - bus = dbus.SessionBus() - try: - remote_object = bus.get_object("org.gnome.zeitgeist", "/org/gnome/zeitgeist") - except dbus.exceptions.DBusException: - _tomboy_logger.error("Could not connect to D-Bus.") - return 0 - iface = dbus.Interface(remote_object, "org.gnome.zeitgeist") - return iface.GetLastInsertionDate(u"/usr/share/applications/tomboy.desktop") - - def __init__(self, note_path=None): - DataProvider.__init__(self, name="tomboy notes") - self.notes = TomboyNotes() - self.__notes_queue = list() - try: - self.__notes_queue = list(self.notes.load_all()) - except OSError, e: - _tomboy_logger.debug("Can't run DataProvider for tomboy, is tomboy installed? (error: %s)" %e) - self.last_timestamp = self.get_last_timestamp() - self.notes.connect("note-changed", self.item_changed) - self.config.connect("configured", self.reload_proxy_config) - - def item_changed(self, monitor, note): - self.__notes_queue.append(note) - self.emit("reload") - - def reload_proxy_config(self, configuration): - self.emit("reload") - - def get_items_uncached(self): - last_timestamp = self.last_timestamp - while self.__notes_queue: - note = self.__notes_queue.pop(0) - _tomboy_logger.debug("processing %r" %note) - times = [(note.date_created, u"CreateEvent"),] - if note.date_changed is not None: - times.append((note.date_changed, u"ModifyEvent")) - for timestamp, use in times: - if timestamp < self.last_timestamp: - continue - last_timestamp = max(timestamp, last_timestamp) - item = { - "timestamp": timestamp, - "uri": note.uri, - "text": note.title, # or note.content - "source": "Tomboy Notes", - "content": u"Note", - "use": u"http://gnome.org/zeitgeist/schema/1.0/core#%s" %use, - "mimetype": u"text/plain", - "tags": u"", - "icon": u"", - "app": u"/usr/share/applications/tomboy.desktop", - "origin": u"", # we are not sure about the origin of this item, - # let's make it NULL, it has to be a string - } - _tomboy_logger.debug("sending %r to the engine" %note) - yield item - self.last_timestamp = last_timestamp - -__datasource__ = TomboySource() |
