Index: Tomboy/Addins/SeahorseEncryption/SeahorseEncryption.addin.xml
===================================================================
--- Tomboy/Addins/SeahorseEncryption/SeahorseEncryption.addin.xml	(revision 0)
+++ Tomboy/Addins/SeahorseEncryption/SeahorseEncryption.addin.xml	(revision 0)
@@ -0,0 +1,21 @@
+<Addin id="SeahorseEncryptionAddin"
+	namespace="Tomboy"
+	name="SeahorseEncryption"
+	author="Tomboy Project"
+	description="Encrypt Notes"
+	category="Desktop Integration"
+	defaultEnabled="false"
+	version="0.1">
+
+	<Runtime>
+		<Import assembly="SeahorseEncryption.Addin.dll" />
+	</Runtime>
+
+	<Dependencies>
+		<Addin id="Tomboy" version="0.12" />
+	</Dependencies>
+
+	<Extension path="/Tomboy/NoteAddins">
+		<NoteAddin type="Tomboy.SeahorseEncryptionAddin.SeahorseEncryptionNoteAddin" />
+	</Extension>
+</Addin>

Property changes on: Tomboy/Addins/SeahorseEncryption/SeahorseEncryption.addin.xml
___________________________________________________________________
Added: svn:mime-type
   + text/xml
Added: svn:eol-style
   + native

