Merge lp:~charlesk/indicator-power/accessiblename into lp:indicator-power/1.0

Proposed by Charles Kerr
Status: Merged
Approved by: Ted Gould
Approved revision: 137
Merged at revision: 137
Proposed branch: lp:~charlesk/indicator-power/accessiblename
Merge into: lp:indicator-power/1.0
Diff against target: 85 lines (+14/-9)
1 file modified
src/indicator-power.c (+14/-9)
To merge this branch: bzr merge lp:~charlesk/indicator-power/accessiblename
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+101278@code.launchpad.net

Description of the change

Fixed bug #953176 by manually setting the menuitem's AtkObject's accessible_name project if possible.

Also fixes three related memory leaks:

 * When building the menuitem, don't leak the object_path and device_icon strings if kind == UP_DEVICE_KIND_LINE_POWER. (The function returned unconditionally without freeing the strings.)
 * Don't leak the GIcons returned by get_device_icon() that we use to create the device menuitem's GtkImage.
 * In get_device_icon(), don't leak the fallback GIcon.

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

Probably should use:

 atk_object_set_name()

Instead of the object property. But otherwise it looks good.

review: Approve
Revision history for this message
Charles Kerr (charlesk) wrote :

> Probably should use atk_object_set_name() instead of the object property

Fixed in r138.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/indicator-power.c'
2--- src/indicator-power.c 2012-02-22 23:39:50 +0000
3+++ src/indicator-power.c 2012-04-09 19:23:20 +0000
4@@ -510,11 +510,9 @@
5 get_device_icon (UpDeviceKind kind,
6 UpDeviceState state,
7 guint64 time_sec,
8- gchar *device_icon)
9+ const gchar *device_icon)
10 {
11- GIcon *gicon;
12-
13- gicon = g_icon_new_for_string (device_icon, NULL);
14+ GIcon *gicon = NULL;
15
16 if (kind == UP_DEVICE_KIND_BATTERY &&
17 (state == UP_DEVICE_STATE_FULLY_CHARGED ||
18@@ -538,6 +536,9 @@
19 }
20 }
21
22+ if (gicon == NULL)
23+ gicon = g_icon_new_for_string (device_icon, NULL);
24+
25 return gicon;
26 }
27
28@@ -553,20 +554,21 @@
29 GtkWidget *details_label;
30 GtkWidget *grid;
31 GIcon *device_gicons;
32- gchar *device_icon = NULL;
33- gchar *object_path = NULL;
34+ const gchar *device_icon = NULL;
35+ const gchar *object_path = NULL;
36 gdouble percentage;
37 guint64 time;
38 const gchar *device_name;
39 gchar *short_details = NULL;
40 gchar *details = NULL;
41 gchar *accessible_name = NULL;
42+ AtkObject *atk_object;
43
44 if (device == NULL)
45 return;
46
47 g_variant_get (device,
48- "(susdut)",
49+ "(&su&sdut)",
50 &object_path,
51 &kind,
52 &device_icon,
53@@ -583,6 +585,7 @@
54 device_gicons = get_device_icon (kind, state, time, device_icon);
55 icon = gtk_image_new_from_gicon (device_gicons,
56 GTK_ICON_SIZE_SMALL_TOOLBAR);
57+ g_clear_object (&device_gicons);
58
59 device_name = device_kind_to_localised_string (kind);
60
61@@ -590,6 +593,9 @@
62
63 /* Create menu item */
64 item = gtk_image_menu_item_new ();
65+ atk_object = gtk_widget_get_accessible(item);
66+ if (atk_object != NULL)
67+ g_object_set (G_OBJECT(atk_object), "accessible-name", accessible_name, NULL);
68
69 grid = gtk_grid_new ();
70 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
71@@ -607,8 +613,6 @@
72 g_free (short_details);
73 g_free (details);
74 g_free (accessible_name);
75- g_free (device_icon);
76- g_free (object_path);
77 }
78
79 static gsize
80@@ -808,6 +812,7 @@
81 gtk_image_set_from_gicon (self->status_image,
82 device_gicons,
83 GTK_ICON_SIZE_LARGE_TOOLBAR);
84+ g_clear_object (&device_gicons);
85 gtk_widget_show (GTK_WIDGET (self->status_image));
86
87

Subscribers

People subscribed via source and target branches