Merge lp:~charlesk/indicator-session/lp-1044015 into lp:indicator-session/12.10

Proposed by Charles Kerr on 2012-08-31
Status: Merged
Approved by: Ted Gould on 2012-08-31
Approved revision: 355
Merged at revision: 353
Proposed branch: lp:~charlesk/indicator-session/lp-1044015
Merge into: lp:indicator-session/12.10
Diff against target: 247 lines (+161/-17)
2 files modified
src/indicator-session.c (+158/-16)
src/shared-names.h (+3/-1)
To merge this branch: bzr merge lp:~charlesk/indicator-session/lp-1044015
Reviewer Review Type Date Requested Status
jenkins (community) continuous-integration Approve on 2012-08-31
Ted Gould (community) 2012-08-31 Approve on 2012-08-31
Review via email: mp+122179@code.launchpad.net

Description of the change

This code is ready for review but I'm marking it "work in progress" because I don't want Tarmac to autoland it before Design has a chance to say what the indicator's a11y text should be here.

To post a comment you must log in.
Charles Kerr (charlesk) wrote :

Neither mpt nor JohnLea had an opinion on the error state a11y text, changing from "work in progress" to "ready for review"

Ted Gould (ted) :
review: Approve
356. By Charles Kerr on 2012-08-31

add a11y case for attention needed, but username display disabled

