From 55b0614a2830ecb2fa4dd070b4f6c2eee6ac1ea6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Feb 2012 13:32:25 -0600 Subject: Changing our defines around to make sure to mark things the way that we think about them. --- libindicator/indicator-desktop-shortcuts.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 2ae78f9..b17ab5e 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -28,9 +28,12 @@ License along with this library. If not, see #include #include "indicator-desktop-shortcuts.h" -#define GROUP_SUFFIX "Shortcut Group" -#define SHORTCUTS_KEY "X-Ayatana-Desktop-Shortcuts" -#define ENVIRON_KEY "TargetEnvironment" +#define ACTIONS_KEY "Actions" +#define ACTION_GROUP_PREFIX "Desktop Action" + +#define OLD_GROUP_SUFFIX "Shortcut Group" +#define OLD_SHORTCUTS_KEY "X-Ayatana-Desktop-Shortcuts" +#define OLD_ENVIRON_KEY "TargetEnvironment" #define PROP_DESKTOP_FILE_S "desktop-file" #define PROP_IDENTITY_S "identity" @@ -173,7 +176,7 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec break; } - if (!g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, SHORTCUTS_KEY, NULL)) { + if (!g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, OLD_SHORTCUTS_KEY, NULL)) { g_key_file_free(keyfile); break; } @@ -256,13 +259,13 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) /* Okay, we've got everything we need. Let's get it on! */ gint i; gsize num_nicks = 0; - gchar ** nicks = g_key_file_get_string_list(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, SHORTCUTS_KEY, &num_nicks, NULL); + gchar ** nicks = g_key_file_get_string_list(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, OLD_SHORTCUTS_KEY, &num_nicks, NULL); /* If there is an error from get_string_list num_nicks should still be zero, so this loop will drop out. */ for (i = 0; i < num_nicks; i++) { /* g_debug("Looking at group nick %s", nicks[i]); */ - gchar * groupname = g_strdup_printf("%s " GROUP_SUFFIX, nicks[i]); + gchar * groupname = g_strdup_printf("%s " OLD_GROUP_SUFFIX, nicks[i]); if (!g_key_file_has_group(priv->keyfile, groupname)) { g_warning("Unable to find group '%s'", groupname); g_free(groupname); @@ -296,12 +299,12 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) static gboolean should_show (GKeyFile * keyfile, const gchar * group, const gchar * identity, gboolean should_have_target) { - if (should_have_target && g_key_file_has_key(keyfile, group, ENVIRON_KEY, NULL)) { + if (should_have_target && g_key_file_has_key(keyfile, group, OLD_ENVIRON_KEY, NULL)) { /* If we've got this key, we're going to return here and not process the deprecated keys. */ gint j; gsize num_env = 0; - gchar ** envs = g_key_file_get_string_list(keyfile, group, ENVIRON_KEY, &num_env, NULL); + gchar ** envs = g_key_file_get_string_list(keyfile, group, OLD_ENVIRON_KEY, &num_env, NULL); for (j = 0; j < num_env; j++) { if (g_strcmp0(envs[j], identity) == 0) { @@ -319,7 +322,7 @@ should_show (GKeyFile * keyfile, const gchar * group, const gchar * identity, gb return TRUE; } else { if (should_have_target) { - g_warning(GROUP_SUFFIX " does not have key '" ENVIRON_KEY "' falling back to deprecated use of '" G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN "' and '" G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN "'."); + g_warning(OLD_GROUP_SUFFIX " does not have key '" OLD_ENVIRON_KEY "' falling back to deprecated use of '" G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN "' and '" G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN "'."); } } @@ -452,7 +455,7 @@ indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, cons g_return_val_if_fail(priv->keyfile != NULL, NULL); g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), NULL); - gchar * groupheader = g_strdup_printf("%s " GROUP_SUFFIX, nick); + gchar * groupheader = g_strdup_printf("%s " OLD_GROUP_SUFFIX, nick); if (!g_key_file_has_group(priv->keyfile, groupheader)) { g_warning("The group for nick '%s' doesn't exist anymore.", nick); g_free(groupheader); @@ -512,7 +515,7 @@ indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gc g_return_val_if_fail(priv->keyfile != NULL, FALSE); g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), FALSE); - gchar * groupheader = g_strdup_printf("%s " GROUP_SUFFIX, nick); + gchar * groupheader = g_strdup_printf("%s " OLD_GROUP_SUFFIX, nick); if (!g_key_file_has_group(priv->keyfile, groupheader)) { g_warning("The group for nick '%s' doesn't exist anymore.", nick); g_free(groupheader); -- cgit v1.2.3 -- cgit v1.2.3 From f7e5502a2a136bedfb6a72fb081883568a1ead3c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Feb 2012 13:39:44 -0600 Subject: Adding a state variable to track what kind of actions we have --- libindicator/indicator-desktop-shortcuts.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index b17ab5e..bb25979 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -38,8 +38,16 @@ License along with this library. If not, see #define PROP_DESKTOP_FILE_S "desktop-file" #define PROP_IDENTITY_S "identity" +typedef enum _actions_t actions_t; +enum _actions_t { + ACTIONS_NONE, + ACTIONS_XAYATANA, + ACTIONS_DESKTOP_SPEC +}; + typedef struct _IndicatorDesktopShortcutsPrivate IndicatorDesktopShortcutsPrivate; struct _IndicatorDesktopShortcutsPrivate { + actions_t actions; GKeyFile * keyfile; gchar * identity; GArray * nicks; @@ -107,6 +115,7 @@ indicator_desktop_shortcuts_init (IndicatorDesktopShortcuts *self) priv->identity = NULL; priv->domain = NULL; priv->nicks = g_array_new(TRUE, TRUE, sizeof(gchar *)); + priv->actions = ACTIONS_NONE; return; } @@ -452,6 +461,7 @@ indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, cons g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), NULL); IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids); + g_return_val_if_fail(priv->actions != ACTIONS_NONE, NULL); g_return_val_if_fail(priv->keyfile != NULL, NULL); g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), NULL); @@ -512,6 +522,7 @@ indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gc g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE); IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids); + g_return_val_if_fail(priv->actions != ACTIONS_NONE, FALSE); g_return_val_if_fail(priv->keyfile != NULL, FALSE); g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), FALSE); -- cgit v1.2.3 From 4baf9b7067554450de88e40d3336d9739ca79de5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Feb 2012 14:25:21 -0600 Subject: Figure out what kind of actions we have --- libindicator/indicator-desktop-shortcuts.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index bb25979..d58c81d 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -174,6 +174,12 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec switch(prop_id) { case PROP_DESKTOP_FILE: { + if (priv->keyfile != NULL) { + g_key_file_free(priv->keyfile); + priv->keyfile = NULL; + priv->actions = ACTIONS_NONE; + } + GError * error = NULL; GKeyFile * keyfile = g_key_file_new(); g_key_file_load_from_file(keyfile, g_value_get_string(value), G_KEY_FILE_NONE, &error); @@ -185,7 +191,17 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec break; } - if (!g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, OLD_SHORTCUTS_KEY, NULL)) { + /* Always prefer the desktop spec if we can get it */ + if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, ACTIONS_KEY, NULL)) { + priv->actions = ACTIONS_DESKTOP_SPEC; + } + + /* But fallback if we can't */ + if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, OLD_SHORTCUTS_KEY, NULL)) { + priv->actions = ACTIONS_XAYATANA; + } + + if (priv->actions == ACTIONS_NONE) { g_key_file_free(keyfile); break; } -- cgit v1.2.3 From 52c42ef36462d3dfc4396b219730a8f1d7bc8dcd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Feb 2012 14:34:52 -0600 Subject: Use the appropriate list of nicks and groups to find our data now --- libindicator/indicator-desktop-shortcuts.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index d58c81d..df588d1 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -281,16 +281,38 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) priv->domain = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-Ubuntu-Gettext-Domain", NULL); } + /* We need to figure out what we're looking for and what we want to + look for in the rest of the file */ + const gchar * list_name = NULL; + const gchar * group_format = NULL; + + switch (priv->actions) { + case ACTIONS_NONE: + /* None, let's just get outta here */ + return; + case ACTIONS_XAYATANA: + list_name = OLD_SHORTCUTS_KEY; + group_format = "%s " OLD_GROUP_SUFFIX; + break; + case ACTIONS_DESKTOP_SPEC: + list_name = ACTIONS_KEY; + group_format = ACTION_GROUP_PREFIX " %s"; + break; + default: + g_assert_not_reached(); + return; + } + /* Okay, we've got everything we need. Let's get it on! */ gint i; gsize num_nicks = 0; - gchar ** nicks = g_key_file_get_string_list(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, OLD_SHORTCUTS_KEY, &num_nicks, NULL); + gchar ** nicks = g_key_file_get_string_list(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, list_name, &num_nicks, NULL); /* If there is an error from get_string_list num_nicks should still be zero, so this loop will drop out. */ for (i = 0; i < num_nicks; i++) { /* g_debug("Looking at group nick %s", nicks[i]); */ - gchar * groupname = g_strdup_printf("%s " OLD_GROUP_SUFFIX, nicks[i]); + gchar * groupname = g_strdup_printf(group_format, nicks[i]); if (!g_key_file_has_group(priv->keyfile, groupname)) { g_warning("Unable to find group '%s'", groupname); g_free(groupname); -- cgit v1.2.3 From 7d3e660ebc647e5ae3520f11d68447f222f5e5de Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Feb 2012 14:38:21 -0600 Subject: Adding a value for whether it should use the TargetEnvironment, I'm removing the warning because we don't care to fix old stuff anymore --- libindicator/indicator-desktop-shortcuts.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index df588d1..9b44e4a 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -285,6 +285,7 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) look for in the rest of the file */ const gchar * list_name = NULL; const gchar * group_format = NULL; + gboolean should_have_target = FALSE; switch (priv->actions) { case ACTIONS_NONE: @@ -293,10 +294,12 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) case ACTIONS_XAYATANA: list_name = OLD_SHORTCUTS_KEY; group_format = "%s " OLD_GROUP_SUFFIX; + should_have_target = TRUE; break; case ACTIONS_DESKTOP_SPEC: list_name = ACTIONS_KEY; group_format = ACTION_GROUP_PREFIX " %s"; + should_have_target = FALSE; break; default: g_assert_not_reached(); @@ -324,7 +327,7 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) continue; } - if (!should_show(priv->keyfile, groupname, priv->identity, TRUE)) { + if (!should_show(priv->keyfile, groupname, priv->identity, should_have_target)) { g_free(groupname); continue; } @@ -367,10 +370,6 @@ should_show (GKeyFile * keyfile, const gchar * group, const gchar * identity, gb return FALSE; } return TRUE; - } else { - if (should_have_target) { - g_warning(OLD_GROUP_SUFFIX " does not have key '" OLD_ENVIRON_KEY "' falling back to deprecated use of '" G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN "' and '" G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN "'."); - } } /* If there is a list of OnlyShowIn entries we need to check -- cgit v1.2.3 From 19c48bd262323258cf0bfbd0e3ed319fcc891076 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Feb 2012 14:40:08 -0600 Subject: Creating a warning for the legacy support --- libindicator/indicator-desktop-shortcuts.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 9b44e4a..f684905 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -199,6 +199,7 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec /* But fallback if we can't */ if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, OLD_SHORTCUTS_KEY, NULL)) { priv->actions = ACTIONS_XAYATANA; + g_warning("Desktop file '%s' is using a depracted format for it's actions that will be dropped soon.", g_value_get_string(value)); } if (priv->actions == ACTIONS_NONE) { -- cgit v1.2.3 From 8c71262d7f91064d34c9a8976c7ad2dde47fca6f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Feb 2012 15:03:43 -0600 Subject: Update test desktop file --- tests/test-well-formed.desktop | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test-well-formed.desktop b/tests/test-well-formed.desktop index 84e2e02..be20f8f 100644 --- a/tests/test-well-formed.desktop +++ b/tests/test-well-formed.desktop @@ -2,23 +2,23 @@ Name=My Application Exec=ls NotShowIn=Germany -X-Ayatana-Desktop-Shortcuts=bob;alvin;jim;touch +Actions=bob;alvin;jim;touch -[bob Shortcut Group] +[Desktop Action bob] Name=bob's shortcut Exec=ls bob -[alvin Shortcut Group] +[Desktop Action alvin] Name=alvin's shortcut Exec=ls alvin OnlyShowIn=France -[jim Shortcut Group] +[Desktop Action jim] Name=Jim's shortcut Exec=ls jim NotShowIn=France -[touch Shortcut Group] +[Desktop Action touch] Name=Touch Test Exec=touch test-desktop-shortcuts-touch-test OnlyShowIn=TouchTest -- cgit v1.2.3 From f6d6509200a393e1f855fc442363792439cd0ebe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Feb 2012 15:05:40 -0600 Subject: Handling the different group names when getting the name as well --- libindicator/indicator-desktop-shortcuts.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index f684905..55998d0 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -503,7 +503,21 @@ indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, cons g_return_val_if_fail(priv->keyfile != NULL, NULL); g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), NULL); - gchar * groupheader = g_strdup_printf("%s " OLD_GROUP_SUFFIX, nick); + const gchar * group_format = NULL; + + switch (priv->actions) { + case ACTIONS_XAYATANA: + group_format = "%s " OLD_GROUP_SUFFIX; + break; + case ACTIONS_DESKTOP_SPEC: + group_format = ACTION_GROUP_PREFIX " %s"; + break; + default: + g_assert_not_reached(); + return NULL; + } + + gchar * groupheader = g_strdup_printf(group_format, nick); if (!g_key_file_has_group(priv->keyfile, groupheader)) { g_warning("The group for nick '%s' doesn't exist anymore.", nick); g_free(groupheader); -- cgit v1.2.3 From a69f559acd97f91614397479ea6fdd6240620cd5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Feb 2012 15:08:19 -0600 Subject: Get the right group in exec too! --- libindicator/indicator-desktop-shortcuts.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 55998d0..13c1667 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -578,7 +578,21 @@ indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gc g_return_val_if_fail(priv->keyfile != NULL, FALSE); g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), FALSE); - gchar * groupheader = g_strdup_printf("%s " OLD_GROUP_SUFFIX, nick); + const gchar * group_format = NULL; + + switch (priv->actions) { + case ACTIONS_XAYATANA: + group_format = "%s " OLD_GROUP_SUFFIX; + break; + case ACTIONS_DESKTOP_SPEC: + group_format = ACTION_GROUP_PREFIX " %s"; + break; + default: + g_assert_not_reached(); + return FALSE; + } + + gchar * groupheader = g_strdup_printf(group_format, nick); if (!g_key_file_has_group(priv->keyfile, groupheader)) { g_warning("The group for nick '%s' doesn't exist anymore.", nick); g_free(groupheader); -- cgit v1.2.3