[gnome-session] gsm: Update format for .session files
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] gsm: Update format for .session files
- Date: Tue, 22 Mar 2011 12:01:09 +0000 (UTC)
commit 22b1affed9d62ad1ad79806115fea50e511113f8
Author: Vincent Untz <vuntz gnome org>
Date: Tue Mar 22 11:33:03 2011 +0100
gsm: Update format for .session files
All components defined in .session files are really required, and the
format should make this clear.
Rename:
- Required to RequiredProviders
- Required-* to DefaultProvider-*
- DefaultApps to RequiredComponents
Make sure to check for all required components and providers at all
time, and reduce code redundancy a bit.
data/gnome-fallback.session.desktop.in.in | 10 +-
data/gnome.session.desktop.in.in | 8 +-
gnome-session/gsm-session-fill.c | 246 +++++++++++++++++------------
3 files changed, 152 insertions(+), 112 deletions(-)
---
diff --git a/data/gnome-fallback.session.desktop.in.in b/data/gnome-fallback.session.desktop.in.in
index 624dc15..73f373c 100644
--- a/data/gnome-fallback.session.desktop.in.in
+++ b/data/gnome-fallback.session.desktop.in.in
@@ -1,7 +1,7 @@
[GNOME Session]
_Name=GNOME fallback
-Required=windowmanager;panel;notifications;
-Required-windowmanager=metacity
-Required-panel=gnome-panel
-Required-notifications=notification-daemon
-DefaultApps=gnome-settings-daemon;
+RequiredComponents=gnome-settings-daemon;
+RequiredProviders=windowmanager;panel;notifications;
+DefaultProvider-windowmanager=metacity
+DefaultProvider-panel=gnome-panel
+DefaultProvider-notifications=notification-daemon
diff --git a/data/gnome.session.desktop.in.in b/data/gnome.session.desktop.in.in
index 654c7de..f7ef146 100644
--- a/data/gnome.session.desktop.in.in
+++ b/data/gnome.session.desktop.in.in
@@ -1,8 +1,8 @@
[GNOME Session]
_Name=GNOME
-Required=windowmanager;panel;
-Required-windowmanager=gnome-shell
-Required-panel=gnome-shell
-DefaultApps=gnome-settings-daemon;
+RequiredComponents=gnome-settings-daemon;
+RequiredProviders=windowmanager;panel;
+DefaultProvider-windowmanager=gnome-shell
+DefaultProvider-panel=gnome-shell
IsRunnableHelper= LIBEXECDIR@/gnome-session-check-accelerated
FallbackSession=gnome-fallback
diff --git a/gnome-session/gsm-session-fill.c b/gnome-session/gsm-session-fill.c
index 07b5b3d..2bbeb24 100644
--- a/gnome-session/gsm-session-fill.c
+++ b/gnome-session/gsm-session-fill.c
@@ -31,153 +31,154 @@
#define GSM_KEYFILE_SESSION_GROUP "GNOME Session"
#define GSM_KEYFILE_RUNNABLE_KEY "IsRunnableHelper"
#define GSM_KEYFILE_FALLBACK_KEY "FallbackSession"
-#define GSM_KEYFILE_REQUIRED_KEY "Required"
-#define GSM_KEYFILE_DEFAULT_KEY "DefaultApps"
+#define GSM_KEYFILE_REQUIRED_COMPONENTS_KEY "RequiredComponents"
+#define GSM_KEYFILE_REQUIRED_PROVIDERS_KEY "RequiredProviders"
+#define GSM_KEYFILE_DEFAULT_PROVIDER_PREFIX "DefaultProvider"
/* See https://bugzilla.gnome.org/show_bug.cgi?id=641992 for discussion */
#define GSM_RUNNABLE_HELPER_TIMEOUT 3000 /* ms */
-/* This doesn't contain the required components, so we need to always
- * call append_required_apps() after a call to append_default_apps(). */
+typedef void (*GsmFillHandleProvider) (const char *provides,
+ const char *default_provider,
+ const char *app_path,
+ gpointer user_data);
+typedef void (*GsmFillHandleComponent) (const char *component,
+ const char *app_path,
+ gpointer user_data);
+
static void
-append_default_apps (GsmManager *manager,
- GKeyFile *keyfile,
- char **autostart_dirs)
+handle_default_providers (GKeyFile *keyfile,
+ char **autostart_dirs,
+ GsmFillHandleProvider callback,
+ gpointer user_data)
{
- char **default_apps;
+ char **default_providers;
int i;
- g_debug ("fill: *** Adding default apps");
-
g_assert (keyfile != NULL);
- g_assert (autostart_dirs != NULL);
+ g_assert (callback != NULL);
- default_apps = g_key_file_get_string_list (keyfile,
- GSM_KEYFILE_SESSION_GROUP, GSM_KEYFILE_DEFAULT_KEY,
- NULL, NULL);
+ default_providers = g_key_file_get_string_list (keyfile,
+ GSM_KEYFILE_SESSION_GROUP,
+ GSM_KEYFILE_REQUIRED_PROVIDERS_KEY,
+ NULL, NULL);
- if (!default_apps)
+ if (!default_providers)
return;
- for (i = 0; default_apps[i] != NULL; i++) {
+ for (i = 0; default_providers[i] != NULL; i++) {
+ char *key;
+ char *value;
char *app_path;
- if (IS_STRING_EMPTY (default_apps[i]))
+ if (IS_STRING_EMPTY (default_providers[i]))
continue;
- app_path = gsm_util_find_desktop_file_for_app_name (default_apps[i], autostart_dirs);
- if (app_path != NULL) {
- gsm_manager_add_autostart_app (manager, app_path, NULL);
- g_free (app_path);
+ key = g_strdup_printf ("%s-%s",
+ GSM_KEYFILE_DEFAULT_PROVIDER_PREFIX,
+ default_providers[i]);
+ value = g_key_file_get_string (keyfile,
+ GSM_KEYFILE_SESSION_GROUP, key,
+ NULL);
+ g_free (key);
+
+ if (IS_STRING_EMPTY (value)) {
+ g_free (value);
+ continue;
}
+
+ 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);
+
+ callback (default_providers[i], value, app_path, user_data);
+ g_free (app_path);
+
+ g_free (value);
}
- g_strfreev (default_apps);
+ g_strfreev (default_providers);
}
static void
-append_required_apps (GsmManager *manager,
- GKeyFile *keyfile)
+handle_required_components (GKeyFile *keyfile,
+ char **autostart_dirs,
+ GsmFillHandleComponent callback,
+ gpointer user_data)
{
char **required_components;
int i;
- g_debug ("fill: *** Adding required apps");
+ g_assert (keyfile != NULL);
+ g_assert (callback != NULL);
required_components = g_key_file_get_string_list (keyfile,
- GSM_KEYFILE_SESSION_GROUP, GSM_KEYFILE_REQUIRED_KEY,
+ GSM_KEYFILE_SESSION_GROUP,
+ GSM_KEYFILE_REQUIRED_COMPONENTS_KEY,
NULL, NULL);
- if (required_components == NULL) {
- g_warning ("No required applications specified");
+ if (!required_components)
return;
- }
for (i = 0; required_components[i] != NULL; i++) {
- char *key;
- char *value;
char *app_path;
- key = g_strdup_printf ("%s-%s", GSM_KEYFILE_REQUIRED_KEY, required_components[i]);
- value = g_key_file_get_string (keyfile,
- GSM_KEYFILE_SESSION_GROUP, key,
- NULL);
- g_free (key);
-
- if (IS_STRING_EMPTY (value)) {
- g_free (value);
- continue;
- }
-
- g_debug ("fill: %s looking for component: '%s'", required_components[i], value);
- app_path = gsm_util_find_desktop_file_for_app_name (value, NULL);
- if (app_path != NULL) {
- gsm_manager_add_required_app (manager, app_path, required_components[i]);
- } else {
- g_warning ("Unable to find provider '%s' of required component '%s'",
- value, required_components[i]);
- }
+ app_path = gsm_util_find_desktop_file_for_app_name (required_components[i], autostart_dirs);
+ callback (required_components[i], app_path, user_data);
g_free (app_path);
-
- g_free (value);
}
- g_debug ("fill: *** Done adding required apps");
-
g_strfreev (required_components);
}
-static gboolean
-check_required_components (GKeyFile *keyfile)
+static void
+check_required_providers_helper (const char *provides,
+ const char *default_provider,
+ const char *app_path,
+ gpointer user_data)
{
- char **required_components;
- int i;
- gboolean result;
+ gboolean *error = user_data;
- g_debug ("fill: *** Checking required apps");
+ if (app_path == NULL) {
+ g_warning ("Unable to find default provider '%s' of required provider '%s'",
+ default_provider, provides);
+ *error = TRUE;
+ }
+}
- required_components = g_key_file_get_string_list (keyfile,
- GSM_KEYFILE_SESSION_GROUP, GSM_KEYFILE_REQUIRED_KEY,
- NULL, NULL);
+static void
+check_required_components_helper (const char *component,
+ const char *app_path,
+ gpointer user_data)
+{
+ gboolean *error = user_data;
- if (required_components == NULL) {
- return TRUE;
+ if (app_path == NULL) {
+ g_warning ("Unable to find required component '%s'", component);
+ *error = TRUE;
}
+}
- result = TRUE;
- for (i = 0; result && required_components[i] != NULL; i++) {
- char *key;
- char *value;
- char *app_path;
+static gboolean
+check_required (GKeyFile *keyfile)
+{
+ char **autostart_dirs;
+ gboolean error = FALSE;
- key = g_strdup_printf ("%s-%s", GSM_KEYFILE_REQUIRED_KEY, required_components[i]);
- value = g_key_file_get_string (keyfile,
- GSM_KEYFILE_SESSION_GROUP, key,
- NULL);
- g_free (key);
+ autostart_dirs = gsm_util_get_autostart_dirs ();
- if (IS_STRING_EMPTY (value)) {
- g_free (value);
- continue;
- }
+ g_debug ("fill: *** Checking required components and providers");
- g_debug ("fill: %s looking for component: '%s'", required_components[i], value);
- app_path = gsm_util_find_desktop_file_for_app_name (value, NULL);
- if (!app_path) {
- g_warning ("Unable to find provider '%s' of required component '%s'",
- value, required_components[i]);
- result = FALSE;
- break;
- }
- g_free (app_path);
- g_free (value);
- }
+ handle_default_providers (keyfile, autostart_dirs,
+ check_required_providers_helper, &error);
+ handle_required_components (keyfile, autostart_dirs,
+ check_required_components_helper, &error);
- g_debug ("fill: *** Done checking required apps");
+ g_debug ("fill: *** Done checking required components and providers");
- g_strfreev (required_components);
+ g_strfreev (autostart_dirs);
- return result;
+ return !error;
}
static void
@@ -198,6 +199,35 @@ maybe_load_saved_session_apps (GsmManager *manager)
}
static void
+append_required_providers_helper (const char *provides,
+ const char *default_provider,
+ const char *app_path,
+ gpointer user_data)
+{
+ GsmManager *manager = user_data;
+
+ if (app_path == NULL)
+ g_warning ("Unable to find default provider '%s' of required provider '%s'",
+ default_provider, provides);
+ else
+ gsm_manager_add_required_app (manager, app_path, provides);
+}
+
+static void
+append_required_components_helper (const char *component,
+ const char *app_path,
+ gpointer user_data)
+{
+ GsmManager *manager = user_data;
+
+ if (app_path == NULL)
+ g_warning ("Unable to find required component '%s'", component);
+ else
+ gsm_manager_add_required_app (manager, app_path, NULL);
+}
+
+
+static void
load_standard_apps (GsmManager *manager,
GKeyFile *keyfile)
{
@@ -213,12 +243,19 @@ load_standard_apps (GsmManager *manager,
gsm_manager_add_autostart_apps_from_dir (manager,
autostart_dirs[i]);
}
+
}
/* We do this at the end in case a saved session contains an
* application that already provides one of the components. */
- append_default_apps (manager, keyfile, autostart_dirs);
- append_required_apps (manager, keyfile);
+ g_debug ("fill: *** Adding required components and providers");
+
+ handle_default_providers (keyfile, autostart_dirs,
+ append_required_providers_helper, manager);
+ handle_required_components (keyfile, autostart_dirs,
+ append_required_components_helper, manager);
+
+ g_debug ("fill: *** Done adding required components and providers");
g_strfreev (autostart_dirs);
}
@@ -254,8 +291,10 @@ get_session_keyfile_if_valid (const char *path)
goto error;
}
+ /* check that we have default providers defined for required providers */
list = g_key_file_get_string_list (keyfile,
- GSM_KEYFILE_SESSION_GROUP, GSM_KEYFILE_REQUIRED_KEY,
+ GSM_KEYFILE_SESSION_GROUP,
+ GSM_KEYFILE_REQUIRED_PROVIDERS_KEY,
&len, NULL);
if (list != NULL) {
int i;
@@ -263,7 +302,7 @@ get_session_keyfile_if_valid (const char *path)
char *value;
for (i = 0; list[i] != NULL; i++) {
- key = g_strdup_printf ("%s-%s", GSM_KEYFILE_REQUIRED_KEY, list[i]);
+ key = g_strdup_printf ("%s-%s", GSM_KEYFILE_DEFAULT_PROVIDER_PREFIX, list[i]);
value = g_key_file_get_string (keyfile,
GSM_KEYFILE_SESSION_GROUP, key,
NULL);
@@ -278,7 +317,7 @@ get_session_keyfile_if_valid (const char *path)
}
if (list[i] != NULL) {
- g_warning ("Cannot use session '%s': required component '%s' is not defined.", path, list[i]);
+ g_warning ("Cannot use session '%s': required provider '%s' is not defined.", path, list[i]);
g_strfreev (list);
goto error;
}
@@ -286,16 +325,17 @@ get_session_keyfile_if_valid (const char *path)
g_strfreev (list);
}
- /* we don't want an empty session, so if there's no required app, check
- * that we do have some default apps */
+ /* we don't want an empty session, so if there's no required provider, check
+ * that we do have some required components */
if (len == 0) {
list = g_key_file_get_string_list (keyfile,
- GSM_KEYFILE_SESSION_GROUP, GSM_KEYFILE_DEFAULT_KEY,
+ GSM_KEYFILE_SESSION_GROUP,
+ GSM_KEYFILE_REQUIRED_COMPONENTS_KEY,
&len, NULL);
if (list)
g_strfreev (list);
if (len == 0) {
- g_warning ("Cannot use session '%s': no application in the session.", path);
+ g_warning ("Cannot use session '%s': no component in the session.", path);
goto error;
}
}
@@ -395,7 +435,7 @@ get_session_keyfile (const char *session,
g_free (value);
if (session_runnable) {
- session_runnable = check_required_components (keyfile);
+ session_runnable = check_required (keyfile);
}
if (session_runnable) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]