GDesktopAppInfo: add enough api to make autostart implementable

gnome-session still uses EggDesktopFile, since GDesktopAppInfo is
missing a handful of APIs that are needed to implement the
autostart spec. This patch adds the minimum that is required.

https://bugzilla.gnome.org/show_bug.cgi?id=688497
This commit is contained in:
Matthias Clasen 2012-11-16 18:22:45 -05:00
parent 563ee093bc
commit 4adbc7aa42
2 changed files with 101 additions and 11 deletions

View File

@ -92,6 +92,8 @@ struct _GDesktopAppInfo
char *desktop_id;
char *filename;
GKeyFile *keyfile;
char *name;
char *generic_name;
char *fullname;
@ -171,6 +173,10 @@ g_desktop_app_info_finalize (GObject *object)
g_free (info->desktop_id);
g_free (info->filename);
if (info->keyfile)
g_key_file_unref (info->keyfile);
g_free (info->name);
g_free (info->generic_name);
g_free (info->fullname);
@ -213,7 +219,7 @@ g_desktop_app_info_set_property(GObject *object,
}
static void
g_desktop_app_info_get_property(GObject *object,
g_desktop_app_info_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
@ -371,6 +377,8 @@ g_desktop_app_info_load_from_keyfile (GDesktopAppInfo *info,
info->path = NULL;
}
info->keyfile = g_key_file_ref (key_file);
return TRUE;
}
@ -392,7 +400,7 @@ g_desktop_app_info_load_file (GDesktopAppInfo *self)
retval = g_desktop_app_info_load_from_keyfile (self, key_file);
}
g_key_file_free (key_file);
g_key_file_unref (key_file);
return retval;
}
@ -527,6 +535,9 @@ g_desktop_app_info_dup (GAppInfo *appinfo)
new_info->filename = g_strdup (info->filename);
new_info->desktop_id = g_strdup (info->desktop_id);
if (info->keyfile)
new_info->keyfile = g_key_file_ref (info->keyfile);
new_info->name = g_strdup (info->name);
new_info->generic_name = g_strdup (info->generic_name);
new_info->fullname = g_strdup (info->fullname);
@ -3443,3 +3454,73 @@ g_desktop_app_info_get_startup_wm_class (GDesktopAppInfo *info)
return info->startup_wm_class;
}
/**
* g_desktop_app_info_get_string:
* @info: a #GDesktopAppInfo
* @key: the key to look up
*
* Looks up a string value in the keyfile backing @info.
*
* The @key is looked up in the "Desktop Entry" group.
*
* Returns: a newly allocated string, or %NULL if the key
* is not found
*
* Since: 2.36
*/
char *
g_desktop_app_info_get_string (GDesktopAppInfo *info,
const char *key)
{
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
return g_key_file_get_string (info->keyfile,
G_KEY_FILE_DESKTOP_GROUP, key, NULL);
}
/**
* g_desktop_app_info_get_boolean:
* @info: a #GDesktopAppInfo
* @key: the key to look up
*
* Looks up a boolean value in the keyfile backing @info.
*
* The @key is looked up in the "Desktop Entry" group.
*
* Returns: the boolean value, or %FALSE if the key
* is not found
*
* Since: 2.36
*/
gboolean
g_desktop_app_info_get_boolean (GDesktopAppInfo *info,
const char *key)
{
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE);
return g_key_file_get_boolean (info->keyfile,
G_KEY_FILE_DESKTOP_GROUP, key, NULL);
}
/**
* g_desktop_app_info_has_key:
* @info: a #GDesktopAppInfo
* @key: the key to look up
*
* Returns whether @key exists in the "Desktop Entry" group
* of the keyfile backing @info.
*
* Returns: %TRUE if the @key exists
*
* Since: 2.26
*/
gboolean
g_desktop_app_info_has_key (GDesktopAppInfo *info,
const char *key)
{
g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE);
return g_key_file_has_key (info->keyfile,
G_KEY_FILE_DESKTOP_GROUP, key, NULL);
}

View File

@ -64,6 +64,15 @@ gboolean g_desktop_app_info_get_is_hidden (GDesktopAppInfo *info);
void g_desktop_app_info_set_desktop_env (const char *desktop_env);
GLIB_AVAILABLE_IN_2_36
gboolean g_desktop_app_info_has_key (GDesktopAppInfo *info,
const char *key);
GLIB_AVAILABLE_IN_2_36
char * g_desktop_app_info_get_string (GDesktopAppInfo *info,
const char *key);
GLIB_AVAILABLE_IN_2_36
gboolean g_desktop_app_info_get_boolean (GDesktopAppInfo *info,
const char *key);
#ifndef G_DISABLE_DEPRECATED