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
=== modified file 'src/app-menu-item.c'
--- src/app-menu-item.c 2011-01-14 19:35:21 +0000
+++ src/app-menu-item.c 2011-04-06 17:46:23 +0000
@@ -52,6 +52,7 @@
52 52
53 gchar * type;53 gchar * type;
54 GAppInfo * appinfo;54 GAppInfo * appinfo;
55 GKeyFile * keyfile;
55 gchar * desktop;56 gchar * desktop;
56 guint unreadcount;57 guint unreadcount;
5758
@@ -129,6 +130,7 @@
129 priv->server = NULL;130 priv->server = NULL;
130 priv->type = NULL;131 priv->type = NULL;
131 priv->appinfo = NULL;132 priv->appinfo = NULL;
133 priv->keyfile = NULL;
132 priv->desktop = NULL;134 priv->desktop = NULL;
133 priv->unreadcount = 0;135 priv->unreadcount = 0;
134136
@@ -179,6 +181,16 @@
179 priv->client = NULL;181 priv->client = NULL;
180 }182 }
181183
184 if (priv->appinfo != NULL) {
185 g_object_unref(priv->appinfo);
186 priv->appinfo = NULL;
187 }
188
189 if (priv->keyfile != NULL) {
190 g_object_unref(priv->keyfile);
191 priv->keyfile = NULL;
192 }
193
182 G_OBJECT_CLASS (app_menu_item_parent_class)->dispose (object);194 G_OBJECT_CLASS (app_menu_item_parent_class)->dispose (object);
183}195}
184196
@@ -192,14 +204,12 @@
192204
193 if (priv->type != NULL) {205 if (priv->type != NULL) {
194 g_free(priv->type);206 g_free(priv->type);
207 priv->type = NULL;
195 }208 }
196209
197 if (priv->desktop != NULL) {210 if (priv->desktop != NULL) {
198 g_free(priv->desktop);211 g_free(priv->desktop);
199 }212 priv->desktop = NULL;
200
201 if (priv->appinfo != NULL) {
202 g_object_unref(priv->appinfo);
203 }213 }
204214
205 G_OBJECT_CLASS (app_menu_item_parent_class)->finalize (object);215 G_OBJECT_CLASS (app_menu_item_parent_class)->finalize (object);
@@ -298,7 +308,7 @@
298/* Callback for when we ask the server for the path308/* Callback for when we ask the server for the path
299 to it's desktop file. We then turn it into an309 to it's desktop file. We then turn it into an
300 app structure and start sucking data out of it.310 app structure and start sucking data out of it.
301 Mostly the name. */311 Mostly the name. And the icon. */
302static void 312static void
303desktop_cb (IndicateListener * listener, IndicateListenerServer * server, const gchar * value, gpointer data)313desktop_cb (IndicateListener * listener, IndicateListenerServer * server, const gchar * value, gpointer data)
304{314{
@@ -325,6 +335,9 @@
325 priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(value));335 priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(value));
326 g_return_if_fail(priv->appinfo != NULL);336 g_return_if_fail(priv->appinfo != NULL);
327337
338 priv->keyfile = g_key_file_new();
339 g_key_file_load_from_file(priv->keyfile, value, G_KEY_FILE_NONE, NULL);
340
328 priv->desktop = g_strdup(value);341 priv->desktop = g_strdup(value);
329342
330 dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);343 dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
@@ -334,8 +347,28 @@
334347
335 const gchar * def_icon = get_default_icon(priv->desktop);348 const gchar * def_icon = get_default_icon(priv->desktop);
336 if (def_icon == NULL) {349 if (def_icon == NULL) {
337 GIcon * icon = g_app_info_get_icon(priv->appinfo);350 gchar * iconstr = NULL;
338 gchar * iconstr = g_icon_to_string(icon);351
352 /* Check for the over ride key and see if we should be using that
353 icon. If we can't get it, then go back to the app info */
354 if (g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, NULL) && iconstr == NULL) {
355 GError * error = NULL;
356
357 iconstr = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, &error);
358
359 if (error != NULL) {
360 /* Can't figure out why this would happen, but sure, let's print something */
361 g_warning("Error getting '" ICON_KEY "' from desktop file: %s", error->message);
362 g_error_free(error);
363 }
364 }
365
366 /* For some reason that didn't work, let's try the app info */
367 if (iconstr == NULL) {
368 GIcon * icon = g_app_info_get_icon(priv->appinfo);
369 iconstr = g_icon_to_string(icon);
370 }
371
339 dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), APPLICATION_MENUITEM_PROP_ICON, iconstr);372 dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), APPLICATION_MENUITEM_PROP_ICON, iconstr);
340 g_free(iconstr);373 g_free(iconstr);
341 } else {374 } else {
342375
=== modified file 'src/default-applications.h'
--- src/default-applications.h 2010-03-04 20:27:29 +0000
+++ src/default-applications.h 2011-04-06 17:46:23 +0000
@@ -22,6 +22,10 @@
22#ifndef DEFAULT_APPLICATIONS_H__22#ifndef DEFAULT_APPLICATIONS_H__
23#define DEFAULT_APPLICATIONS_H__ 123#define DEFAULT_APPLICATIONS_H__ 1
2424
25/* Used for override icons in the normal case, but didn't
26 have a better place to put it. */
27#define ICON_KEY "X-Ayatana-Messaging-Menu-Icon"
28
25const gchar * get_default_name (const gchar * desktop_path);29const gchar * get_default_name (const gchar * desktop_path);
26const gchar * get_default_setup (const gchar * desktop_path);30const gchar * get_default_setup (const gchar * desktop_path);
27const gchar * get_default_icon (const gchar * desktop_path);31const gchar * get_default_icon (const gchar * desktop_path);
2832
=== modified file 'src/launcher-menu-item.c'
--- src/launcher-menu-item.c 2011-02-23 20:46:22 +0000
+++ src/launcher-menu-item.c 2011-04-06 17:46:23 +0000
@@ -44,6 +44,7 @@
44struct _LauncherMenuItemPrivate44struct _LauncherMenuItemPrivate
45{45{
46 GAppInfo * appinfo;46 GAppInfo * appinfo;
47 GKeyFile * keyfile;
47 gchar * desktop;48 gchar * desktop;
48 IndicatorDesktopShortcuts * ids;49 IndicatorDesktopShortcuts * ids;
49 GList * shortcuts;50 GList * shortcuts;
@@ -93,6 +94,7 @@
9394
94 priv->appinfo = NULL;95 priv->appinfo = NULL;
95 priv->desktop = NULL;96 priv->desktop = NULL;
97 priv->keyfile = NULL;
9698
97 priv->ids = NULL;99 priv->ids = NULL;
98 priv->shortcuts = NULL;100 priv->shortcuts = NULL;
@@ -120,6 +122,11 @@
120 priv->appinfo = NULL;122 priv->appinfo = NULL;
121 }123 }
122124
125 if (priv->keyfile != NULL) {
126 g_object_unref(priv->keyfile);
127 priv->keyfile = NULL;
128 }
129
123 if (priv->ids != NULL) {130 if (priv->ids != NULL) {
124 g_object_unref(priv->ids);131 g_object_unref(priv->ids);
125 priv->ids = NULL;132 priv->ids = NULL;
@@ -160,6 +167,8 @@
160167
161 /* Parse the desktop file we've been given. */168 /* Parse the desktop file we've been given. */
162 priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file));169 priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file));
170 priv->keyfile = g_key_file_new();
171 g_key_file_load_from_file(priv->keyfile, desktop_file, G_KEY_FILE_NONE, NULL);
163 priv->desktop = g_strdup(desktop_file);172 priv->desktop = g_strdup(desktop_file);
164173
165 /* Set the appropriate values on this menu item based on the174 /* Set the appropriate values on this menu item based on the
@@ -250,18 +259,35 @@
250 return;259 return;
251}260}
252261
262/* Figure out the appropriate icon for this launcher */
253gchar *263gchar *
254launcher_menu_item_get_icon (LauncherMenuItem * appitem)264launcher_menu_item_get_icon (LauncherMenuItem * appitem)
255{265{
256 LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(appitem);266 LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(appitem);
257267 gchar * retval = NULL;
258 if (priv->appinfo == NULL) {268
259 return NULL;269 /* Check to see if there is a specific icon for the messaging
260 } else {270 menu first. */
271 if (g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, NULL) && retval == NULL) {
272 GError * error = NULL;
273
274 retval = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, &error);
275
276 if (error != NULL) {
277 /* Can't figure out why this would happen, but sure, let's print something */
278 g_warning("Error getting '" ICON_KEY "' from desktop file: %s", error->message);
279 g_error_free(error);
280 }
281 }
282
283 /* If there's not, or there is an error, we'll use the one
284 from the application info */
285 if (priv->appinfo != NULL && retval == NULL) {
261 GIcon * icon = g_app_info_get_icon(priv->appinfo);286 GIcon * icon = g_app_info_get_icon(priv->appinfo);
262 gchar * iconstr = g_icon_to_string(icon);287 retval = g_icon_to_string(icon);
263 return iconstr;
264 }288 }
289
290 return retval;
265}291}
266292
267/* When the menu item is clicked on it tries to launch293/* When the menu item is clicked on it tries to launch

Subscribers

People subscribed via source and target branches

to all changes: