static void maybe_load_saved_session_apps(GsmManager* manager)
{
	GsmConsolekit* consolekit = NULL;
#ifdef HAVE_SYSTEMD
	GsmSystemd* systemd = NULL;
#endif
	char* session_type;
	gboolean is_login;

#ifdef HAVE_SYSTEMD
	if (LOGIND_RUNNING()) {
		systemd = gsm_get_systemd();
		session_type = gsm_systemd_get_current_session_type(systemd);
		is_login = g_strcmp0 (session_type, GSM_SYSTEMD_SESSION_TYPE_LOGIN_WINDOW) == 0;
	}
	else {
#endif
	consolekit = gsm_get_consolekit();
	session_type = gsm_consolekit_get_current_session_type(consolekit);
	is_login = g_strcmp0 (session_type, GSM_CONSOLEKIT_SESSION_TYPE_LOGIN_WINDOW) == 0;
#ifdef HAVE_SYSTEMD
	}
#endif

	if (!is_login)
	{
		GSettings* settings;
		gboolean autostart;

		settings = g_settings_new (GSM_SCHEMA);
		autostart = g_settings_get_boolean (settings, KEY_AUTOSAVE);
		g_object_unref (settings);

		if (autostart == TRUE)
			gsm_manager_add_autostart_apps_from_dir(manager, gsm_util_get_saved_session_dir());
	}

	if (consolekit != NULL)
		g_object_unref(consolekit);
#ifdef HAVE_SYSTEMD
	if (systemd != NULL)
		g_object_unref(systemd);
#endif
	g_free(session_type);
}
static gboolean
gsm_logout_dialog_timeout (gpointer data)
{
        GsmLogoutDialog *logout_dialog;
        char            *seconds_warning;
        char            *secondary_text;
        static char     *session_type = NULL;
        static gboolean  is_not_login;

        logout_dialog = (GsmLogoutDialog *) data;

        if (!logout_dialog->priv->timeout) {
                gtk_dialog_response (GTK_DIALOG (logout_dialog),
                                     logout_dialog->priv->default_response);

                return FALSE;
        }

        switch (logout_dialog->priv->type) {
        case GSM_DIALOG_LOGOUT_TYPE_LOGOUT:
                seconds_warning = ngettext ("You will be automatically logged "
                                            "out in %d second",
                                            "You will be automatically logged "
                                            "out in %d seconds",
                                            logout_dialog->priv->timeout);
                break;

        case GSM_DIALOG_LOGOUT_TYPE_SHUTDOWN:
                seconds_warning = ngettext ("This system will be automatically "
                                            "shut down in %d second",
                                            "This system will be automatically "
                                            "shut down in %d seconds",
                                            logout_dialog->priv->timeout);
                break;

        default:
                g_assert_not_reached ();
        }
        seconds_warning = g_strdup_printf (seconds_warning, logout_dialog->priv->timeout);

        if (session_type == NULL) {
#ifdef HAVE_SYSTEMD
                if (LOGIND_RUNNING()) {
                    GsmSystemd *systemd;
                    systemd = gsm_get_systemd ();
                    session_type = gsm_systemd_get_current_session_type (systemd);
                    g_object_unref (systemd);
                    is_not_login = (g_strcmp0 (session_type, GSM_SYSTEMD_SESSION_TYPE_LOGIN_WINDOW) != 0);
                }
                else {
#endif
                GsmConsolekit *consolekit;
                consolekit = gsm_get_consolekit ();
                session_type = gsm_consolekit_get_current_session_type (consolekit);
                g_object_unref (consolekit);
                is_not_login = (g_strcmp0 (session_type, GSM_CONSOLEKIT_SESSION_TYPE_LOGIN_WINDOW) != 0);
#ifdef HAVE_SYSTEMD
                }
#endif
        }

        if (is_not_login) {
                char *name;

                name = g_locale_to_utf8 (g_get_real_name (), -1, NULL, NULL, NULL);

                if (!name || name[0] == '\0' || strcmp (name, "Unknown") == 0) {
                        name = g_locale_to_utf8 (g_get_user_name (), -1 , NULL, NULL, NULL);
                }

                if (!name) {
                        name = g_strdup (g_get_user_name ());
                }

                secondary_text = g_strdup_printf (_("You are currently logged in as \"%s\"."), name);

                g_free (name);
        } else {
                secondary_text = g_strdup (seconds_warning);
        }

        gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (logout_dialog->priv->progressbar),
                                       logout_dialog->priv->timeout / 60.0);
        gtk_progress_bar_set_text (GTK_PROGRESS_BAR (logout_dialog->priv->progressbar),
                                   seconds_warning);

        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (logout_dialog),
                                                  secondary_text,
                                                  NULL);

        logout_dialog->priv->timeout--;

        g_free (secondary_text);
        g_free (seconds_warning);

        return TRUE;
}
static void
gsm_logout_set_info_text (GsmLogoutDialog *logout_dialog,
                          int              seconds)
{
    const char *info_text;
    char       *markup = NULL;
    static char     *session_type = NULL;

    switch (logout_dialog->priv->default_response) {
    case GSM_LOGOUT_RESPONSE_LOGOUT:
        info_text = ngettext ("You will be automatically logged "
                              "out in %d second.",
                              "You will be automatically logged "
                              "out in %d seconds.",
                              seconds);
        break;

    case GSM_LOGOUT_RESPONSE_SHUTDOWN:
        info_text = ngettext ("This system will be automatically "
                              "shut down in %d second.",
                              "This system will be automatically "
                              "shut down in %d seconds.",
                              seconds);
        break;

    case GTK_RESPONSE_CANCEL:
        info_text = NULL;
        break;

    default:
        g_assert_not_reached ();
    }

    if (session_type == NULL) {
        GsmConsolekit *consolekit;

        consolekit = gsm_get_consolekit ();
        session_type = gsm_consolekit_get_current_session_type (consolekit);
        g_object_unref (consolekit);
    }

    if (g_strcmp0 (session_type, GSM_CONSOLEKIT_SESSION_TYPE_LOGIN_WINDOW) != 0) {
        char *name, *buf, *buf2;
        name = g_locale_to_utf8 (g_get_real_name (), -1, NULL, NULL, NULL);

        if (!name || name[0] == '\0' || strcmp (name, "Unknown") == 0) {
            name = g_locale_to_utf8 (g_get_user_name (), -1 , NULL, NULL, NULL);
        }

        if (!name) {
            name = g_strdup (g_get_user_name ());
        }

        buf = g_strdup_printf (_("You are currently logged in as \"%s\"."), name);
        if (info_text != NULL) {
            buf2 = g_strdup_printf (info_text, seconds);
            markup = g_markup_printf_escaped ("<i>%s</i>", g_strconcat (buf, "\n", buf2, NULL));
            g_free (buf2);
        } else {
            markup = g_markup_printf_escaped ("<i>%s</i>", buf);
        }
        g_free (buf);
        g_free (name);
    } else if (info_text != NULL) {
        char *buf2;
        buf2 = g_strdup_printf (info_text, seconds);
        markup = g_markup_printf_escaped ("<i>%s</i>", buf2);
        g_free (buf2);
    }

    gtk_label_set_markup (GTK_LABEL (logout_dialog->priv->info_label),
                          markup ? markup : "");

    if (markup != NULL)
        g_free (markup);
}