Commit e752a3e6 authored by Nick Schermer's avatar Nick Schermer
Browse files

Directly use upower for suspend/hibernate.

Working with Xfpm is too much work to get right for 4.10,
so readd the upower dbus communication.
parent 34191257
......@@ -139,56 +139,42 @@ main (int argc, char **argv)
}
/* create messsage */
if (opt_suspend || opt_hibernate)
proxy = dbus_g_proxy_new_for_name_owner (conn,
"org.xfce.SessionManager",
"/org/xfce/SessionManager",
"org.xfce.Session.Manager",
&err);
if (proxy != NULL)
{
proxy = dbus_g_proxy_new_for_name_owner (conn,
"org.xfce.PowerManager",
"/org/xfce/PowerManager",
"org.xfce.PowerManager",
&err);
if (proxy != NULL)
if (opt_halt)
{
if (opt_halt)
{
result = dbus_g_proxy_call (proxy, "Suspend", &err,
G_TYPE_INVALID, G_TYPE_INVALID);
}
else
{
result = dbus_g_proxy_call (proxy, "Hibernate", &err,
G_TYPE_INVALID, G_TYPE_INVALID);
}
result = dbus_g_proxy_call (proxy, "Shutdown", &err,
G_TYPE_BOOLEAN, allow_save,
G_TYPE_INVALID, G_TYPE_INVALID);
}
}
else
{
proxy = dbus_g_proxy_new_for_name_owner (conn,
"org.xfce.SessionManager",
"/org/xfce/SessionManager",
"org.xfce.Session.Manager",
&err);
if (proxy != NULL)
else if (opt_reboot)
{
result = dbus_g_proxy_call (proxy, "Restart", &err,
G_TYPE_BOOLEAN, allow_save,
G_TYPE_INVALID, G_TYPE_INVALID);
}
else if (opt_suspend)
{
result = dbus_g_proxy_call (proxy, "Suspend", &err,
G_TYPE_INVALID, G_TYPE_INVALID);
}
else if (opt_hibernate)
{
result = dbus_g_proxy_call (proxy, "Hibernate", &err,
G_TYPE_INVALID, G_TYPE_INVALID);
}
else
{
if (opt_halt)
{
result = dbus_g_proxy_call (proxy, "Shutdown", &err,
G_TYPE_BOOLEAN, allow_save,
G_TYPE_INVALID, G_TYPE_INVALID);
}
else if (opt_reboot)
{
result = dbus_g_proxy_call (proxy, "Restart", &err,
G_TYPE_BOOLEAN, allow_save,
G_TYPE_INVALID, G_TYPE_INVALID);
}
else
{
show_dialog = !opt_logout;
result = dbus_g_proxy_call (proxy, "Logout", &err,
G_TYPE_BOOLEAN, show_dialog,
G_TYPE_BOOLEAN, allow_save,
G_TYPE_INVALID, G_TYPE_INVALID);
}
show_dialog = !opt_logout;
result = dbus_g_proxy_call (proxy, "Logout", &err,
G_TYPE_BOOLEAN, show_dialog,
G_TYPE_BOOLEAN, allow_save,
G_TYPE_INVALID, G_TYPE_INVALID);
}
}
......
......@@ -60,7 +60,9 @@ xfce4_session_SOURCES = \
xfsm-splash-screen.c \
xfsm-splash-screen.h \
xfsm-startup.c \
xfsm-startup.h
xfsm-startup.h \
xfsm-upower.c \
xfsm-upower.h
xfce4_session_CFLAGS = \
$(GNOME_KEYRING_CFLAGS) \
......
......@@ -98,6 +98,7 @@ xfsm_consolekit_dbus_filter (DBusConnection *connection,
if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected")
&& g_strcmp0 (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0)
{
g_debug ("Consolekit disconnected");
xfsm_consolekit_proxy_free (XFSM_CONSOLEKIT (data));
}
......@@ -120,6 +121,8 @@ xfsm_consolekit_name_owner_changed (DBusGProxy *dbus_proxy,
if (g_strcmp0 (name, CK_NAME) == 0)
{
g_debug ("Consolekit owner changed");
/* only reconnect the consolekit proxy */
if (consolekit->ck_proxy != NULL)
{
......
......@@ -20,8 +20,8 @@
* MA 02110-1301 USA.
*/
#ifndef __XFSM_SHUTDOWN_HELPER_H__
#define __XFSM_SHUTDOWN_HELPER_H__
#ifndef __XFSM_CONSOLEKIT_HELPER_H__
#define __XFSM_CONSOLEKIT_HELPER_H__
typedef struct _XfsmConsolekitClass XfsmConsolekitClass;
typedef struct _XfsmConsolekit XfsmConsolekit;
......@@ -51,4 +51,4 @@ gboolean xfsm_consolekit_can_shutdown (XfsmConsolekit *consolekit,
gboolean *can_shutdown,
GError **error);
#endif /* !__XFSM_SHUTDOWN_HELPER_H__ */
#endif /* !__XFSM_CONSOLEKIT_HELPER_H__ */
......@@ -151,12 +151,14 @@ xfsm_logout_dialog_init (XfsmLogoutDialog *dialog)
gboolean can_restart;
gboolean can_suspend = FALSE;
gboolean can_hibernate = FALSE;
gboolean auth_suspend = FALSE;
gboolean auth_hibernate = FALSE;
GError *error = NULL;
XfconfChannel *channel;
GtkWidget *entry;
GtkWidget *image;
GtkWidget *separator;
gboolean xfpm_not_found = FALSE;
gboolean upower_not_found = FALSE;
dialog->type_clicked = XFSM_SHUTDOWN_LOGOUT;
dialog->shutdown = xfsm_shutdown_get ();
......@@ -296,56 +298,62 @@ xfsm_logout_dialog_init (XfsmLogoutDialog *dialog)
/**
* Suspend
*
* Hide the button if Xfpm is not installed
* Hide the button if UPower is not installed or system cannot suspend
**/
if (xfconf_channel_get_bool (channel, "/shutdown/ShowSuspend", TRUE))
{
if (xfsm_shutdown_can_suspend (dialog->shutdown, &can_suspend, &error))
if (xfsm_shutdown_can_suspend (dialog->shutdown, &can_suspend, &auth_suspend, &error))
{
button = xfsm_logout_dialog_button (_("Sus_pend"), "system-suspend",
"xfsm-suspend", XFSM_SHUTDOWN_SUSPEND,
dialog);
if (can_suspend)
{
button = xfsm_logout_dialog_button (_("Sus_pend"), "system-suspend",
"xfsm-suspend", XFSM_SHUTDOWN_SUSPEND,
dialog);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_set_sensitive (button, can_suspend);
gtk_widget_show (button);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_set_sensitive (button, auth_suspend);
gtk_widget_show (button);
gtk_widget_show (hbox);
gtk_widget_show (hbox);
}
}
else
{
g_printerr ("%s: Querying CanSuspend failed. %s\n\n",
g_printerr ("%s: Querying suspend failed: %s\n\n",
PACKAGE_NAME, ERROR_MSG (error));
g_clear_error (&error);
/* don't try hibernate again */
xfpm_not_found = TRUE;
upower_not_found = TRUE;
}
}
/**
* Hibernate
*
* Hide the button if Xfpm is not installed
* Hide the button if UPower is not installed or system cannot suspend
**/
if (!xfpm_not_found
if (!upower_not_found
&& xfconf_channel_get_bool (channel, "/shutdown/ShowHibernate", TRUE))
{
if (xfsm_shutdown_can_hibernate (dialog->shutdown, &can_hibernate, &error))
if (xfsm_shutdown_can_hibernate (dialog->shutdown, &can_hibernate, &auth_hibernate, &error))
{
button = xfsm_logout_dialog_button (_("_Hibernate"), "system-hibernate",
"xfsm-hibernate", XFSM_SHUTDOWN_HIBERNATE,
dialog);
if (can_hibernate)
{
button = xfsm_logout_dialog_button (_("_Hibernate"), "system-hibernate",
"xfsm-hibernate", XFSM_SHUTDOWN_HIBERNATE,
dialog);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_set_sensitive (button, can_hibernate);
gtk_widget_show (button);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_set_sensitive (button, auth_hibernate);
gtk_widget_show (button);
gtk_widget_show (hbox);
gtk_widget_show (hbox);
}
}
else
{
g_printerr ("%s: Querying CanHibernate failed. %s\n\n",
g_printerr ("%s: Querying hibernate failed: %s\n\n",
PACKAGE_NAME, ERROR_MSG (error));
g_clear_error (&error);
}
......
......@@ -79,7 +79,7 @@
<method name="Checkpoint">
<arg direction="in" name="session_name" type="s"/>
</method>
<!--
void org.Xfce.Session.Manager.Logout
-->
......@@ -116,6 +116,38 @@
<arg direction="out" name="can_restart" type="b"/>
</method>
<!--
void org.Xfce.Session.Manager.Suspend
This will possibly be removed in the future
-->
<method name="Suspend" />
<!--
void org.Xfce.Session.Manager.CanSuspend
This will possibly be removed in the future
-->
<method name="CanSuspend">
<arg direction="out" name="can_suspend" type="b"/>
</method>
<!--
void org.Xfce.Session.Manager.Hibernate
This will possibly be removed in the future
-->
<method name="Hibernate" />
<!--
void org.Xfce.Session.Manager.CanHibernate
This will possibly be removed in the future
-->
<method name="CanHibernate">
<arg direction="out" name="can_hibernate" type="b"/>
</method>
<!--
void org.xfce.Session.Manager.StateChanged(Unsigned Int old_state,
Unsigned Int new_state)
......
......@@ -1821,6 +1821,16 @@ static gboolean xfsm_manager_dbus_restart (XfsmManager *manager,
static gboolean xfsm_manager_dbus_can_restart (XfsmManager *manager,
gboolean *can_restart,
GError **error);
static gboolean xfsm_manager_dbus_suspend (XfsmManager *manager,
GError **error);
static gboolean xfsm_manager_dbus_can_suspend (XfsmManager *manager,
gboolean *can_suspend,
GError **error);
static gboolean xfsm_manager_dbus_hibernate (XfsmManager *manager,
GError **error);
static gboolean xfsm_manager_dbus_can_hibernate (XfsmManager *manager,
gboolean *can_hibernate,
GError **error);
/* eader needs the above fwd decls */
......@@ -2077,3 +2087,58 @@ xfsm_manager_dbus_can_restart (XfsmManager *manager,
return xfsm_shutdown_can_restart (manager->shutdown_helper,
can_restart, error);
}
static gboolean
xfsm_manager_dbus_suspend (XfsmManager *manager,
GError **error)
{
g_return_val_if_fail (XFSM_IS_MANAGER (manager), FALSE);
return xfsm_shutdown_try_suspend (manager->shutdown_helper, error);
}
static gboolean
xfsm_manager_dbus_can_suspend (XfsmManager *manager,
gboolean *can_suspend,
GError **error)
{
gboolean retval;
gboolean auth_suspend;
g_return_val_if_fail (XFSM_IS_MANAGER (manager), FALSE);
retval = xfsm_shutdown_can_suspend (manager->shutdown_helper,
can_suspend, &auth_suspend, error);
if (!auth_suspend)
can_suspend = FALSE;
return retval;
}
static gboolean
xfsm_manager_dbus_hibernate (XfsmManager *manager,
GError **error)
{
g_return_val_if_fail (XFSM_IS_MANAGER (manager), FALSE);
return xfsm_shutdown_try_hibernate (manager->shutdown_helper, error);
}
static gboolean
xfsm_manager_dbus_can_hibernate (XfsmManager *manager,
gboolean *can_hibernate,
GError **error)
{
gboolean retval;
gboolean auth_hibernate;
g_return_val_if_fail (XFSM_IS_MANAGER (manager), FALSE);
retval = xfsm_shutdown_can_hibernate (manager->shutdown_helper,
can_hibernate, &auth_hibernate, error);
if (!auth_hibernate)
can_hibernate = FALSE;
return retval;
}
......@@ -61,6 +61,7 @@
#include <xfce4-session/xfsm-global.h>
#include <xfce4-session/xfsm-legacy.h>
#include <xfce4-session/xfsm-consolekit.h>
#include <xfce4-session/xfsm-upower.h>
......@@ -87,6 +88,7 @@ struct _XfsmShutdown
GObject __parent__;
XfsmConsolekit *consolekit;
XfsmUPower *upower;
/* kiosk settings */
gboolean kiosk_can_shutdown;
......@@ -124,6 +126,7 @@ xfsm_shutdown_init (XfsmShutdown *shutdown)
XfceKiosk *kiosk;
shutdown->consolekit = xfsm_consolekit_get ();
shutdown->upower = xfsm_upower_get ();
shutdown->helper_state = SUDO_NOT_INITIAZED;
shutdown->helper_require_password = FALSE;
......@@ -142,6 +145,7 @@ xfsm_shutdown_finalize (GObject *object)
XfsmShutdown *shutdown = XFSM_SHUTDOWN (object);
g_object_unref (G_OBJECT (shutdown->consolekit));
g_object_unref (G_OBJECT (shutdown->upower));
/* close down helper */
xfsm_shutdown_sudo_free (shutdown);
......@@ -521,46 +525,6 @@ xfsm_shutdown_sudo_send_password (XfsmShutdown *shutdown,
static gboolean
xfsm_shutdown_query_xfpm (XfsmShutdown *shutdown,
const gchar *method,
gboolean *can_method,
GError **error)
{
DBusGConnection *conn;
DBusGProxy *proxy;
gboolean result = FALSE;
g_return_val_if_fail (can_method != NULL, FALSE);
/* never return true if something fails */
*can_method = FALSE;
conn = dbus_g_bus_get (DBUS_BUS_SESSION, error);
if (conn == NULL)
return FALSE;
proxy = dbus_g_proxy_new_for_name_owner (conn,
"org.xfce.PowerManagement",
"/org/xfce/PowerManagement",
"org.xfce.PowerManagement",
error);
if (proxy != NULL)
{
result = dbus_g_proxy_call (proxy, method, error,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, can_method,
G_TYPE_INVALID);
g_object_unref (proxy);
}
dbus_g_connection_unref (conn);
return result;
}
static gboolean
xfsm_shutdown_kiosk_can_shutdown (XfsmShutdown *shutdown,
GError **error)
......@@ -576,43 +540,6 @@ xfsm_shutdown_kiosk_can_shutdown (XfsmShutdown *shutdown,
static gboolean
xfsm_shutdown_run_xfpm (XfsmShutdown *shutdown,
const gchar *method,
GError **error)
{
DBusGConnection *conn;
DBusGProxy *proxy;
gboolean result = FALSE;
if (!xfsm_shutdown_kiosk_can_shutdown (shutdown, error))
return FALSE;
conn = dbus_g_bus_get (DBUS_BUS_SESSION, error);
if (conn == NULL)
return FALSE;
proxy = dbus_g_proxy_new_for_name_owner (conn,
"org.xfce.PowerManagement",
"/org/xfce/PowerManagement",
"org.xfce.PowerManagement",
error);
if (proxy != NULL)
{
result = dbus_g_proxy_call (proxy, method, error,
G_TYPE_INVALID,
G_TYPE_INVALID);
g_object_unref (proxy);
}
dbus_g_connection_unref (conn);
return result;
}
XfsmShutdown *
xfsm_shutdown_get (void)
{
......@@ -736,7 +663,7 @@ xfsm_shutdown_try_suspend (XfsmShutdown *shutdown,
{
g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
return xfsm_shutdown_run_xfpm (shutdown, "Suspend", error);
return xfsm_upower_try_suspend (shutdown->upower, error);
}
......@@ -747,7 +674,7 @@ xfsm_shutdown_try_hibernate (XfsmShutdown *shutdown,
{
g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
return xfsm_shutdown_run_xfpm (shutdown, "Hibernate", error);
return xfsm_upower_try_hibernate (shutdown->upower, error);
}
......@@ -794,12 +721,10 @@ xfsm_shutdown_can_shutdown (XfsmShutdown *shutdown,
/* This function only queries the CanSuspend state of
* xfce4-power-manager. If this package is not installed,
* suspend is not supported. */
gboolean
xfsm_shutdown_can_suspend (XfsmShutdown *shutdown,
gboolean *can_suspend,
gboolean *auth_suspend,
GError **error)
{
g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
......@@ -810,18 +735,16 @@ xfsm_shutdown_can_suspend (XfsmShutdown *shutdown,
return TRUE;
}
return xfsm_shutdown_query_xfpm (shutdown, "CanSuspend",
can_suspend, error);
return xfsm_upower_can_suspend (shutdown->upower, can_suspend,
auth_suspend, error);
}
/* This function only queries the CanHibernate state of
* xfce4-power-manager. If this package is not installed,
* hibernation is not supported. */
gboolean
xfsm_shutdown_can_hibernate (XfsmShutdown *shutdown,
gboolean *can_hibernate,
gboolean *auth_hibernate,
GError **error)
{
g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
......@@ -832,8 +755,8 @@ xfsm_shutdown_can_hibernate (XfsmShutdown *shutdown,
return TRUE;
}
return xfsm_shutdown_query_xfpm (shutdown, "CanHibernate",
can_hibernate, error);
return xfsm_upower_can_hibernate (shutdown->upower, can_hibernate,
auth_hibernate, error);
}
......
......@@ -88,10 +88,12 @@ gboolean xfsm_shutdown_can_shutdown (XfsmShutdown *shutdown,
gboolean xfsm_shutdown_can_suspend (XfsmShutdown *shutdown,
gboolean *can_suspend,
gboolean *auth_suspend,
GError **error);
gboolean xfsm_shutdown_can_hibernate (XfsmShutdown *shutdown,
gboolean *can_hibernate,
gboolean *auth_hibernate,
GError **error);
gboolean xfsm_shutdown_can_save_session (XfsmShutdown *shutdown);
......
/*-
* Copyright (c) 2011 Nick Schermer <nick@xfce.org>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*/
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <xfce4-session/xfsm-upower.h>
#define UPOWER_NAME "org.freedesktop.UPower"
#define UPOWER_PATH "/org/freedesktop/UPower"
#define UPOWER_INTERFACE UPOWER_NAME
static void xfsm_upower_finalize (GObject *object);
static gboolean xfsm_upower_proxy_ensure (XfsmUPower *upower,
GError **error);
static void xfsm_upower_proxy_free (XfsmUPower *upower);
struct _XfsmUPowerClass
{
GObjectClass __parent__;
};
struct _XfsmUPower
{
GObject __parent__;
DBusGConnection *dbus_conn;
DBusGProxy *upower_proxy;
DBusGProxy *props_proxy;
};
G_DEFINE_TYPE (XfsmUPower, xfsm_upower, G_TYPE_OBJECT)
static void
xfsm_upower_class_init (XfsmUPowerClass *klass)
{
GObjectClass *gobject_class;
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = xfsm_upower_finalize;