Zim

Merge lp:~marcelstimberg/zim/zeitgeist-plugin into lp:~jaap.karssenberg/zim/pyzim

Proposed by Marcel Stimberg
Status: Merged
Merged at revision: 555
Proposed branch: lp:~marcelstimberg/zim/zeitgeist-plugin
Merge into: lp:~jaap.karssenberg/zim/pyzim
Diff against target: 127 lines (+107/-0)
3 files modified
data/manual/Plugins.txt (+1/-0)
data/manual/Plugins/Log_events_with_Zeitgeist.txt (+11/-0)
zim/plugins/zeitgeist-logger.py (+95/-0)
To merge this branch: bzr merge lp:~marcelstimberg/zim/zeitgeist-plugin
Reviewer Review Type Date Requested Status
Jaap Karssenberg Pending
Review via email: mp+108640@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

No problem merging the plugin. Would be nice though to have a manual
page as well for it (in data/manual/) so users can check what it is
for. Nothing fancy, just short description and reference to zeitgeist
documentation will do.

Thanks,

Jaap

357. By Marcel Stimberg

add a short help page for the Zeitgeist plugin

Revision history for this message
Marcel Stimberg (marcelstimberg) wrote :

Thanks, Jaap. I updated the branch with a little help page for the plugin.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/manual/Plugins.txt'
2--- data/manual/Plugins.txt 2012-03-18 11:40:18 +0000
3+++ data/manual/Plugins.txt 2012-06-05 19:42:20 +0000
4@@ -17,6 +17,7 @@
5 * [[+Insert Symbol|Insert Symbol]]
6 * [[+Inline Calculator|Inline Calculator]]
7 * [[+Link Map|Link Map]]
8+* [[+Log events with Zeitgeist|Log events with Zeitgeist]]
9 * [[+Quick Note|Quick Note]]
10 * [[+Spell Checker|Spell Checker]]
11 * [[+Table Of Contents|Table Of Contents]]
12
13=== added file 'data/manual/Plugins/Log_events_with_Zeitgeist.txt'
14--- data/manual/Plugins/Log_events_with_Zeitgeist.txt 1970-01-01 00:00:00 +0000
15+++ data/manual/Plugins/Log_events_with_Zeitgeist.txt 2012-06-05 19:42:20 +0000
16@@ -0,0 +1,11 @@
17+Content-Type: text/x-zim-wiki
18+Wiki-Format: zim 0.4
19+Creation-Date: 2012-06-05T20:52:03+02:00
20+
21+====== Log events with Zeitgeist ======
22+
23+When this plugin is activated, information about accessing, creating and modifying Zim Wiki pages is logged using the Zeitgeist framework. This allows applications like the Unity Dash to display recently used pages or the Activity Journal to give a timeline overview of your activities.
24+
25+**Dependencies:** This plugin requires the Python bindings for Zeitgeist. For Debian and Ubuntu, these bindings are available in the ''python-zeitgeist'' package.
26+
27+For more information about the Zeitgeist project see: http://zeitgeist-project.com
28
29=== added file 'zim/plugins/zeitgeist-logger.py'
30--- zim/plugins/zeitgeist-logger.py 1970-01-01 00:00:00 +0000
31+++ zim/plugins/zeitgeist-logger.py 2012-06-05 19:42:20 +0000
32@@ -0,0 +1,95 @@
33+# -*- coding: utf-8 -*-
34+
35+# Copyright 2011 Marcel Stimberg <stimberg@users.sourceforge.net>
36+
37+'''Push events to the Zeitgeist daemon'''
38+
39+import gio
40+import logging
41+import sys
42+from zim.plugins import PluginClass
43+import zim.fs
44+
45+logger = logging.getLogger('zim.plugins.zeitgeist')
46+
47+try:
48+ from zeitgeist.client import ZeitgeistClient
49+ from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
50+except:
51+ ZeitgeistClient = None
52+
53+class ZeitgeistPlugin(PluginClass):
54+
55+ plugin_info = {
56+ 'name': _('Log events with Zeitgeist'),
57+ 'description': _('Pushes events to the Zeitgeist daemon.'),
58+ 'author': 'Marcel Stimberg',
59+ 'help': 'Plugins:Log events with Zeitgeist',
60+ }
61+
62+ def __init__(self, ui):
63+ PluginClass.__init__(self, ui)
64+ try:
65+ self.zeitgeist_client = ZeitgeistClient()
66+ except RuntimeError, e:
67+ logger.exception('Loading zeitgeist client failed, will not log events')
68+ self.zeitgeist_client = None
69+
70+ def initialize_ui(self, ui):
71+ if self.zeitgeist_client is not None:
72+ self.zeitgeist_client.register_data_source('application://zim.desktop',
73+ _('Zim'), _('A desktop wiki'), [])
74+ self.ui.connect_after('open-page', self.do_open_page)
75+ self.ui.connect_after('close-page', self.do_close_page)
76+
77+ def finalize_notebook(self, ui):
78+ if self.zeitgeist_client is not None:
79+ self.ui.notebook.connect_after('deleted-page', self.do_delete_page)
80+ self.ui.notebook.connect_after('stored-page', self.do_store_page)
81+
82+ @classmethod
83+ def check_dependencies(klass):
84+ has_zeitgeist = not ZeitgeistClient is None
85+ return has_zeitgeist, [('libzeitgeist', has_zeitgeist, False)]
86+
87+ def create_and_send_event(self, page, path, event_type):
88+ #FIXME: Assumes file store
89+ store = self.ui.notebook.get_store(page.name)
90+ if path is not None:
91+ fileobj = store._get_file(path)
92+ else:
93+ fileobj = store._get_file(page)
94+
95+ uri = fileobj.uri
96+ origin = gio.File(uri).get_parent().get_uri()
97+ text = _('Wiki page: %s') % page.name
98+
99+ subject = Subject.new_for_values(mimetype='text/x-zim-wiki',
100+ uri=uri,
101+ origin=origin,
102+ interpretation=Interpretation.TEXT_DOCUMENT,
103+ manifestation=Manifestation.FILE_DATA_OBJECT,
104+ text=text)
105+ event = Event.new_for_values(actor='application://zim.desktop',
106+ interpretation=event_type,
107+ manifestation=Manifestation.USER_ACTIVITY,
108+ subjects=[subject,])
109+
110+ self.zeitgeist_client.insert_event(event)
111+
112+ def do_open_page(self, ui, page, path):
113+ logger.debug("Opened page: %s", page.name)
114+ self.create_and_send_event(page, path, Interpretation.ACCESS_EVENT)
115+
116+ def do_close_page(self, ui, page):
117+ logger.debug("Left page: %s", page.name)
118+ self.create_and_send_event(page, None, Interpretation.LEAVE_EVENT)
119+
120+ def do_delete_page(self, page, path):
121+ logger.debug("Deleted page: %s", page.name)
122+ self.create_and_send_event(page, path, Interpretation.DELETE_EVENT)
123+
124+ def do_store_page(self, page, path):
125+ logger.debug("Modified page: %s", page.name)
126+ self.create_and_send_event(page, path, Interpretation.MODIFY_EVENT)
127+