[gnome-session] gsm: Add gsm_consolekit_is_current_session_login() utility function
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] gsm: Add gsm_consolekit_is_current_session_login() utility function
- Date: Mon, 19 Sep 2011 21:37:40 +0000 (UTC)
commit fd9fec86836a808570dc1d109b05819fbad56d25
Author: Vincent Untz <vuntz gnome org>
Date: Mon Sep 19 23:33:37 2011 +0200
gsm: Add gsm_consolekit_is_current_session_login() utility function
We use the same code in different places, so let's use a function
instead.
gnome-session/gsm-consolekit.c | 18 ++++++++++++++++++
gnome-session/gsm-consolekit.h | 2 ++
gnome-session/gsm-manager.c | 26 +++++---------------------
gnome-session/gsm-session-fill.c | 14 +++-----------
4 files changed, 28 insertions(+), 32 deletions(-)
---
diff --git a/gnome-session/gsm-consolekit.c b/gnome-session/gsm-consolekit.c
index 66bebd1..e83a559 100644
--- a/gnome-session/gsm-consolekit.c
+++ b/gnome-session/gsm-consolekit.c
@@ -883,3 +883,21 @@ gsm_get_consolekit (void)
return g_object_ref (manager);
}
+
+gboolean
+gsm_consolekit_is_current_session_login (void)
+{
+ GsmConsolekit *consolekit;
+ char *session_type;
+ gboolean ret;
+
+ consolekit = gsm_get_consolekit ();
+ session_type = gsm_consolekit_get_current_session_type (consolekit);
+
+ ret = (g_strcmp0 (session_type, GSM_CONSOLEKIT_SESSION_TYPE_LOGIN_WINDOW) == 0);
+
+ g_object_unref (consolekit);
+ g_free (session_type);
+
+ return ret;
+}
diff --git a/gnome-session/gsm-consolekit.h b/gnome-session/gsm-consolekit.h
index 870f74a..376a11e 100644
--- a/gnome-session/gsm-consolekit.h
+++ b/gnome-session/gsm-consolekit.h
@@ -87,6 +87,8 @@ gchar *gsm_consolekit_get_current_session_type (GsmConsolekit *manager
GsmConsolekit *gsm_get_consolekit (void);
+gboolean gsm_consolekit_is_current_session_login (void);
+
G_END_DECLS
#endif /* __GSM_CONSOLEKIT_H__ */
diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c
index 7dcee3b..4d111ea 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -276,21 +276,15 @@ on_required_app_failure (GsmManager *manager,
const gchar *app_id;
gboolean want_extensions_ui;
gboolean allow_logout;
- GsmConsolekit *consolekit;
- char *session_type;
app_id = gsm_app_peek_app_id (app);
want_extensions_ui = g_str_equal (app_id, "gnome-shell.desktop");
- consolekit = gsm_get_consolekit ();
- session_type = gsm_consolekit_get_current_session_type (consolekit);
- if (g_strcmp0 (session_type, GSM_CONSOLEKIT_SESSION_TYPE_LOGIN_WINDOW) == 0) {
+ if (gsm_consolekit_is_current_session_login ()) {
allow_logout = FALSE;
} else {
allow_logout = !_log_out_is_locked_down (manager);
}
- g_object_unref (consolekit);
- g_free (session_type);
gsm_fail_whale_dialog_we_failed (FALSE,
allow_logout,
@@ -2184,27 +2178,21 @@ auto_save_is_enabled (GsmManager *manager)
static void
maybe_save_session (GsmManager *manager)
{
- GsmConsolekit *consolekit;
- char *session_type;
GError *error;
- consolekit = gsm_get_consolekit ();
- session_type = gsm_consolekit_get_current_session_type (consolekit);
-
- if (g_strcmp0 (session_type, GSM_CONSOLEKIT_SESSION_TYPE_LOGIN_WINDOW) == 0) {
- goto out;
- }
+ if (gsm_consolekit_is_current_session_login ())
+ return;
/* We only allow session saving when session is running or when
* logging out */
if (manager->priv->phase != GSM_MANAGER_PHASE_RUNNING &&
manager->priv->phase != GSM_MANAGER_PHASE_END_SESSION) {
- goto out;
+ return;
}
if (!auto_save_is_enabled (manager)) {
gsm_session_save_clear ();
- goto out;
+ return;
}
error = NULL;
@@ -2214,10 +2202,6 @@ maybe_save_session (GsmManager *manager)
g_warning ("Error saving session: %s", error->message);
g_error_free (error);
}
-
-out:
- g_object_unref (consolekit);
- g_free (session_type);
}
static void
diff --git a/gnome-session/gsm-session-fill.c b/gnome-session/gsm-session-fill.c
index 344224b..61541b5 100644
--- a/gnome-session/gsm-session-fill.c
+++ b/gnome-session/gsm-session-fill.c
@@ -181,18 +181,10 @@ check_required (GKeyFile *keyfile)
static void
maybe_load_saved_session_apps (GsmManager *manager)
{
- GsmConsolekit *consolekit;
- char *session_type;
-
- consolekit = gsm_get_consolekit ();
- session_type = gsm_consolekit_get_current_session_type (consolekit);
-
- if (g_strcmp0 (session_type, GSM_CONSOLEKIT_SESSION_TYPE_LOGIN_WINDOW) != 0) {
- gsm_manager_add_autostart_apps_from_dir (manager, gsm_util_get_saved_session_dir ());
- }
+ if (gsm_consolekit_is_current_session_login ())
+ return;
- g_object_unref (consolekit);
- g_free (session_type);
+ gsm_manager_add_autostart_apps_from_dir (manager, gsm_util_get_saved_session_dir ());
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]