2
* Copyright 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Ted Gould <ted.gould@canonical.com>
22
/* Check to make sure we have the sections and keys we want */
24
verify_keyfile (GKeyFile * inkeyfile, const gchar * desktop)
26
if (inkeyfile == NULL) return FALSE;
28
if (!g_key_file_has_group(inkeyfile, "Desktop Entry")) {
29
g_warning("Desktop file '%s' is missing the 'Desktop Entry' group", desktop);
33
if (!g_key_file_has_key(inkeyfile, "Desktop Entry", "Exec", NULL)) {
34
g_warning("Desktop file '%s' is missing the 'Exec' key", desktop);
41
/* Try to find a desktop file in a particular data directory */
43
try_dir (const char * dir, const gchar * desktop)
45
gchar * fullpath = g_build_filename(dir, "applications", desktop, NULL);
46
GKeyFile * keyfile = g_key_file_new();
48
/* NOTE: Leaving off the error here as we'll get a bunch of them,
49
so individuals aren't really useful */
50
gboolean loaded = g_key_file_load_from_file(keyfile, fullpath, G_KEY_FILE_NONE, NULL);
55
g_key_file_free(keyfile);
59
if (!verify_keyfile(keyfile, desktop)) {
60
g_key_file_free(keyfile);
67
/* Find the keyfile that we need for a particular AppID and return it.
68
Or NULL if we can't find it. */
70
keyfile_for_appid (const gchar * appid, gchar ** desktopfile)
72
gchar * desktop = g_strdup_printf("%s.desktop", appid);
74
const char * const * data_dirs = g_get_system_data_dirs();
75
GKeyFile * keyfile = NULL;
78
keyfile = try_dir(g_get_user_data_dir(), desktop);
79
if (keyfile != NULL && desktopfile != NULL && *desktopfile == NULL) {
80
*desktopfile = g_build_filename(g_get_user_data_dir(), "applications", desktop, NULL);
83
for (i = 0; data_dirs[i] != NULL && keyfile == NULL; i++) {
84
keyfile = try_dir(data_dirs[i], desktop);
86
if (keyfile != NULL && desktopfile != NULL && *desktopfile == NULL) {
87
*desktopfile = g_build_filename(data_dirs[i], "applications", desktop, NULL);