libegg r903 - trunk/libegg/smclient
- From: danw svn gnome org
- To: svn-commits-list gnome org
- Subject: libegg r903 - trunk/libegg/smclient
- Date: Thu, 2 Oct 2008 16:00:49 +0000 (UTC)
Author: danw
Date: Thu Oct 2 16:00:49 2008
New Revision: 903
URL: http://svn.gnome.org/viewvc/libegg?rev=903&view=rev
Log:
* eggdesktopfile.c: Sync API changes from gnome-session
* eggsmclient-xsmp.c: update for that
Modified:
trunk/libegg/smclient/ChangeLog
trunk/libegg/smclient/eggdesktopfile.c
trunk/libegg/smclient/eggdesktopfile.h
trunk/libegg/smclient/eggsmclient-xsmp.c
Modified: trunk/libegg/smclient/eggdesktopfile.c
==============================================================================
--- trunk/libegg/smclient/eggdesktopfile.c (original)
+++ trunk/libegg/smclient/eggdesktopfile.c Thu Oct 2 16:00:49 2008
@@ -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 @@
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 @@
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 @@
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 @@
* @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 @@
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_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 @@
if (!exec)
{
egg_desktop_file_free (desktop_file);
- g_free(type);
+ g_free (type);
return NULL;
}
@@ -235,7 +263,7 @@
if (!url)
{
egg_desktop_file_free (desktop_file);
- g_free(type);
+ g_free (type);
return NULL;
}
g_free (url);
@@ -245,7 +273,7 @@
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 @@
}
}
- desktop_file->key_file = key_file;
return desktop_file;
}
@@ -291,22 +318,6 @@
}
/**
- * 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 @@
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
@@ -1136,6 +1222,9 @@
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,
Modified: trunk/libegg/smclient/eggdesktopfile.h
==============================================================================
--- trunk/libegg/smclient/eggdesktopfile.h (original)
+++ trunk/libegg/smclient/eggdesktopfile.h Thu Oct 2 16:00:49 2008
@@ -31,22 +31,23 @@
EGG_DESKTOP_FILE_TYPE_APPLICATION,
EGG_DESKTOP_FILE_TYPE_LINK,
- EGG_DESKTOP_FILE_TYPE_DIRECTORY,
+ EGG_DESKTOP_FILE_TYPE_DIRECTORY
} EggDesktopFileType;
EggDesktopFile *egg_desktop_file_new (const char *desktop_file_path,
GError **error);
-EggDesktopFile *egg_desktop_file_new_from_data_dirs (const char *desktop_file_path,
- GError **error);
-EggDesktopFile *egg_desktop_file_new_from_key_file (GKeyFile *desktop,
+EggDesktopFile *egg_desktop_file_new_from_data_dirs (const char *desktop_file_path,
+ GError **error);
+EggDesktopFile *egg_desktop_file_new_from_dirs (const char *desktop_file_path,
+ const char **search_dirs,
+ GError **error);
+EggDesktopFile *egg_desktop_file_new_from_key_file (GKeyFile *key_file,
const char *source,
GError **error);
void egg_desktop_file_free (EggDesktopFile *desktop_file);
-GKeyFile *egg_desktop_file_get_key_file (EggDesktopFile *desktop_file);
-
const char *egg_desktop_file_get_source (EggDesktopFile *desktop_file);
EggDesktopFileType egg_desktop_file_get_desktop_file_type (EggDesktopFile *desktop_file);
@@ -109,6 +110,34 @@
#define EGG_DESKTOP_FILE_KEY_STARTUP_WM_CLASS "StartupWMClass"
#define EGG_DESKTOP_FILE_KEY_URL "URL"
+/* Accessors */
+gboolean egg_desktop_file_has_key (EggDesktopFile *desktop_file,
+ const char *key,
+ GError **error);
+char *egg_desktop_file_get_string (EggDesktopFile *desktop_file,
+ const char *key,
+ GError **error) G_GNUC_MALLOC;
+char *egg_desktop_file_get_locale_string (EggDesktopFile *desktop_file,
+ const char *key,
+ const char *locale,
+ GError **error) G_GNUC_MALLOC;
+gboolean egg_desktop_file_get_boolean (EggDesktopFile *desktop_file,
+ const char *key,
+ GError **error);
+double egg_desktop_file_get_numeric (EggDesktopFile *desktop_file,
+ const char *key,
+ GError **error);
+char **egg_desktop_file_get_string_list (EggDesktopFile *desktop_file,
+ const char *key,
+ gsize *length,
+ GError **error) G_GNUC_MALLOC;
+char **egg_desktop_file_get_locale_string_list (EggDesktopFile *desktop_file,
+ const char *key,
+ const char *locale,
+ gsize *length,
+ GError **error) G_GNUC_MALLOC;
+
+
/* Errors */
#define EGG_DESKTOP_FILE_ERROR egg_desktop_file_error_quark()
@@ -117,7 +146,7 @@
typedef enum {
EGG_DESKTOP_FILE_ERROR_INVALID,
EGG_DESKTOP_FILE_ERROR_NOT_LAUNCHABLE,
- EGG_DESKTOP_FILE_ERROR_UNRECOGNIZED_OPTION,
+ EGG_DESKTOP_FILE_ERROR_UNRECOGNIZED_OPTION
} EggDesktopFileError;
/* Global application desktop file */
Modified: trunk/libegg/smclient/eggsmclient-xsmp.c
==============================================================================
--- trunk/libegg/smclient/eggsmclient-xsmp.c (original)
+++ trunk/libegg/smclient/eggsmclient-xsmp.c Thu Oct 2 16:00:49 2008
@@ -220,19 +220,14 @@
desktop_file = egg_get_desktop_file ();
if (desktop_file)
{
- GKeyFile *key_file;
GError *err = NULL;
char *cmdline, **argv;
int argc;
- key_file = egg_desktop_file_get_key_file (desktop_file);
-
if (xsmp->restart_style == SmRestartIfRunning)
{
- if (g_key_file_has_key (key_file, EGG_DESKTOP_FILE_GROUP,
- "X-GNOME-AutoRestart", NULL) &&
- g_key_file_get_boolean (key_file, EGG_DESKTOP_FILE_GROUP,
- "X-GNOME-AutoRestart", NULL))
+ if (egg_desktop_file_get_boolean (desktop_file,
+ "X-GNOME-AutoRestart", NULL))
xsmp->restart_style = SmRestartImmediately;
}
@@ -771,30 +766,6 @@
}
static void
-merge_keyfiles (GKeyFile *dest, GKeyFile *source)
-{
- int g, k;
- char **groups, **keys, *value;
-
- groups = g_key_file_get_groups (source, NULL);
- for (g = 0; groups[g]; g++)
- {
- keys = g_key_file_get_keys (source, groups[g], NULL, NULL);
- for (k = 0; keys[k]; k++)
- {
- value = g_key_file_get_value (source, groups[g], keys[k], NULL);
- if (value)
- {
- g_key_file_set_value (dest, groups[g], keys[k], value);
- g_free (value);
- }
- }
- g_strfreev (keys);
- }
- g_strfreev (groups);
-}
-
-static void
save_state (EggSMClientXSMP *xsmp)
{
GKeyFile *state_file;
@@ -824,30 +795,54 @@
if (desktop_file)
{
GKeyFile *merged_file;
- char *exec;
- int i;
merged_file = g_key_file_new ();
- merge_keyfiles (merged_file, egg_desktop_file_get_key_file (desktop_file));
- merge_keyfiles (merged_file, state_file);
+ if (g_key_file_load_from_file (merged_file,
+ egg_desktop_file_get_source (desktop_file),
+ G_KEY_FILE_KEEP_COMMENTS |
+ G_KEY_FILE_KEEP_TRANSLATIONS, NULL))
+ {
+ int g, k, i;
+ char **groups, **keys, *value, *exec;
+
+ groups = g_key_file_get_groups (state_file, NULL);
+ for (g = 0; groups[g]; g++)
+ {
+ keys = g_key_file_get_keys (state_file, groups[g], NULL, NULL);
+ for (k = 0; keys[k]; k++)
+ {
+ value = g_key_file_get_value (state_file, groups[g],
+ keys[k], NULL);
+ if (value)
+ {
+ g_key_file_set_value (merged_file, groups[g],
+ keys[k], value);
+ g_free (value);
+ }
+ }
+ g_strfreev (keys);
+ }
+ g_strfreev (groups);
- g_key_file_free (state_file);
- state_file = merged_file;
+ g_key_file_free (state_file);
+ state_file = merged_file;
- /* Update Exec key using "--sm-client-state-file %k" */
- restart = generate_command (xsmp->restart_command,
- NULL, "%k");
- for (i = 0; i < restart->len; i++)
- restart->pdata[i] = g_shell_quote (restart->pdata[i]);
- g_ptr_array_add (restart, NULL);
- exec = g_strjoinv (" ", (char **)restart->pdata);
- g_strfreev ((char **)restart->pdata);
- g_ptr_array_free (restart, FALSE);
-
- g_key_file_set_string (state_file, EGG_DESKTOP_FILE_GROUP,
- EGG_DESKTOP_FILE_KEY_EXEC,
- exec);
- g_free (exec);
+ /* Update Exec key using "--sm-client-state-file %k" */
+ restart = generate_command (xsmp->restart_command,
+ NULL, "%k");
+ for (i = 0; i < restart->len; i++)
+ restart->pdata[i] = g_shell_quote (restart->pdata[i]);
+ g_ptr_array_add (restart, NULL);
+ exec = g_strjoinv (" ", (char **)restart->pdata);
+ g_strfreev ((char **)restart->pdata);
+ g_ptr_array_free (restart, FALSE);
+
+ g_key_file_set_string (state_file, EGG_DESKTOP_FILE_GROUP,
+ EGG_DESKTOP_FILE_KEY_EXEC,
+ exec);
+ g_free (exec);
+
+ }
}
/* Now write state_file to disk. (We can't use mktemp(), because
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]