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