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
1=== modified file 'libindicator/indicator-desktop-shortcuts.c'
2--- libindicator/indicator-desktop-shortcuts.c 2012-02-09 13:05:55 +0000
3+++ libindicator/indicator-desktop-shortcuts.c 2012-02-27 21:23:20 +0000
4@@ -28,15 +28,26 @@
5 #include <gio/gdesktopappinfo.h>
6 #include "indicator-desktop-shortcuts.h"
7
8-#define GROUP_SUFFIX "Shortcut Group"
9-#define SHORTCUTS_KEY "X-Ayatana-Desktop-Shortcuts"
10-#define ENVIRON_KEY "TargetEnvironment"
11+#define ACTIONS_KEY "Actions"
12+#define ACTION_GROUP_PREFIX "Desktop Action"
13+
14+#define OLD_GROUP_SUFFIX "Shortcut Group"
15+#define OLD_SHORTCUTS_KEY "X-Ayatana-Desktop-Shortcuts"
16+#define OLD_ENVIRON_KEY "TargetEnvironment"
17
18 #define PROP_DESKTOP_FILE_S "desktop-file"
19 #define PROP_IDENTITY_S "identity"
20
21+typedef enum _actions_t actions_t;
22+enum _actions_t {
23+ ACTIONS_NONE,
24+ ACTIONS_XAYATANA,
25+ ACTIONS_DESKTOP_SPEC
26+};
27+
28 typedef struct _IndicatorDesktopShortcutsPrivate IndicatorDesktopShortcutsPrivate;
29 struct _IndicatorDesktopShortcutsPrivate {
30+ actions_t actions;
31 GKeyFile * keyfile;
32 gchar * identity;
33 GArray * nicks;
34@@ -104,6 +115,7 @@
35 priv->identity = NULL;
36 priv->domain = NULL;
37 priv->nicks = g_array_new(TRUE, TRUE, sizeof(gchar *));
38+ priv->actions = ACTIONS_NONE;
39
40 return;
41 }
42@@ -162,6 +174,12 @@
43
44 switch(prop_id) {
45 case PROP_DESKTOP_FILE: {
46+ if (priv->keyfile != NULL) {
47+ g_key_file_free(priv->keyfile);
48+ priv->keyfile = NULL;
49+ priv->actions = ACTIONS_NONE;
50+ }
51+
52 GError * error = NULL;
53 GKeyFile * keyfile = g_key_file_new();
54 g_key_file_load_from_file(keyfile, g_value_get_string(value), G_KEY_FILE_NONE, &error);
55@@ -173,7 +191,18 @@
56 break;
57 }
58
59- if (!g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, SHORTCUTS_KEY, NULL)) {
60+ /* Always prefer the desktop spec if we can get it */
61+ if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, ACTIONS_KEY, NULL)) {
62+ priv->actions = ACTIONS_DESKTOP_SPEC;
63+ }
64+
65+ /* But fallback if we can't */
66+ if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, OLD_SHORTCUTS_KEY, NULL)) {
67+ priv->actions = ACTIONS_XAYATANA;
68+ g_warning("Desktop file '%s' is using a depracted format for it's actions that will be dropped soon.", g_value_get_string(value));
69+ }
70+
71+ if (priv->actions == ACTIONS_NONE) {
72 g_key_file_free(keyfile);
73 break;
74 }
75@@ -253,16 +282,41 @@
76 priv->domain = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-Ubuntu-Gettext-Domain", NULL);
77 }
78
79+ /* We need to figure out what we're looking for and what we want to
80+ look for in the rest of the file */
81+ const gchar * list_name = NULL;
82+ const gchar * group_format = NULL;
83+ gboolean should_have_target = FALSE;
84+
85+ switch (priv->actions) {
86+ case ACTIONS_NONE:
87+ /* None, let's just get outta here */
88+ return;
89+ case ACTIONS_XAYATANA:
90+ list_name = OLD_SHORTCUTS_KEY;
91+ group_format = "%s " OLD_GROUP_SUFFIX;
92+ should_have_target = TRUE;
93+ break;
94+ case ACTIONS_DESKTOP_SPEC:
95+ list_name = ACTIONS_KEY;
96+ group_format = ACTION_GROUP_PREFIX " %s";
97+ should_have_target = FALSE;
98+ break;
99+ default:
100+ g_assert_not_reached();
101+ return;
102+ }
103+
104 /* Okay, we've got everything we need. Let's get it on! */
105 gint i;
106 gsize num_nicks = 0;
107- gchar ** nicks = g_key_file_get_string_list(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, SHORTCUTS_KEY, &num_nicks, NULL);
108+ gchar ** nicks = g_key_file_get_string_list(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, list_name, &num_nicks, NULL);
109
110 /* If there is an error from get_string_list num_nicks should still
111 be zero, so this loop will drop out. */
112 for (i = 0; i < num_nicks; i++) {
113 /* g_debug("Looking at group nick %s", nicks[i]); */
114- gchar * groupname = g_strdup_printf("%s " GROUP_SUFFIX, nicks[i]);
115+ gchar * groupname = g_strdup_printf(group_format, nicks[i]);
116 if (!g_key_file_has_group(priv->keyfile, groupname)) {
117 g_warning("Unable to find group '%s'", groupname);
118 g_free(groupname);
119@@ -274,7 +328,7 @@
120 continue;
121 }
122
123- if (!should_show(priv->keyfile, groupname, priv->identity, TRUE)) {
124+ if (!should_show(priv->keyfile, groupname, priv->identity, should_have_target)) {
125 g_free(groupname);
126 continue;
127 }
128@@ -296,12 +350,12 @@
129 static gboolean
130 should_show (GKeyFile * keyfile, const gchar * group, const gchar * identity, gboolean should_have_target)
131 {
132- if (should_have_target && g_key_file_has_key(keyfile, group, ENVIRON_KEY, NULL)) {
133+ if (should_have_target && g_key_file_has_key(keyfile, group, OLD_ENVIRON_KEY, NULL)) {
134 /* If we've got this key, we're going to return here and not
135 process the deprecated keys. */
136 gint j;
137 gsize num_env = 0;
138- gchar ** envs = g_key_file_get_string_list(keyfile, group, ENVIRON_KEY, &num_env, NULL);
139+ gchar ** envs = g_key_file_get_string_list(keyfile, group, OLD_ENVIRON_KEY, &num_env, NULL);
140
141 for (j = 0; j < num_env; j++) {
142 if (g_strcmp0(envs[j], identity) == 0) {
143@@ -317,10 +371,6 @@
144 return FALSE;
145 }
146 return TRUE;
147- } else {
148- if (should_have_target) {
149- 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 "'.");
150- }
151 }
152
153 /* If there is a list of OnlyShowIn entries we need to check
154@@ -449,10 +499,25 @@
155 g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), NULL);
156 IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids);
157
158+ g_return_val_if_fail(priv->actions != ACTIONS_NONE, NULL);
159 g_return_val_if_fail(priv->keyfile != NULL, NULL);
160 g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), NULL);
161
162- gchar * groupheader = g_strdup_printf("%s " GROUP_SUFFIX, nick);
163+ const gchar * group_format = NULL;
164+
165+ switch (priv->actions) {
166+ case ACTIONS_XAYATANA:
167+ group_format = "%s " OLD_GROUP_SUFFIX;
168+ break;
169+ case ACTIONS_DESKTOP_SPEC:
170+ group_format = ACTION_GROUP_PREFIX " %s";
171+ break;
172+ default:
173+ g_assert_not_reached();
174+ return NULL;
175+ }
176+
177+ gchar * groupheader = g_strdup_printf(group_format, nick);
178 if (!g_key_file_has_group(priv->keyfile, groupheader)) {
179 g_warning("The group for nick '%s' doesn't exist anymore.", nick);
180 g_free(groupheader);
181@@ -509,10 +574,25 @@
182 g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE);
183 IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids);
184
185+ g_return_val_if_fail(priv->actions != ACTIONS_NONE, FALSE);
186 g_return_val_if_fail(priv->keyfile != NULL, FALSE);
187 g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), FALSE);
188
189- gchar * groupheader = g_strdup_printf("%s " GROUP_SUFFIX, nick);
190+ const gchar * group_format = NULL;
191+
192+ switch (priv->actions) {
193+ case ACTIONS_XAYATANA:
194+ group_format = "%s " OLD_GROUP_SUFFIX;
195+ break;
196+ case ACTIONS_DESKTOP_SPEC:
197+ group_format = ACTION_GROUP_PREFIX " %s";
198+ break;
199+ default:
200+ g_assert_not_reached();
201+ return FALSE;
202+ }
203+
204+ gchar * groupheader = g_strdup_printf(group_format, nick);
205 if (!g_key_file_has_group(priv->keyfile, groupheader)) {
206 g_warning("The group for nick '%s' doesn't exist anymore.", nick);
207 g_free(groupheader);
208
209=== modified file 'tests/test-well-formed.desktop'
210--- tests/test-well-formed.desktop 2010-02-17 03:40:50 +0000
211+++ tests/test-well-formed.desktop 2012-02-27 21:23:20 +0000
212@@ -2,23 +2,23 @@
213 Name=My Application
214 Exec=ls
215 NotShowIn=Germany
216-X-Ayatana-Desktop-Shortcuts=bob;alvin;jim;touch
217+Actions=bob;alvin;jim;touch
218
219-[bob Shortcut Group]
220+[Desktop Action bob]
221 Name=bob's shortcut
222 Exec=ls bob
223
224-[alvin Shortcut Group]
225+[Desktop Action alvin]
226 Name=alvin's shortcut
227 Exec=ls alvin
228 OnlyShowIn=France
229
230-[jim Shortcut Group]
231+[Desktop Action jim]
232 Name=Jim's shortcut
233 Exec=ls jim
234 NotShowIn=France
235
236-[touch Shortcut Group]
237+[Desktop Action touch]
238 Name=Touch Test
239 Exec=touch test-desktop-shortcuts-touch-test
240 OnlyShowIn=TouchTest

Subscribers

People subscribed via source and target branches