Merge lp:~ted/libindicator/lp942042 into lp:libindicator/0.5

Proposed by Ted Gould on 2012-02-27
Status: Merged
Merged at revision: 454
Proposed branch: lp:~ted/libindicator/lp942042
Merge into: lp:libindicator/0.5
Diff against target: 240 lines (+100/-20)
2 files modified
libindicator/indicator-desktop-shortcuts.c (+95/-15)
tests/test-well-formed.desktop (+5/-5)
To merge this branch: bzr merge lp:~ted/libindicator/lp942042
Reviewer Review Type Date Requested Status
Conor Curran (community) 2012-02-27 Approve on 2012-03-02
Review via email: mp+94853@code.launchpad.net

Description of the change

Adds support for the new desktop file entry for actions instead of the legacy X-Ayatana- stuff

To post a comment you must log in.
Conor Curran (cjcurran) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libindicator/indicator-desktop-shortcuts.c'
--- libindicator/indicator-desktop-shortcuts.c 2012-02-09 13:05:55 +0000
+++ libindicator/indicator-desktop-shortcuts.c 2012-02-27 21:23:20 +0000
@@ -28,15 +28,26 @@
28#include <gio/gdesktopappinfo.h>28#include <gio/gdesktopappinfo.h>
29#include "indicator-desktop-shortcuts.h"29#include "indicator-desktop-shortcuts.h"
3030
31#define GROUP_SUFFIX "Shortcut Group"31#define ACTIONS_KEY "Actions"
32#define SHORTCUTS_KEY "X-Ayatana-Desktop-Shortcuts"32#define ACTION_GROUP_PREFIX "Desktop Action"
33#define ENVIRON_KEY "TargetEnvironment"33
34#define OLD_GROUP_SUFFIX "Shortcut Group"
35#define OLD_SHORTCUTS_KEY "X-Ayatana-Desktop-Shortcuts"
36#define OLD_ENVIRON_KEY "TargetEnvironment"
3437
35#define PROP_DESKTOP_FILE_S "desktop-file"38#define PROP_DESKTOP_FILE_S "desktop-file"
36#define PROP_IDENTITY_S "identity"39#define PROP_IDENTITY_S "identity"
3740
41typedef enum _actions_t actions_t;
42enum _actions_t {
43 ACTIONS_NONE,
44 ACTIONS_XAYATANA,
45 ACTIONS_DESKTOP_SPEC
46};
47
38typedef struct _IndicatorDesktopShortcutsPrivate IndicatorDesktopShortcutsPrivate;48typedef struct _IndicatorDesktopShortcutsPrivate IndicatorDesktopShortcutsPrivate;
39struct _IndicatorDesktopShortcutsPrivate {49struct _IndicatorDesktopShortcutsPrivate {
50 actions_t actions;
40 GKeyFile * keyfile;51 GKeyFile * keyfile;
41 gchar * identity;52 gchar * identity;
42 GArray * nicks;53 GArray * nicks;
@@ -104,6 +115,7 @@
104 priv->identity = NULL;115 priv->identity = NULL;
105 priv->domain = NULL;116 priv->domain = NULL;
106 priv->nicks = g_array_new(TRUE, TRUE, sizeof(gchar *));117 priv->nicks = g_array_new(TRUE, TRUE, sizeof(gchar *));
118 priv->actions = ACTIONS_NONE;
107119
108 return;120 return;
109}121}
@@ -162,6 +174,12 @@
162174
163 switch(prop_id) {175 switch(prop_id) {
164 case PROP_DESKTOP_FILE: {176 case PROP_DESKTOP_FILE: {
177 if (priv->keyfile != NULL) {
178 g_key_file_free(priv->keyfile);
179 priv->keyfile = NULL;
180 priv->actions = ACTIONS_NONE;
181 }
182
165 GError * error = NULL;183 GError * error = NULL;
166 GKeyFile * keyfile = g_key_file_new();184 GKeyFile * keyfile = g_key_file_new();
167 g_key_file_load_from_file(keyfile, g_value_get_string(value), G_KEY_FILE_NONE, &error);185 g_key_file_load_from_file(keyfile, g_value_get_string(value), G_KEY_FILE_NONE, &error);
@@ -173,7 +191,18 @@
173 break;191 break;
174 }192 }
175193
176 if (!g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, SHORTCUTS_KEY, NULL)) {194 /* Always prefer the desktop spec if we can get it */
195 if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, ACTIONS_KEY, NULL)) {
196 priv->actions = ACTIONS_DESKTOP_SPEC;
197 }
198
199 /* But fallback if we can't */
200 if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, OLD_SHORTCUTS_KEY, NULL)) {
201 priv->actions = ACTIONS_XAYATANA;
202 g_warning("Desktop file '%s' is using a depracted format for it's actions that will be dropped soon.", g_value_get_string(value));
203 }
204
205 if (priv->actions == ACTIONS_NONE) {
177 g_key_file_free(keyfile);206 g_key_file_free(keyfile);
178 break;207 break;
179 }208 }
@@ -253,16 +282,41 @@
253 priv->domain = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-Ubuntu-Gettext-Domain", NULL);282 priv->domain = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-Ubuntu-Gettext-Domain", NULL);
254 }283 }
255284
285 /* We need to figure out what we're looking for and what we want to
286 look for in the rest of the file */
287 const gchar * list_name = NULL;
288 const gchar * group_format = NULL;
289 gboolean should_have_target = FALSE;
290
291 switch (priv->actions) {
292 case ACTIONS_NONE:
293 /* None, let's just get outta here */
294 return;
295 case ACTIONS_XAYATANA:
296 list_name = OLD_SHORTCUTS_KEY;
297 group_format = "%s " OLD_GROUP_SUFFIX;
298 should_have_target = TRUE;
299 break;
300 case ACTIONS_DESKTOP_SPEC:
301 list_name = ACTIONS_KEY;
302 group_format = ACTION_GROUP_PREFIX " %s";
303 should_have_target = FALSE;
304 break;
305 default:
306 g_assert_not_reached();
307 return;
308 }
309
256 /* Okay, we've got everything we need. Let's get it on! */310 /* Okay, we've got everything we need. Let's get it on! */
257 gint i;311 gint i;
258 gsize num_nicks = 0;312 gsize num_nicks = 0;
259 gchar ** nicks = g_key_file_get_string_list(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, SHORTCUTS_KEY, &num_nicks, NULL);313 gchar ** nicks = g_key_file_get_string_list(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, list_name, &num_nicks, NULL);
260314
261 /* If there is an error from get_string_list num_nicks should still315 /* If there is an error from get_string_list num_nicks should still
262 be zero, so this loop will drop out. */316 be zero, so this loop will drop out. */
263 for (i = 0; i < num_nicks; i++) {317 for (i = 0; i < num_nicks; i++) {
264 /* g_debug("Looking at group nick %s", nicks[i]); */318 /* g_debug("Looking at group nick %s", nicks[i]); */
265 gchar * groupname = g_strdup_printf("%s " GROUP_SUFFIX, nicks[i]);319 gchar * groupname = g_strdup_printf(group_format, nicks[i]);
266 if (!g_key_file_has_group(priv->keyfile, groupname)) {320 if (!g_key_file_has_group(priv->keyfile, groupname)) {
267 g_warning("Unable to find group '%s'", groupname);321 g_warning("Unable to find group '%s'", groupname);
268 g_free(groupname);322 g_free(groupname);
@@ -274,7 +328,7 @@
274 continue;328 continue;
275 }329 }
276330
277 if (!should_show(priv->keyfile, groupname, priv->identity, TRUE)) {331 if (!should_show(priv->keyfile, groupname, priv->identity, should_have_target)) {
278 g_free(groupname);332 g_free(groupname);
279 continue;333 continue;
280 }334 }
@@ -296,12 +350,12 @@
296static gboolean350static gboolean
297should_show (GKeyFile * keyfile, const gchar * group, const gchar * identity, gboolean should_have_target)351should_show (GKeyFile * keyfile, const gchar * group, const gchar * identity, gboolean should_have_target)
298{352{
299 if (should_have_target && g_key_file_has_key(keyfile, group, ENVIRON_KEY, NULL)) {353 if (should_have_target && g_key_file_has_key(keyfile, group, OLD_ENVIRON_KEY, NULL)) {
300 /* If we've got this key, we're going to return here and not354 /* If we've got this key, we're going to return here and not
301 process the deprecated keys. */355 process the deprecated keys. */
302 gint j;356 gint j;
303 gsize num_env = 0;357 gsize num_env = 0;
304 gchar ** envs = g_key_file_get_string_list(keyfile, group, ENVIRON_KEY, &num_env, NULL);358 gchar ** envs = g_key_file_get_string_list(keyfile, group, OLD_ENVIRON_KEY, &num_env, NULL);
305359
306 for (j = 0; j < num_env; j++) {360 for (j = 0; j < num_env; j++) {
307 if (g_strcmp0(envs[j], identity) == 0) {361 if (g_strcmp0(envs[j], identity) == 0) {
@@ -317,10 +371,6 @@
317 return FALSE;371 return FALSE;
318 }372 }
319 return TRUE; 373 return TRUE;
320 } else {
321 if (should_have_target) {
322 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 "'.");
323 }
324 }374 }
325375
326 /* If there is a list of OnlyShowIn entries we need to check376 /* If there is a list of OnlyShowIn entries we need to check
@@ -449,10 +499,25 @@
449 g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), NULL);499 g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), NULL);
450 IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids);500 IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids);
451501
502 g_return_val_if_fail(priv->actions != ACTIONS_NONE, NULL);
452 g_return_val_if_fail(priv->keyfile != NULL, NULL);503 g_return_val_if_fail(priv->keyfile != NULL, NULL);
453 g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), NULL);504 g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), NULL);
454505
455 gchar * groupheader = g_strdup_printf("%s " GROUP_SUFFIX, nick);506 const gchar * group_format = NULL;
507
508 switch (priv->actions) {
509 case ACTIONS_XAYATANA:
510 group_format = "%s " OLD_GROUP_SUFFIX;
511 break;
512 case ACTIONS_DESKTOP_SPEC:
513 group_format = ACTION_GROUP_PREFIX " %s";
514 break;
515 default:
516 g_assert_not_reached();
517 return NULL;
518 }
519
520 gchar * groupheader = g_strdup_printf(group_format, nick);
456 if (!g_key_file_has_group(priv->keyfile, groupheader)) {521 if (!g_key_file_has_group(priv->keyfile, groupheader)) {
457 g_warning("The group for nick '%s' doesn't exist anymore.", nick);522 g_warning("The group for nick '%s' doesn't exist anymore.", nick);
458 g_free(groupheader);523 g_free(groupheader);
@@ -509,10 +574,25 @@
509 g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE);574 g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE);
510 IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids);575 IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids);
511576
577 g_return_val_if_fail(priv->actions != ACTIONS_NONE, FALSE);
512 g_return_val_if_fail(priv->keyfile != NULL, FALSE);578 g_return_val_if_fail(priv->keyfile != NULL, FALSE);
513 g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), FALSE);579 g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), FALSE);
514580
515 gchar * groupheader = g_strdup_printf("%s " GROUP_SUFFIX, nick);581 const gchar * group_format = NULL;
582
583 switch (priv->actions) {
584 case ACTIONS_XAYATANA:
585 group_format = "%s " OLD_GROUP_SUFFIX;
586 break;
587 case ACTIONS_DESKTOP_SPEC:
588 group_format = ACTION_GROUP_PREFIX " %s";
589 break;
590 default:
591 g_assert_not_reached();
592 return FALSE;
593 }
594
595 gchar * groupheader = g_strdup_printf(group_format, nick);
516 if (!g_key_file_has_group(priv->keyfile, groupheader)) {596 if (!g_key_file_has_group(priv->keyfile, groupheader)) {
517 g_warning("The group for nick '%s' doesn't exist anymore.", nick);597 g_warning("The group for nick '%s' doesn't exist anymore.", nick);
518 g_free(groupheader);598 g_free(groupheader);
519599
=== modified file 'tests/test-well-formed.desktop'
--- tests/test-well-formed.desktop 2010-02-17 03:40:50 +0000
+++ tests/test-well-formed.desktop 2012-02-27 21:23:20 +0000
@@ -2,23 +2,23 @@
2Name=My Application2Name=My Application
3Exec=ls3Exec=ls
4NotShowIn=Germany4NotShowIn=Germany
5X-Ayatana-Desktop-Shortcuts=bob;alvin;jim;touch5Actions=bob;alvin;jim;touch
66
7[bob Shortcut Group]7[Desktop Action bob]
8Name=bob's shortcut8Name=bob's shortcut
9Exec=ls bob9Exec=ls bob
1010
11[alvin Shortcut Group]11[Desktop Action alvin]
12Name=alvin's shortcut12Name=alvin's shortcut
13Exec=ls alvin13Exec=ls alvin
14OnlyShowIn=France14OnlyShowIn=France
1515
16[jim Shortcut Group]16[Desktop Action jim]
17Name=Jim's shortcut17Name=Jim's shortcut
18Exec=ls jim18Exec=ls jim
19NotShowIn=France19NotShowIn=France
2020
21[touch Shortcut Group]21[Desktop Action touch]
22Name=Touch Test22Name=Touch Test
23Exec=touch test-desktop-shortcuts-touch-test23Exec=touch test-desktop-shortcuts-touch-test
24OnlyShowIn=TouchTest24OnlyShowIn=TouchTest

Subscribers

People subscribed via source and target branches