~ubuntu-branches/ubuntu/utopic/upstart-app-launch/utopic-proposed

« back to all changes in this revision

Viewing changes to desktop-exec.c

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Ted Gould, Ubuntu daily release
  • Date: 2013-09-19 22:04:58 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20130919220458-bpate85dqjhw4nxb
Tags: 0.1+13.10.20130919.4-0ubuntu1
[ Ted Gould ]
* Support a desktop file key so legacy applications can be single
  instance.

[ Ubuntu daily release ]
* Automatic snapshot from revision 60

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "helpers.h"
26
26
 
27
 
gboolean verify_keyfile (GKeyFile * inkeyfile, const gchar * desktop);
28
 
 
29
 
/* Try to find a desktop file in a particular data directory */
30
 
GKeyFile *
31
 
try_dir (const char * dir, const gchar * desktop)
32
 
{
33
 
        gchar * fullpath = g_build_filename(dir, "applications", desktop, NULL);
34
 
        GKeyFile * keyfile = g_key_file_new();
35
 
 
36
 
        /* NOTE: Leaving off the error here as we'll get a bunch of them,
37
 
           so individuals aren't really useful */
38
 
        gboolean loaded = g_key_file_load_from_file(keyfile, fullpath, G_KEY_FILE_NONE, NULL);
39
 
 
40
 
        g_free(fullpath);
41
 
 
42
 
        if (!loaded) {
43
 
                g_key_file_free(keyfile);
44
 
                return NULL;
45
 
        }
46
 
 
47
 
        if (!verify_keyfile(keyfile, desktop)) {
48
 
                g_key_file_free(keyfile);
49
 
                return NULL;
50
 
        }
51
 
 
52
 
        return keyfile;
53
 
}
54
 
 
55
 
/* Check to make sure we have the sections and keys we want */
56
 
gboolean
57
 
verify_keyfile (GKeyFile * inkeyfile, const gchar * desktop)
58
 
{
59
 
        if (inkeyfile == NULL) return FALSE;
60
 
 
61
 
        if (!g_key_file_has_group(inkeyfile, "Desktop Entry")) {
62
 
                g_warning("Desktop file '%s' is missing the 'Desktop Entry' group", desktop);
63
 
                return FALSE;
64
 
        }
65
 
 
66
 
        if (!g_key_file_has_key(inkeyfile, "Desktop Entry", "Exec", NULL)) {
67
 
                g_warning("Desktop file '%s' is missing the 'Exec' key", desktop);
68
 
                return FALSE;
69
 
        }
70
 
 
71
 
        return TRUE;
72
 
}
73
 
 
74
27
int
75
28
main (int argc, char * argv[])
76
29
{
79
32
                return 1;
80
33
        }
81
34
 
82
 
        gchar * desktop = g_strdup_printf("%s.desktop", argv[1]);
83
 
 
84
 
        const char * const * data_dirs = g_get_system_data_dirs();
85
 
        GKeyFile * keyfile = NULL;
86
 
        int i;
87
 
 
88
 
        keyfile = try_dir(g_get_user_data_dir(), desktop);
89
 
 
90
 
        for (i = 0; data_dirs[i] != NULL && keyfile == NULL; i++) {
91
 
                keyfile = try_dir(data_dirs[i], desktop);
92
 
        }
 
35
        GKeyFile * keyfile = keyfile_for_appid(argv[1]);
93
36
 
94
37
        if (keyfile == NULL) {
95
38
                g_error("Unable to find keyfile for application '%s'", argv[0]);
113
56
        set_upstart_variable("APP_EXEC", execline);
114
57
 
115
58
        g_key_file_free(keyfile);
116
 
        g_free(desktop);
117
59
        g_free(execline);
118
60
 
119
61
        return 0;