libnotify in gnome-applets



Hi

Since there is a huge list of people in the gnome-applets' MAINTAINERS
file, sending the patch here.

This adds libnotify to some applets to display nice notifications when
something changes. Some stuff though:

* not sure about the trash applet, since it already changes its icon and
tooltip when something changes in the applet.

* someone mentioned on IRC the idea of replacing the trash applet thing
with a generic 'watch this folder' feature in nautilus, which will
display a notification whenever there is a change in that folder. I
can't think myself though how this can be useful, so, would this be a
good idea?

* I'm going to add support for hints in the notifications, so that the
notification itself shows up next to the applet sending it.

For screenshots -> http://blogs.gnome.org/view/rodrigo/2005/07/04/0

So, can this be committed?
-- 
Rodrigo Moya <rodrigo gnome-db org>
? cpufreq/GNOME_CPUFreqApplet.server
? cpufreq/GNOME_CPUFreqApplet.server.in
? cpufreq/cpufreq-applet.schemas
? cpufreq/help/C/cpufreq-applet-C.omf.out
? cpufreq/help/C/omf_timestamp
? cpufreq/help/uk/cpufreq-applet-uk.omf.out
? cpufreq/help/uk/omf_timestamp
? cpufreq/src/cpufreq-applet
? cpufreq/src/cpufreq-selector/cpufreq-selector
? m4/intltool.m4
? mini-commander/src/mini-commander-global.schemas
? modemlights/GNOME_ModemLights.server
? modemlights/GNOME_ModemLights.server.in
? modemlights/modem_applet
? null_applet/GNOME_CDPlayerApplet.server
? null_applet/GNOME_MailcheckApplet_Factory.server
? null_applet/GNOME_NullApplet_Factory.server
? null_applet/GNOME_NullApplet_Factory.server.in
? null_applet/GNOME_Panel_WirelessApplet.server
? null_applet/null_applet
Index: battstat/ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-applets/battstat/ChangeLog,v
retrieving revision 1.160
diff -u -p -r1.160 ChangeLog
--- battstat/ChangeLog	19 Jun 2005 10:53:56 -0000	1.160
+++ battstat/ChangeLog	4 Jul 2005 11:42:03 -0000
@@ -1,3 +1,8 @@
+2005-07-05  Rodrigo Moya <rodrigo novell com>
+
+	* battstat_applet.c (battery_full_notify): adapt to new libnotify
+	API.
+
 2005-06-19  Davyd Madeley  <davyd madeley id au>
 
 	* Makefile.am:
Index: battstat/battstat_applet.c
===================================================================
RCS file: /cvs/gnome/gnome-applets/battstat/battstat_applet.c,v
retrieving revision 1.105
diff -u -p -r1.105 battstat_applet.c
--- battstat/battstat_applet.c	19 Jun 2005 10:53:56 -0000	1.105
+++ battstat/battstat_applet.c	4 Jul 2005 11:42:03 -0000
@@ -431,6 +431,7 @@ battery_full_notify (void)
 				NULL,		/* body text */
 				icon,		/* icon */
 				TRUE, 0,	/* expiry, server default */
+				NULL,		/* hints */
 				NULL,		/* no user_data */
 				0))		/* no actions */
 		return FALSE;
Index: gweather/ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-applets/gweather/ChangeLog,v
retrieving revision 1.390
diff -u -p -r1.390 ChangeLog
--- gweather/ChangeLog	1 Jul 2005 12:44:56 -0000	1.390
+++ gweather/ChangeLog	4 Jul 2005 11:42:04 -0000
@@ -1,3 +1,10 @@
+2005-07-04  Rodrigo Moya <rodrigo novell com>
+
+	* gweather-applet.c (update_finish): when libnotify is available,
+	display a nice notification about the new forecast.
+
+	* Makefile.am: use LIBNOTIFY_CFLAGS|LIBS.
+
 2005-07-01  Esteban Sanchez  <esteban steve-0 com>
 
         * gweather.h (struct _GWeatherApplet): Added pref_find_entry and
Index: gweather/Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-applets/gweather/Makefile.am,v
retrieving revision 1.33
diff -u -p -r1.33 Makefile.am
--- gweather/Makefile.am	11 Jan 2005 07:59:44 -0000	1.33
+++ gweather/Makefile.am	4 Jul 2005 11:42:04 -0000
@@ -7,6 +7,7 @@ INCLUDES =				\
 	-DGTK_ENABLE_BROKEN		\
 	$(GNOME_APPLETS_CFLAGS)		\
 	$(GNOME_VFS_APPLETS_CFLAGS)	\
