Merge lp:~laszlok/zeitgeist-datasources/trunk into lp:zeitgeist-datasources/0.8

Proposed by Laszlo Pandy
Status: Merged
Merged at revision: not available
Proposed branch: lp:~laszlok/zeitgeist-datasources/trunk
Merge into: lp:zeitgeist-datasources/0.8
Diff against target: 308 lines (+264/-0)
6 files modified
gedit/zeitgeist_plugin.py (+1/-0)
rhythmbox/__init__.py (+1/-0)
tomboy/Zeitgeist.addin.xml (+21/-0)
tomboy/Zeitgeist.cs (+200/-0)
tomboy/Zeitgeist.mdp (+28/-0)
tomboy/install.sh (+13/-0)
To merge this branch: bzr merge lp:~laszlok/zeitgeist-datasources/trunk
Reviewer Review Type Date Requested Status
Seif Lotfy Pending
Review via email: mp+18533@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Seif Lotfy (seif) wrote :

only works with trunk for now. But still stable :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gedit/zeitgeist_plugin.py'
2--- gedit/zeitgeist_plugin.py 2010-02-02 01:57:56 +0000
3+++ gedit/zeitgeist_plugin.py 2010-02-03 16:27:14 +0000
4@@ -3,6 +3,7 @@
5 # Zeitgeist
6 #
7 # Copyright © 2009 Seif Lotfy <seif@lotfy.com>
8+# Copyright © 2010 Laszlo Pandy <laszlok2@gmail.com>
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Lesser General Public License as published by
12
13=== modified file 'rhythmbox/__init__.py'
14--- rhythmbox/__init__.py 2010-01-30 18:44:53 +0000
15+++ rhythmbox/__init__.py 2010-02-03 16:27:14 +0000
16@@ -3,6 +3,7 @@
17 # Zeitgeist
18 #
19 # Copyright © 2009 Markus Korn <thekorn@gmx.de>
20+# Copyright © 2010 Laszlo Pandy <laszlok2@gmail.com>
21 #
22 # This program is free software: you can redistribute it and/or modify
23 # it under the terms of the GNU Lesser General Public License as published by
24
25=== added directory 'tomboy'
26=== added file 'tomboy/Zeitgeist.addin.xml'
27--- tomboy/Zeitgeist.addin.xml 1970-01-01 00:00:00 +0000
28+++ tomboy/Zeitgeist.addin.xml 2010-02-03 16:27:14 +0000
29@@ -0,0 +1,21 @@
30+<Addin id="Zeitgeist"
31+ namespace="Tomboy"
32+ name="Zeitgeist Integration"
33+ author="Tomboy Project"
34+ description="Logs usage data to Zeitgeist."
35+ category="Tools"
36+ defaultEnabled="true"
37+ version="0.1">
38+
39+ <Runtime>
40+ <Import assembly="Zeitgeist.dll" />
41+ </Runtime>
42+
43+ <Dependencies>
44+ <Addin id="Tomboy" version="1.1.2" />
45+ </Dependencies>
46+
47+ <Extension path="/Tomboy/ApplicationAddins">
48+ <ApplicationAddin type="Tomboy.Zeitgeist.ZeitgeistAddin" />
49+ </Extension>
50+</Addin>
51\ No newline at end of file
52
53=== added file 'tomboy/Zeitgeist.cs'
54--- tomboy/Zeitgeist.cs 1970-01-01 00:00:00 +0000
55+++ tomboy/Zeitgeist.cs 2010-02-03 16:27:14 +0000
56@@ -0,0 +1,200 @@
57+
58+using System;
59+using System.Collections.Generic;
60+using Tomboy;
61+using NDesk.DBus;
62+using Gtk;
63+using GLib;
64+using Mono.Unix.Native;
65+
66+namespace Tomboy.Zeitgeist
67+{
68+ class NoteHandler
69+ {
70+ private static List<string> handled_notes = new List<string>();
71+ private Note note;
72+
73+ public NoteHandler(Note note) {
74+ if (handled_notes.Contains(note.Id) == false) {
75+ this.note = note;
76+ note.Opened += HandleNoteOpened;
77+ if (note.HasWindow) {
78+ HandleNoteOpened();
79+ }
80+ }
81+ }
82+
83+ void HandleNoteOpened (object sender, EventArgs e) {
84+ HandleNoteOpened();
85+ }
86+ void HandleNoteOpened() {
87+ note.Window.Hidden += HandleNoteWindowHidden;
88+ note.Window.Shown += HandleNoteWindowShown;
89+ note.Renamed += HandleNoteRenamed;
90+ if (note.Window.Visible) {
91+ HandleNoteWindowShown();
92+ }
93+ }
94+
95+ void HandleNoteRenamed (Note sender, string old_title)
96+ {
97+ Console.WriteLine("Zg: Renamed: " + note.Title);
98+ ZeitgeistDbus.SendToZeitgeist(note, ZeitgeistDbus.EventInterpretation.ModifyEvent);
99+ }
100+
101+ void HandleNoteWindowShown (object sender, EventArgs e) {
102+ HandleNoteWindowShown();
103+ }
104+ void HandleNoteWindowShown ()
105+ {
106+ Console.WriteLine("Zg: Note window opened: " + note.Title);
107+ ZeitgeistDbus.SendToZeitgeist(note, ZeitgeistDbus.EventInterpretation.OpenEvent);
108+ }
109+
110+ void HandleNoteWindowHidden (object sender, EventArgs e)
111+ {
112+ Console.WriteLine("Zg: Note window closed: " + note.Title);
113+ ZeitgeistDbus.SendToZeitgeist(note, ZeitgeistDbus.EventInterpretation.CloseEvent);
114+ }
115+ }
116+
117+ class ZeitgeistDbus
118+ {
119+ private static ILogger zeitgeist_proxy =
120+ Bus.Session.GetObject<ILogger>("org.gnome.zeitgeist.Engine",
121+ new ObjectPath("/org/gnome/zeitgeist/log/activity"));
122+
123+ public enum EventInterpretation {
124+ OpenEvent,
125+ CloseEvent,
126+ CreateEvent,
127+ ModifyEvent,
128+ }
129+
130+ private static string GetEventInterpetation(EventInterpretation e) {
131+ switch(e) {
132+ case EventInterpretation.OpenEvent:
133+ return "http://zeitgeist-project.com/schema/1.0/core#OpenEvent";
134+ case EventInterpretation.CloseEvent:
135+ return "http://zeitgeist-project.com/schema/1.0/core#CloseEvent";
136+ case EventInterpretation.CreateEvent:
137+ return "http://zeitgeist-project.com/schema/1.0/core#CreateEvent";
138+ case EventInterpretation.ModifyEvent:
139+ return "http://zeitgeist-project.com/schema/1.0/core#ModifyEvent";
140+ default:
141+ return null;
142+ }
143+ }
144+
145+ public static void SendToZeitgeist(Note note, EventInterpretation ev_interp) {
146+ if (zeitgeist_proxy == null) {
147+ Console.WriteLine("Zg: cannot connect to zeitgeist, dbus proxy is null");
148+ return;
149+ }
150+
151+ string ev_interp_string = GetEventInterpetation(ev_interp);
152+ if (ev_interp_string == null) {
153+ Console.WriteLine("Zg: unknown interpretation type: " + ev_interp.ToString());
154+ return;
155+ }
156+
157+ Timeval t;
158+ Syscall.gettimeofday(out t);
159+ long millis_now = (t.tv_sec * 1000) + (t.tv_usec / 1000);
160+
161+ Event e = new Event();
162+ e.metadata = new string[5];
163+ e.metadata[0] = ""; //id (filled in by Zeitgeist)
164+ e.metadata[1] = millis_now.ToString();
165+ e.metadata[2] = ev_interp_string;
166+ e.metadata[3] = "http://zeitgeist-project.com/schema/1.0/core#UserActivity";
167+ e.metadata[4] = "application://tomboy.desktop";
168+
169+ string[] subject = new string[7];
170+ subject[0] = note.Uri;
171+ subject[1] = "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/#Document";
172+ subject[2] = "http://www.semanticdesktop.org/ontologies/nfo/#FileDataObject";
173+ subject[3] = ""; //origin
174+ subject[4] = "application/x-tomboy"; //mimetype
175+ subject[5] = note.Title;
176+ subject[6] = ""; //storage id
177+
178+ e.subjects = new string[][] { subject };
179+ e.payload = new byte[0];
180+
181+ GLib.Idle.Add(delegate() {
182+ SendEvent(e);
183+ return false;
184+ });
185+ }
186+
187+ private static void SendEvent(Event e) {
188+ int[] inserted;
189+ try {
190+ inserted = zeitgeist_proxy.InsertEvents(new Event[] { e });
191+ } catch (Exception ex) {
192+ Console.WriteLine("Zg: insertion failed: " + ex.Message);
193+ return;
194+ }
195+
196+ if (inserted.Length > 0) {
197+ Console.WriteLine("Zg: Inserted event: " + inserted[0]);
198+ }
199+ else {
200+ Console.WriteLine("Zg: Insertion failed");
201+ }
202+ return;
203+ }
204+ }
205+
206+ [NDesk.DBus.Interface ("org.gnome.zeitgeist.Log")]
207+ interface ILogger {
208+ int[] InsertEvents(Event[] events);
209+ }
210+
211+ struct Event {
212+ public string[] metadata;
213+ public string[][] subjects;
214+ public byte[] payload;
215+ }
216+
217+ public class ZeitgeistAddin : ApplicationAddin
218+ {
219+ private bool _init = false;
220+ public override bool Initialized {
221+ get { return _init; }
222+ }
223+
224+ public override
225+ void Initialize() {
226+ Console.WriteLine("Zg: init new");
227+ init_handlers();
228+ _init = true;
229+ }
230+
231+ public override
232+ void Shutdown() {
233+ Console.WriteLine("Zg: shutdown");
234+ }
235+
236+ void HandleNoteAdded(object sender, Note new_note) {
237+ Console.WriteLine("Zg: Note added: " + new_note.Title);
238+ Console.WriteLine("\t" + new_note.Uri);
239+
240+ new NoteHandler(new_note);
241+ ZeitgeistDbus.SendToZeitgeist(new_note, ZeitgeistDbus.EventInterpretation.CreateEvent);
242+ }
243+
244+ public void init_handlers() {
245+ foreach (Note note in Tomboy.DefaultNoteManager.Notes) {
246+ new NoteHandler(note);
247+ }
248+
249+ Tomboy.DefaultNoteManager.NoteAdded -= HandleNoteAdded;
250+ Tomboy.DefaultNoteManager.NoteAdded += HandleNoteAdded;
251+ }
252+ }
253+
254+
255+
256+}
257
258=== added file 'tomboy/Zeitgeist.mdp'
259--- tomboy/Zeitgeist.mdp 1970-01-01 00:00:00 +0000
260+++ tomboy/Zeitgeist.mdp 2010-02-03 16:27:14 +0000
261@@ -0,0 +1,28 @@
262+<Project name="Zeitgeist" fileversion="2.0" DefaultNamespace="Zeitgeist" language="C#" targetFramework="2.0" ctype="DotNetProject">
263+ <Configurations active="Debug">
264+ <Configuration name="Debug" ctype="DotNetProjectConfiguration">
265+ <Output directory="bin/Debug" assembly="Zeitgeist" />
266+ <Build debugmode="True" target="Library" />
267+ <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" />
268+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
269+ </Configuration>
270+ <Configuration name="Release" ctype="DotNetProjectConfiguration">
271+ <Output directory="bin/Release" assembly="Zeitgeist" />
272+ <Build debugmode="False" target="Library" />
273+ <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" />
274+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
275+ </Configuration>
276+ </Configurations>
277+ <Contents>
278+ <File subtype="Code" buildaction="Compile" name="Zeitgeist.cs" />
279+ <File subtype="Code" buildaction="EmbedAsResource" name="Zeitgeist.addin.xml" />
280+ </Contents>
281+ <References>
282+ <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
283+ <ProjectReference type="Gac" localcopy="True" refto="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
284+ <ProjectReference type="Gac" localcopy="True" refto="NDesk.DBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099" />
285+ <ProjectReference type="Gac" localcopy="True" refto="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
286+ <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
287+ <ProjectReference type="Assembly" localcopy="True" specificVersion="False" refto="../../tomboy/Tomboy/Tomboy.exe" />
288+ </References>
289+</Project>
290\ No newline at end of file
291
292=== added file 'tomboy/install.sh'
293--- tomboy/install.sh 1970-01-01 00:00:00 +0000
294+++ tomboy/install.sh 2010-02-03 16:27:14 +0000
295@@ -0,0 +1,13 @@
296+#!/bin/sh
297+
298+mkdir -p ~/.config/tomboy/addins/
299+
300+# Please install monodevelop to get mdtool.
301+# Please edit Zeitgeist.mdp and change the local path of Tomboy.exe
302+# to the correct one for your environment (so it can link to the
303+# correct version of Tomboy).
304+mdtool build Zeitgeist.mdp
305+
306+cp bin/Debug/Zeitgeist.dll ~/.config/tomboy/addins/Zeitgeist.dll
307+
308+

Subscribers

People subscribed via source and target branches