Merge lp:~ted/indicator-session/strings-allocation into lp:indicator-session/0.1

Proposed by Conor Curran
Status: Merged
Merged at revision: 192
Proposed branch: lp:~ted/indicator-session/strings-allocation
Merge into: lp:indicator-session/0.1
Diff against target: 107 lines (+21/-20)
1 file modified
src/udev-mgr.c (+21/-20)
To merge this branch: bzr merge lp:~ted/indicator-session/strings-allocation
Reviewer Review Type Date Requested Status
Conor Curran Pending
Review via email: mp+72941@code.launchpad.net

Description of the change

string allocation fixes

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/udev-mgr.c'
2--- src/udev-mgr.c 2011-08-25 16:05:41 +0000
3+++ src/udev-mgr.c 2011-08-25 18:54:24 +0000
4@@ -50,8 +50,9 @@
5 UdevMgrDeviceAction action);
6
7 static gchar* format_device_name (UdevMgr* self,
8- gchar* brand,
9- gchar* type);
10+ const gchar* brand,
11+ const gchar* generic,
12+ const gchar* branded) G_GNUC_WARN_UNUSED_RESULT;
13 struct _UdevMgr
14 {
15 GObject parent_instance;
16@@ -247,11 +248,11 @@
17 manufacturer = g_udev_device_get_property (device, "ID_VENDOR");
18
19 if (manufacturer != NULL){
20+ gchar * label = format_device_name(self, manufacturer, _("Webcam"), _("%s Webcam"));
21 dbusmenu_menuitem_property_set (self->webcam_item,
22 DBUSMENU_MENUITEM_PROP_LABEL,
23- format_device_name (self,
24- g_strdup(manufacturer),
25- "Webcam"));
26+ label);
27+ g_free(label);
28 }
29
30 g_hash_table_insert (self->webcams_present,
31@@ -322,11 +323,11 @@
32 manufacturer = g_udev_device_get_property (device, "ID_VENDOR");
33
34 if (manufacturer != NULL){
35+ gchar * label = format_device_name(self, manufacturer, _("Scanner"), _("%s Scanner"));
36 dbusmenu_menuitem_property_set (self->scanner_item,
37 DBUSMENU_MENUITEM_PROP_LABEL,
38- format_device_name (self,
39- g_strdup(manufacturer),
40- "Scanner"));
41+ label);
42+ g_free(label);
43 }
44
45 gchar* random_scanner_name = g_strdup_printf("%p--scanner", self);
46@@ -387,11 +388,11 @@
47 manufacturer = g_udev_device_get_property (device, "ID_VENDOR");
48
49 if (manufacturer != NULL){
50+ gchar * label = format_device_name(self, manufacturer, _("Scanner"), _("%s Scanner"));
51 dbusmenu_menuitem_property_set (self->scanner_item,
52 DBUSMENU_MENUITEM_PROP_LABEL,
53- format_device_name (self,
54- g_strdup(manufacturer),
55- "Scanner"));
56+ label);
57+ g_free(label);
58 }
59 g_hash_table_insert (self->scanners_present,
60 g_strdup(vendor),
61@@ -453,12 +454,11 @@
62
63 manufacturer = g_udev_device_get_property (device, "ID_VENDOR");
64 if (manufacturer != NULL){
65-
66+ gchar * label = format_device_name(self, manufacturer, _("Scanner"), _("%s Scanner"));
67 dbusmenu_menuitem_property_set (self->scanner_item,
68 DBUSMENU_MENUITEM_PROP_LABEL,
69- format_device_name (self,
70- g_strdup(manufacturer),
71- "Scanner"));
72+ label);
73+ g_free(label);
74 }
75
76 g_hash_table_insert (self->scanners_present,
77@@ -513,24 +513,25 @@
78 }
79
80 static gchar* format_device_name (UdevMgr* self,
81- gchar* brand,
82- gchar* type)
83+ const gchar* brand,
84+ const gchar* generic,
85+ const gchar* branded)
86 {
87 // We don't want to accommodate long names
88 if (strlen(brand) > 7)
89- return type;
90+ return g_strdup(generic);
91
92 gint i = 0;
93
94 // If it contains something other than an alphabetic entry ignore it.
95 for(i = 0; i < sizeof(brand); i++){
96 if ( !g_ascii_isalpha (brand[i]) )
97- return type;
98+ return g_strdup(generic);
99 }
100
101 gchar* lowered = g_ascii_strdown (brand, -1);
102 lowered[0] = g_ascii_toupper (lowered[0]);
103- gchar* label = g_strdup_printf(_("%s %s"), lowered, type);
104+ gchar* label = g_strdup_printf(branded, lowered);
105 g_free (lowered);
106 return label;
107 }

Subscribers

People subscribed via source and target branches