error);
}
+static GVariant *
+login1_call_function (const gchar *function, GVariant *parameters, GError **error)
+{
+ GVariant *r;
+ gchar *str_result;
+
+ if (!login1_proxy)
+ {
+ login1_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ NULL,
+ error);
+ if (!login1_proxy)
+ return NULL;
+ }
+
+ r = g_dbus_proxy_call_sync (login1_proxy,
+ function,
+ parameters,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ error);
+
+ return r;
+}
+
/**
* lightdm_get_can_suspend:
*
gboolean
lightdm_get_can_suspend (void)
{
- GVariant *result;
gboolean can_suspend = FALSE;
+ GVariant *r;
- result = upower_call_function ("SuspendAllowed", NULL);
- if (!result)
- return FALSE;
-
- if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(b)")))
- g_variant_get (result, "(b)", &can_suspend);
- g_variant_unref (result);
+ r = login1_call_function ("CanSuspend", NULL, NULL);
+ if (r)
+ {
+ gchar *result;
+ if (g_variant_is_of_type (r, G_VARIANT_TYPE ("(s)")))
+ {
+ g_variant_get (r, "(&s)", &result);
+ can_suspend = g_strcmp0 (result, "yes") == 0;
+ }
+ }
+ else
+ {
+ r = upower_call_function ("CanSuspend", NULL);
+ if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
+ g_variant_get (r, "(b)", &can_suspend);
+ }
+ if (r)
+ g_variant_unref (r);
return can_suspend;
}
lightdm_suspend (GError **error)
{
GVariant *result;
-
- result = upower_call_function ("Suspend", error);
+ gboolean suspended;
+
+ result = login1_call_function ("Suspend", g_variant_new("(b)", FALSE), error);
+
if (!result)
- return FALSE;
+ {
+ if (error)
+ g_printerr ("Can't suspend using lightdm; falling back to UPower: %s",
+ (*error)->message);
+ g_clear_error (error);
+ result = upower_call_function ("Suspend", error);
+ }
+
+ suspended = result != NULL;
+ if (result)
+ g_variant_unref (result);
- g_variant_unref (result);
+ return suspended;
- return TRUE;
}
/**
gboolean
lightdm_get_can_hibernate (void)
{
- GVariant *result;
gboolean can_hibernate = FALSE;
-
- result = upower_call_function ("HibernateAllowed", NULL);
- if (!result)
- return FALSE;
+ GVariant *r;
- if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(b)")))
- g_variant_get (result, "(b)", &can_hibernate);
- g_variant_unref (result);
+ r = login1_call_function ("CanHibernate", NULL, NULL);
+ if (r)
+ {
+ gchar *result;
+ if (g_variant_is_of_type (r, G_VARIANT_TYPE ("(s)")))
+ {
+ g_variant_get (r, "(&s)", &result);
+ can_hibernate = g_strcmp0 (result, "yes") == 0;
+ }
+ }
+ else
+ {
+ r = upower_call_function ("CanHibernate", NULL);
+ if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
+ g_variant_get (r, "(b)", &can_hibernate);
+ }
+ if (r)
+ g_variant_unref (r);
return can_hibernate;
}
lightdm_hibernate (GError **error)
{
GVariant *result;
-
- result = upower_call_function ("Hibernate", error);
+ gboolean hibernated;
+
+ result = login1_call_function ("Hibernate", g_variant_new("(b)", FALSE), error);
+
if (!result)
- return FALSE;
+ {
+ if (error)
+ g_printerr ("Can't hibernate using lightdm; falling back to UPower: %s",
+ (*error)->message);
+ g_clear_error (error);
+ result = upower_call_function ("Hibernate", error);
+ }
- g_variant_unref (result);
+ hibernated = result != NULL;
+ if (result)
+ g_variant_unref (result);
- return TRUE;
+ return hibernated;
}
static GVariant *
return r;
}
-static GVariant *
-login1_call_function (const gchar *function, GVariant *parameters, GError **error)
-{
- GVariant *r;
- gchar *str_result;
-
- if (!login1_proxy)
- {
- login1_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- NULL,
- error);
- if (!login1_proxy)
- return NULL;
- }
-
- r = g_dbus_proxy_call_sync (login1_proxy,
- function,
- parameters,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- error);
-
- return r;
-}
-
/**
* lightdm_get_can_restart:
*
gboolean restarted;
r = login1_call_function ("Reboot", g_variant_new("(b)", FALSE), error);
+
if (!r)
{
g_clear_error (error);
bool PowerInterface::canSuspend()
{
+ if (d->login1Interface->isValid())
+ {
+ QDBusReply<QString> reply = d->login1Interface->call("CanSuspend");
+ if (reply.isValid())
+ {
+ return reply.value() == "yes";
+ }
+ }
+
+ qWarning() << d->login1Interface->lastError();
+
QDBusReply<bool> reply = d->powerManagementInterface->call("SuspendAllowed");
if (reply.isValid()) {
return reply.value();
bool PowerInterface::suspend()
{
- QDBusReply<void> reply = d->powerManagementInterface->call("Suspend");
+ QDBusReply<void> reply;
+ if (d->login1Interface->isValid())
+ reply = d->login1Interface->call("Hibernate", false);
+ else
+ reply = d->powerManagementInterface->call("Hibernate");
+
return reply.isValid ();
}
bool PowerInterface::canHibernate()
{
+ if (d->login1Interface->isValid())
+ {
+ QDBusReply<QString> reply = d->login1Interface->call("CanHibernate");
+ if (reply.isValid())
+ {
+ return reply.value() == "yes";
+ }
+ }
+
+ qWarning() << d->login1Interface->lastError();
+
QDBusReply<bool> reply = d->powerManagementInterface->call("HibernateAllowed");
if (reply.isValid()) {
return reply.value();
bool PowerInterface::hibernate()
{
- QDBusReply<void> reply = d->powerManagementInterface->call("Hibernate");
+ QDBusReply<void> reply;
+ if (d->login1Interface->isValid())
+ reply = d->login1Interface->call("Hibernate", false);
+ else
+ reply = d->powerManagementInterface->call("Hibernate");
+
return reply.isValid ();
}