[notification-daemon] Add support for action-icons hint and server capability



commit 380b3875ae0c87e4abd3046a0ffada0445603087
Author: William Jon McCann <jmccann redhat com>
Date:   Fri Oct 29 19:00:02 2010 -0400

    Add support for action-icons hint and server capability

 src/daemon.c              |    1 +
 src/nd-bubble.c           |   50 +++++++++++++++++++++++++-------------------
 src/nd-notification-box.c |   42 +++++++++++++++++++++----------------
 src/nd-notification.c     |   17 +++++++++++++++
 src/nd-notification.h     |    1 +
 5 files changed, 71 insertions(+), 40 deletions(-)
---
diff --git a/src/daemon.c b/src/daemon.c
index 85e924e..e7306c2 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -317,6 +317,7 @@ handle_get_capabilities (NotifyDaemon          *daemon,
         g_variant_builder_add (builder, "s", "icon-static");
         g_variant_builder_add (builder, "s", "sound");
         g_variant_builder_add (builder, "s", "persistence");
+        g_variant_builder_add (builder, "s", "action-icons");
 
         g_dbus_method_invocation_return_value (invocation,
                                                g_variant_new ("(as)", builder));
diff --git a/src/nd-bubble.c b/src/nd-bubble.c
index fe7df77..7f341f8 100644
--- a/src/nd-bubble.c
+++ b/src/nd-bubble.c
@@ -835,7 +835,6 @@ add_notification_action (NdBubble       *bubble,
                          const char     *text,
                          const char     *key)
 {
-        GtkWidget *label;
         GtkWidget *button;
         GtkWidget *hbox;
         GdkPixbuf *pixbuf;
@@ -868,37 +867,44 @@ add_notification_action (NdBubble       *bubble,
         gtk_widget_show (hbox);
         gtk_container_add (GTK_CONTAINER (button), hbox);
 
-        /* Try to be smart and find a suitable icon. */
-        buf = g_strdup_printf ("stock_%s", key);
-        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (bubble))),
-                                           buf,
-                                           16,
-                                           GTK_ICON_LOOKUP_USE_BUILTIN,
-                                           NULL);
-        g_free(buf);
+        pixbuf = NULL;
+        /* try to load an icon if requested */
+        if (nd_notification_get_action_icons (bubble->priv->notification)) {
+                pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (bubble))),
+                                                   key,
+                                                   20,
+                                                   GTK_ICON_LOOKUP_USE_BUILTIN,
+                                                   NULL);
+        }
 
         if (pixbuf != NULL) {
-                GtkWidget *image = gtk_image_new_from_pixbuf (pixbuf);
+                GtkWidget *image;
+
+                image = gtk_image_new_from_pixbuf (pixbuf);
                 g_signal_connect (G_OBJECT (image),
                                   "style-set",
                                   G_CALLBACK (on_style_set),
                                   bubble);
+                atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (button)),
+                                     text);
                 gtk_widget_show (image);
                 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
                 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5);
-        }
+        } else {
+                GtkWidget *label;
 
-        label = gtk_label_new (NULL);
-        g_signal_connect (G_OBJECT (label),
-                          "style-set",
-                          G_CALLBACK (on_style_set),
-                          bubble);
-        gtk_widget_show (label);
-        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
-        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
-        buf = g_strdup_printf ("<small>%s</small>", text);
-        gtk_label_set_markup (GTK_LABEL (label), buf);
-        g_free (buf);
+                label = gtk_label_new (NULL);
+                g_signal_connect (G_OBJECT (label),
+                                  "style-set",
+                                  G_CALLBACK (on_style_set),
+                                  bubble);
+                gtk_widget_show (label);
+                gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+                gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+                buf = g_strdup_printf ("<small>%s</small>", text);
+                gtk_label_set_markup (GTK_LABEL (label), buf);
+                g_free (buf);
+        }
 
         g_object_set_data_full (G_OBJECT (button),
                                 "_action_key", g_strdup (key), g_free);
