[gnome-session] GsmManager: add a command for showing a reboot dialog
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] GsmManager: add a command for showing a reboot dialog
- Date: Sat, 7 Jul 2012 16:14:44 +0000 (UTC)
commit 03f69091b71ad66c1559701efce643b15d0eaed4
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun Jun 3 17:25:38 2012 +0200
GsmManager: add a command for showing a reboot dialog
Before OS upgrades, applications may request a reboot. Add the
necessary infrastructure for showing a confirmation dialog, both
in fallback mode and in gnome-shell.
https://bugzilla.gnome.org/show_bug.cgi?id=679084
gnome-session/gsm-logout-dialog.c | 36 +++++++++++++++----
gnome-session/gsm-logout-dialog.h | 9 ++++-
gnome-session/gsm-manager.c | 50 +++++++++++++++++++++++++---
gnome-session/gsm-manager.h | 2 +
gnome-session/org.gnome.SessionManager.xml | 10 +++++-
tools/gnome-session-quit.c | 18 +++++++---
6 files changed, 104 insertions(+), 21 deletions(-)
---
diff --git a/gnome-session/gsm-logout-dialog.c b/gnome-session/gsm-logout-dialog.c
index b6cf489..e48afa7 100644
--- a/gnome-session/gsm-logout-dialog.c
+++ b/gnome-session/gsm-logout-dialog.c
@@ -43,11 +43,6 @@
#define LOCKDOWN_SCHEMA "org.gnome.desktop.lockdown"
#define KEY_DISABLE_USER_SWITCHING "disable-user-switching"
-typedef enum {
- GSM_DIALOG_LOGOUT_TYPE_LOGOUT,
- GSM_DIALOG_LOGOUT_TYPE_SHUTDOWN
-} GsmDialogLogoutType;
-
struct _GsmLogoutDialogPrivate
{
GsmDialogLogoutType type;
@@ -283,6 +278,14 @@ gsm_logout_dialog_timeout (gpointer data)
seconds_to_show);
break;
+ case GSM_DIALOG_LOGOUT_TYPE_REBOOT:
+ seconds_warning = ngettext ("This system will be automatically "
+ "restarted in %d second.",
+ "This system will be automatically "
+ "restarted in %d seconds.",
+ seconds_to_show);
+ break;
+
default:
g_assert_not_reached ();
}
@@ -419,6 +422,22 @@ gsm_get_dialog (GsmDialogLogoutType type,
GSM_LOGOUT_RESPONSE_SHUTDOWN);
}
break;
+ case GSM_DIALOG_LOGOUT_TYPE_REBOOT:
+ icon_name = GSM_ICON_SHUTDOWN;
+ primary_text = _("Restart this system now?");
+
+ logout_dialog->priv->default_response = GSM_LOGOUT_RESPONSE_REBOOT;
+
+ gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL);
+
+ if (gsm_logout_supports_reboot (logout_dialog)) {
+ gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
+ _("_Restart"),
+ GSM_LOGOUT_RESPONSE_REBOOT);
+ }
+ break;
default:
g_assert_not_reached ();
}
@@ -440,10 +459,11 @@ gsm_get_dialog (GsmDialogLogoutType type,
}
GtkWidget *
-gsm_get_shutdown_dialog (GdkScreen *screen,
- guint32 activate_time)
+gsm_get_shutdown_dialog (GdkScreen *screen,
+ guint32 activate_time,
+ GsmDialogLogoutType type)
{
- return gsm_get_dialog (GSM_DIALOG_LOGOUT_TYPE_SHUTDOWN,
+ return gsm_get_dialog (type,
screen,
activate_time);
}
diff --git a/gnome-session/gsm-logout-dialog.h b/gnome-session/gsm-logout-dialog.h
index 32d26f2..a48c1a9 100644
--- a/gnome-session/gsm-logout-dialog.h
+++ b/gnome-session/gsm-logout-dialog.h
@@ -38,6 +38,12 @@ enum
GSM_LOGOUT_RESPONSE_SLEEP
};
+typedef enum {
+ GSM_DIALOG_LOGOUT_TYPE_LOGOUT,
+ GSM_DIALOG_LOGOUT_TYPE_SHUTDOWN,
+ GSM_DIALOG_LOGOUT_TYPE_REBOOT
+} GsmDialogLogoutType;
+
#define GSM_TYPE_LOGOUT_DIALOG (gsm_logout_dialog_get_type ())
#define GSM_LOGOUT_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSM_TYPE_LOGOUT_DIALOG, GsmLogoutDialog))
#define GSM_LOGOUT_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSM_TYPE_LOGOUT_DIALOG, GsmLogoutDialogClass))
@@ -66,7 +72,8 @@ GType gsm_logout_dialog_get_type (void) G_GNUC_CONST;
GtkWidget *gsm_get_logout_dialog (GdkScreen *screen,
guint32 activate_time);
GtkWidget *gsm_get_shutdown_dialog (GdkScreen *screen,
- guint32 activate_time);
+ guint32 activate_time,
+ GsmDialogLogoutType type);
G_END_DECLS
diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c
index c9b18ba..0f0f491 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -3120,7 +3120,8 @@ logout_dialog_response (GsmLogoutDialog *logout_dialog,
}
static void
-show_fallback_shutdown_dialog (GsmManager *manager)
+show_fallback_shutdown_dialog (GsmManager *manager,
+ gboolean is_reboot)
{
GtkWidget *dialog;
@@ -3132,7 +3133,10 @@ show_fallback_shutdown_dialog (GsmManager *manager)
manager->priv->logout_mode = GSM_MANAGER_LOGOUT_MODE_NORMAL;
dialog = gsm_get_shutdown_dialog (gdk_screen_get_default (),
- gtk_get_current_event_time ());
+ gtk_get_current_event_time (),
+ is_reboot ?
+ GSM_DIALOG_LOGOUT_TYPE_REBOOT :
+ GSM_DIALOG_LOGOUT_TYPE_SHUTDOWN);
g_signal_connect (dialog,
"response",
@@ -3390,15 +3394,51 @@ gsm_manager_shutdown (GsmManager *manager,
shell_running = gsm_shell_is_running (manager->priv->shell);
- if (!shell_running) {
- show_fallback_shutdown_dialog (manager);
- } else {
+ if (!shell_running)
+ show_fallback_shutdown_dialog (manager, FALSE);
+ else
request_shutdown (manager);
+
+ return TRUE;
+}
+
+gboolean
+gsm_manager_reboot (GsmManager *manager,
+ GError **error)
+{
+ gboolean shell_running;
+
+ g_debug ("GsmManager: Reboot called");
+
+ g_return_val_if_fail (GSM_IS_MANAGER (manager), FALSE);
+
+ if (manager->priv->phase != GSM_MANAGER_PHASE_RUNNING) {
+ g_set_error (error,
+ GSM_MANAGER_ERROR,
+ GSM_MANAGER_ERROR_NOT_IN_RUNNING,
+ "Reboot interface is only available during the Running phase");
+ return FALSE;
}
+ if (_log_out_is_locked_down (manager)) {
+ g_set_error (error,
+ GSM_MANAGER_ERROR,
+ GSM_MANAGER_ERROR_LOCKED_DOWN,
+ "Logout has been locked down");
+ return FALSE;
+ }
+
+ shell_running = gsm_shell_is_running (manager->priv->shell);
+
+ if (!shell_running)
+ show_fallback_shutdown_dialog (manager, TRUE);
+ else
+ request_reboot (manager);
+
return TRUE;
}
+
gboolean
gsm_manager_can_shutdown (GsmManager *manager,
gboolean *shutdown_available,
diff --git a/gnome-session/gsm-manager.h b/gnome-session/gsm-manager.h
index 0cd2ef7..175c0ab 100644
--- a/gnome-session/gsm-manager.h
+++ b/gnome-session/gsm-manager.h
@@ -163,6 +163,8 @@ gboolean gsm_manager_is_inhibited (GsmManager
gboolean gsm_manager_shutdown (GsmManager *manager,
GError **error);
+gboolean gsm_manager_reboot (GsmManager *manager,
+ GError **error);
gboolean gsm_manager_can_shutdown (GsmManager *manager,
gboolean *shutdown_available,
diff --git a/gnome-session/org.gnome.SessionManager.xml b/gnome-session/org.gnome.SessionManager.xml
index 8311ce3..4de612b 100644
--- a/gnome-session/org.gnome.SessionManager.xml
+++ b/gnome-session/org.gnome.SessionManager.xml
@@ -255,7 +255,15 @@
<method name="Shutdown">
<doc:doc>
<doc:description>
- <doc:para>Request a shutdown dialog</doc:para>
+ <doc:para>Request a shutdown dialog.</doc:para>
+ </doc:description>
+ </doc:doc>
+ </method>
+
+ <method name="Reboot">
+ <doc:doc>
+ <doc:description>
+ <doc:para>Request a reboot dialog.</doc:para>
</doc:description>
</doc:doc>
</method>
diff --git a/tools/gnome-session-quit.c b/tools/gnome-session-quit.c
index f5d1838..6d34127 100644
--- a/tools/gnome-session-quit.c
+++ b/tools/gnome-session-quit.c
@@ -45,12 +45,14 @@ enum {
static gboolean logout = FALSE;
static gboolean power_off = FALSE;
+static gboolean reboot = FALSE;
static gboolean no_prompt = FALSE;
static gboolean force = FALSE;
static GOptionEntry options[] = {
{"logout", '\0', 0, G_OPTION_ARG_NONE, &logout, N_("Log out"), NULL},
{"power-off", '\0', 0, G_OPTION_ARG_NONE, &power_off, N_("Power off"), NULL},
+ {"reboot", '\0', 0, G_OPTION_ARG_NONE, &reboot, N_("Reboot"), NULL},
{"force", '\0', 0, G_OPTION_ARG_NONE, &force, N_("Ignoring any existing inhibitors"), NULL},
{"no-prompt", '\0', 0, G_OPTION_ARG_NONE, &no_prompt, N_("Don't prompt for user confirmation"), NULL},
{NULL}
@@ -139,7 +141,7 @@ do_logout (unsigned int mode)
}
static void
-do_power_off (void)
+do_power_off (const char *action)
{
DBusGProxy *sm_proxy;
GError *error;
@@ -152,18 +154,18 @@ do_power_off (void)
error = NULL;
res = dbus_g_proxy_call (sm_proxy,
- "Shutdown",
+ action,
&error,
G_TYPE_INVALID,
G_TYPE_INVALID);
if (!res) {
if (error != NULL) {
- g_warning ("Failed to call shutdown: %s",
- error->message);
+ g_warning ("Failed to call %s: %s",
+ action, error->message);
g_error_free (error);
} else {
- g_warning ("Failed to call shutdown");
+ g_warning ("Failed to call %s", action);
}
}
@@ -195,11 +197,15 @@ main (int argc, char *argv[])
conflicting_options++;
if (power_off)
conflicting_options++;
+ if (reboot)
+ conflicting_options++;
if (conflicting_options > 1)
display_error (_("Program called with conflicting options"));
if (power_off) {
- do_power_off ();
+ do_power_off ("Shutdown");
+ } else if (reboot) {
+ do_power_off ("Reboot");
} else {
/* default to logout */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]