Re: libnotify in gnome-applets



On Mon, 2005-07-04 at 22:42 +0800, Davyd Madeley wrote:
> On Mon, 2005-07-04 at 16:20 +0200, Rodrigo Moya wrote:
>  
> > I attached the patch to my first mail.
> 
> I am quite obviously an idiot.
> 
> Perhaps a patch with this as an easter egg, hidden in GConf. We can add
> UI later if this appears to be popular.
> 
ok, updated patch attached, without the trash applet part (by popular
demand :), with the GConf hidden key, and a leak I just fixed in
gweather-dialog.c
-- 
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.161
diff -u -p -r1.161 ChangeLog
--- battstat/ChangeLog	4 Jul 2005 07:15:40 -0000	1.161
+++ battstat/ChangeLog	4 Jul 2005 15:24:47 -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-07-04  Ryan Lortie  <desrt desrt ca>
 
 	* battstat-hal.c:
Index: battstat/battstat_applet.c
===================================================================
RCS file: /cvs/gnome/gnome-applets/battstat/battstat_applet.c,v
retrieving revision 1.106
diff -u -p -r1.106 battstat_applet.c
--- battstat/battstat_applet.c	4 Jul 2005 07:15:40 -0000	1.106
+++ battstat/battstat_applet.c	4 Jul 2005 15:24:48 -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 15:24:50 -0000
@@ -1,3 +1,12 @@
+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.
+
+	* gweather-dialog.c (get_system_monospace_font): fixed leak.
+
+	* 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 15:24:50 -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 15:24:50 -0000
@@ -18,10 +18,15 @@
 #include <stdlib.h>
 #include <assert.h>
 
+#include <gconf/gconf-client.h>
 #include <gnome.h>
 #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 +419,15 @@ 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;
+    GConfClient *conf;
+#endif
     char *s;
     GWeatherApplet *gw_applet = info->applet;
-  
+    
     if (FALSE == info->valid)
     {
 	    /* there has been an error during retrival
@@ -451,9 +461,69 @@ 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
+            conf = gconf_client_get_default ();
+            if (!gconf_client_get_bool (conf, "/apps/panel/applets/weather/use_libnotify", NULL))
+            {
+                g_object_unref (conf);
+                return;
+            }
+            g_object_unref (conf);
+
+            /* 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 +559,4 @@ void gweather_update (GWeatherApplet *gw
         update_success = weather_info_new((gpointer)gw_applet, 
         		 gw_applet->gweather_pref.location, update_finish);
     }
-    
-    return;
 }
Index: gweather/gweather-dialog.c
===================================================================
RCS file: /cvs/gnome/gnome-applets/gweather/gweather-dialog.c,v
retrieving revision 1.55
diff -u -p -r1.55 gweather-dialog.c
--- gweather/gweather-dialog.c	29 Mar 2005 03:11:04 -0000	1.55
+++ gweather/gweather-dialog.c	4 Jul 2005 15:24:51 -0000
@@ -584,6 +584,9 @@ static PangoFontDescription *get_system_
     	desc = pango_font_description_from_string (name);
     	g_free (name);
     }
+
+    g_object_unref (conf);
+
     return desc;
 }
 


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