Index: Tomboy/Addins/SeahorseEncryption/CryptoService.cs
===================================================================
--- Tomboy/Addins/SeahorseEncryption/CryptoService.cs	(revision 0)
+++ Tomboy/Addins/SeahorseEncryption/CryptoService.cs	(revision 0)
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+
+using NDesk.DBus;
+using org.freedesktop.DBus;
+
+namespace SeahorseEncryption
+{
+	[Interface("org.gnome.seahorse.CryptoService")]
+		public interface CryptoService 
+		{
+			string VerifyText(string ktype, int flags, string crypttext);
+			string DecryptText(string ktype, int flags, string crypttext);
+			string SignText(string signer, int flags, string cleartext);
+			string EncryptText(string[] recipients, string signer, int flags, string cleartext);
+
+		}
+}
Index: Tomboy/Addins/SeahorseEncryption/Makefile.am
===================================================================
--- Tomboy/Addins/SeahorseEncryption/Makefile.am	(revision 0)
+++ Tomboy/Addins/SeahorseEncryption/Makefile.am	(revision 0)
@@ -0,0 +1,48 @@
+include $(top_srcdir)/Makefile.include
+
+CSFLAGS = 		\
+	-debug 		\
+	-define:DEBUG 	\
+	-target:library
+
+ASSEMBLIES = 					\
+	$(LINK_TOMBOY_EXE)			\
+	$(GTKSHARP_LIBS) 			\
+	$(LINK_MONO_ADDINS)			\
+	$(DBUS_LIBS)				\
+	-r:Mono.Posix
+
+#	-r:/home/boyd/stage/tasque/lib/tasque/Tasque.exe
+
+ADDIN_NAME = SeahorseEncryption
+
+if ENABLE_DBUS
+TARGET = $(ADDIN_NAME).Addin.dll
+CSFILES = \
+	$(srcdir)/SeahorseEncryptionNoteAddin.cs \
+	$(srcdir)/CryptoService.cs
+RESOURCES = \
+	-resource:$(srcdir)/$(ADDIN_NAME).addin.xml \
+	-resource:$(srcdir)/tasque-22.png,tasque.png
+
+$(TARGET).mdb: $(TARGET)
+
+$(TARGET): $(CSFILES) $(top_builddir)/Tomboy/Tomboy.exe
+	$(CSC) -out:$@ $(CSFLAGS) $(ASSEMBLIES) $(CSFILES) $(RESOURCES)
+
+
+addinsdir = $(pkglibdir)/addins
+addins_DATA = 			\
+	$(TARGET)		\
+	$(TARGET).mdb
+endif
+
+EXTRA_DIST =            	\
+	$(CSFILES) \
+	$(srcdir)/$(ADDIN_NAME).addin.xml \
+	$(srcdir)/tasque-22.png
+
+CLEANFILES =				\
+	$(TARGET).mdb \
+	$(TARGET)
+
Index: Tomboy/Addins/SeahorseEncryption/SeahorseEncryptionNoteAddin.cs
===================================================================
--- Tomboy/Addins/SeahorseEncryption/SeahorseEncryptionNoteAddin.cs	(revision 0)
+++ Tomboy/Addins/SeahorseEncryption/SeahorseEncryptionNoteAddin.cs	(revision 0)
@@ -0,0 +1,149 @@
+
+using System;
+using System.Collections;
+
+using Mono.Unix;
+
+using Tomboy;
+
+using NDesk.DBus;
+using org.freedesktop.DBus;
+
+namespace Tomboy.SeahorseEncryptionAddin
+{
+	public class SeahorseEncryptionNoteAddin : NoteAddin
+	{
+		static ObjectPath SeahorsePath =
+			new ObjectPath ("/org/gnome/seahorse/crypto");
+		static string SeahorseNamespace = "org.gnome.seahorse";
+		static string KeyType = "openpgp";
+
+		static SeahorseEncryptionNoteAddin ()
+		{
+		}
+
+		Gtk.ImageMenuItem item1, item2;
+
+		public override void Initialize ()
+		{
+			item1 = new Gtk.ImageMenuItem (Catalog.GetString ("_Encode"));
+			item1.Activated += OnMenuItem1Activated;
+			item1.Image = new Gtk.Image (Gtk.Stock.GoForward, Gtk.IconSize.Menu);
+			item1.Show ();
+			AddPluginMenuItem (item1);
+
+			item2 = new Gtk.ImageMenuItem (Catalog.GetString ("_Decode"));
+			item2.Activated += OnMenuItem2Activated;
+			item2.Image = new Gtk.Image (Gtk.Stock.GoBack, Gtk.IconSize.Menu);
+			item2.Show ();
+			AddPluginMenuItem (item2);
+		}
+
+		public override void Shutdown ()
+		{
+			if (item1 != null)
+				item1.Activated -= OnMenuItem1Activated;
+			if (item2 != null)
+				item2.Activated -= OnMenuItem2Activated;
+		}
+
+		public override void OnNoteOpened ()
+		{
+			// TODO maybe detect if note is encrypted and bug user about it
+		}
+
+		void OnMenuItem1Activated (object sender, EventArgs args)
+		{
+			SeahorseEncryption.CryptoService cryptoService = GetSeahorseCryptoService ();
+			if (cryptoService == null)
+				return;
+
+			string crypttext = "";
+			string[] recipients = new string[1];
+			recipients[0] = Preferences.Get("/desktop/pgp/default_key") as string;
+
+			if (recipients[0] == null || ! recipients[0].StartsWith(KeyType))
+			{
+				string message = Catalog.GetString ("No default key of type {0} set in system preferences");
+				message = String.Format (message, KeyType);
+				Logger.Log (message);
+				HIGMessageDialog dialog =
+					new HIGMessageDialog (Note.Window as Gtk.Window,
+							Gtk.DialogFlags.DestroyWithParent,
+							Gtk.MessageType.Info,
+							Gtk.ButtonsType.Ok,
+							Catalog.GetString ("No encryption key"),
+							message);
+				dialog.Run ();
+				dialog.Destroy ();
+				return;
+			}
+
+			try {
+				crypttext = cryptoService.EncryptText (recipients, "", 0, GetXmlContent());
+			} catch (Exception e) {
+				Logger.Debug ("Exception calling CryptoService.EncryptText (): {0}",
+						e.Message);
+				return;
+			}
+
+			SetContent(crypttext);
+		}
+
+		void OnMenuItem2Activated (object sender, EventArgs args)
+		{
+			SeahorseEncryption.CryptoService cryptoService = GetSeahorseCryptoService ();
+			if (cryptoService == null)
+				return;
+
+			string cleartext = "";
+			try {
+				cleartext =  cryptoService.DecryptText (KeyType, 0, 
+						Note.Buffer.Text);
+			} catch (Exception e) {
+				Logger.Debug ("Exception calling CryptoService.EncryptText (): {0}",
+						e.Message);
+				return;
+			}
+
+			SetContent(cleartext);
+		}
+
+		string GetXmlContent()
+		{
+			string content = "";
+			content = Note.XmlContent;
+			content = content.Substring (content.IndexOf ("\n"));
+			content = content.Substring (0,content.LastIndexOf ("</note-content>"));
+			return content;
+		}
+
+		void SetContent(string text)
+		{
+			if (text == "")
+				return;
+			Note.XmlContent = "<note-content version=\"0.1\">" + 
+				Note.Title + "\n" +
+				text + "</note-content>";
+		}
+
+		SeahorseEncryption.CryptoService GetSeahorseCryptoService ()
+		{
+			SeahorseEncryption.CryptoService cryptoService = null;
+
+			try {
+				if (Bus.Session.NameHasOwner (SeahorseNamespace) == false)
+					return null;
+
+				cryptoService = Bus.Session.GetObject<SeahorseEncryption.CryptoService> (
+						SeahorseNamespace,
+						SeahorsePath);
+			} catch (Exception e) {
+				Logger.Debug ("Exception when getting SeahorseEncryption.CryptoService: {0}",
+						e.Message);
+			}
+
+			return cryptoService;
+		}
+	}
+}
Index: Tomboy/Addins/Makefile.am
===================================================================
--- Tomboy/Addins/Makefile.am	(revision 2326)
+++ Tomboy/Addins/Makefile.am	(working copy)
@@ -9,6 +9,7 @@
 	InsertTimestamp		\
 	NoteOfTheDay		\
 	PrintNotes			\
+	SeahorseEncryption	\
 	Sketching			\
 	SshSyncService		\
 	StickyNoteImport	\