jenkins (martin-mrazik+qa) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/indicator-session.c'
2--- src/indicator-session.c 2012-08-22 00:12:32 +0000
3+++ src/indicator-session.c 2012-08-31 16:38:18 +0000
4@@ -63,6 +63,7 @@
5 GCancellable * service_proxy_cancel;
6 GDBusProxy * service_proxy;
7 GSettings * settings;
8+ DbusmenuClient * menu_client;
9 };
10
11 static gboolean greeter_mode;
12@@ -82,6 +83,8 @@
13 DbusmenuMenuitem * parent,
14 DbusmenuClient * client,
15 gpointer user_data);
16+static void on_menu_layout_updated (DbusmenuClient * client, IndicatorSession * session);
17+static void indicator_session_update_icon_and_a11y (IndicatorSession * self);
18 static void indicator_session_update_users_label (IndicatorSession* self,
19 const gchar* name);
20 static void service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointer user_data);
21@@ -116,8 +119,6 @@
22 static void
23 indicator_session_init (IndicatorSession *self)
24 {
25- const gchar * icon_name;
26-
27 self->settings = g_settings_new ("com.canonical.indicator.session");
28
29 /* Now let's fire these guys up. */
30@@ -130,30 +131,38 @@
31 greeter_mode = !g_strcmp0(g_getenv("INDICATOR_GREETER_MODE"), "1");
32
33 self->entry.name_hint = PACKAGE;
34- self->entry.accessible_desc = _("Session Menu");
35 self->entry.label = GTK_LABEL (gtk_label_new ("User Name"));
36- icon_name = greeter_mode ? GREETER_ICON_DEFAULT : ICON_DEFAULT;
37- self->entry.image = GTK_IMAGE (gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON));
38+ self->entry.image = GTK_IMAGE (gtk_image_new());
39 self->entry.menu = GTK_MENU (dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME,
40 INDICATOR_SESSION_DBUS_OBJECT));
41+ indicator_session_update_icon_and_a11y (self);
42 g_settings_bind (self->settings, "show-real-name-on-panel",
43 self->entry.label, "visible",
44 G_SETTINGS_BIND_GET);
45
46+ /* show-real-name-on-panel affects the a11y string */
47+ g_signal_connect_swapped (self->settings,
48+ "notify::show-real-name-on-panel",
49+ G_CALLBACK(indicator_session_update_icon_and_a11y),
50+ self);
51+
52 gtk_widget_show (GTK_WIDGET(self->entry.menu));
53 gtk_widget_show (GTK_WIDGET(self->entry.image));
54 g_object_ref_sink (self->entry.menu);
55 g_object_ref_sink (self->entry.image);
56
57 // set up the handlers
58- DbusmenuClient * menu_client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(DBUSMENU_GTKMENU(self->entry.menu)));
59- dbusmenu_client_add_type_handler (menu_client,
60+ self->menu_client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(DBUSMENU_GTKMENU(self->entry.menu)));
61+ g_signal_connect (self->menu_client, "layout-updated",
62+ G_CALLBACK(on_menu_layout_updated), self);
63+
64+ dbusmenu_client_add_type_handler (self->menu_client,
65 USER_ITEM_TYPE,
66 new_user_item);
67- dbusmenu_client_add_type_handler (menu_client,
68+ dbusmenu_client_add_type_handler (self->menu_client,
69 RESTART_ITEM_TYPE,
70 build_restart_item);
71- dbusmenu_gtkclient_set_accel_group (DBUSMENU_GTKCLIENT(menu_client),
72+ dbusmenu_gtkclient_set_accel_group (DBUSMENU_GTKCLIENT(self->menu_client),
73 gtk_accel_group_new());
74 }
75
76@@ -339,13 +348,6 @@
77 g_variant_get (parameters, "(&s)", &username);
78 indicator_session_update_users_label (self, username);
79 }
80- else if (!g_strcmp0(signal_name, "RestartRequired"))
81- {
82- const gchar * icon_name = greeter_mode ? GREETER_ICON_RESTART : ICON_RESTART;
83- gtk_image_set_from_icon_name (GTK_IMAGE(self->entry.image), icon_name, GTK_ICON_SIZE_MENU);
84- self->entry.accessible_desc = _("Device Menu (reboot required)");
85- g_signal_emit (G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, 0, &self->entry);
86- }
87 }
88
89
90@@ -412,3 +414,143 @@
91 {
92 gtk_label_set_text (self->entry.label, name ? name : "");
93 }
94+
95+/***
96+**** Disposition
97+***/
98+
99+enum
100+{
101+ DISPOSITION_NORMAL,
102+ DISPOSITION_INFO,
103+ DISPOSITION_WARNING,
104+ DISPOSITION_ALERT
105+};
106+
107+static void
108+indicator_session_update_a11y_from_disposition (IndicatorSession * indicator,
109+ int disposition)
110+{
111+ gchar * a11y;
112+ const gchar * username = gtk_label_get_text (indicator->entry.label);
113+ const gboolean need_attn = disposition != DISPOSITION_NORMAL;
114+ const gboolean show_name = g_settings_get_boolean (indicator->settings,
115+ "show-real-name-on-panel");
116+
117+ if (show_name && need_attn)
118+ a11y = g_strdup_printf (_("System %s (Attention Required)"), username);
119+ else if (show_name)
120+ a11y = g_strdup_printf (_("System %s"), username);
121+ else if (need_attn)
122+ a11y = g_strdup (_("System (Attention Required)"));
123+ else
124+ a11y = g_strdup (_("System"));
125+
126+ g_debug (G_STRLOC" setting a11y to \"%s\"", a11y);
127+ g_clear_pointer (&indicator->entry.accessible_desc, g_free);
128+ indicator->entry.accessible_desc = a11y;
129+ g_signal_emit (indicator,
130+ INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID,
131+ 0,
132+ &indicator->entry);
133+}
134+
135+static void
136+indicator_session_update_icon_from_disposition (IndicatorSession * indicator,
137+ int disposition)
138+{
139+ const gchar * icon;
140+
141+ if (greeter_mode)
142+ {
143+ if (disposition == DISPOSITION_NORMAL)
144+ icon = GREETER_ICON_DEFAULT;
145+ else
146+ icon = GREETER_ICON_RESTART;
147+ }
148+ else
149+ {
150+ if (disposition == DISPOSITION_NORMAL)
151+ icon = ICON_DEFAULT;
152+ else if (disposition == DISPOSITION_INFO)
153+ icon = ICON_INFO;
154+ else
155+ icon = ICON_ALERT;
156+ }
157+
158+ g_debug (G_STRLOC" setting icon to \"%s\"", icon);
159+ gtk_image_set_from_icon_name (GTK_IMAGE(indicator->entry.image),
160+ icon,
161+ GTK_ICON_SIZE_BUTTON);
162+}
163+
164+static int
165+calculate_disposition (IndicatorSession * indicator)
166+{
167+ GList * l;
168+ DbusmenuMenuitem * root = dbusmenu_client_get_root (indicator->menu_client);
169+ GList * children = dbusmenu_menuitem_get_children (root);
170+ int ret = DISPOSITION_NORMAL;
171+
172+ for (l=children; l!=NULL; l=l->next)
173+ {
174+ int val;
175+ const gchar * key = DBUSMENU_MENUITEM_PROP_DISPOSITION;
176+ const gchar * val_str = dbusmenu_menuitem_property_get (l->data, key);
177+
178+ if (!g_strcmp0 (val_str, DBUSMENU_MENUITEM_DISPOSITION_ALERT))
179+ val = DISPOSITION_ALERT;
180+ else if (!g_strcmp0 (val_str, DBUSMENU_MENUITEM_DISPOSITION_WARNING))
181+ val = DISPOSITION_WARNING;
182+ else if (!g_strcmp0 (val_str, DBUSMENU_MENUITEM_DISPOSITION_INFORMATIVE))
183+ val = DISPOSITION_INFO;
184+ else
185+ val = DISPOSITION_NORMAL;
186+
187+ if (ret < val)
188+ ret = val;
189+ }
190+
191+ return ret;
192+}
193+
194+static void
195+indicator_session_update_icon_and_a11y (IndicatorSession * indicator)
196+{
197+ const int disposition = calculate_disposition (indicator);
198+ indicator_session_update_a11y_from_disposition (indicator, disposition);
199+ indicator_session_update_icon_from_disposition (indicator, disposition);
200+}
201+
202+static void
203+on_menuitem_property_changed (DbusmenuMenuitem * mi,
204+ gchar * property,
205+ GValue * value,
206+ gpointer indicator)
207+{
208+ if (!g_strcmp0 (property, DBUSMENU_MENUITEM_PROP_DISPOSITION))
209+ indicator_session_update_icon_and_a11y (indicator);
210+}
211+
212+static void
213+on_menu_layout_updated (DbusmenuClient * client, IndicatorSession * session)
214+{
215+ GList * l;
216+ DbusmenuMenuitem * root = dbusmenu_client_get_root (client);
217+ GList * children = dbusmenu_menuitem_get_children (root);
218+ static GQuark tag = 0;
219+
220+ if (G_UNLIKELY (tag == 0))
221+ {
222+ tag = g_quark_from_static_string ("x-tagged-by-indicator-session");
223+ }
224+
225+ for (l=children; l!=NULL; l=l->next)
226+ {
227+ if (g_object_get_qdata (l->data, tag) == NULL)
228+ {
229+ g_object_set_qdata (l->data, tag, GINT_TO_POINTER(1));
230+ g_signal_connect (l->data, "property-changed", G_CALLBACK(on_menuitem_property_changed), session);
231+ }
232+ }
233+}
234
235=== modified file 'src/shared-names.h'
236--- src/shared-names.h 2012-06-18 17:35:05 +0000
237+++ src/shared-names.h 2012-08-31 16:38:18 +0000
238@@ -41,7 +41,9 @@
239 #define RESTART_ITEM_ICON "restart-icon"
240
241 #define ICON_DEFAULT "system-devices-panel"
242-#define ICON_RESTART "system-devices-panel-alert"
243+#define ICON_INFO "system-devices-panel-information"
244+#define ICON_ALERT "system-devices-panel-alert"
245+
246 #define GREETER_ICON_DEFAULT "system-shutdown-panel"
247 #define GREETER_ICON_RESTART "system-shutdown-panel-restart"
248

Subscribers

People subscribed via source and target branches