Commit f825a3d0 authored by Kalev Lember's avatar Kalev Lember

session manager: Add new RebootToUpdate DBus API

This adds a new API that callers (gnome-software) can use to control how
updates are presented in the shutdown dialog.
parent 2bb33887
......@@ -118,6 +118,7 @@ typedef enum
GSM_MANAGER_LOGOUT_LOGOUT,
GSM_MANAGER_LOGOUT_REBOOT,
GSM_MANAGER_LOGOUT_REBOOT_INTERACT,
GSM_MANAGER_LOGOUT_REBOOT_TO_UPDATE,
GSM_MANAGER_LOGOUT_SHUTDOWN,
GSM_MANAGER_LOGOUT_SHUTDOWN_INTERACT,
} GsmManagerLogoutType;
......@@ -171,6 +172,7 @@ struct GsmManagerPrivate
gboolean dbus_disconnected : 1;
GsmShell *shell;
GVariant *shell_end_session_dialog_options;
guint shell_end_session_dialog_canceled_id;
guint shell_end_session_dialog_open_failed_id;
guint shell_end_session_dialog_confirmed_logout_id;
......@@ -209,7 +211,8 @@ static void _handle_client_end_session_response (GsmManager *manager,
gboolean cancel,
const char *reason);
static void show_shell_end_session_dialog (GsmManager *manager,
GsmShellEndSessionDialogType type);
GsmShellEndSessionDialogType type,
GVariant *options);
static gpointer manager_object = NULL;
G_DEFINE_TYPE (GsmManager, gsm_manager, G_TYPE_OBJECT)
......@@ -491,6 +494,7 @@ gsm_manager_quit (GsmManager *manager)
break;
case GSM_MANAGER_LOGOUT_REBOOT:
case GSM_MANAGER_LOGOUT_REBOOT_INTERACT:
case GSM_MANAGER_LOGOUT_REBOOT_TO_UPDATE:
gsm_system_complete_shutdown (manager->priv->system);
gsm_quit ();
break;
......@@ -1164,6 +1168,9 @@ end_session_or_show_shell_dialog (GsmManager *manager)
case GSM_MANAGER_LOGOUT_REBOOT_INTERACT:
type = GSM_SHELL_END_SESSION_DIALOG_TYPE_RESTART;
break;
case GSM_MANAGER_LOGOUT_REBOOT_TO_UPDATE:
type = GSM_SHELL_END_SESSION_DIALOG_TYPE_RESTART_TO_UPDATE;
break;
case GSM_MANAGER_LOGOUT_SHUTDOWN:
case GSM_MANAGER_LOGOUT_SHUTDOWN_INTERACT:
type = GSM_SHELL_END_SESSION_DIALOG_TYPE_SHUTDOWN;
......@@ -1182,7 +1189,7 @@ end_session_or_show_shell_dialog (GsmManager *manager)
switch (manager->priv->logout_mode) {
case GSM_MANAGER_LOGOUT_MODE_NORMAL:
if (logout_inhibited || logout_prompt) {
show_shell_end_session_dialog (manager, type);
show_shell_end_session_dialog (manager, type, manager->priv->shell_end_session_dialog_options);
} else {
end_phase (manager);
}
......@@ -1190,7 +1197,7 @@ end_session_or_show_shell_dialog (GsmManager *manager)
case GSM_MANAGER_LOGOUT_MODE_NO_CONFIRMATION:
if (logout_inhibited) {
show_shell_end_session_dialog (manager, type);
show_shell_end_session_dialog (manager, type, manager->priv->shell_end_session_dialog_options);
} else {
end_phase (manager);
}
......@@ -2369,6 +2376,7 @@ gsm_manager_dispose (GObject *object)
g_clear_object (&manager->priv->lockdown_settings);
g_clear_object (&manager->priv->system);
g_clear_object (&manager->priv->shell);
g_clear_pointer (&manager->priv->shell_end_session_dialog_options, g_variant_unref);
if (manager->priv->skeleton != NULL) {
g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON (manager->priv->skeleton),
......@@ -2515,6 +2523,21 @@ request_reboot (GsmManager *manager)
end_phase (manager);
}
static void
request_reboot_to_update (GsmManager *manager, GVariant *options)
{
g_debug ("GsmManager: requesting reboot to update");
/* See the comment in request_reboot() for some more details about
* what work needs to be done here. */
manager->priv->logout_type = GSM_MANAGER_LOGOUT_REBOOT_TO_UPDATE;
g_clear_pointer (&manager->priv->shell_end_session_dialog_options, g_variant_unref);
manager->priv->shell_end_session_dialog_options = g_variant_ref (options);
end_phase (manager);
}
static void
request_shutdown (GsmManager *manager)
{
......@@ -2608,6 +2631,42 @@ gsm_manager_reboot (GsmExportedManager *skeleton,
return TRUE;
}
static gboolean
gsm_manager_reboot_to_update (GsmExportedManager *skeleton,
GDBusMethodInvocation *invocation,
GVariant *options,
GsmManager *manager)
{
GTask *task;
g_debug ("GsmManager: RebootToUpdate called");
if (manager->priv->phase < GSM_MANAGER_PHASE_RUNNING) {
g_dbus_method_invocation_return_error (invocation,
GSM_MANAGER_ERROR,
GSM_MANAGER_ERROR_NOT_IN_RUNNING,
"RebootToUpdate interface is only available after the Running phase starts");
return TRUE;
}
if (_log_out_is_locked_down (manager)) {
g_dbus_method_invocation_return_error (invocation,
GSM_MANAGER_ERROR,
GSM_MANAGER_ERROR_LOCKED_DOWN,
"Logout has been locked down");
return TRUE;
}
task = g_task_new (manager, manager->priv->end_session_cancellable, (GAsyncReadyCallback) complete_end_session_task, invocation);
manager->priv->pending_end_session_tasks = g_slist_prepend (manager->priv->pending_end_session_tasks,
task);
request_reboot_to_update (manager, options);
return TRUE;
}
static gboolean
gsm_manager_can_shutdown (GsmExportedManager *skeleton,
GDBusMethodInvocation *invocation,
......@@ -3307,6 +3366,8 @@ register_manager (GsmManager *manager)
G_CALLBACK (gsm_manager_logout_dbus), manager);
g_signal_connect (skeleton, "handle-reboot",
G_CALLBACK (gsm_manager_reboot), manager);
g_signal_connect (skeleton, "handle-reboot-to-update",
G_CALLBACK (gsm_manager_reboot_to_update), manager);
g_signal_connect (skeleton, "handle-register-client",
G_CALLBACK (gsm_manager_register_client), manager);
g_signal_connect (skeleton, "handle-set-reboot-to-firmware-setup",
......@@ -3556,14 +3617,16 @@ connect_shell_dialog_signals (GsmManager *manager)
static void
show_shell_end_session_dialog (GsmManager *manager,
GsmShellEndSessionDialogType type)
GsmShellEndSessionDialogType type,
GVariant *options)
{
if (!gsm_shell_is_running (manager->priv->shell))
return;
gsm_shell_open_end_session_dialog (manager->priv->shell,
type,
manager->priv->inhibitors);
manager->priv->inhibitors,
options);
connect_shell_dialog_signals (manager);
}
......
......@@ -51,6 +51,7 @@ struct _GsmShellPrivate
gboolean dialog_is_open;
GsmShellEndSessionDialogType end_session_dialog_type;
GVariant *end_session_dialog_options;
guint update_idle_id;
guint watch_id;
......@@ -236,6 +237,8 @@ gsm_shell_finalize (GObject *object)
g_object_unref (shell->priv->inhibitors);
g_clear_pointer (&shell->priv->end_session_dialog_options, g_variant_unref);
if (shell->priv->watch_id != 0) {
g_bus_unwatch_name (shell->priv->watch_id);
shell->priv->watch_id = 0;
......@@ -398,7 +401,8 @@ on_need_end_session_dialog_update (GsmShell *shell)
gsm_shell_open_end_session_dialog (shell,
shell->priv->end_session_dialog_type,
shell->priv->inhibitors);
shell->priv->inhibitors,
shell->priv->end_session_dialog_options);
return FALSE;
}
......@@ -415,7 +419,8 @@ queue_end_session_dialog_update (GsmShell *shell)
gboolean
gsm_shell_open_end_session_dialog (GsmShell *shell,
GsmShellEndSessionDialogType type,
GsmStore *inhibitors)
GsmStore *inhibitors,
GVariant *options)
{
GDBusProxy *proxy;
GError *error;
......@@ -488,6 +493,9 @@ gsm_shell_open_end_session_dialog (GsmShell *shell,
shell->priv->dialog_is_open = TRUE;
shell->priv->end_session_dialog_type = type;
g_clear_pointer (&shell->priv->end_session_dialog_options, g_variant_unref);
shell->priv->end_session_dialog_options = g_variant_ref (options);
return TRUE;
}
......
......@@ -46,6 +46,7 @@ typedef enum
GSM_SHELL_END_SESSION_DIALOG_TYPE_LOGOUT = 0,
GSM_SHELL_END_SESSION_DIALOG_TYPE_SHUTDOWN,
GSM_SHELL_END_SESSION_DIALOG_TYPE_RESTART,
GSM_SHELL_END_SESSION_DIALOG_TYPE_RESTART_TO_UPDATE,
} GsmShellEndSessionDialogType;
struct _GsmShell
......@@ -79,7 +80,8 @@ gboolean gsm_shell_is_running (GsmShell *shell);
gboolean gsm_shell_open_end_session_dialog (GsmShell *shell,
GsmShellEndSessionDialogType type,
GsmStore *inhibitors);
GsmStore *inhibitors,
GVariant *options);
void gsm_shell_close_end_session_dialog (GsmShell *shell);
G_END_DECLS
......
......@@ -290,6 +290,19 @@
</doc:doc>
</method>
<method name="RebootToUpdate">
<arg type="a{sv}" direction="in" name="options">
<doc:doc>
<doc:summary>Allows the caller to change how updates are presented in the shutdown dialog</doc:summary>
</doc:doc>
</arg>
<doc:doc>
<doc:description>
<doc:para>Request a reboot dialog for installing updates.</doc:para>
</doc:description>
</doc:doc>
</method>
<method name="CanShutdown">
<arg name="is_available" direction="out" type="b">
<doc:doc>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment