~ci-train-bot/ubuntu-app-launch/ubuntu-app-launch-ubuntu-xenial-landing-058

« back to all changes in this revision

Viewing changes to libubuntu-app-launch/app-info.c

  • Committer: CI Train Bot
  • Author(s): Ted Gould
  • Date: 2015-08-17 21:38:29 UTC
  • mfrom: (191.1.16 libual-desktop-file)
  • Revision ID: ci-train-bot@canonical.com-20150817213829-a146col07xtjd689
Provide an API to find the desktop file and directory of an AppID
Approved by: Renato Araujo Oliveira Filho

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "app-info.h"
25
25
 
26
26
/* Try and get a manifest and do a couple sanity checks on it */
27
 
static JsonObject *
28
 
get_manifest (const gchar * pkg)
 
27
JsonObject *
 
28
get_manifest (const gchar * pkg, gchar ** pkgpath)
29
29
{
30
30
        /* Get the directory from click */
31
31
        GError * error = NULL;
55
55
                g_object_unref(user);
56
56
                return NULL;
57
57
        }
 
58
 
 
59
        if (pkgpath != NULL) {
 
60
                *pkgpath = click_user_get_path(user, pkg, &error);
 
61
                if (error != NULL) {
 
62
                        g_warning("Unable to get the Click package directory for %s: %s", pkg, error->message);
 
63
                        g_error_free(error);
 
64
                        g_object_unref(user);
 
65
                        return NULL;
 
66
                }
 
67
        }
58
68
        g_object_unref(user);
59
69
 
60
70
        if (!json_object_has_member(manifest, "version")) {
93
103
        }
94
104
 
95
105
        if (*manifest == NULL) {
96
 
                *manifest = get_manifest(pkg);
 
106
                *manifest = get_manifest(pkg, NULL);
97
107
        }
98
108
 
99
109
        JsonObject * hooks = json_object_get_object_member(*manifest, "hooks");
138
148
                return original_ver;
139
149
        } else  {
140
150
                if (*manifest == NULL) {
141
 
                        *manifest = get_manifest(pkg);
 
151
                        *manifest = get_manifest(pkg, NULL);
142
152
                }
143
153
                g_return_val_if_fail(*manifest != NULL, NULL);
144
154
 
190
200
        }
191
201
}
192
202
 
 
203
/* Look to see if the app id results in a desktop file, if so, fill in the params */
 
204
static gboolean
 
205
evaluate_dir (const gchar * dir, const gchar * desktop, gchar ** appdir, gchar ** appdesktop)
 
206
{
 
207
        char * fulldir = g_build_filename(dir, "applications", desktop, NULL);
 
208
        gboolean found = FALSE;
 
209
 
 
210
        if (g_file_test(fulldir, G_FILE_TEST_EXISTS)) {
 
211
                if (appdir != NULL) {
 
212
                        *appdir = g_strdup(dir);
 
213
                }
 
214
 
 
215
                if (appdesktop != NULL) {
 
216
                        *appdesktop = g_strdup_printf("applications/%s", desktop);
 
217
                }
 
218
 
 
219
                found = TRUE;
 
220
        }
 
221
 
 
222
        g_free(fulldir);
 
223
        return found;
 
224
}
 
225
 
 
226
/* Handle the legacy case where we look through the data directories */
 
227
gboolean
 
228
app_info_legacy (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
 
229
{
 
230
        gchar * desktop = g_strdup_printf("%s.desktop", appid);
 
231
 
 
232
        /* Special case the user's dir */
 
233
        if (evaluate_dir(g_get_user_data_dir(), desktop, appdir, appdesktop)) {
 
234
                g_free(desktop);
 
235
                return TRUE;
 
236
        }
 
237
 
 
238
        const char * const * data_dirs = g_get_system_data_dirs();
 
239
        int i;
 
240
        for (i = 0; data_dirs[i] != NULL; i++) {
 
241
                if (evaluate_dir(data_dirs[i], desktop, appdir, appdesktop)) {
 
242
                        g_free(desktop);
 
243
                        return TRUE;
 
244
                }
 
245
        }
 
246
 
 
247
        return FALSE;
 
248
}
 
249
 
193
250
/* Handle the libertine case where we look in the container */
194
251
gboolean
195
252
app_info_libertine (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
225
282
                }
226
283
        }
227
284
 
 
285
        if (appdir != NULL) {
 
286
                *appdir = desktopdir;
 
287
        } else {
 
288
                g_free(desktopdir);
 
289
        }
 
290
 
 
291
        if (appdesktop != NULL) {
 
292
                *appdesktop = g_build_filename("applications", desktopname, NULL);
 
293
        }
 
294
 
 
295
        g_free(desktopfile);
228
296
        g_free(desktopname);
229
297
        g_free(container);
230
298
        g_free(app);
231
299
 
232
 
        if (appdir != NULL) {
233
 
                *appdir = desktopdir;
234
 
        } else {
235
 
                g_free(desktopdir);
236
 
        }
 
300
        return TRUE;
 
301
}
 
302
 
 
303
/* Get the information on where the desktop file is from libclick */
 
304
gboolean
 
305
app_info_click (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
 
306
{
 
307
        gchar * package = NULL;
 
308
        gchar * application = NULL;
 
309
 
 
310
        if (!ubuntu_app_launch_app_id_parse(appid, &package, &application, NULL)) {
 
311
                return FALSE;
 
312
        }
 
313
 
 
314
        JsonObject * manifest = get_manifest(package, appdir);
 
315
        if (manifest == NULL) {
 
316
                g_free(package);
 
317
                g_free(application);
 
318
                return FALSE;
 
319
        }
 
320
 
 
321
        g_free(package);
237
322
 
238
323
        if (appdesktop != NULL) {
239
 
                *appdesktop = desktopfile;
 
324
                JsonObject * hooks = json_object_get_object_member(manifest, "hooks");
 
325
                if (hooks == NULL) {
 
326
                        json_object_unref(manifest);
 
327
                        g_free(application);
 
328
                        return FALSE;
 
329
                }
 
330
 
 
331
                JsonObject * appobj = json_object_get_object_member(hooks, application);
 
332
                g_free(application);
 
333
 
 
334
                if (appobj == NULL) {
 
335
                        json_object_unref(manifest);
 
336
                        return FALSE;
 
337
                }
 
338
 
 
339
                const gchar * desktop = json_object_get_string_member(appobj, "desktop");
 
340
                if (desktop == NULL) {
 
341
                        json_object_unref(manifest);
 
342
                        return FALSE;
 
343
                }
 
344
 
 
345
                *appdesktop = g_strdup(desktop);
240
346
        } else {
241
 
                g_free(desktopfile);
 
347
                g_free(application);
242
348
        }
243
349
 
 
350
        json_object_unref(manifest);
 
351
 
244
352
        return TRUE;
245
353
}
 
354