From 3bcd1a92caefa661b4f0451bd91d66867e09a7c5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Aug 2012 20:33:11 -0500 Subject: add a disposition handler to indicator-session --- src/indicator-session.c | 150 ++++++++++++++++++++++++++++++++++++++++++------ src/shared-names.h | 4 +- 2 files changed, 137 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/indicator-session.c b/src/indicator-session.c index 3038948..d22cd33 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -63,6 +63,7 @@ struct _IndicatorSession GCancellable * service_proxy_cancel; GDBusProxy * service_proxy; GSettings * settings; + DbusmenuClient * menu_client; }; static gboolean greeter_mode; @@ -82,6 +83,8 @@ static gboolean build_restart_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); +static void on_menu_layout_updated (DbusmenuClient * client, IndicatorSession * session); +static void indicator_session_update_icon (IndicatorSession * self); static void indicator_session_update_users_label (IndicatorSession* self, const gchar* name); static void service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointer user_data); @@ -116,8 +119,6 @@ indicator_session_class_init (IndicatorSessionClass *klass) static void indicator_session_init (IndicatorSession *self) { - const gchar * icon_name; - self->settings = g_settings_new ("com.canonical.indicator.session"); /* Now let's fire these guys up. */ @@ -130,12 +131,11 @@ indicator_session_init (IndicatorSession *self) greeter_mode = !g_strcmp0(g_getenv("INDICATOR_GREETER_MODE"), "1"); self->entry.name_hint = PACKAGE; - self->entry.accessible_desc = _("Session Menu"); self->entry.label = GTK_LABEL (gtk_label_new ("User Name")); - icon_name = greeter_mode ? GREETER_ICON_DEFAULT : ICON_DEFAULT; - self->entry.image = GTK_IMAGE (gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON)); + self->entry.image = GTK_IMAGE (gtk_image_new()); self->entry.menu = GTK_MENU (dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT)); + indicator_session_update_icon (self); g_settings_bind (self->settings, "show-real-name-on-panel", self->entry.label, "visible", G_SETTINGS_BIND_GET); @@ -146,14 +146,17 @@ indicator_session_init (IndicatorSession *self) g_object_ref_sink (self->entry.image); // set up the handlers - DbusmenuClient * menu_client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(DBUSMENU_GTKMENU(self->entry.menu))); - dbusmenu_client_add_type_handler (menu_client, + self->menu_client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(DBUSMENU_GTKMENU(self->entry.menu))); + g_signal_connect (self->menu_client, "layout-updated", + G_CALLBACK(on_menu_layout_updated), self); + + dbusmenu_client_add_type_handler (self->menu_client, USER_ITEM_TYPE, new_user_item); - dbusmenu_client_add_type_handler (menu_client, + dbusmenu_client_add_type_handler (self->menu_client, RESTART_ITEM_TYPE, build_restart_item); - dbusmenu_gtkclient_set_accel_group (DBUSMENU_GTKCLIENT(menu_client), + dbusmenu_gtkclient_set_accel_group (DBUSMENU_GTKCLIENT(self->menu_client), gtk_accel_group_new()); } @@ -339,13 +342,6 @@ receive_signal (GDBusProxy * proxy, g_variant_get (parameters, "(&s)", &username); indicator_session_update_users_label (self, username); } - else if (!g_strcmp0(signal_name, "RestartRequired")) - { - const gchar * icon_name = greeter_mode ? GREETER_ICON_RESTART : ICON_RESTART; - gtk_image_set_from_icon_name (GTK_IMAGE(self->entry.image), icon_name, GTK_ICON_SIZE_MENU); - self->entry.accessible_desc = _("Device Menu (reboot required)"); - g_signal_emit (G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, 0, &self->entry); - } } @@ -412,3 +408,125 @@ indicator_session_update_users_label (IndicatorSession * self, { gtk_label_set_text (self->entry.label, name ? name : ""); } + +/*** +**** Disposition +***/ + +enum +{ + DISPOSITION_NORMAL, + DISPOSITION_INFO, + DISPOSITION_WARNING, + DISPOSITION_ALERT +}; + +static void +indicator_session_update_from_disposition (IndicatorSession * indicator, + int disposition) +{ + const gchar * icon; + const gchar * a11y; + + if (disposition == DISPOSITION_NORMAL) + a11y = _("Session Menu"); + else + a11y = _("Session Menu (attention required)"); + + if (greeter_mode) + { + if (disposition == DISPOSITION_NORMAL) + icon = GREETER_ICON_DEFAULT; + else + icon = GREETER_ICON_RESTART; + } + else + { + if (disposition == DISPOSITION_NORMAL) + icon = ICON_DEFAULT; + else if (disposition == DISPOSITION_INFO) + icon = ICON_INFO; + else + icon = ICON_ALERT; + } + + g_debug (G_STRLOC" setting icon to \"%s\", a11y to \"%s\"", icon, a11y); + gtk_image_set_from_icon_name (GTK_IMAGE(indicator->entry.image), + icon, + GTK_ICON_SIZE_BUTTON); + indicator->entry.accessible_desc = a11y; + g_signal_emit (indicator, + INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, + 0, + &indicator->entry); +} + +static int +calculate_disposition (IndicatorSession * indicator) +{ + GList * l; + DbusmenuMenuitem * root = dbusmenu_client_get_root (indicator->menu_client); + GList * children = dbusmenu_menuitem_get_children (root); + int ret = DISPOSITION_NORMAL; + + for (l=children; l!=NULL; l=l->next) + { + int val; + const gchar * key = DBUSMENU_MENUITEM_PROP_DISPOSITION; + const gchar * val_str = dbusmenu_menuitem_property_get (l->data, key); + + if (!g_strcmp0 (val_str, DBUSMENU_MENUITEM_DISPOSITION_ALERT)) + val = DISPOSITION_ALERT; + else if (!g_strcmp0 (val_str, DBUSMENU_MENUITEM_DISPOSITION_WARNING)) + val = DISPOSITION_WARNING; + else if (!g_strcmp0 (val_str, DBUSMENU_MENUITEM_DISPOSITION_INFORMATIVE)) + val = DISPOSITION_INFO; + else + val = DISPOSITION_NORMAL; + + if (ret < val) + ret = val; + } + + return ret; +} + +static void +indicator_session_update_icon (IndicatorSession * indicator) +{ + const int disposition = calculate_disposition (indicator); + indicator_session_update_from_disposition (indicator, disposition); +} + +static void +on_menuitem_property_changed (DbusmenuMenuitem * mi, + gchar * property, + GValue * value, + gpointer indicator) +{ + if (!g_strcmp0 (property, DBUSMENU_MENUITEM_PROP_DISPOSITION)) + indicator_session_update_icon (indicator); +} + +static void +on_menu_layout_updated (DbusmenuClient * client, IndicatorSession * session) +{ + GList * l; + DbusmenuMenuitem * root = dbusmenu_client_get_root (client); + GList * children = dbusmenu_menuitem_get_children (root); + static GQuark tag = 0; + + if (G_UNLIKELY (tag == 0)) + { + tag = g_quark_from_static_string ("x-tagged-by-indicator-session"); + } + + for (l=children; l!=NULL; l=l->next) + { + if (g_object_get_qdata (l->data, tag) == NULL) + { + g_object_set_qdata (l->data, tag, GINT_TO_POINTER(1)); + g_signal_connect (l->data, "property-changed", G_CALLBACK(on_menuitem_property_changed), session); + } + } +} diff --git a/src/shared-names.h b/src/shared-names.h index dcda182..e82aef8 100644 --- a/src/shared-names.h +++ b/src/shared-names.h @@ -41,7 +41,9 @@ with this program. If not, see . #define RESTART_ITEM_ICON "restart-icon" #define ICON_DEFAULT "system-devices-panel" -#define ICON_RESTART "system-devices-panel-alert" +#define ICON_INFO "system-devices-panel-information" +#define ICON_ALERT "system-devices-panel-alert" + #define GREETER_ICON_DEFAULT "system-shutdown-panel" #define GREETER_ICON_RESTART "system-shutdown-panel-restart" -- cgit v1.2.3 From 64cf80553784cdee851cf7112fdc468ab46a61be Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 31 Aug 2012 07:16:03 -0500 Subject: have the a11y text follow the SystemMenu spec --- src/indicator-session.c | 62 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/indicator-session.c b/src/indicator-session.c index d22cd33..72e3a0b 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -84,7 +84,7 @@ static gboolean build_restart_item (DbusmenuMenuitem * newitem, DbusmenuClient * client, gpointer user_data); static void on_menu_layout_updated (DbusmenuClient * client, IndicatorSession * session); -static void indicator_session_update_icon (IndicatorSession * self); +static void indicator_session_update_icon_and_a11y (IndicatorSession * self); static void indicator_session_update_users_label (IndicatorSession* self, const gchar* name); static void service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointer user_data); @@ -135,11 +135,17 @@ indicator_session_init (IndicatorSession *self) self->entry.image = GTK_IMAGE (gtk_image_new()); self->entry.menu = GTK_MENU (dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT)); - indicator_session_update_icon (self); + indicator_session_update_icon_and_a11y (self); g_settings_bind (self->settings, "show-real-name-on-panel", self->entry.label, "visible", G_SETTINGS_BIND_GET); + /* show-real-name-on-panel affects the a11y string */ + g_signal_connect_swapped (self->settings, + "notify::show-real-name-on-panel", + G_CALLBACK(indicator_session_update_icon_and_a11y), + self); + gtk_widget_show (GTK_WIDGET(self->entry.menu)); gtk_widget_show (GTK_WIDGET(self->entry.image)); g_object_ref_sink (self->entry.menu); @@ -422,16 +428,36 @@ enum }; static void -indicator_session_update_from_disposition (IndicatorSession * indicator, - int disposition) +indicator_session_update_a11y_from_disposition (IndicatorSession * indicator, + int disposition) { - const gchar * icon; - const gchar * a11y; + GString * a11y = g_string_new (_("System")); - if (disposition == DISPOSITION_NORMAL) - a11y = _("Session Menu"); - else - a11y = _("Session Menu (attention required)"); + if (g_settings_get_boolean (indicator->settings, "show-real-name-on-panel")) + { + const gchar * username = gtk_label_get_text (indicator->entry.label); + g_string_append_printf (a11y, " %s", username); + } + + if (disposition != DISPOSITION_NORMAL) + { + g_string_append (a11y, _(" (Attention Required)")); + } + + g_debug (G_STRLOC" setting a11y to \"%s\"", a11y->str); + g_clear_pointer (&indicator->entry.accessible_desc, g_free); + indicator->entry.accessible_desc = g_string_free (a11y, FALSE); + g_signal_emit (indicator, + INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, + 0, + &indicator->entry); +} + +static void +indicator_session_update_icon_from_disposition (IndicatorSession * indicator, + int disposition) +{ + const gchar * icon; if (greeter_mode) { @@ -450,17 +476,12 @@ indicator_session_update_from_disposition (IndicatorSession * indicator, icon = ICON_ALERT; } - g_debug (G_STRLOC" setting icon to \"%s\", a11y to \"%s\"", icon, a11y); + g_debug (G_STRLOC" setting icon to \"%s\"", icon); gtk_image_set_from_icon_name (GTK_IMAGE(indicator->entry.image), icon, GTK_ICON_SIZE_BUTTON); - indicator->entry.accessible_desc = a11y; - g_signal_emit (indicator, - INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, - 0, - &indicator->entry); } - + static int calculate_disposition (IndicatorSession * indicator) { @@ -492,10 +513,11 @@ calculate_disposition (IndicatorSession * indicator) } static void -indicator_session_update_icon (IndicatorSession * indicator) +indicator_session_update_icon_and_a11y (IndicatorSession * indicator) { const int disposition = calculate_disposition (indicator); - indicator_session_update_from_disposition (indicator, disposition); + indicator_session_update_a11y_from_disposition (indicator, disposition); + indicator_session_update_icon_from_disposition (indicator, disposition); } static void @@ -505,7 +527,7 @@ on_menuitem_property_changed (DbusmenuMenuitem * mi, gpointer indicator) { if (!g_strcmp0 (property, DBUSMENU_MENUITEM_PROP_DISPOSITION)) - indicator_session_update_icon (indicator); + indicator_session_update_icon_and_a11y (indicator); } static void -- cgit v1.2.3 From ed7d1fd6fd9d035156a15e8b0ed695de5e8e3f60 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 31 Aug 2012 11:28:21 -0500 Subject: revise indicator_session_update_a11y_from_disposition() to be easier to internationalize --- src/indicator-session.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/indicator-session.c b/src/indicator-session.c index 72e3a0b..ec95328 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -431,22 +431,22 @@ static void indicator_session_update_a11y_from_disposition (IndicatorSession * indicator, int disposition) { - GString * a11y = g_string_new (_("System")); - - if (g_settings_get_boolean (indicator->settings, "show-real-name-on-panel")) - { - const gchar * username = gtk_label_get_text (indicator->entry.label); - g_string_append_printf (a11y, " %s", username); - } - - if (disposition != DISPOSITION_NORMAL) - { - g_string_append (a11y, _(" (Attention Required)")); - } + gchar * a11y; + const gchar * username = gtk_label_get_text (indicator->entry.label); + const gboolean need_attn = disposition != DISPOSITION_NORMAL; + const gboolean show_name = g_settings_get_boolean (indicator->settings, + "show-real-name-on-panel"); + + if (show_name && need_attn) + a11y = g_strdup_printf (_("System %s (Attention Required)"), username); + else if (show_name) + a11y = g_strdup_printf (_("System %s"), username); + else + a11y = g_strdup (_("System")); - g_debug (G_STRLOC" setting a11y to \"%s\"", a11y->str); + g_debug (G_STRLOC" setting a11y to \"%s\"", a11y); g_clear_pointer (&indicator->entry.accessible_desc, g_free); - indicator->entry.accessible_desc = g_string_free (a11y, FALSE); + indicator->entry.accessible_desc = a11y; g_signal_emit (indicator, INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, 0, -- cgit v1.2.3 From 8c9120287ace0a37c26c38bfa94b1fd06dfa5578 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 31 Aug 2012 11:36:06 -0500 Subject: add a11y case for attention needed, but username display disabled --- src/indicator-session.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/indicator-session.c b/src/indicator-session.c index ec95328..aa328dd 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -441,6 +441,8 @@ indicator_session_update_a11y_from_disposition (IndicatorSession * indicator, a11y = g_strdup_printf (_("System %s (Attention Required)"), username); else if (show_name) a11y = g_strdup_printf (_("System %s"), username); + else if (need_attn) + a11y = g_strdup (_("System (Attention Required)")); else a11y = g_strdup (_("System")); -- cgit v1.2.3