Merge lp:~ted/indicator-messages/specific-icon into lp:indicator-messages/0.5

Proposed by Ted Gould
Status: Merged
Approved by: Kalle Valo
Approved revision: 216
Merged at revision: 211
Proposed branch: lp:~ted/indicator-messages/specific-icon
Merge into: lp:indicator-messages/0.5
Diff against target: 201 lines (+76/-13)
3 files modified
src/app-menu-item.c (+40/-7)
src/default-applications.h (+4/-0)
src/launcher-menu-item.c (+32/-6)
To merge this branch: bzr merge lp:~ted/indicator-messages/specific-icon
Reviewer Review Type Date Requested Status
Kalle Valo (community) Approve
Review via email: mp+56623@code.launchpad.net

Description of the change

Allow for a property in the desktop file to choose the icon instead of just always using the application icon.

To post a comment you must log in.
Revision history for this message
Kalle Valo (kvalo) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app-menu-item.c'
2--- src/app-menu-item.c 2011-01-14 19:35:21 +0000
3+++ src/app-menu-item.c 2011-04-06 17:46:23 +0000
4@@ -52,6 +52,7 @@
5
6 gchar * type;
7 GAppInfo * appinfo;
8+ GKeyFile * keyfile;
9 gchar * desktop;
10 guint unreadcount;
11
12@@ -129,6 +130,7 @@
13 priv->server = NULL;
14 priv->type = NULL;
15 priv->appinfo = NULL;
16+ priv->keyfile = NULL;
17 priv->desktop = NULL;
18 priv->unreadcount = 0;
19
20@@ -179,6 +181,16 @@
21 priv->client = NULL;
22 }
23
24+ if (priv->appinfo != NULL) {
25+ g_object_unref(priv->appinfo);
26+ priv->appinfo = NULL;
27+ }
28+
29+ if (priv->keyfile != NULL) {
30+ g_object_unref(priv->keyfile);
31+ priv->keyfile = NULL;
32+ }
33+
34 G_OBJECT_CLASS (app_menu_item_parent_class)->dispose (object);
35 }
36
37@@ -192,14 +204,12 @@
38
39 if (priv->type != NULL) {
40 g_free(priv->type);
41+ priv->type = NULL;
42 }
43
44 if (priv->desktop != NULL) {
45 g_free(priv->desktop);
46- }
47-
48- if (priv->appinfo != NULL) {
49- g_object_unref(priv->appinfo);
50+ priv->desktop = NULL;
51 }
52
53 G_OBJECT_CLASS (app_menu_item_parent_class)->finalize (object);
54@@ -298,7 +308,7 @@
55 /* Callback for when we ask the server for the path
56 to it's desktop file. We then turn it into an
57 app structure and start sucking data out of it.
58- Mostly the name. */
59+ Mostly the name. And the icon. */
60 static void
61 desktop_cb (IndicateListener * listener, IndicateListenerServer * server, const gchar * value, gpointer data)
62 {
63@@ -325,6 +335,9 @@
64 priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(value));
65 g_return_if_fail(priv->appinfo != NULL);
66
67+ priv->keyfile = g_key_file_new();
68+ g_key_file_load_from_file(priv->keyfile, value, G_KEY_FILE_NONE, NULL);
69+
70 priv->desktop = g_strdup(value);
71
72 dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
73@@ -334,8 +347,28 @@
74
75 const gchar * def_icon = get_default_icon(priv->desktop);
76 if (def_icon == NULL) {
77- GIcon * icon = g_app_info_get_icon(priv->appinfo);
78- gchar * iconstr = g_icon_to_string(icon);
79+ gchar * iconstr = NULL;
80+
81+ /* Check for the over ride key and see if we should be using that
82+ icon. If we can't get it, then go back to the app info */
83+ if (g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, NULL) && iconstr == NULL) {
84+ GError * error = NULL;
85+
86+ iconstr = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, &error);
87+
88+ if (error != NULL) {
89+ /* Can't figure out why this would happen, but sure, let's print something */
90+ g_warning("Error getting '" ICON_KEY "' from desktop file: %s", error->message);
91+ g_error_free(error);
92+ }
93+ }
94+
95+ /* For some reason that didn't work, let's try the app info */
96+ if (iconstr == NULL) {
97+ GIcon * icon = g_app_info_get_icon(priv->appinfo);
98+ iconstr = g_icon_to_string(icon);
99+ }
100+
101 dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), APPLICATION_MENUITEM_PROP_ICON, iconstr);
102 g_free(iconstr);
103 } else {
104
105=== modified file 'src/default-applications.h'
106--- src/default-applications.h 2010-03-04 20:27:29 +0000
107+++ src/default-applications.h 2011-04-06 17:46:23 +0000
108@@ -22,6 +22,10 @@
109 #ifndef DEFAULT_APPLICATIONS_H__
110 #define DEFAULT_APPLICATIONS_H__ 1
111
112+/* Used for override icons in the normal case, but didn't
113+ have a better place to put it. */
114+#define ICON_KEY "X-Ayatana-Messaging-Menu-Icon"
115+
116 const gchar * get_default_name (const gchar * desktop_path);
117 const gchar * get_default_setup (const gchar * desktop_path);
118 const gchar * get_default_icon (const gchar * desktop_path);
119
120=== modified file 'src/launcher-menu-item.c'
121--- src/launcher-menu-item.c 2011-02-23 20:46:22 +0000
122+++ src/launcher-menu-item.c 2011-04-06 17:46:23 +0000
123@@ -44,6 +44,7 @@
124 struct _LauncherMenuItemPrivate
125 {
126 GAppInfo * appinfo;
127+ GKeyFile * keyfile;
128 gchar * desktop;
129 IndicatorDesktopShortcuts * ids;
130 GList * shortcuts;
131@@ -93,6 +94,7 @@
132
133 priv->appinfo = NULL;
134 priv->desktop = NULL;
135+ priv->keyfile = NULL;
136
137 priv->ids = NULL;
138 priv->shortcuts = NULL;
139@@ -120,6 +122,11 @@
140 priv->appinfo = NULL;
141 }
142
143+ if (priv->keyfile != NULL) {
144+ g_object_unref(priv->keyfile);
145+ priv->keyfile = NULL;
146+ }
147+
148 if (priv->ids != NULL) {
149 g_object_unref(priv->ids);
150 priv->ids = NULL;
151@@ -160,6 +167,8 @@
152
153 /* Parse the desktop file we've been given. */
154 priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file));
155+ priv->keyfile = g_key_file_new();
156+ g_key_file_load_from_file(priv->keyfile, desktop_file, G_KEY_FILE_NONE, NULL);
157 priv->desktop = g_strdup(desktop_file);
158
159 /* Set the appropriate values on this menu item based on the
160@@ -250,18 +259,35 @@
161 return;
162 }
163
164+/* Figure out the appropriate icon for this launcher */
165 gchar *
166 launcher_menu_item_get_icon (LauncherMenuItem * appitem)
167 {
168 LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(appitem);
169-
170- if (priv->appinfo == NULL) {
171- return NULL;
172- } else {
173+ gchar * retval = NULL;
174+
175+ /* Check to see if there is a specific icon for the messaging
176+ menu first. */
177+ if (g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, NULL) && retval == NULL) {
178+ GError * error = NULL;
179+
180+ retval = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, &error);
181+
182+ if (error != NULL) {
183+ /* Can't figure out why this would happen, but sure, let's print something */
184+ g_warning("Error getting '" ICON_KEY "' from desktop file: %s", error->message);
185+ g_error_free(error);
186+ }
187+ }
188+
189+ /* If there's not, or there is an error, we'll use the one
190+ from the application info */
191+ if (priv->appinfo != NULL && retval == NULL) {
192 GIcon * icon = g_app_info_get_icon(priv->appinfo);
193- gchar * iconstr = g_icon_to_string(icon);
194- return iconstr;
195+ retval = g_icon_to_string(icon);
196 }
197+
198+ return retval;
199 }
200
201 /* When the menu item is clicked on it tries to launch

Subscribers

People subscribed via source and target branches

to all changes: