[gnome-disk-utility] Don't use a status icon just use notifications
- From: William Jon McCann <mccann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility] Don't use a status icon just use notifications
- Date: Wed, 27 Oct 2010 22:18:32 +0000 (UTC)
commit 575f884eb645e4ee3699de774b74caab923e4b63
Author: William Jon McCann <jmccann redhat com>
Date: Wed Oct 27 17:53:54 2010 -0400
Don't use a status icon just use notifications
Recent notification daemon's support message persistence
so there is no need to back notifications with a status icon.
https://bugzilla.gnome.org/show_bug.cgi?id=631738
src/notification/notification-main.c | 236 ++++++----------------------------
1 files changed, 40 insertions(+), 196 deletions(-)
---
diff --git a/src/notification/notification-main.c b/src/notification/notification-main.c
index b6a713f..71ec138 100644
--- a/src/notification/notification-main.c
+++ b/src/notification/notification-main.c
@@ -39,16 +39,12 @@ typedef struct
{
GduPool *pool;
- GtkStatusIcon *status_icon;
-
/* List of GduDevice objects currently being unmounted */
GList *devices_being_unmounted;
/* List of GduDevice objects with ATA SMART failures */
GList *ata_smart_failures;
- gboolean show_icon_for_ata_smart_failures;
-
NotifyNotification *ata_smart_notification;
GFileMonitor *ata_smart_ignore_monitor;
@@ -69,9 +65,7 @@ static void update_unmount_dialogs (NotificationData *data);
static void update_ata_smart_failures (NotificationData *data);
-static void update_status_icon (NotificationData *data);
-
-static void show_menu_for_status_icon (NotificationData *data);
+static void update_notification (NotificationData *data);
/* ---------------------------------------------------------------------------------------------------- */
@@ -119,24 +113,6 @@ on_device_job_changed (GduPool *pool,
}
static void
-on_status_icon_activate (GtkStatusIcon *status_icon,
- gpointer user_data)
-{
- NotificationData *data = user_data;
- show_menu_for_status_icon (data);
-}
-
-static void
-on_status_icon_popup_menu (GtkStatusIcon *status_icon,
- guint button,
- guint activate_time,
- gpointer user_data)
-{
- NotificationData *data = user_data;
- show_menu_for_status_icon (data);
-}
-
-static void
on_ata_smart_ignore_monitor_changed (GFileMonitor *monitor,
GFile *file,
GFile *other_file,
@@ -164,13 +140,6 @@ notification_data_new (void)
g_signal_connect (data->pool, "device-changed", G_CALLBACK (on_device_changed), data);
g_signal_connect (data->pool, "device-job-changed", G_CALLBACK (on_device_job_changed), data);
- data->status_icon = gtk_status_icon_new ();
- gtk_status_icon_set_visible (data->status_icon, FALSE);
- gtk_status_icon_set_from_icon_name (data->status_icon, "gdu-warning");
- gtk_status_icon_set_tooltip_markup (data->status_icon, _("One or more disks are failing"));
- g_signal_connect (data->status_icon, "activate", G_CALLBACK (on_status_icon_activate), data);
- g_signal_connect (data->status_icon, "popup-menu", G_CALLBACK (on_status_icon_popup_menu), data);
-
dir_path = g_build_filename (g_get_user_config_dir (),
"gnome-disk-utility",
"ata-smart-ignore",
@@ -208,10 +177,6 @@ notification_data_new (void)
static void
notification_data_free (NotificationData *data)
{
- g_signal_handlers_disconnect_by_func (data->status_icon, on_status_icon_activate, data);
- g_signal_handlers_disconnect_by_func (data->status_icon, on_status_icon_popup_menu, data);
- g_object_unref (data->status_icon);
-
g_signal_handlers_disconnect_by_func (data->pool, on_device_added, data);
g_signal_handlers_disconnect_by_func (data->pool, on_device_removed, data);
g_signal_handlers_disconnect_by_func (data->pool, on_device_changed, data);
@@ -478,194 +443,73 @@ update_ata_smart_failures (NotificationData *data)
g_list_foreach (devices, (GFunc) g_object_unref, NULL);
g_list_free (devices);
- update_status_icon (data);
+ update_notification (data);
}
/* ---------------------------------------------------------------------------------------------------- */
-static gboolean
-show_notification (NotificationData *data)
+static void
+on_examine_action_clicked (NotifyNotification *notification,
+ char *action,
+ NotificationData *data)
{
- static int count = 0;
-
- /* wait for the panel to be settled before showing a bubble */
- if (gtk_status_icon_is_embedded (data->status_icon)) {
- notify_notification_show (data->ata_smart_notification, NULL);
- } else if (count < 20) {
- count++;
- g_timeout_add_seconds (1, (GSourceFunc) show_notification, data);
- } else {
- g_warning ("No notification area. Notification bubbles will not be displayed.");
- }
- return FALSE;
+ g_spawn_command_line_async ("palimpsest", NULL);
}
static void
-update_status_icon (NotificationData *data)
+update_notification (NotificationData *data)
{
- gboolean show_icon;
- gboolean old_show_icon_for_ata_smart_failures;
+ int num_drives;
- old_show_icon_for_ata_smart_failures = data->show_icon_for_ata_smart_failures;
-
- data->show_icon_for_ata_smart_failures = FALSE;
- if (g_list_length (data->ata_smart_failures) > 0)
- data->show_icon_for_ata_smart_failures = TRUE;
-
- show_icon = data->show_icon_for_ata_smart_failures;
-
- if (!show_icon) {
+ if (g_list_length (data->ata_smart_failures) == 0) {
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 (
- /* Translators: This is used as the title of the notification */
- _("A hard disk may be failing"),
- /* Translators: This is used as the text of the notification*/
- _("One or more hard disks report health problems. Click the icon to get more information."),
- "gtk-dialog-warning");
+ num_drives = g_list_length (data->ata_smart_failures);
+ if (data->ata_smart_notification == NULL) {
+ data->ata_smart_notification = notify_notification_new (
+ /* Translators: This is used as the title of the notification */
+ _("Hard Disk Problems Detected"),
+ /* Translators: This is used as the text of the notification*/
+ g_dngettext (GETTEXT_PACKAGE,
+ N_("A hard disk is reporting health problems."),
+ N_("Multiple system hard disks are reporting health problems."),
+ num_drives),
+ "gdu-warning");
notify_notification_set_urgency (data->ata_smart_notification, NOTIFY_URGENCY_CRITICAL);
notify_notification_set_timeout (data->ata_smart_notification, NOTIFY_EXPIRES_NEVER);
- show_notification (data);
+ notify_notification_add_action (data->ata_smart_notification,
+ "examine",
+ _("Examine"),
+ (NotifyActionCallback) on_examine_action_clicked,
+ data,
+ NULL);
+ } else {
+ notify_notification_update (data->ata_smart_notification,
+ /* Translators: This is used as the title of the notification */
+ _("Hard Disk Problems Detected"),
+ /* Translators: This is used as the text of the notification*/
+ g_dngettext (GETTEXT_PACKAGE,
+ N_("A hard disk is reporting health problems."),
+ N_("Multiple hard disks are reporting health problems."),
+ num_drives),
+ "gdu-warning");
}
+ notify_notification_show (data->ata_smart_notification, NULL);
+
out:
;
}
/* ---------------------------------------------------------------------------------------------------- */
-static void
-on_menu_item_activated (GtkMenuItem *menu_item,
- gpointer user_data)
-{
- NotificationData *data = user_data;
- GduDevice *device;
- GdkScreen *screen;
- gchar *command_line;
-
- device = GDU_DEVICE (g_object_get_data (G_OBJECT (menu_item), "gdu-device"));
-
- screen = gtk_status_icon_get_screen (data->status_icon);
- command_line = g_strdup_printf ("palimpsest --show-drive=%s", gdu_device_get_device_file (device));
- gdk_spawn_command_line_on_screen (screen, command_line, NULL);
- g_free (command_line);
-}
-
-static void
-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...
- * -----------------------------------------------
- * [Icon] 80 GB ATA INTEL SSDSA2MH08
- * [Icon] 250GB WD 2500JB External
- *
- * but unfortunately that would require fucking with gtk+'s
- * internals the same way the display-settings applet does
- * it; see e.g. line 951 of
- *
- * 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);
- GduPresentable *presentable;
- gchar *name;
- gchar *vpd_name;
- const gchar *status;
- gchar *status_desc;
- gboolean highlight;
- GdkPixbuf *pixbuf;
- GtkWidget *image;
- GtkWidget *menu_item;
- gchar *s;
-
- presentable = gdu_pool_get_drive_by_device (data->pool, device);
- name = gdu_presentable_get_name (presentable);
- vpd_name = gdu_presentable_get_vpd_name (presentable);
-
- status = gdu_device_drive_ata_smart_get_status (device);
- status_desc = gdu_util_ata_smart_status_to_desc (status, &highlight, NULL, NULL);
-
- if (highlight) {
- s = g_strdup_printf ("<span fgcolor=\"red\"><b>%s</b></span>", status_desc);
- g_free (status_desc);
- status_desc = s;
- }
-
- s = g_strdup_printf ("<b>%s</b> â?? %s\n"
- "<small>%s</small>",
- name,
- vpd_name,
- status_desc);
-
- menu_item = gtk_image_menu_item_new_with_label (s);
- gtk_label_set_use_markup (GTK_LABEL (gtk_bin_get_child (GTK_BIN (menu_item))), TRUE);
- gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menu_item), TRUE);
-
- g_object_set_data_full (G_OBJECT (menu_item), "gdu-device", g_object_ref (device), g_object_unref);
-
- pixbuf = gdu_util_get_pixbuf_for_presentable (presentable, GTK_ICON_SIZE_SMALL_TOOLBAR);
- image = gtk_image_new_from_pixbuf (pixbuf);
- g_object_unref (pixbuf);
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
-
- g_signal_connect (menu_item,
- "activate",
- G_CALLBACK (on_menu_item_activated),
- data);
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
-
- g_free (name);
- g_free (vpd_name);
- g_free (status_desc);
- g_free (s);
- g_object_unref (presentable);
- }
- gtk_widget_show_all (menu);
-
- gtk_menu_popup (GTK_MENU (menu),
- NULL,
- NULL,
- gtk_status_icon_position_menu,
- data->status_icon,
- 0,
- gtk_get_current_event_time ());
-
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
int
main (int argc, char **argv)
{
@@ -690,7 +534,7 @@ main (int argc, char **argv)
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- notify_init ("gdu-notification-daemon");
+ notify_init (_("Disk Utility"));
gtk_window_set_default_icon_name ("palimpsest");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]