Merge lp:~ted/ubuntu-app-launch/triplet-app-name into lp:ubuntu-app-launch/14.04

Proposed by Ted Gould
Status: Merged
Approved by: Charles Kerr
Approved revision: 117
Merged at revision: 108
Proposed branch: lp:~ted/ubuntu-app-launch/triplet-app-name
Merge into: lp:ubuntu-app-launch/14.04
Diff against target: 229 lines (+151/-21)
4 files modified
libupstart-app-launch/upstart-app-launch.c (+96/-14)
libupstart-app-launch/upstart-app-launch.h (+13/-5)
tests/click-app-dir/.click/info/com.test.multiple.manifest (+20/-0)
tests/libual-test.cc (+22/-2)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/triplet-app-name
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+203658@code.launchpad.net

Commit message

Add application list handling to the triplet function

Description of the change

This brings the triplet function here up to parity with the URL dispatcher one so that URL dispatcher can depend on this function.

To post a comment you must log in.
117. By Ted Gould

Add documentation for application listing

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

So you're migrating the code from url-dispatcher to upstart-app-launch so that both can use the same implementation instead of reinventing the wheel? Nice job.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libupstart-app-launch/upstart-app-launch.c'
2--- libupstart-app-launch/upstart-app-launch.c 2014-01-14 20:52:13 +0000
3+++ libupstart-app-launch/upstart-app-launch.c 2014-01-29 02:34:09 +0000
4@@ -698,7 +698,7 @@
5 }
6
7 /* Try and get a manifest file and do a couple sanity checks on it */
8-JsonParser *
9+static JsonParser *
10 get_manifest_file (const gchar * pkg)
11 {
12 /* Get the directory from click */
13@@ -753,20 +753,88 @@
14 return parser;
15 }
16
17+/* Types of search we can do for an app name */
18+typedef enum _app_name_t app_name_t;
19+enum _app_name_t {
20+ APP_NAME_ONLY,
21+ APP_NAME_FIRST,
22+ APP_NAME_LAST
23+};
24+
25+/* Figure out the app name if it's one of the keywords */
26+static const gchar *
27+manifest_app_name (JsonParser ** manifest, const gchar * pkg, const gchar * original_app)
28+{
29+ app_name_t app_type = APP_NAME_FIRST;
30+
31+ if (original_app == NULL) {
32+ /* first */
33+ } else if (g_strcmp0(original_app, "first-listed-app") == 0) {
34+ /* first */
35+ } else if (g_strcmp0(original_app, "last-listed-app") == 0) {
36+ app_type = APP_NAME_LAST;
37+ } else if (g_strcmp0(original_app, "only-listed-app") == 0) {
38+ app_type = APP_NAME_ONLY;
39+ } else {
40+ return original_app;
41+ }
42+
43+ if (*manifest == NULL) {
44+ *manifest = get_manifest_file(pkg);
45+ }
46+
47+ JsonNode * root_node = json_parser_get_root(*manifest);
48+ JsonObject * root_obj = json_node_get_object(root_node);
49+ JsonObject * hooks = json_object_get_object_member(root_obj, "hooks");
50+
51+ if (hooks == NULL) {
52+ return NULL;
53+ }
54+
55+ GList * apps = json_object_get_members(hooks);
56+ if (apps == NULL) {
57+ return NULL;
58+ }
59+
60+ const gchar * retapp = NULL;
61+
62+ switch (app_type) {
63+ case APP_NAME_ONLY:
64+ if (g_list_length(apps) == 1) {
65+ retapp = (const gchar *)apps->data;
66+ }
67+ break;
68+ case APP_NAME_FIRST:
69+ retapp = (const gchar *)apps->data;
70+ break;
71+ case APP_NAME_LAST:
72+ retapp = (const gchar *)(g_list_last(apps)->data);
73+ break;
74+ default:
75+ break;
76+ }
77+
78+ g_list_free(apps);
79+
80+ return retapp;
81+}
82+
83 /* Figure out the app version using the manifest */
84-gchar *
85-manifest_version (const gchar * pkg, const gchar * original_ver)
86+static const gchar *
87+manifest_version (JsonParser ** manifest, const gchar * pkg, const gchar * original_ver)
88 {
89- if (g_strcmp0(original_ver, "current-user-version") != 0) {
90- return g_strdup(original_ver);
91+ if (original_ver != NULL && g_strcmp0(original_ver, "current-user-version") != 0) {
92+ return original_ver;
93 } else {
94- JsonParser * manifest = get_manifest_file(pkg);
95- g_return_val_if_fail(manifest != NULL, NULL);
96- JsonNode * node = json_parser_get_root(manifest);
97+ if (*manifest == NULL) {
98+ *manifest = get_manifest_file(pkg);
99+ }
100+ g_return_val_if_fail(*manifest != NULL, NULL);
101+
102+ JsonNode * node = json_parser_get_root(*manifest);
103 JsonObject * obj = json_node_get_object(node);
104- gchar * ret = g_strdup(json_object_get_string_member(obj, "version"));
105- g_object_unref(manifest);
106- return ret;
107+
108+ return g_strdup(json_object_get_string_member(obj, "version"));
109 }
110
111 return NULL;
112@@ -775,8 +843,22 @@
113 gchar *
114 upstart_app_launch_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver)
115 {
116- gchar * version = NULL;
117- version = manifest_version(pkg, ver);
118+ g_return_val_if_fail(pkg != NULL, NULL);
119+
120+ const gchar * version = NULL;
121+ const gchar * application = NULL;
122+ JsonParser * manifest = NULL;
123+
124+ version = manifest_version(&manifest, pkg, ver);
125 g_return_val_if_fail(version != NULL, NULL);
126- return g_strdup_printf("%s_%s_%s", pkg, app, version);
127+
128+ application = manifest_app_name(&manifest, pkg, app);
129+ g_return_val_if_fail(application != NULL, NULL);
130+
131+ gchar * retval = g_strdup_printf("%s_%s_%s", pkg, application, version);
132+
133+ /* The parser may hold allocation for some of our strings used above */
134+ g_clear_object(&manifest);
135+
136+ return retval;
137 }
138
139=== modified file 'libupstart-app-launch/upstart-app-launch.h'
140--- libupstart-app-launch/upstart-app-launch.h 2014-01-13 15:16:24 +0000
141+++ libupstart-app-launch/upstart-app-launch.h 2014-01-29 02:34:09 +0000
142@@ -274,13 +274,21 @@
143 /**
144 * upstart_app_launch_triplet_to_app_id:
145 * @pkg: Click package name
146- * @app: Application name
147- * @version: Specific version or "current-user-version"
148- *
149- * Constructs an appid from pkg, app, version triple.
150+ * @app: (allow-none): Application name, see description
151+ * @version: (allow-none): Specific version or wildcard, see description
152+ *
153+ * Constructs an appid from pkg, app, version triple. Wildcards are allowed
154+ * for the @app and @version parameters.
155+ *
156+ * For the @app parameter the wildcards * "first-listed-app", "last-listed-app"
157+ * and "only-listed-app" can be used. A NULL value will default to the
158+ * first listed app.
159+ *
160+ * For the @version parameter only one wildcard is allowed, "current-user-version".
161+ * If NULL is passed that is the default.
162 *
163 * Return Value: Either the properly constructed @appid or NULL if it failed
164- * to find the version installed.
165+ * to construct it.
166 */
167 gchar * upstart_app_launch_triplet_to_app_id (const gchar * pkg,
168 const gchar * app,
169
170=== added file 'tests/click-app-dir/.click/info/com.test.multiple.manifest'
171--- tests/click-app-dir/.click/info/com.test.multiple.manifest 1970-01-01 00:00:00 +0000
172+++ tests/click-app-dir/.click/info/com.test.multiple.manifest 2014-01-29 02:34:09 +0000
173@@ -0,0 +1,20 @@
174+{
175+ "version": "1.2.3",
176+ "hooks": {
177+ "first": {
178+ "desktop": "application.desktop"
179+ },
180+ "second": {
181+ "desktop": "application.desktop"
182+ },
183+ "third": {
184+ "desktop": "application.desktop"
185+ },
186+ "fourth": {
187+ "desktop": "application.desktop"
188+ },
189+ "fifth": {
190+ "desktop": "application.desktop"
191+ }
192+ }
193+}
194
195=== modified file 'tests/libual-test.cc'
196--- tests/libual-test.cc 2014-01-14 18:03:03 +0000
197+++ tests/libual-test.cc 2014-01-29 02:34:09 +0000
198@@ -288,9 +288,29 @@
199 TEST_F(LibUAL, ApplicationId)
200 {
201 /* Test with current-user-version, should return the version in the manifest */
202- ASSERT_STREQ(upstart_app_launch_triplet_to_app_id("com.test.good", "application", "current-user-version"), "com.test.good_application_1.2.3");
203+ EXPECT_STREQ("com.test.good_application_1.2.3", upstart_app_launch_triplet_to_app_id("com.test.good", "application", "current-user-version"));
204+
205 /* Test with version specified, shouldn't even read the manifest */
206- ASSERT_STREQ(upstart_app_launch_triplet_to_app_id("com.test.good", "application", "1.2.4"), "com.test.good_application_1.2.4");
207+ EXPECT_STREQ("com.test.good_application_1.2.4", upstart_app_launch_triplet_to_app_id("com.test.good", "application", "1.2.4"));
208+
209+ /* Test with out a version or app, should return the version in the manifest */
210+ EXPECT_STREQ("com.test.good_application_1.2.3", upstart_app_launch_triplet_to_app_id("com.test.good", "first-listed-app", "current-user-version"));
211+
212+ /* Test with a version or but wildcard app, should return the version in the manifest */
213+ EXPECT_STREQ("com.test.good_application_1.2.4", upstart_app_launch_triplet_to_app_id("com.test.good", "last-listed-app", "1.2.4"));
214+
215+ /* Make sure we can select the app from a list correctly */
216+ EXPECT_STREQ("com.test.multiple_first_1.2.3", upstart_app_launch_triplet_to_app_id("com.test.multiple", "first-listed-app", NULL));
217+ EXPECT_STREQ("com.test.multiple_first_1.2.3", upstart_app_launch_triplet_to_app_id("com.test.multiple", NULL, NULL));
218+ EXPECT_STREQ("com.test.multiple_fifth_1.2.3", upstart_app_launch_triplet_to_app_id("com.test.multiple", "last-listed-app", NULL));
219+ EXPECT_EQ(nullptr, upstart_app_launch_triplet_to_app_id("com.test.multiple", "only-listed-app", NULL));
220+ EXPECT_STREQ("com.test.good_application_1.2.3", upstart_app_launch_triplet_to_app_id("com.test.good", "only-listed-app", NULL));
221+
222+ /* A bunch that should be NULL */
223+ EXPECT_EQ(nullptr, upstart_app_launch_triplet_to_app_id("com.test.no-hooks", NULL, NULL));
224+ EXPECT_EQ(nullptr, upstart_app_launch_triplet_to_app_id("com.test.no-json", NULL, NULL));
225+ EXPECT_EQ(nullptr, upstart_app_launch_triplet_to_app_id("com.test.no-object", NULL, NULL));
226+ EXPECT_EQ(nullptr, upstart_app_launch_triplet_to_app_id("com.test.no-version", NULL, NULL));
227 }
228
229 TEST_F(LibUAL, ApplicationList)

Subscribers

People subscribed via source and target branches