+	$(LIBNOTIFY_CFLAGS)		\
 	-DGWEATHER_XML_LOCATION=\""$(pkgdatadir)/gweather/"\"
 
 libexec_PROGRAMS = gweather-applet-2
@@ -24,6 +25,7 @@ gweather_applet_2_SOURCES = \
 	gweather-xml.c gweather-xml.h
 
 gweather_applet_2_LDADD = \
+	$(LIBNOTIFY_LIBS) \
 	$(GNOME_APPLETS_LIBS)	\
 	$(GNOME_VFS_APPLETS_LIBS)
 
Index: gweather/gweather-applet.c
===================================================================
RCS file: /cvs/gnome/gnome-applets/gweather/gweather-applet.c,v
retrieving revision 1.94
diff -u -p -r1.94 gweather-applet.c
--- gweather/gweather-applet.c	9 Jun 2005 08:42:59 -0000	1.94
+++ gweather/gweather-applet.c	4 Jul 2005 11:42:04 -0000
@@ -22,6 +22,10 @@
 #include <panel-applet.h>
 #include <libgnomeui/gnome-window-icon.h>
 
+#ifdef HAVE_LIBNOTIFY
+#include <libnotify/notify.h>
+#endif
+
 #include "weather.h"
 #include "gweather.h"
 #include "gweather-about.h"
@@ -414,10 +418,14 @@ gint timeout_cb (gpointer data)
 void update_finish (WeatherInfo *info)
 {
     static int gw_fault_counter = 0;
-    
+#ifdef HAVE_LIBNOTIFY
+    static NotifyIcon *icon = NULL;
+    char *notification_message, *notification_detail;
+    GdkPixbuf *pixbuf = NULL;
+#endif
     char *s;
     GWeatherApplet *gw_applet = info->applet;
-  
+    
     if (FALSE == info->valid)
     {
 	    /* there has been an error during retrival
@@ -451,9 +459,61 @@ void update_finish (WeatherInfo *info)
 	        	gtk_timeout_add (
 				gw_applet->gweather_pref.update_interval * 1000,
 	                        timeout_cb, gw_applet);
-	    
+
 	    /* Update dialog -- if one is present */
 	    gweather_dialog_update(gw_applet);
+	    
+#ifdef HAVE_LIBNOTIFY
+            /* Show notifications if possible */
+            if (!notify_is_initted ())
+                if (!notify_init (_("Weather Forecast")))
+                    return;
+            
+            /* Get the icon for the notification message */
+            if (icon) {
+                notify_icon_destroy (icon);
+                icon = NULL;
+            }
+            weather_info_get_pixbuf (gw_applet->gweather_info, &pixbuf);
+            if (pixbuf) {
+                gchar *tmp;
+                GError *error = NULL;
+                
+                tmp = g_strdup_printf ("%s/.gnome2/gweather-icon.png", g_get_home_dir ());
+                if (gdk_pixbuf_save (pixbuf, tmp, "png", &error, NULL))
+                    icon = notify_icon_new_from_uri (tmp);
+                else
+                    g_warning ("Unable to save weather icon: %s\n", error->message);
+                
+                if (error != NULL)
+                    g_error_free (error);
+                
+                g_free (tmp);
+            }
+            
+            /* Show notification */
+            notification_message = g_strdup_printf ("%s: %s",
+                                                    weather_info_get_location (info),
+                                                    weather_info_get_sky (info));
+            notification_detail = g_strdup_printf (_("City: %s\nSky: %s\nTemperature: %s"),
+            		                           weather_info_get_location (info),
+            		                           weather_info_get_sky (info),
+            		                           weather_info_get_temp_summary (info));
+            
+            if (!notify_send_notification (NULL, "transfer",
+                                           NOTIFY_URGENCY_LOW,
+	                                   notification_message,
+	                                   notification_detail,	/* body text */
+	                                   icon,		/* icon */
+	                                   TRUE, 0,		/* expiry, server default */
+	                                   NULL,		/* hints */
+	                                   NULL,		/* no user_data */
+	                                   0))			/* no actions */
+	        g_warning ("Could not send notification to daemon\n");
+
+	    g_free (notification_message);
+	    g_free (notification_detail);
+#endif
     }
 }
 
@@ -489,6 +549,4 @@ void gweather_update (GWeatherApplet *gw
         update_success = weather_info_new((gpointer)gw_applet, 
         		 gw_applet->gweather_pref.location, update_finish);
     }
-    
-    return;
 }
