Commit 9d822240 authored by Matthias Clasen's avatar Matthias Clasen

Add a function to create a GDesktopAppInfo from a GKeyFile. Proposed by

        * gio.symbols:
        * gdesktopappinfo.[hc]: Add a function to create a
        GDesktopAppInfo from a GKeyFile. Proposed by Josselin Mouette.


svn path=/trunk/; revision=7143
parent fef22bfe
2008-07-02 Matthias Clasen <mclasen@redhat.com>
* gio/gio-sections.txt: Add g_desktop_app_info_new_from_keyfile
2008-07-01 Matthias Clasen <mclasen@redhat.com>
* gio/gio.types: Add missing types. Pointed out by David Zeuthen.
......
......@@ -1172,6 +1172,7 @@ GUnixVolumeMonitorClass
<TITLE>Desktop file based GAppInfo</TITLE>
GDesktopAppInfo
g_desktop_app_info_new_from_filename
g_desktop_app_info_new_from_keyfile
g_desktop_app_info_new
g_desktop_app_info_get_is_hidden
g_desktop_app_info_set_desktop_env
......
2008-07-02 Matthias Clasen <mclasen@redhat.com>
Bug 534639 – add g_desktop_app_info_new_from_keyfile
* gio.symbols:
* gdesktopappinfo.[hc]: Add a function to create a
GDesktopAppInfo from a GKeyFile. Proposed by Josselin Mouette.
2008-07-02 Wouter Bolsterlee <wbolster@svn.gnome.org>
* gappinfo.c: Fix ulink in doc to make gtk-doc happy.
......
......@@ -186,38 +186,27 @@ binary_from_exec (const char *exec)
}
/**
* g_desktop_app_info_new_from_filename:
* @filename: a string containing a file name.
* g_desktop_app_info_new_from_keyfile:
* @key_file: an opened #GKeyFile
*
* Creates a new #GDesktopAppInfo.
*
* Returns: a new #GDesktopAppInfo or %NULL on error.
*
* Since: 2.18
**/
GDesktopAppInfo *
g_desktop_app_info_new_from_filename (const char *filename)
g_desktop_app_info_new_from_keyfile (GKeyFile *key_file)
{
GDesktopAppInfo *info;
GKeyFile *key_file;
char *start_group;
char *type;
char *try_exec;
key_file = g_key_file_new ();
if (!g_key_file_load_from_file (key_file,
filename,
G_KEY_FILE_NONE,
NULL))
{
g_key_file_free (key_file);
return NULL;
}
start_group = g_key_file_get_start_group (key_file);
if (start_group == NULL || strcmp (start_group, G_KEY_FILE_DESKTOP_GROUP) != 0)
{
g_free (start_group);
g_key_file_free (key_file);
return NULL;
}
g_free (start_group);
......@@ -229,7 +218,6 @@ g_desktop_app_info_new_from_filename (const char *filename)
if (type == NULL || strcmp (type, G_KEY_FILE_DESKTOP_TYPE_APPLICATION) != 0)
{
g_free (type);
g_key_file_free (key_file);
return NULL;
}
g_free (type);
......@@ -245,14 +233,14 @@ g_desktop_app_info_new_from_filename (const char *filename)
if (t == NULL)
{
g_free (try_exec);
g_key_file_free (key_file);
return NULL;
}
g_free (t);
}
g_free (try_exec);
info = g_object_new (G_TYPE_DESKTOP_APP_INFO, NULL);
info->filename = g_strdup (filename);
info->filename = NULL;
info->name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
info->comment = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
......@@ -266,8 +254,6 @@ g_desktop_app_info_new_from_filename (const char *filename)
info->terminal = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL) != FALSE;
info->startup_notify = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, NULL) != FALSE;
info->hidden = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_HIDDEN, NULL) != FALSE;
g_key_file_free (key_file);
info->icon = NULL;
if (info->icon_name)
......@@ -290,6 +276,37 @@ g_desktop_app_info_new_from_filename (const char *filename)
return info;
}
/**
* g_desktop_app_info_new_from_filename:
* @filename: a string containing a file name.
*
* Creates a new #GDesktopAppInfo.
*
* Returns: a new #GDesktopAppInfo or %NULL on error.
**/
GDesktopAppInfo *
g_desktop_app_info_new_from_filename (const char *filename)
{
GKeyFile *key_file;
GDesktopAppInfo *info = NULL;
key_file = g_key_file_new ();
if (g_key_file_load_from_file (key_file,
filename,
G_KEY_FILE_NONE,
NULL))
{
info = g_desktop_app_info_new_from_keyfile (key_file);
if (info)
info->filename = g_strdup (filename);
}
g_key_file_free (key_file);
return info;
}
/**
* g_desktop_app_info_new:
* @desktop_id: the desktop file id
......
......@@ -46,6 +46,8 @@ struct _GDesktopAppInfoClass
GType g_desktop_app_info_get_type (void) G_GNUC_CONST;
GDesktopAppInfo *g_desktop_app_info_new_from_filename (const char *filename);
GDesktopAppInfo *g_desktop_app_info_new_from_keyfile (GKeyFile *key_file);
GDesktopAppInfo *g_desktop_app_info_new (const char *desktop_id);
gboolean g_desktop_app_info_get_is_hidden (GDesktopAppInfo *info);
......
......@@ -68,6 +68,7 @@ g_app_info_get_default_for_uri_scheme
#if IN_FILE(__G_DESKTOP_APP_INFO_C__)
#ifdef G_OS_UNIX
g_desktop_app_info_new_from_filename
g_desktop_app_info_new_from_keyfile
g_desktop_app_info_new
g_desktop_app_info_get_type G_GNUC_CONST
g_desktop_app_info_get_is_hidden
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment