diff options
-rw-r--r-- | tomboy/Zeitgeist.addin.xml | 21 | ||||
-rw-r--r-- | tomboy/Zeitgeist.cs | 200 | ||||
-rw-r--r-- | tomboy/Zeitgeist.mdp | 28 | ||||
-rwxr-xr-x | tomboy/install.sh | 13 |
4 files changed, 262 insertions, 0 deletions
diff --git a/tomboy/Zeitgeist.addin.xml b/tomboy/Zeitgeist.addin.xml new file mode 100644 index 0000000..68fd38c --- /dev/null +++ b/tomboy/Zeitgeist.addin.xml @@ -0,0 +1,21 @@ +<Addin id="Zeitgeist" + namespace="Tomboy" + name="Zeitgeist Integration" + author="Tomboy Project" + description="Logs usage data to Zeitgeist." + category="Tools" + defaultEnabled="true" + version="0.1"> + + <Runtime> + <Import assembly="Zeitgeist.dll" /> + </Runtime> + + <Dependencies> + <Addin id="Tomboy" version="1.1.2" /> + </Dependencies> + + <Extension path="/Tomboy/ApplicationAddins"> + <ApplicationAddin type="Tomboy.Zeitgeist.ZeitgeistAddin" /> + </Extension> +</Addin>
\ No newline at end of file diff --git a/tomboy/Zeitgeist.cs b/tomboy/Zeitgeist.cs new file mode 100644 index 0000000..27571ee --- /dev/null +++ b/tomboy/Zeitgeist.cs @@ -0,0 +1,200 @@ + +using System; +using System.Collections.Generic; +using Tomboy; +using NDesk.DBus; +using Gtk; +using GLib; +using Mono.Unix.Native; + +namespace Tomboy.Zeitgeist +{ + class NoteHandler + { + private static List<string> handled_notes = new List<string>(); + private Note note; + + public NoteHandler(Note note) { + if (handled_notes.Contains(note.Id) == false) { + this.note = note; + note.Opened += HandleNoteOpened; + if (note.HasWindow) { + HandleNoteOpened(); + } + } + } + + void HandleNoteOpened (object sender, EventArgs e) { + HandleNoteOpened(); + } + void HandleNoteOpened() { + note.Window.Hidden += HandleNoteWindowHidden; + note.Window.Shown += HandleNoteWindowShown; + note.Renamed += HandleNoteRenamed; + if (note.Window.Visible) { + HandleNoteWindowShown(); + } + } + + void HandleNoteRenamed (Note sender, string old_title) + { + Console.WriteLine("Zg: Renamed: " + note.Title); + ZeitgeistDbus.SendToZeitgeist(note, ZeitgeistDbus.EventInterpretation.ModifyEvent); + } + + void HandleNoteWindowShown (object sender, EventArgs e) { + HandleNoteWindowShown(); + } + void HandleNoteWindowShown () + { + Console.WriteLine("Zg: Note window opened: " + note.Title); + ZeitgeistDbus.SendToZeitgeist(note, ZeitgeistDbus.EventInterpretation.OpenEvent); + } + + void HandleNoteWindowHidden (object sender, EventArgs e) + { + Console.WriteLine("Zg: Note window closed: " + note.Title); + ZeitgeistDbus.SendToZeitgeist(note, ZeitgeistDbus.EventInterpretation.CloseEvent); + } + } + + class ZeitgeistDbus + { + private static ILogger zeitgeist_proxy = + Bus.Session.GetObject<ILogger>("org.gnome.zeitgeist.Engine", + new ObjectPath("/org/gnome/zeitgeist/log/activity")); + + public enum EventInterpretation { + OpenEvent, + CloseEvent, + CreateEvent, + ModifyEvent, + } + + private static string GetEventInterpetation(EventInterpretation e) { + switch(e) { + case EventInterpretation.OpenEvent: + return "http://zeitgeist-project.com/schema/1.0/core#OpenEvent"; + case EventInterpretation.CloseEvent: + return "http://zeitgeist-project.com/schema/1.0/core#CloseEvent"; + case EventInterpretation.CreateEvent: + return "http://zeitgeist-project.com/schema/1.0/core#CreateEvent"; + case EventInterpretation.ModifyEvent: + return "http://zeitgeist-project.com/schema/1.0/core#ModifyEvent"; + default: + return null; + } + } + + public static void SendToZeitgeist(Note note, EventInterpretation ev_interp) { + if (zeitgeist_proxy == null) { + Console.WriteLine("Zg: cannot connect to zeitgeist, dbus proxy is null"); + return; + } + + string ev_interp_string = GetEventInterpetation(ev_interp); + if (ev_interp_string == null) { + Console.WriteLine("Zg: unknown interpretation type: " + ev_interp.ToString()); + return; + } + + Timeval t; + Syscall.gettimeofday(out t); + long millis_now = (t.tv_sec * 1000) + (t.tv_usec / 1000); + + Event e = new Event(); + e.metadata = new string[5]; + e.metadata[0] = ""; //id (filled in by Zeitgeist) + e.metadata[1] = millis_now.ToString(); + e.metadata[2] = ev_interp_string; + e.metadata[3] = "http://zeitgeist-project.com/schema/1.0/core#UserActivity"; + e.metadata[4] = "application://tomboy.desktop"; + + string[] subject = new string[7]; + subject[0] = note.Uri; + subject[1] = "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/#Document"; + subject[2] = "http://www.semanticdesktop.org/ontologies/nfo/#FileDataObject"; + subject[3] = ""; //origin + subject[4] = "application/x-tomboy"; //mimetype + subject[5] = note.Title; + subject[6] = ""; //storage id + + e.subjects = new string[][] { subject }; + e.payload = new byte[0]; + + GLib.Idle.Add(delegate() { + SendEvent(e); + return false; + }); + } + + private static void SendEvent(Event e) { + int[] inserted; + try { + inserted = zeitgeist_proxy.InsertEvents(new Event[] { e }); + } catch (Exception ex) { + Console.WriteLine("Zg: insertion failed: " + ex.Message); + return; + } + + if (inserted.Length > 0) { + Console.WriteLine("Zg: Inserted event: " + inserted[0]); + } + else { + Console.WriteLine("Zg: Insertion failed"); + } + return; + } + } + + [NDesk.DBus.Interface ("org.gnome.zeitgeist.Log")] + interface ILogger { + int[] InsertEvents(Event[] events); + } + + struct Event { + public string[] metadata; + public string[][] subjects; + public byte[] payload; + } + + public class ZeitgeistAddin : ApplicationAddin + { + private bool _init = false; + public override bool Initialized { + get { return _init; } + } + + public override + void Initialize() { + Console.WriteLine("Zg: init new"); + init_handlers(); + _init = true; + } + + public override + void Shutdown() { + Console.WriteLine("Zg: shutdown"); + } + + void HandleNoteAdded(object sender, Note new_note) { + Console.WriteLine("Zg: Note added: " + new_note.Title); + Console.WriteLine("\t" + new_note.Uri); + + new NoteHandler(new_note); + ZeitgeistDbus.SendToZeitgeist(new_note, ZeitgeistDbus.EventInterpretation.CreateEvent); + } + + public void init_handlers() { + foreach (Note note in Tomboy.DefaultNoteManager.Notes) { + new NoteHandler(note); + } + + Tomboy.DefaultNoteManager.NoteAdded -= HandleNoteAdded; + Tomboy.DefaultNoteManager.NoteAdded += HandleNoteAdded; + } + } + + + +} diff --git a/tomboy/Zeitgeist.mdp b/tomboy/Zeitgeist.mdp new file mode 100644 index 0000000..7167ae7 --- /dev/null +++ b/tomboy/Zeitgeist.mdp @@ -0,0 +1,28 @@ +<Project name="Zeitgeist" fileversion="2.0" DefaultNamespace="Zeitgeist" language="C#" targetFramework="2.0" ctype="DotNetProject"> + <Configurations active="Debug"> + <Configuration name="Debug" ctype="DotNetProjectConfiguration"> + <Output directory="bin/Debug" assembly="Zeitgeist" /> + <Build debugmode="True" target="Library" /> + <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" /> + <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" /> + </Configuration> + <Configuration name="Release" ctype="DotNetProjectConfiguration"> + <Output directory="bin/Release" assembly="Zeitgeist" /> + <Build debugmode="False" target="Library" /> + <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" /> + <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" generatexmldocumentation="False" ctype="CSharpCompilerParameters" /> + </Configuration> + </Configurations> + <Contents> + <File subtype="Code" buildaction="Compile" name="Zeitgeist.cs" /> + <File subtype="Code" buildaction="EmbedAsResource" name="Zeitgeist.addin.xml" /> + </Contents> + <References> + <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> + <ProjectReference type="Gac" localcopy="True" refto="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" /> + <ProjectReference type="Gac" localcopy="True" refto="NDesk.DBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099" /> + <ProjectReference type="Gac" localcopy="True" refto="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" /> + <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" /> + <ProjectReference type="Assembly" localcopy="True" specificVersion="False" refto="../../tomboy/Tomboy/Tomboy.exe" /> + </References> +</Project>
\ No newline at end of file diff --git a/tomboy/install.sh b/tomboy/install.sh new file mode 100755 index 0000000..cda2198 --- /dev/null +++ b/tomboy/install.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +mkdir -p ~/.config/tomboy/addins/ + +# Please install monodevelop to get mdtool. +# Please edit Zeitgeist.mdp and change the local path of Tomboy.exe +# to the correct one for your environment (so it can link to the +# correct version of Tomboy). +mdtool build Zeitgeist.mdp + +cp bin/Debug/Zeitgeist.dll ~/.config/tomboy/addins/Zeitgeist.dll + + |