diff options
author | Christian Persch <chpe@src.gnome.org> | 2008-10-18 05:54:51 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2008-10-18 05:54:51 +0800 |
commit | c4f0f138e21b189ce04cfe07ccbd5184205c8df9 (patch) | |
tree | 3828a447111acba02a1dbd59e0cf9c1c61a7d6f0 /lib/egg/eggdesktopfile.c | |
parent | efbf42491d8a8c99db911be9c20cba68424c0b3f (diff) | |
download | gsoc2013-epiphany-c4f0f138e21b189ce04cfe07ccbd5184205c8df9.tar gsoc2013-epiphany-c4f0f138e21b189ce04cfe07ccbd5184205c8df9.tar.gz gsoc2013-epiphany-c4f0f138e21b189ce04cfe07ccbd5184205c8df9.tar.bz2 gsoc2013-epiphany-c4f0f138e21b189ce04cfe07ccbd5184205c8df9.tar.lz gsoc2013-epiphany-c4f0f138e21b189ce04cfe07ccbd5184205c8df9.tar.xz gsoc2013-epiphany-c4f0f138e21b189ce04cfe07ccbd5184205c8df9.tar.zst gsoc2013-epiphany-c4f0f138e21b189ce04cfe07ccbd5184205c8df9.zip |
Update from libegg
svn path=/trunk/; revision=8584
Diffstat (limited to 'lib/egg/eggdesktopfile.c')
-rw-r--r-- | lib/egg/eggdesktopfile.c | 159 |
1 files changed, 124 insertions, 35 deletions
diff --git a/lib/egg/eggdesktopfile.c b/lib/egg/eggdesktopfile.c index d7b2a039f..e88930597 100644 --- a/lib/egg/eggdesktopfile.c +++ b/lib/egg/eggdesktopfile.c @@ -31,7 +31,6 @@ #include <unistd.h> #include <glib/gi18n.h> -#include <gdk/gdk.h> #include <gdk/gdkx.h> #include <gtk/gtk.h> @@ -56,7 +55,6 @@ struct EggDesktopFile { EggDesktopFile * egg_desktop_file_new (const char *desktop_file_path, GError **error) { - EggDesktopFile *desktop_file; GKeyFile *key_file; key_file = g_key_file_new (); @@ -66,13 +64,8 @@ egg_desktop_file_new (const char *desktop_file_path, GError **error) return NULL; } - desktop_file = egg_desktop_file_new_from_key_file (key_file, - desktop_file_path, - error); - if (!desktop_file) - g_key_file_free (key_file); - - return desktop_file; + return egg_desktop_file_new_from_key_file (key_file, desktop_file_path, + error); } /** @@ -106,9 +99,42 @@ egg_desktop_file_new_from_data_dirs (const char *desktop_file_path, full_path, error); g_free (full_path); - if (!desktop_file) - g_key_file_free (key_file); + return desktop_file; +} +/** + * egg_desktop_file_new_from_dirs: + * @desktop_file_path: relative path to a Freedesktop-style Desktop file + * @search_dirs: NULL-terminated array of directories to search + * @error: error pointer + * + * Looks for @desktop_file_path in the paths returned from + * g_get_user_data_dir() and g_get_system_data_dirs(), and creates + * a new #EggDesktopFile from it. + * + * Return value: the new #EggDesktopFile, or %NULL on error. + **/ +EggDesktopFile * +egg_desktop_file_new_from_dirs (const char *desktop_file_path, + const char **search_dirs, + GError **error) +{ + EggDesktopFile *desktop_file; + GKeyFile *key_file; + char *full_path; + + key_file = g_key_file_new (); + if (!g_key_file_load_from_dirs (key_file, desktop_file_path, search_dirs, + &full_path, 0, error)) + { + g_key_file_free (key_file); + return NULL; + } + + desktop_file = egg_desktop_file_new_from_key_file (key_file, + full_path, + error); + g_free (full_path); return desktop_file; } @@ -119,8 +145,8 @@ egg_desktop_file_new_from_data_dirs (const char *desktop_file_path, * @error: error pointer * * Creates a new #EggDesktopFile for @key_file. Assumes ownership of - * @key_file on success (meaning it will be freed when the desktop_file - * is freed). + * @key_file (on success or failure); you should consider @key_file to + * be freed after calling this function. * * Return value: the new #EggDesktopFile, or %NULL on error. **/ @@ -137,6 +163,7 @@ egg_desktop_file_new_from_key_file (GKeyFile *key_file, g_set_error (error, EGG_DESKTOP_FILE_ERROR, EGG_DESKTOP_FILE_ERROR_INVALID, _("File is not a valid .desktop file")); + g_key_file_free (key_file); return NULL; } @@ -160,13 +187,14 @@ egg_desktop_file_new_from_key_file (GKeyFile *key_file, EGG_DESKTOP_FILE_ERROR_INVALID, _("Unrecognized desktop file Version '%s'"), version); g_free (version); + g_key_file_free (key_file); return NULL; } - else g_free (version); } desktop_file = g_new0 (EggDesktopFile, 1); + desktop_file->key_file = key_file; if (g_path_is_absolute (source)) desktop_file->source = g_filename_to_uri (source, NULL, NULL); @@ -202,7 +230,7 @@ egg_desktop_file_new_from_key_file (GKeyFile *key_file, if (!exec) { egg_desktop_file_free (desktop_file); - g_free(type); + g_free (type); return NULL; } @@ -235,7 +263,7 @@ egg_desktop_file_new_from_key_file (GKeyFile *key_file, if (!url) { egg_desktop_file_free (desktop_file); - g_free(type); + g_free (type); return NULL; } g_free (url); @@ -245,7 +273,7 @@ egg_desktop_file_new_from_key_file (GKeyFile *key_file, else desktop_file->type = EGG_DESKTOP_FILE_TYPE_UNRECOGNIZED; - g_free(type); + g_free (type); /* Check the Icon key */ desktop_file->icon = g_key_file_get_string (key_file, @@ -270,7 +298,6 @@ egg_desktop_file_new_from_key_file (GKeyFile *key_file, } } - desktop_file->key_file = key_file; return desktop_file; } @@ -291,22 +318,6 @@ egg_desktop_file_free (EggDesktopFile *desktop_file) } /** - * egg_desktop_file_get_key_file: - * @desktop_file: an #EggDesktopFile - * - * Gets the #GKeyFile associated with @desktop_file. You must not free - * this value, and changes made to it will not be reflected by - * @desktop_file. - * - * Return value: the #GKeyFile associated with @desktop_file. - **/ -GKeyFile * -egg_desktop_file_get_key_file (EggDesktopFile *desktop_file) -{ - return desktop_file->key_file; -} - -/** * egg_desktop_file_get_source: * @desktop_file: an #EggDesktopFile * @@ -369,6 +380,81 @@ egg_desktop_file_get_icon (EggDesktopFile *desktop_file) return desktop_file->icon; } +gboolean +egg_desktop_file_has_key (EggDesktopFile *desktop_file, + const char *key, + GError **error) +{ + return g_key_file_has_key (desktop_file->key_file, + EGG_DESKTOP_FILE_GROUP, key, + error); +} + +char * +egg_desktop_file_get_string (EggDesktopFile *desktop_file, + const char *key, + GError **error) +{ + return g_key_file_get_string (desktop_file->key_file, + EGG_DESKTOP_FILE_GROUP, key, + error); +} + +char * +egg_desktop_file_get_locale_string (EggDesktopFile *desktop_file, + const char *key, + const char *locale, + GError **error) +{ + return g_key_file_get_locale_string (desktop_file->key_file, + EGG_DESKTOP_FILE_GROUP, key, locale, + error); +} + +gboolean +egg_desktop_file_get_boolean (EggDesktopFile *desktop_file, + const char *key, + GError **error) +{ + return g_key_file_get_boolean (desktop_file->key_file, + EGG_DESKTOP_FILE_GROUP, key, + error); +} + +double +egg_desktop_file_get_numeric (EggDesktopFile *desktop_file, + const char *key, + GError **error) +{ + return g_key_file_get_double (desktop_file->key_file, + EGG_DESKTOP_FILE_GROUP, key, + error); +} + +char ** +egg_desktop_file_get_string_list (EggDesktopFile *desktop_file, + const char *key, + gsize *length, + GError **error) +{ + return g_key_file_get_string_list (desktop_file->key_file, + EGG_DESKTOP_FILE_GROUP, key, length, + error); +} + +char ** +egg_desktop_file_get_locale_string_list (EggDesktopFile *desktop_file, + const char *key, + const char *locale, + gsize *length, + GError **error) +{ + return g_key_file_get_locale_string_list (desktop_file->key_file, + EGG_DESKTOP_FILE_GROUP, key, + locale, length, + error); +} + /** * egg_desktop_file_can_launch: * @desktop_file: an #EggDesktopFile @@ -939,7 +1025,7 @@ set_startup_notification_timeout (GdkDisplay *display, static GPtrArray * array_putenv (GPtrArray *env, char *variable) { - int i, keylen; + guint i, keylen; if (!env) { @@ -1136,6 +1222,9 @@ egg_desktop_file_launchv (EggDesktopFile *desktop_file, startup_id = NULL; #endif /* GTK 2.12 */ + if (env != NULL) + g_ptr_array_add (env, NULL); + current_success = g_spawn_async_with_pipes (directory, argv, |