[muine] use notify-sharp



commit e259faf29250f09fe8b851e026fab3a74c72b794
Author: daniel g. siegel <dgsiegel gnome org>
Date:   Wed Oct 14 21:36:43 2009 +0200

    use notify-sharp
    
    update muine to use notify-sharp instead of using the C API

 configure.in        |    4 ++
 plugins/Makefile.am |    1 +
 plugins/TrayIcon.cs |   80 ++++++++++++++++++---------------------------------
 3 files changed, 33 insertions(+), 52 deletions(-)
---
diff --git a/configure.in b/configure.in
index 95973f7..221a8fb 100644
--- a/configure.in
+++ b/configure.in
@@ -29,6 +29,7 @@ MONO_REQUIRED=1.1
 GTKSHARP_REQUIRED=2.12.9
 TAGLIBSHARP_REQUIRED=2.0.3
 MONODOC_REQUIRED=1.1.9
+NOTIFYSHARP_REQUIRED=0.4.0
 
 dnl Pkgconfig
 PKG_PROG_PKG_CONFIG
@@ -55,6 +56,9 @@ PKG_CHECK_MODULES(GTKSHARP,
 PKG_CHECK_MODULES(TAGLIBSHARP,
                  taglib-sharp >= $TAGLIBSHARP_REQUIRED)
 
+PKG_CHECK_MODULES(NOTIFYSHARP,
+                 notify-sharp >= $NOTIFYSHARP_REQUIRED)
+
 dnl ndesk-dbus
 PKG_CHECK_MODULES(DBUS, ndesk-dbus-1.0 >= 0.4 \
 	ndesk-dbus-glib-1.0 >= 0.3, have_dbus="yes", have_dbus="no")
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index e14faa8..6aadf56 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -27,6 +27,7 @@ TRAY_ICON_EXTRA_CSFILES =		\
 
 TRAY_ICON_EXTRA_ASSEMBLIES =		\
 	$(GTKSHARP_LIBS)		\
+	$(NOTIFYSHARP_LIBS)		\
 	-r:Mono.Posix
 
 TRAY_ICON_RESOURCES =							  \
diff --git a/plugins/TrayIcon.cs b/plugins/TrayIcon.cs
index 629ef9e..b1f6b56 100644
--- a/plugins/TrayIcon.cs
+++ b/plugins/TrayIcon.cs
@@ -26,6 +26,8 @@ using Gdk;
 
 using Mono.Unix;
 
+using Notifications;
+
 using Muine.PluginLib;
 
 namespace Muine
@@ -51,7 +53,7 @@ namespace Muine
 		private static readonly string string_notification_message_format = 
 			Catalog.GetString ("by {0}");
 
-                private const string GConfKeyShowNotifications = "/apps/muine/show_notifications";
+		private const string GConfKeyShowNotifications = "/apps/muine/show_notifications";
 		// Widgets
 		private Plug icon;
 		private EventBox ebox;
@@ -61,6 +63,7 @@ namespace Muine
 
 		// Objects
 		private IPlayer player;
+		private static Notification notif;
 
 		// Variables
 		private int menu_x;
@@ -284,11 +287,11 @@ namespace Muine
 			Init ();
 		}
 
-                // Handlers :: OnShowNotificationsChanged
-                private void OnShowNotificationsChanged (object o, GConf.NotifyEventArgs args)
-                {
-                        showNotifications = (bool) args.Value;
-                }
+		// Handlers :: OnShowNotificationsChanged
+		private void OnShowNotificationsChanged (object o, GConf.NotifyEventArgs args)
+		{
+			showNotifications = (bool) args.Value;
+		}
 
 		// Handlers :: OnSongChangedEvent
 		private void OnSongChangedEvent (ISong song)
@@ -321,62 +324,35 @@ namespace Muine
 			UpdateImage ();
 		}
 
-		/* Libnotify bindings */
-
-		[DllImport("notify")]
-		private static extern bool notify_init(string app_name);
-
-		[DllImport("notify")]
-		private static extern void notify_uninit();
-
-		[DllImport("notify")]
-		private static extern IntPtr notify_notification_new(string summary, string message,
-				string icon, IntPtr widget);
-
-		[DllImport("notify")]
-		private static extern void notify_notification_set_timeout(IntPtr notification,
-				int timeout);
-		
-		[DllImport("notify")]
-		private static extern void notify_notification_set_urgency(IntPtr notification,
-				int urgency);
-
-		[DllImport("notify")]
-		private static extern void notify_notification_set_icon_from_pixbuf(IntPtr notification, IntPtr icon);
-
-		[DllImport("notify")]
-		private static extern bool notify_notification_show(IntPtr notification, IntPtr error);
-
-		[DllImport("gobject-2.0")]
-		private static extern void g_object_unref(IntPtr o);
-
 		public static void Notify(string summary, string message,
 				Pixbuf cover, Widget widget)
 		{
-                        if (!showNotifications)
+			if (!showNotifications)
 				return;
 
-			try {
-				if(!notify_init("Muine"))
-					return;
 
-				summary = StringUtils.EscapeForPango(summary);
-				message = StringUtils.EscapeForPango(message);
+			summary = StringUtils.EscapeForPango(summary);
+			message = StringUtils.EscapeForPango(message);
+			if (cover != null) {
+				cover = cover.ScaleSimple(42, 42, InterpType.Bilinear);
+			}
 
-				IntPtr notif = notify_notification_new(summary, message, null, widget.Handle);
-				notify_notification_set_timeout(notif, 4000);
-				notify_notification_set_urgency(notif, 0);
+			if (notif == null) {
 				if (cover != null) {
-					cover = cover.ScaleSimple(42, 42, InterpType.Bilinear);
-					notify_notification_set_icon_from_pixbuf(notif, cover.Handle);
+					notif = new Notification(summary, message, cover);
+				} else {
+					notif = new Notification(summary, message);
+				}
+			} else {
+				notif.Summary = summary;
+				notif.Body = message;
+				notif.IconName = "media-optical";
+				if (cover != null) {
+					notif.Icon = cover;
 				}
-				notify_notification_show(notif, IntPtr.Zero);
-				g_object_unref(notif);
-				notify_uninit();
-
-			} catch (Exception) {
-				showNotifications = false;
 			}
+
+			notif.Show();
 		}
 
 		private void OnWindowEvent (object o, WidgetEventArgs args)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]