[gnome-session] gsm: Force common code path to look for .desktop files in directories
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] gsm: Force common code path to look for .desktop files in directories
- Date: Tue, 22 Mar 2011 12:01:24 +0000 (UTC)
commit d754aa829542f944e2899db939b6d15ad9751780
Author: Vincent Untz <vuntz gnome org>
Date: Tue Mar 22 12:44:25 2011 +0100
gsm: Force common code path to look for .desktop files in directories
We make sure we always have the right set of directories this way,
instead of always looking in different places for autostart directories.
This also makes it easier to look at the saved session directory if
needed.
gnome-session/gsm-inhibit-dialog.c | 2 +-
gnome-session/gsm-session-fill.c | 35 +++++++--------
gnome-session/gsm-util.c | 80 ++++++++++++++++--------------------
gnome-session/gsm-util.h | 8 ++-
gnome-session/gsm-xsmp-client.c | 7 +---
5 files changed, 59 insertions(+), 73 deletions(-)
---
diff --git a/gnome-session/gsm-inhibit-dialog.c b/gnome-session/gsm-inhibit-dialog.c
index a22dbde..2678caa 100644
--- a/gnome-session/gsm-inhibit-dialog.c
+++ b/gnome-session/gsm-inhibit-dialog.c
@@ -496,7 +496,7 @@ add_inhibitor (GsmInhibitDialog *dialog,
}
if (desktop_filename != NULL) {
- search_dirs = gsm_util_get_desktop_dirs ();
+ search_dirs = gsm_util_get_desktop_dirs (TRUE, FALSE);
if (g_path_is_absolute (desktop_filename)) {
char *basename;
diff --git a/gnome-session/gsm-session-fill.c b/gnome-session/gsm-session-fill.c
index 2bbeb24..db3cd4d 100644
--- a/gnome-session/gsm-session-fill.c
+++ b/gnome-session/gsm-session-fill.c
@@ -47,10 +47,10 @@ typedef void (*GsmFillHandleComponent) (const char *component,
gpointer user_data);
static void
-handle_default_providers (GKeyFile *keyfile,
- char **autostart_dirs,
- GsmFillHandleProvider callback,
- gpointer user_data)
+handle_default_providers (GKeyFile *keyfile,
+ gboolean look_in_saved_session,
+ GsmFillHandleProvider callback,
+ gpointer user_data)
{
char **default_providers;
int i;
@@ -89,7 +89,8 @@ handle_default_providers (GKeyFile *keyfile,
g_debug ("fill: provider '%s' looking for component: '%s'",
default_providers[i], value);
- app_path = gsm_util_find_desktop_file_for_app_name (value, autostart_dirs);
+ app_path = gsm_util_find_desktop_file_for_app_name (value,
+ look_in_saved_session, TRUE);
callback (default_providers[i], value, app_path, user_data);
g_free (app_path);
@@ -101,10 +102,10 @@ handle_default_providers (GKeyFile *keyfile,
}
static void
-handle_required_components (GKeyFile *keyfile,
- char **autostart_dirs,
- GsmFillHandleComponent callback,
- gpointer user_data)
+handle_required_components (GKeyFile *keyfile,
+ gboolean look_in_saved_session,
+ GsmFillHandleComponent callback,
+ gpointer user_data)
{
char **required_components;
int i;
@@ -123,7 +124,8 @@ handle_required_components (GKeyFile *keyfile,
for (i = 0; required_components[i] != NULL; i++) {
char *app_path;
- app_path = gsm_util_find_desktop_file_for_app_name (required_components[i], autostart_dirs);
+ app_path = gsm_util_find_desktop_file_for_app_name (required_components[i],
+ look_in_saved_session, TRUE);
callback (required_components[i], app_path, user_data);
g_free (app_path);
}
@@ -162,22 +164,17 @@ check_required_components_helper (const char *component,
static gboolean
check_required (GKeyFile *keyfile)
{
- char **autostart_dirs;
gboolean error = FALSE;
- autostart_dirs = gsm_util_get_autostart_dirs ();
-
g_debug ("fill: *** Checking required components and providers");
- handle_default_providers (keyfile, autostart_dirs,
+ handle_default_providers (keyfile, FALSE,
check_required_providers_helper, &error);
- handle_required_components (keyfile, autostart_dirs,
+ handle_required_components (keyfile, FALSE,
check_required_components_helper, &error);
g_debug ("fill: *** Done checking required components and providers");
- g_strfreev (autostart_dirs);
-
return !error;
}
@@ -250,9 +247,9 @@ load_standard_apps (GsmManager *manager,
* application that already provides one of the components. */
g_debug ("fill: *** Adding required components and providers");
- handle_default_providers (keyfile, autostart_dirs,
+ handle_default_providers (keyfile, !gsm_manager_get_failsafe (manager),
append_required_providers_helper, manager);
- handle_required_components (keyfile, autostart_dirs,
+ handle_required_components (keyfile, !gsm_manager_get_failsafe (manager),
append_required_components_helper, manager);
g_debug ("fill: *** Done adding required components and providers");
diff --git a/gnome-session/gsm-util.c b/gnome-session/gsm-util.c
index d139b95..9f28a1e 100644
--- a/gnome-session/gsm-util.c
+++ b/gnome-session/gsm-util.c
@@ -40,7 +40,8 @@ static gchar *_saved_session_dir = NULL;
char *
gsm_util_find_desktop_file_for_app_name (const char *name,
- char **autostart_dirs)
+ gboolean look_in_saved_session,
+ gboolean autostart_first)
{
char *app_path;
char **app_dirs;
@@ -50,7 +51,7 @@ gsm_util_find_desktop_file_for_app_name (const char *name,
app_path = NULL;
- app_dirs = gsm_util_get_app_dirs ();
+ app_dirs = gsm_util_get_desktop_dirs (look_in_saved_session, autostart_first);
key_file = g_key_file_new ();
@@ -70,23 +71,10 @@ gsm_util_find_desktop_file_for_app_name (const char *name,
NULL);
if (app_path != NULL) {
- g_debug ("GsmUtil: found in XDG app dirs: '%s'", app_path);
+ g_debug ("GsmUtil: found in XDG dirs: '%s'", app_path);
}
- if (app_path == NULL && autostart_dirs != NULL) {
- g_key_file_load_from_dirs (key_file,
- desktop_file,
- (const char **) autostart_dirs,
- &app_path,
- G_KEY_FILE_NONE,
- NULL);
- if (app_path != NULL) {
- g_debug ("GsmUtil: found in autostart dirs: '%s'", app_path);
- }
-
- }
-
- /* look for gnome vender prefix */
+ /* look for gnome vendor prefix */
if (app_path == NULL) {
g_free (desktop_file);
desktop_file = g_strdup_printf ("gnome-%s.desktop", name);
@@ -98,19 +86,7 @@ gsm_util_find_desktop_file_for_app_name (const char *name,
G_KEY_FILE_NONE,
NULL);
if (app_path != NULL) {
- g_debug ("GsmUtil: found in XDG app dirs: '%s'", app_path);
- }
- }
-
- if (app_path == NULL && autostart_dirs != NULL) {
- g_key_file_load_from_dirs (key_file,
- desktop_file,
- (const char **) autostart_dirs,
- &app_path,
- G_KEY_FILE_NONE,
- NULL);
- if (app_path != NULL) {
- g_debug ("GsmUtil: found in autostart dirs: '%s'", app_path);
+ g_debug ("GsmUtil: found in XDG dirs: '%s'", app_path);
}
}
@@ -268,7 +244,8 @@ gsm_util_get_app_dirs ()
}
char **
-gsm_util_get_desktop_dirs ()
+gsm_util_get_desktop_dirs (gboolean include_saved_session,
+ gboolean autostart_first)
{
char **apps;
char **autostart;
@@ -282,24 +259,39 @@ gsm_util_get_desktop_dirs ()
size = 0;
for (i = 0; apps[i] != NULL; i++) { size++; }
for (i = 0; autostart[i] != NULL; i++) { size++; }
- size += 2; /* saved session + last NULL */
+ if (include_saved_session)
+ size += 1;
- result = g_new (char *, size + 1);
+ result = g_new (char *, size + 1); /* including last NULL */
- for (i = 0; apps[i] != NULL; i++) {
- result[i] = apps[i];
- }
- g_free (apps);
- size = i;
+ size = 0;
+
+ if (autostart_first) {
+ if (include_saved_session)
+ result[size++] = g_strdup (gsm_util_get_saved_session_dir ());
- for (i = 0; autostart[i] != NULL; i++) {
- result[size + i] = autostart[i];
- }
+ for (i = 0; autostart[i] != NULL; i++, size++) {
+ result[size] = autostart[i];
+ }
+ for (i = 0; apps[i] != NULL; i++, size++) {
+ result[size] = apps[i];
+ }
+ } else {
+ for (i = 0; apps[i] != NULL; i++, size++) {
+ result[size] = apps[i];
+ }
+ for (i = 0; autostart[i] != NULL; i++, size++) {
+ result[size] = autostart[i];
+ }
+
+ if (include_saved_session)
+ result[size++] = g_strdup (gsm_util_get_saved_session_dir ());
+ }
+
+ g_free (apps);
g_free (autostart);
- size = size + i;
- result[size] = g_strdup (gsm_util_get_saved_session_dir ());
- result[size + 1] = NULL;
+ result[size] = NULL;
return result;
}
diff --git a/gnome-session/gsm-util.h b/gnome-session/gsm-util.h
index 1a437f7..82fa3dd 100644
--- a/gnome-session/gsm-util.h
+++ b/gnome-session/gsm-util.h
@@ -26,8 +26,9 @@ G_BEGIN_DECLS
#define IS_STRING_EMPTY(x) ((x)==NULL||(x)[0]=='\0')
-char * gsm_util_find_desktop_file_for_app_name (const char *app_name,
- char **dirs);
+char * gsm_util_find_desktop_file_for_app_name (const char *app_name,
+ gboolean look_in_saved_session,
+ gboolean autostart_first);
gchar *gsm_util_get_empty_tmp_session_dir (void);
@@ -37,7 +38,8 @@ gchar** gsm_util_get_app_dirs (void);
gchar** gsm_util_get_autostart_dirs (void);
-gchar ** gsm_util_get_desktop_dirs (void);
+gchar ** gsm_util_get_desktop_dirs (gboolean include_saved_session,
+ gboolean autostart_first);
gboolean gsm_util_text_is_blank (const char *str);
diff --git a/gnome-session/gsm-xsmp-client.c b/gnome-session/gsm-xsmp-client.c
index f62cb4f..0c44855 100644
--- a/gnome-session/gsm-xsmp-client.c
+++ b/gnome-session/gsm-xsmp-client.c
@@ -505,7 +505,6 @@ get_desktop_file_path (GsmXSMPClient *client)
{
SmProp *prop;
char *desktop_file_path = NULL;
- char **dirs;
const char *program_name;
/* XSMP clients using eggsmclient defines a special property
@@ -524,13 +523,9 @@ get_desktop_file_path (GsmXSMPClient *client)
prop = find_property (client, SmProgram, NULL);
program_name = prop->vals[0].value;
- dirs = gsm_util_get_autostart_dirs ();
-
desktop_file_path =
gsm_util_find_desktop_file_for_app_name (program_name,
- dirs);
-
- g_strfreev (dirs);
+ TRUE, FALSE);
out:
g_debug ("GsmXSMPClient: desktop file for client %s is %s",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]