diff --git a/src/nd-notification-box.c b/src/nd-notification-box.c
index 3261ad6..da53f21 100644
--- a/src/nd-notification-box.c
+++ b/src/nd-notification-box.c
@@ -110,7 +110,6 @@ create_notification_action (NdNotificationBox *box,
                             const char        *text,
                             const char        *key)
 {
-        GtkWidget *label;
         GtkWidget *button;
         GtkWidget *hbox;
         GdkPixbuf *pixbuf;
@@ -125,30 +124,37 @@ create_notification_action (NdNotificationBox *box,
         gtk_widget_show (hbox);
         gtk_container_add (GTK_CONTAINER (button), hbox);
 
-        /* Try to be smart and find a suitable icon. */
-        buf = g_strdup_printf ("stock_%s", key);
-        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (box))),
-                                           buf,
-                                           16,
-                                           GTK_ICON_LOOKUP_USE_BUILTIN,
-                                           NULL);
-        g_free (buf);
+        pixbuf = NULL;
+        /* try to load an icon if requested */
+        if (nd_notification_get_action_icons (box->priv->notification)) {
+                pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (box))),
+                                                   key,
+                                                   20,
+                                                   GTK_ICON_LOOKUP_USE_BUILTIN,
+                                                   NULL);
+        }
 
         if (pixbuf != NULL) {
-                GtkWidget *image = gtk_image_new_from_pixbuf (pixbuf);
+                GtkWidget *image;
+
+                image = gtk_image_new_from_pixbuf (pixbuf);
+                atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (button)),
+                                     text);
                 gtk_widget_show (image);
                 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
                 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5);
+        } else {
+                GtkWidget *label;
+
+                label = gtk_label_new (NULL);
+                gtk_widget_show (label);
+                gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+                gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+                buf = g_strdup_printf ("<small>%s</small>", text);
+                gtk_label_set_markup (GTK_LABEL (label), buf);
+                g_free (buf);
         }
 
-        label = gtk_label_new (NULL);
-        gtk_widget_show (label);
-        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
-        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
-        buf = g_strdup_printf ("<small>%s</small>", text);
-        gtk_label_set_markup (GTK_LABEL (label), buf);
-        g_free (buf);
-
         g_object_set_data_full (G_OBJECT (button),
                                 "_action_key", g_strdup (key), g_free);
         g_signal_connect (G_OBJECT (button),
diff --git a/src/nd-notification.c b/src/nd-notification.c
index 755eb9a..a53d124 100644
--- a/src/nd-notification.c
+++ b/src/nd-notification.c
@@ -257,6 +257,23 @@ nd_notification_get_is_resident (NdNotification *notification)
         return ret;
 }
 
+gboolean
+nd_notification_get_action_icons (NdNotification *notification)
+{
+        gboolean  ret;
+        GVariant *value;
+
+        ret = FALSE;
+        g_return_val_if_fail (ND_IS_NOTIFICATION (notification), FALSE);
+
+        value = g_hash_table_lookup (notification->hints, "action-icons");
+        if (value != NULL) {
+                ret = g_variant_get_boolean (value);
+        }
+
+        return ret;
+}
+
 guint32
 nd_notification_get_id (NdNotification *notification)
 {
diff --git a/src/nd-notification.h b/src/nd-notification.h
index 2d4b264..1505375 100644
--- a/src/nd-notification.h
+++ b/src/nd-notification.h
@@ -74,6 +74,7 @@ GdkPixbuf *           nd_notification_load_image          (NdNotification *notif
                                                            int             size);
 gboolean              nd_notification_get_is_resident     (NdNotification *notification);
 gboolean              nd_notification_get_is_transient    (NdNotification *notification);
+gboolean              nd_notification_get_action_icons    (NdNotification *notification);
 
 void                  nd_notification_close               (NdNotification *notification,
                                                            NdNotificationClosedReason reason);



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