muine r1217 - in trunk: . data plugins



Author: iain
Date: Sun Sep 28 01:43:32 2008
New Revision: 1217
URL: http://svn.gnome.org/viewvc/muine?rev=1217&view=rev

Log:
2008-09-28  Iain Holmes  <iain gnome org>

        Bug 336248 â Notifications using libnotify

        * data/muine.schemas.in: Add key to turn on notifications.
        Off by default

        * plugins/Makefile.am: Actually install the TrayIcon plugin

        * plugins/TrayIcon.cs: Add Notifications using libnotify, if 
present
        and turned on.

        * plugins/TrayIcon.dll.config: Add map for libnotify and gobject



Modified:
   trunk/ChangeLog
   trunk/data/muine.schemas.in
   trunk/plugins/Makefile.am
   trunk/plugins/TrayIcon.cs
   trunk/plugins/TrayIcon.dll.config

Modified: trunk/data/muine.schemas.in
==============================================================================
--- trunk/data/muine.schemas.in	(original)
+++ trunk/data/muine.schemas.in	Sun Sep 28 01:43:32 2008
@@ -167,5 +167,16 @@
 	<long>Your Amazon Dev Tag for fetching album cover art</long>
       </locale>
     </schema>
+    <schema>
+      <key>/schemas/apps/muine/show_notifications</key>
+      <applyto>/apps/muine/show_notifications</applyto>
+      <owner>muine</owner>
+      <type>bool</type>
+      <default>0</default>
+      <locale name="C">
+        <short>Show Notifications</short>
+	<long>Whether or not the tray icon shows song change notifications</long>
+      </locale>
+    </schema>
   </schemalist>
 </gconfschemafile>

Modified: trunk/plugins/Makefile.am
==============================================================================
--- trunk/plugins/Makefile.am	(original)
+++ trunk/plugins/Makefile.am	Sun Sep 28 01:43:32 2008
@@ -3,9 +3,9 @@
 plugindir = $(libdir)/muine/plugins
 
 if ENABLE_INOTIFY
-plugin_DATA = InotifyPlugin.dll InotifyPlugin.dll.config
+plugin_DATA = TrayIcon.dll TrayIcon.dll.config InotifyPlugin.dll InotifyPlugin.dll.config
 else
-plugin_DATA =
+plugin_DATA = TrayIcon.dll TrayIcon.dll.config
 endif
 
 muinelibdir = $(pkglibdir)

Modified: trunk/plugins/TrayIcon.cs
==============================================================================
--- trunk/plugins/TrayIcon.cs	(original)
+++ trunk/plugins/TrayIcon.cs	Sun Sep 28 01:43:32 2008
@@ -18,6 +18,7 @@
  */
 
 using System;
+using System.Runtime.InteropServices;
 
 using GConf;
 using Gtk;
@@ -40,6 +41,17 @@
 		private static readonly string string_tooltip_format = 
 			Catalog.GetString ("{0} - {1}");
 
+		// Strings :: Notification Format
+		//	song artists - song title
+		private static readonly string string_notification_summary_format = 
+			Catalog.GetString ("Now playing: {0}");
+
+		// Strings :: Notification Format
+		//	Album name
+		private static readonly string string_notification_message_format = 
+			Catalog.GetString ("by {0}");
+
+                private const string GConfKeyShowNotifications = "/apps/muine/show_notifications";
 		// Widgets
 		private Plug icon;
 		private EventBox ebox;
@@ -56,6 +68,8 @@
 		
 		private string tooltip = String.Empty; 
 
+		private static bool showNotifications = false;
+
 		private bool playing = false;
 
 		// GConf settings (mouse button behaviour)
@@ -69,6 +83,11 @@
 			// Initialize gettext
 			Catalog.Init ("muine", Defines.GNOME_LOCALE_DIR);
 
+                        GConf.Client gconf_client = new GConf.Client ();
+                        gconf_client.AddNotify (GConfKeyShowNotifications, 
+                                                new GConf.NotifyEventHandler (OnShowNotificationsChanged));
+                        showNotifications = (bool) gconf_client.Get (GConfKeyShowNotifications);
+
 			// Load stock icons
 			InitStockIcons ();
 
@@ -265,12 +284,28 @@
 			Init ();
 		}
 
+                // Handlers :: OnShowNotificationsChanged
+                private void OnShowNotificationsChanged (object o, GConf.NotifyEventArgs args)
+                {
+                        showNotifications = (bool) args.Value;
+                }
+
 		// Handlers :: OnSongChangedEvent
 		private void OnSongChangedEvent (ISong song)
 		{
 			tooltip = (song == null) ? null : CreateTooltip (song);
 
 			UpdateTooltip ();
+
+			if (showNotifications && (song != null)) {
+				Notify(
+						String.Format(string_notification_summary_format, song.Title),
+						String.Format(
+							string_notification_message_format,
+							StringUtils.JoinHumanReadable (song.Artists)),
+						song.CoverImage,
+						ebox);
+			}
 		}
 
 		// Handlers :: OnStateChangedEvent
@@ -286,15 +321,72 @@
 			UpdateImage ();
 		}
 
-		private void OnWindowEvent (object o, WidgetEventArgs args)
+		/* 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 (args.Event.Type == EventType.Delete && !old_mouse_behaviour)
-			{
-				player.SetWindowVisible (false, 0);
-				args.RetVal = true;
+                        if (!showNotifications)
+				return;
+
+			try {
+				if(!notify_init("Muine"))
+					return;
+
+				summary = StringUtils.EscapeForPango(summary);
+				message = StringUtils.EscapeForPango(message);
+
+				IntPtr notif = notify_notification_new(summary, message, null, widget.Handle);
+				notify_notification_set_timeout(notif, 4000);
+				notify_notification_set_urgency(notif, 0);
+				if (cover != null) {
+					cover = cover.ScaleSimple(42, 42, InterpType.Bilinear);
+					notify_notification_set_icon_from_pixbuf(notif, cover.Handle);
+				}
+				notify_notification_show(notif, IntPtr.Zero);
+				g_object_unref(notif);
+				notify_uninit();
+
+			} catch (Exception) {
+				showNotifications = false;
 			}
 		}
 
+		private void OnWindowEvent (object o, WidgetEventArgs args)
+                {
+			if (args.Event.Type == EventType.Delete && !old_mouse_behaviour) {
+                                player.SetWindowVisible (false, 0);
+                                args.RetVal = true;
+                        }
+                }
+
 		private void BehaviourNotify (object sender, NotifyEventArgs args)
 		{
 			old_mouse_behaviour = (bool) args.Value;

Modified: trunk/plugins/TrayIcon.dll.config
==============================================================================
--- trunk/plugins/TrayIcon.dll.config	(original)
+++ trunk/plugins/TrayIcon.dll.config	Sun Sep 28 01:43:32 2008
@@ -1,4 +1,6 @@
 <configuration>
   <dllmap dll="gdk-x11-2.0" target="libgdk-x11-2.0.so.0"/>
   <dllmap dll="libX11" target="libX11.so.6"/>
+  <dllmap dll="notify" target="libnotify.so.1"/>
+  <dllmap dll="gobject-2.0" target="libgobject-2.0.so.0"/>
 </configuration>



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