summaryrefslogtreecommitdiff
path: root/tomboy/ZeitgeistAddin.cs
blob: 117a3ca3837653f5d6567ae86a6879a6e6143607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using Tomboy;
using System.Collections.Generic;
using System.IO;
using Zeitgeist.Datamodel;
using Zeitgeist;

namespace Tomboy.Zeitgeist
{
	public class ZeitgeistAddin  : ApplicationAddin
	{
		public ZeitgeistAddin ()
		{
			notesList = new List<NoteHandler>();
			
			dsReg = new DataSourceClient();
			handler = new ZeitgeistHandler();
		}

		
		#region Overridden methods
		
		public override bool Initialized
		{
			get
			{
				return _init;
			}
		}
		
		public override void Initialize()
		{
			Console.WriteLine("Zg#: init new");
			
			Event ev = new Event();
			ev.Actor = ZeitgeistAddin.TomboyUri;
			Subject sub = new Subject();
			sub.Interpretation = Interpretation.Instance.Document.Document;
			sub.Manifestation = Manifestation.Instance.FileDataObject.FileDataObject;
			ev.Subjects.Add(sub);
			
			try
			{
				dsReg.RegisterDataSources(tomboyDataSourceId, 
			                          	tomboyDataSourceName, 
			                          	tomboyDataSourceDesc , 
			                          	new List<Event>(){ev});
			}
			catch(Exception)
			{}
			
			// Initialize the handlers for hooking into Tomboy
			InitHandlers();
			
			_init = true;
		}
		
		public override void Shutdown()
		{
			Console.WriteLine("Zg#: shutdown");
		}
		
		#endregion
		
		public void InitHandlers()
		{
			// For every note present in the store
			
			foreach (Note note in Tomboy.DefaultNoteManager.Notes)
			{
				notesList.Add(new NoteHandler(note, handler));
			}
			
			Tomboy.DefaultNoteManager.NoteAdded -= HandleNoteAdded;
			Tomboy.DefaultNoteManager.NoteAdded += HandleNoteAdded;
			
			Tomboy.DefaultNoteManager.NoteDeleted -= HandleNoteDeleted;
			Tomboy.DefaultNoteManager.NoteDeleted += HandleNoteDeleted;
		}
		
		void HandleNoteAdded(object sender, Note new_note)
		{
			Console.WriteLine("Zg#: Note added: " + new_note.Title);
			Console.WriteLine("\t" + new_note.Uri);
			
			notesList.Add(new NoteHandler(new_note, handler));
			
			handler.SendEvent(new_note, Interpretation.Instance.EventInterpretation.CreateEvent);
		}
		
		void HandleNoteDeleted(object sender, Note new_note)
		{
			Console.WriteLine("Zg#: Note deleted: " + new_note.Title);
			Console.WriteLine("\t" + new_note.Uri);
			
			handler.SendEvent(new_note, Interpretation.Instance.EventInterpretation.DeleteEvent);
		}
		
		List<NoteHandler> notesList;
		
		private bool _init = false;
		
		private DataSourceClient dsReg; 
		
		private ZeitgeistHandler handler;
		
		#region Public Constants
				
		public const string TomboyUri = "application://tomboy.desktop";
		
		public const string NoteMimetype = "application/x-note";
		
		#endregion
		
		#region Private Constants
		
		private const string tomboyDataSourceId = "org.gnome.Tomboy,dataprovider";
		
		private const string tomboyDataSourceName = "Tomboy Datasource";
		
		private const string tomboyDataSourceDesc = "This datasource pushes the 4 events for tomboy - Open/Close Note, Create/Delete Note";
		
		#endregion
	}
}