[gnome-disk-utility] use libnotify to show a notification when a disk is failing



commit da5dd2b06ccfe0725e2e9d20f0e51e366eaa51a6
Author: David Zeuthen <davidz redhat com>
Date:   Wed Apr 15 12:14:34 2009 -0400

    use libnotify to show a notification when a disk is failing
    
    http://people.freedesktop.org/~david/gdu-ata-smart-notification.png
---
 configure.ac                         |    2 +
 src/notification/Makefile.am         |    2 +
 src/notification/notification-main.c |   49 ++++++++++++++++++++++++++++++++-
 3 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5450819..01a29c3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -127,6 +127,7 @@ GNOME_KEYRING_REQUIRED=2.22
 GTK2_REQUIRED=2.6.0
 LIBSEXY_REQUIRED=0.1.11
 UNIQUE_REQUIRED=1.0
+LIBNOTIFY_REQUIRED=0.3.0
 
 SCROLLKEEPER_REQUIRED=0.3.14
 INTLTOOL_REQUIRED=0.35.0
@@ -142,6 +143,7 @@ PKG_CHECK_MODULES(GNOME_KEYRING, gnome-keyring-1 >= $GNOME_KEYRING_REQUIRED)
 PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= $GTK2_REQUIRED)
 PKG_CHECK_MODULES(LIBSEXY, libsexy >= $LIBSEXY_REQUIRED)
 PKG_CHECK_MODULES(UNIQUE, unique-1.0 >= $UNIQUE_REQUIRED)
+PKG_CHECK_MODULES(LIBNOTIFY, libnotify  >= $LIBNOTIFY_REQUIRED)
 
 # *************
 # Documentation
diff --git a/src/notification/Makefile.am b/src/notification/Makefile.am
index 0a978a3..5ad1e30 100644
--- a/src/notification/Makefile.am
+++ b/src/notification/Makefile.am
@@ -27,6 +27,7 @@ gdu_notification_daemon_CFLAGS = 			\
 	$(WARN_CFLAGS)					\
 	$(POLKIT_DBUS_CFLAGS)				\
 	$(POLKIT_GNOME_CFLAGS)				\
+	$(LIBNOTIFY_CFLAGS)				\
 	$(AM_CFLAGS)
 
 gdu_notification_daemon_LDFLAGS = 			\
@@ -37,6 +38,7 @@ gdu_notification_daemon_LDADD = 			\
 	$(GOBJECT2_LIBS)				\
 	$(GIO2_LIBS)					\
 	$(GTK2_LIBS)					\
+	$(LIBNOTIFY_LIBS)				\
 	$(top_builddir)/src/gdu/libgdu.la		\
 	$(top_builddir)/src/gdu-gtk/libgdu-gtk.la
 
diff --git a/src/notification/notification-main.c b/src/notification/notification-main.c
index e4f19b2..d34028d 100644
--- a/src/notification/notification-main.c
+++ b/src/notification/notification-main.c
@@ -26,6 +26,7 @@
 
 #include <gdu/gdu.h>
 #include <gdu-gtk/gdu-gtk.h>
+#include <libnotify/notify.h>
 
 #include "gdu-slow-unmount-dialog.h"
 
@@ -42,6 +43,11 @@ typedef struct
 
         /* List of GduDevice objects with ATA SMART failures */
         GList *ata_smart_failures;
+
+        gboolean show_icon_for_ata_smart_failures;
+
+        NotifyNotification *ata_smart_notification;
+
 } NotificationData;
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -382,17 +388,44 @@ static void
 update_status_icon (NotificationData *data)
 {
         gboolean show_icon;
+        gboolean old_show_icon_for_ata_smart_failures;
+
+        old_show_icon_for_ata_smart_failures = data->show_icon_for_ata_smart_failures;
 
-        show_icon = FALSE;
+        data->show_icon_for_ata_smart_failures = FALSE;
         if (g_list_length (data->ata_smart_failures) > 0)
-                show_icon = TRUE;
+                data->show_icon_for_ata_smart_failures = TRUE;
+
+        show_icon = data->show_icon_for_ata_smart_failures;
 
         if (!show_icon) {
+                if (data->ata_smart_notification != NULL) {
+                        notify_notification_close (data->ata_smart_notification, NULL);
+                        g_object_unref (data->ata_smart_notification);
+                        data->ata_smart_notification = NULL;
+                }
+
                 gtk_status_icon_set_visible (data->status_icon, FALSE);
                 goto out;
         }
 
         gtk_status_icon_set_visible (data->status_icon, TRUE);
+
+        /* we've started showing the icon for ATA RAID failures; pop up a libnotify notification */
+        if (old_show_icon_for_ata_smart_failures != data->show_icon_for_ata_smart_failures) {
+
+		data->ata_smart_notification = notify_notification_new
+                        (_("A hard disk is failing"),
+                         _("One or more hard disks report health problems. Click the icon to get more information."),
+                         "gtk-dialog-warning",
+                         NULL);
+                notify_notification_attach_to_status_icon (data->ata_smart_notification,
+                                                           data->status_icon);
+                notify_notification_set_urgency (data->ata_smart_notification, NOTIFY_URGENCY_CRITICAL);
+                notify_notification_set_timeout (data->ata_smart_notification, NOTIFY_EXPIRES_NEVER);
+                notify_notification_show (data->ata_smart_notification, NULL);
+        }
+
  out:
         ;
 }
@@ -422,6 +455,13 @@ show_menu_for_status_icon (NotificationData *data)
         GtkWidget *menu;
         GList *l;
 
+        /* remove notifications when the user clicks the icon */
+        if (data->ata_smart_notification != NULL) {
+                notify_notification_close (data->ata_smart_notification, NULL);
+                g_object_unref (data->ata_smart_notification);
+                data->ata_smart_notification = NULL;
+        }
+
         /* TODO: it would be nice to display something like
          *
          *              Select a disk to get more information...
@@ -436,6 +476,10 @@ show_menu_for_status_icon (NotificationData *data)
          * http://svn.gnome.org/viewvc/gnome-settings-daemon/trunk/plugins/xrandr/gsd-xrandr-manager.c?revision=810&view=markup
          */
 
+        /* TODO: Perhaps it would also be nice to have a "Preferences..." menu item such
+         *       that the user can turn off notifications on a per-device basis.
+         */
+
         menu = gtk_menu_new ();
         for (l = data->ata_smart_failures; l != NULL; l = l->next) {
                 GduDevice *device = GDU_DEVICE (l->data);
@@ -486,6 +530,7 @@ main (int argc, char **argv)
         NotificationData *data;
 
         gtk_init (&argc, &argv);
+        notify_init ("gdu-notification-daemon");
 
         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");



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