ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #03540
[Branch ~indicator-applet-developers/indicator-messages/trunk] Rev 211: Add support for a specific icon on the menu
Merge authors:
Ted Gould (ted)
Related merge proposals:
https://code.launchpad.net/~ted/indicator-messages/specific-icon/+merge/56623
proposed by: Ted Gould (ted)
review: Approve - Kalle Valo (kvalo)
------------------------------------------------------------
revno: 211 [merge]
committer: Ted Gould <ted@xxxxxxxx>
branch nick: trunk
timestamp: Wed 2011-04-06 16:43:21 -0500
message:
Add support for a specific icon on the menu
modified:
src/app-menu-item.c
src/default-applications.h
src/launcher-menu-item.c
--
lp:indicator-messages
https://code.launchpad.net/~indicator-applet-developers/indicator-messages/trunk
Your team ayatana-commits is subscribed to branch lp:indicator-messages.
To unsubscribe from this branch go to https://code.launchpad.net/~indicator-applet-developers/indicator-messages/trunk/+edit-subscription
=== 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 16:24:05 +0000
@@ -52,6 +52,7 @@
gchar * type;
GAppInfo * appinfo;
+ GKeyFile * keyfile;
gchar * desktop;
guint unreadcount;
@@ -129,6 +130,7 @@
priv->server = NULL;
priv->type = NULL;
priv->appinfo = NULL;
+ priv->keyfile = NULL;
priv->desktop = NULL;
priv->unreadcount = 0;
@@ -179,6 +181,16 @@
priv->client = NULL;
}
+ if (priv->appinfo != NULL) {
+ g_object_unref(priv->appinfo);
+ priv->appinfo = NULL;
+ }
+
+ if (priv->keyfile != NULL) {
+ g_object_unref(priv->keyfile);
+ priv->keyfile = NULL;
+ }
+
G_OBJECT_CLASS (app_menu_item_parent_class)->dispose (object);
}
@@ -192,14 +204,12 @@
if (priv->type != NULL) {
g_free(priv->type);
+ priv->type = NULL;
}
if (priv->desktop != NULL) {
g_free(priv->desktop);
- }
-
- if (priv->appinfo != NULL) {
- g_object_unref(priv->appinfo);
+ priv->desktop = NULL;
}
G_OBJECT_CLASS (app_menu_item_parent_class)->finalize (object);
@@ -298,7 +308,7 @@
/* Callback for when we ask the server for the path
to it's desktop file. We then turn it into an
app structure and start sucking data out of it.
- Mostly the name. */
+ Mostly the name. And the icon. */
static void
desktop_cb (IndicateListener * listener, IndicateListenerServer * server, const gchar * value, gpointer data)
{
@@ -325,6 +335,9 @@
priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(value));
g_return_if_fail(priv->appinfo != NULL);
+ priv->keyfile = g_key_file_new();
+ g_key_file_load_from_file(priv->keyfile, value, G_KEY_FILE_NONE, NULL);
+
priv->desktop = g_strdup(value);
dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
@@ -334,8 +347,28 @@
const gchar * def_icon = get_default_icon(priv->desktop);
if (def_icon == NULL) {
- GIcon * icon = g_app_info_get_icon(priv->appinfo);
- gchar * iconstr = g_icon_to_string(icon);
+ gchar * iconstr = NULL;
+
+ /* Check for the over ride key and see if we should be using that
+ icon. If we can't get it, then go back to the app info */
+ if (g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, NULL) && iconstr == NULL) {
+ GError * error = NULL;
+
+ iconstr = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, &error);
+
+ if (error != NULL) {
+ /* Can't figure out why this would happen, but sure, let's print something */
+ g_warning("Error getting '" ICON_KEY "' from desktop file: %s", error->message);
+ g_error_free(error);
+ }
+ }
+
+ /* For some reason that didn't work, let's try the app info */
+ if (iconstr == NULL) {
+ GIcon * icon = g_app_info_get_icon(priv->appinfo);
+ iconstr = g_icon_to_string(icon);
+ }
+
dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), APPLICATION_MENUITEM_PROP_ICON, iconstr);
g_free(iconstr);
} else {
=== modified file 'src/default-applications.h'
--- src/default-applications.h 2010-03-04 20:27:29 +0000
+++ src/default-applications.h 2011-04-06 16:20:08 +0000
@@ -22,6 +22,10 @@
#ifndef DEFAULT_APPLICATIONS_H__
#define DEFAULT_APPLICATIONS_H__ 1
+/* Used for override icons in the normal case, but didn't
+ have a better place to put it. */
+#define ICON_KEY "X-Ayatana-Messaging-Menu-Icon"
+
const gchar * get_default_name (const gchar * desktop_path);
const gchar * get_default_setup (const gchar * desktop_path);
const gchar * get_default_icon (const gchar * desktop_path);
=== 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 16:20:08 +0000
@@ -44,6 +44,7 @@
struct _LauncherMenuItemPrivate
{
GAppInfo * appinfo;
+ GKeyFile * keyfile;
gchar * desktop;
IndicatorDesktopShortcuts * ids;
GList * shortcuts;
@@ -93,6 +94,7 @@
priv->appinfo = NULL;
priv->desktop = NULL;
+ priv->keyfile = NULL;
priv->ids = NULL;
priv->shortcuts = NULL;
@@ -120,6 +122,11 @@
priv->appinfo = NULL;
}
+ if (priv->keyfile != NULL) {
+ g_object_unref(priv->keyfile);
+ priv->keyfile = NULL;
+ }
+
if (priv->ids != NULL) {
g_object_unref(priv->ids);
priv->ids = NULL;
@@ -160,6 +167,8 @@
/* Parse the desktop file we've been given. */
priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file));
+ priv->keyfile = g_key_file_new();
+ g_key_file_load_from_file(priv->keyfile, desktop_file, G_KEY_FILE_NONE, NULL);
priv->desktop = g_strdup(desktop_file);
/* Set the appropriate values on this menu item based on the
@@ -250,18 +259,35 @@
return;
}
+/* Figure out the appropriate icon for this launcher */
gchar *
launcher_menu_item_get_icon (LauncherMenuItem * appitem)
{
LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(appitem);
-
- if (priv->appinfo == NULL) {
- return NULL;
- } else {
+ gchar * retval = NULL;
+
+ /* Check to see if there is a specific icon for the messaging
+ menu first. */
+ if (g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, NULL) && retval == NULL) {
+ GError * error = NULL;
+
+ retval = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, ICON_KEY, &error);
+
+ if (error != NULL) {
+ /* Can't figure out why this would happen, but sure, let's print something */
+ g_warning("Error getting '" ICON_KEY "' from desktop file: %s", error->message);
+ g_error_free(error);
+ }
+ }
+
+ /* If there's not, or there is an error, we'll use the one
+ from the application info */
+ if (priv->appinfo != NULL && retval == NULL) {
GIcon * icon = g_app_info_get_icon(priv->appinfo);
- gchar * iconstr = g_icon_to_string(icon);
- return iconstr;
+ retval = g_icon_to_string(icon);
}
+
+ return retval;
}
/* When the menu item is clicked on it tries to launch