Index: trashapplet/ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-applets/trashapplet/ChangeLog,v
retrieving revision 1.21
diff -u -p -r1.21 ChangeLog
--- trashapplet/ChangeLog	16 May 2005 22:24:17 -0000	1.21
+++ trashapplet/ChangeLog	4 Jul 2005 11:42:05 -0000
@@ -1,3 +1,10 @@
+2005-07-05  Rodrigo Moya <rodrigo novell com>
+
+	* trashapplet.c (trash_applet_update): when libnotify is available,
+	show a nice notification of the trash's status.
+	
+	* Makefile.am: use LIBNOTIFY_CFLAGS|LIBS.
+
 2005-05-17  Kjartan Maraas  <kmaraas gnome org>
 
 	* Add a separator in the context menu. Closes bug #302797.
Index: trashapplet/src/Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-applets/trashapplet/src/Makefile.am,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile.am
--- trashapplet/src/Makefile.am	31 Mar 2005 18:56:20 -0000	1.5
+++ trashapplet/src/Makefile.am	4 Jul 2005 11:42:05 -0000
@@ -1,6 +1,7 @@
 INCLUDES = -I$(top_srcdir)		\
 	   $(GNOME_APPLETS_CFLAGS)	\
 	   $(GNOME_VFS_APPLETS_CFLAGS) \
+	   $(LIBNOTIFY_CFLAGS)		\
            $(LIBGLADE_CFLAGS)
 
 libexec_PROGRAMS = trashapplet
@@ -15,4 +16,4 @@ trashapplet_SOURCES = \
 	xstuff.c \
 	xstuff.h
 
-trashapplet_LDADD = $(GNOME_APPLETS_LIBS) $(GNOME_VFS_APPLETS_LIBS) $(LIBGLADE_CFLAGS)
+trashapplet_LDADD = $(GNOME_APPLETS_LIBS) $(GNOME_VFS_APPLETS_LIBS) $(LIBGLADE_CFLAGS) $(LIBNOTIFY_LIBS)
Index: trashapplet/src/trashapplet.c
===================================================================
RCS file: /cvs/gnome/gnome-applets/trashapplet/src/trashapplet.c,v
retrieving revision 1.20
diff -u -p -r1.20 trashapplet.c
--- trashapplet/src/trashapplet.c	31 Mar 2005 18:56:20 -0000	1.20
+++ trashapplet/src/trashapplet.c	4 Jul 2005 11:42:05 -0000
@@ -32,6 +32,10 @@
 #include <libgnome/gnome-help.h>
 #include <glade/glade.h>
 
+#ifdef HAVE_LIBNOTIFY
+#include <libnotify/notify.h>
+#endif
+
 #include "eel-extension.h"
 #include "trashapplet.h"
 #include "trash-monitor.h"
@@ -380,6 +384,11 @@ trash_applet_update (gpointer user_data)
 
 	new_item_count = trash_monitor_get_item_count (applet->monitor);
 	if (new_item_count != applet->item_count) {
+#ifdef HAVE_LIBNOTIFY
+		char *notification_message;
+		gboolean nd_initted = FALSE;
+#endif
+
 		applet->item_count = new_item_count;
 		applet->is_empty = (applet->item_count == 0);
 
@@ -394,6 +403,9 @@ trash_applet_update (gpointer user_data)
 		switch (applet->item_count) {
 		case 0:
 			tip_text = g_strdup (_("No Items in Trash"));
+#ifdef HAVE_LIBNOTIFY
+			notification_message = g_strdup (_("Trash has been emptied"));
+#endif
 			break;
 		default:
 			tip_text = g_strdup_printf (ngettext (
@@ -401,10 +413,36 @@ trash_applet_update (gpointer user_data)
 						"%d Items in Trash",
 						applet->item_count), 
 						    applet->item_count);
+#ifdef HAVE_LIBNOTIFY
+			notification_message = g_strdup (tip_text);
+#endif
 		}
 		gtk_tooltips_set_tip (applet->tooltips, GTK_WIDGET (applet),
 				      tip_text, NULL);
 		g_free (tip_text);
+
+#ifdef HAVE_LIBNOTIFY
+		if (!notify_is_initted ()) {
+			if (notify_init (_("Trash Applet")))
+				nd_initted = TRUE;
+		} else
+			nd_initted = TRUE;
+
+		if (nd_initted) {
+			if (!notify_send_notification (
+				NULL, "device", NOTIFY_URGENCY_LOW,
+				_("Trash has changed"),
+				notification_message, 	/* body text */
+				NULL,			/* icon */
+				TRUE, 0,		/* expiry, server default */
+				NULL,			/* hints */
+				NULL,			/* no user_data */
+				0))			/* no actions */
+				g_warning ("Could not send notification to daemon\n");
+		}
+		
+		g_free (notification_message);
+#endif
 	}
 
 	/* work out what icon to use */


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