import gtk import gnome.ui import atexit try: from dockmanager.dockmanager import DockManagerItem, DockManagerSink, DOCKITEM_IFACE from zeitgeist.client import ZeitgeistClient from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation, StorageState from signal import signal, SIGTERM from sys import exit except ImportError, e: exit() try: CLIENT = ZeitgeistClient() version = [int(x) for x in CLIENT.get_version()] MIN_VERSION = [0, 3, 1, 0] if version < MIN_VERSION: print "PLEASE USE ZEITGEIST 0.3.1 or above" exit() except RuntimeError, e: print "Unable to connect to Zeitgeist, won't send events. Reason: '%s'" %e exit() INTERPRETATION = { "http://zeitgeist-project.com/schema/1.0/core#VisitEvent":"OPENED", "http://zeitgeist-project.com/schema/1.0/core#ModifyEvent":"SAVED", "http://zeitgeist-project.com/schema/1.0/core#CreateEvent":"CREATED" }
import time import datetime import logging gaj_path = '/home/jendrik/projects/RedNotebook/ref/gnome-activity-journal/' sys.path.insert(0, gaj_path) sys.path.insert(0, os.path.join(gaj_path, 'src')) import gtk import gobject try: import zeitgeist from zeitgeist.client import ZeitgeistClient CLIENT = ZeitgeistClient() if CLIENT.get_version() < [0, 3, 1, 99]: logging.info('Zeitgeist version too old. You need at least 0.3.2') zeitgeist = None else: from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation, \ ResultType, TimeRange from widgets import Item from common import shade_gdk_color, combine_gdk_color, get_gtk_rgba from daywidgets import DayPartWidget except ImportError, e: logging.info('Zeitgeist not available') zeitgeist = None except RuntimeError, e: logging.error("Unable to connect to Zeitgeist: %s" % e) zeitgeist = None
import time import datetime import logging gaj_path = '/home/jendrik/projects/RedNotebook/ref/gnome-activity-journal/' sys.path.insert(0, gaj_path) sys.path.insert(0, os.path.join(gaj_path, 'src')) import gtk import gobject try: import zeitgeist from zeitgeist.client import ZeitgeistClient CLIENT = ZeitgeistClient() if CLIENT.get_version() < [0, 3, 1, 99]: logging.info('Zeitgeist version too old. You need at least 0.3.2') zeitgeist = None else: from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation, \ ResultType, TimeRange from widgets import Item from common import shade_gdk_color, combine_gdk_color, get_gtk_rgba from daywidgets import DayPartWidget except ImportError, e: logging.info('Zeitgeist not available') zeitgeist = None except RuntimeError, e: logging.error("Unable to connect to Zeitgeist: %s" % e) zeitgeist = None
raise SystemExit else: print _("Attempting to restart Zeitgeist...") self._restarted = True CLIENT._iface.Quit() self._extension.reconnect() return self.__getattr__(name) try: CLIENT = ZeitgeistClient() except RuntimeError, e: print "%s: %s" % (_("ERROR"), _("Unable to connect to Zeitgeist:")) print "%s" % e CLIENT = CLIENT_VERSION = CLIENT_EXTENSION = None else: CLIENT_VERSION = CLIENT.get_version() CLIENT_EXTENSION = ClientExtension() STORE = None try: BUS = dbus.SessionBus() except Exception: BUS = None # Telepathy TELEPATHY = None # Hamster
class Zeitgeist(modules.ThreadedModule): def __init__(self): """ Constructor """ handlers = { consts.MSG_EVT_APP_QUIT: self.onModUnloaded, consts.MSG_EVT_NEW_TRACK: self.onNewTrack, consts.MSG_EVT_MOD_LOADED: self.onModLoaded, consts.MSG_EVT_APP_STARTED: self.onModLoaded, consts.MSG_EVT_MOD_UNLOADED: self.onModUnloaded, } modules.ThreadedModule.__init__(self, handlers) # --== Message handlers ==-- def onModLoaded(self): """ The module has been loaded """ self.client = None try: from zeitgeist.client import ZeitgeistClient from zeitgeist.datamodel import Event self.client = ZeitgeistClient() if self.client.get_version() >= [0, 3, 2, 999]: self.client.register_data_source("Pogo", "Pogo", "Play your music", [Event.new_for_values(actor="application://pogo.desktop")]) except: logger.info('[%s] Could not create Zeitgeist client\n\n%s' % (MOD_INFO[modules.MODINFO_NAME], traceback.format_exc())) def onModUnloaded(self): """ The module has been unloaded """ self.client = None def onNewTrack(self, track): """ Send track information to Zeitgeist """ if self.client is None: return from zeitgeist.datamodel import Interpretation if hasattr(Interpretation, 'ACCESS_EVENT'): event_type = Interpretation.ACCESS_EVENT else: event_type = Interpretation.OPEN_EVENT self.send_to_zeitgeist(track, event_type) def send_to_zeitgeist(self, track, event_type): """ Other players (e.g. Rhythmbox) log the playing of individual files, but we want to log albums. Maybe it would be better to log individual files, but then we would have to distinguish between Manifestation.USER_ACTIVITY and Manifestation.SCHEDULED_ACTIVITY. Another possible addition would be logging Interpretation.LEAVE_EVENT. """ import mimetypes, os.path from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation mime, encoding = mimetypes.guess_type(track.getFilePath(), strict=False) title = track.getTitle() album = track.getAlbum() artist = track.getArtist() uri = track.getURI() origin = os.path.dirname(uri) # Handle "unknown" tags if 'unknown' in title.lower(): title = track.getBasename() if 'unknown' in album.lower(): album = '' if 'unknown' in artist.lower(): artist = '' subject = Subject.new_for_values( uri = origin, text = ' - '.join([part for part in [artist, album] if part]), mimetype = mime, manifestation = unicode(Manifestation.FILE_DATA_OBJECT), interpretation = unicode(Interpretation.AUDIO), origin = origin, ) event = Event.new_for_values( actor = "application://pogo.desktop", subjects = [subject,], interpretation = unicode(event_type), timestamp = int(time.time() * 1000), ) self.client.insert_event(event)