gnome-session r5244 - in trunk: . gnome-session



Author: lucasr
Date: Wed Feb 11 20:11:16 2009
New Revision: 5244
URL: http://svn.gnome.org/viewvc/gnome-session?rev=5244&view=rev

Log:
2009-02-11  Lucas Rocha  <lucasr gnome org>

	Bug 556439 â improve logout/shutdown dialog messages

	* gnome-session/gsm-consolekit.[ch]: add new
	gsm_consolekit_get_current_session_type function to GsmConsolekit.
	* gnome-session/gsm-logout-dialog.c (gsm_logout_dialog_timeout): only
	message about logged user when using logout dialog from gdm.
	Patch by Matthias Clasen.

Modified:
   trunk/ChangeLog
   trunk/gnome-session/gsm-consolekit.c
   trunk/gnome-session/gsm-consolekit.h
   trunk/gnome-session/gsm-logout-dialog.c

Modified: trunk/gnome-session/gsm-consolekit.c
==============================================================================
--- trunk/gnome-session/gsm-consolekit.c	(original)
+++ trunk/gnome-session/gsm-consolekit.c	Wed Feb 11 20:11:16 2009
@@ -989,6 +989,65 @@
 #endif
 }
 
+gchar *
+gsm_consolekit_get_current_session_type (GsmConsolekit *manager)
+{
+	DBusConnection *connection;
+	DBusError error;
+	DBusMessage *message = NULL;
+	DBusMessage *reply = NULL;
+	gchar *session_id;
+	gchar *ret;
+	DBusMessageIter iter;
+	const char *value;
+
+	session_id = NULL;
+	ret = NULL;
+
+	connection = dbus_g_connection_get_connection (manager->priv->dbus_connection);
+	if (!get_current_session_id (connection, &session_id)) {
+		goto out;
+	}
+
+	dbus_error_init (&error);
+	message = dbus_message_new_method_call (CK_NAME,
+						session_id,
+						CK_SESSION_INTERFACE,
+						"GetSessionType");
+	if (message == NULL) {
+		goto out;
+	}
+
+	reply = dbus_connection_send_with_reply_and_block (connection,
+							   message,
+							   -1,
+							   &error);
+
+	if (reply == NULL) {
+		if (dbus_error_is_set (&error)) {
+			g_warning ("Unable to determine session type: %s", error.message);
+			dbus_error_free (&error);
+		}
+		goto out;
+	}
+
+	dbus_message_iter_init (reply, &iter);
+	dbus_message_iter_get_basic (&iter, &value);
+	ret = g_strdup (value);
+
+out:
+	if (message != NULL) {
+		dbus_message_unref (message);
+	}
+	if (reply != NULL) {
+		dbus_message_unref (reply);
+	}
+	g_free (session_id);
+
+	return ret;
+}
+
+
 GsmConsolekit *
 gsm_get_consolekit (void)
 {

Modified: trunk/gnome-session/gsm-consolekit.h
==============================================================================
--- trunk/gnome-session/gsm-consolekit.h	(original)
+++ trunk/gnome-session/gsm-consolekit.h	Wed Feb 11 20:11:16 2009
@@ -81,6 +81,8 @@
 void             gsm_consolekit_set_session_idle (GsmConsolekit *manager,
                                                   gboolean       is_idle);
 
+gchar           *gsm_consolekit_get_current_session_type (GsmConsolekit *manager);
+
 GsmConsolekit   *gsm_get_consolekit             (void);
 
 G_END_DECLS

Modified: trunk/gnome-session/gsm-logout-dialog.c
==============================================================================
--- trunk/gnome-session/gsm-logout-dialog.c	(original)
+++ trunk/gnome-session/gsm-logout-dialog.c	Wed Feb 11 20:11:16 2009
@@ -256,9 +256,10 @@
 gsm_logout_dialog_timeout (gpointer data)
 {
         GsmLogoutDialog *logout_dialog;
+        char            *seconds_warning;
         char            *secondary_text;
-        char            *name;
         int              seconds_to_show;
+        static char     *session_type = NULL;
 
         logout_dialog = (GsmLogoutDialog *) data;
 
@@ -280,52 +281,63 @@
 
         switch (logout_dialog->priv->type) {
         case GSM_DIALOG_LOGOUT_TYPE_LOGOUT:
-                secondary_text = ngettext ("You are currently logged in as "
-                                           "\"%s\".\n"
-                                           "You will be automatically logged "
-                                           "out in %d second.",
-                                           "You are currently logged in as "
-                                           "\"%s\".\n"
-                                           "You will be automatically logged "
-                                           "out in %d seconds.",
-                                           seconds_to_show);
+                seconds_warning = ngettext ("You will be automatically logged "
+                                            "out in %d second.",
+                                            "You will be automatically logged "
+                                            "out in %d seconds.",
+                                            seconds_to_show);
                 break;
 
         case GSM_DIALOG_LOGOUT_TYPE_SHUTDOWN:
-                secondary_text = ngettext ("You are currently logged in as "
-                                           "\"%s\".\n"
-                                           "This system will be automatically "
-                                           "shut down in %d second.",
-                                           "You are currently logged in as "
-                                           "\"%s\".\n"
-                                           "This system will be automatically "
-                                           "shut down in %d seconds.",
-                                           seconds_to_show);
+                seconds_warning = ngettext ("This system will be automatically "
+                                            "shut down in %d second.",
+                                            "This system will be automatically "
+                                            "shut down in %d seconds.",
+                                            seconds_to_show);
                 break;
 
         default:
                 g_assert_not_reached ();
         }
 
-        name = g_locale_to_utf8 (g_get_real_name (), -1, NULL, NULL, NULL);
+        if (session_type == NULL) {
+		GsmConsolekit *consolekit;
 
-        if (!name || name[0] == '\0' || strcmp (name, "Unknown") == 0) {
-                name = g_locale_to_utf8 (g_get_user_name (), -1 , NULL, NULL, NULL);
+                consolekit = gsm_get_consolekit ();
+                session_type = gsm_consolekit_get_current_session_type (consolekit);
+                g_object_unref (consolekit);
         }
 
-        if (!name) {
-                name = g_strdup (g_get_user_name ());
-        }
+        if (g_strcmp0 (session_type, "LoginWindow") != 0) {
+                char *name, *tmp;
+
+                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 ());
+                }
+
+                tmp = g_strdup_printf (_("You are currently logged in as \"%s\"."), name);
+                secondary_text = g_strconcat (tmp, "\n", seconds_warning, NULL);
+                g_free (tmp);
+
+                g_free (name);
+	} else {
+		secondary_text = g_strdup (seconds_warning);
+	}
 
         gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (logout_dialog),
                                                   secondary_text,
-                                                  name,
                                                   seconds_to_show,
                                                   NULL);
 
         logout_dialog->priv->timeout--;
 
-        g_free (name);
+        g_free (secondary_text);
 
         return TRUE;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]