summaryrefslogtreecommitdiff
path: root/mate-session
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2013-11-07 19:38:44 +0100
committerStefano Karapetsas <[email protected]>2013-11-07 19:38:44 +0100
commitc38e25ccb5f77ae4bfca9a43e54b4554220bdba9 (patch)
tree3917c71710a202026cef5ac72237f0680401becf /mate-session
parentc17333cbd562c8021ad152b6a41d7eaa46617719 (diff)
downloadmate-session-manager-c38e25ccb5f77ae4bfca9a43e54b4554220bdba9.tar.bz2
mate-session-manager-c38e25ccb5f77ae4bfca9a43e54b4554220bdba9.tar.xz
Make upower optional
This commit is just an improved version of the pull request by Wolfgang Ulbrich at https://github.com/mate-desktop/mate-session-manager/pull/38 making it working with both upower and systemd, and improving configure part
Diffstat (limited to 'mate-session')
-rw-r--r--mate-session/Makefile.am2
-rw-r--r--mate-session/gsm-logout-dialog.c25
-rw-r--r--mate-session/gsm-manager.c35
3 files changed, 44 insertions, 18 deletions
diff --git a/mate-session/Makefile.am b/mate-session/Makefile.am
index 2c73d63..9485fec 100644
--- a/mate-session/Makefile.am
+++ b/mate-session/Makefile.am
@@ -7,6 +7,7 @@ noinst_PROGRAMS = \
AM_CPPFLAGS = \
$(MATE_SESSION_CFLAGS) \
$(SYSTEMD_CFLAGS) \
+ $(UPOWER_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS)
AM_CFLAGS = $(WARN_CFLAGS)
@@ -78,6 +79,7 @@ mate_session_LDADD = \
$(XEXT_LIBS) \
$(MATE_SESSION_LIBS) \
$(SYSTEMD_LIBS) \
+ $(UPOWER_LIBS) \
$(EXECINFO_LIBS)
libgsmutil_la_SOURCES = \
diff --git a/mate-session/gsm-logout-dialog.c b/mate-session/gsm-logout-dialog.c
index 1a79875..323f123 100644
--- a/mate-session/gsm-logout-dialog.c
+++ b/mate-session/gsm-logout-dialog.c
@@ -27,7 +27,9 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#ifdef HAVE_UPOWER
#include <upower.h>
+#endif
#include "gsm-logout-dialog.h"
#ifdef HAVE_SYSTEMD
@@ -52,8 +54,9 @@ typedef enum {
struct _GsmLogoutDialogPrivate
{
GsmDialogLogoutType type;
-
+#ifdef HAVE_UPOWER
UpClient *up_client;
+#endif
#ifdef HAVE_SYSTEMD
GsmSystemd *systemd;
#endif
@@ -147,9 +150,9 @@ gsm_logout_dialog_init (GsmLogoutDialog *logout_dialog)
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (logout_dialog), TRUE);
gtk_window_set_keep_above (GTK_WINDOW (logout_dialog), TRUE);
gtk_window_stick (GTK_WINDOW (logout_dialog));
-
+#ifdef HAVE_UPOWER
logout_dialog->priv->up_client = up_client_new ();
-
+#endif
#ifdef HAVE_SYSTEMD
if (LOGIND_RUNNING())
logout_dialog->priv->systemd = gsm_get_systemd ();
@@ -176,12 +179,12 @@ gsm_logout_dialog_destroy (GsmLogoutDialog *logout_dialog,
g_source_remove (logout_dialog->priv->timeout_id);
logout_dialog->priv->timeout_id = 0;
}
-
+#ifdef HAVE_UPOWER
if (logout_dialog->priv->up_client) {
g_object_unref (logout_dialog->priv->up_client);
logout_dialog->priv->up_client = NULL;
}
-
+#endif
#ifdef HAVE_SYSTEMD
if (logout_dialog->priv->systemd) {
g_object_unref (logout_dialog->priv->systemd);
@@ -201,13 +204,17 @@ static gboolean
gsm_logout_supports_system_suspend (GsmLogoutDialog *logout_dialog)
{
gboolean ret;
+ ret = FALSE;
#ifdef HAVE_SYSTEMD
if (LOGIND_RUNNING())
ret = gsm_systemd_can_suspend (logout_dialog->priv->systemd);
+#endif
+#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER)
else
#endif
+#ifdef HAVE_UPOWER
ret = up_client_get_can_suspend (logout_dialog->priv->up_client);
-
+#endif
return ret;
}
@@ -215,13 +222,17 @@ static gboolean
gsm_logout_supports_system_hibernate (GsmLogoutDialog *logout_dialog)
{
gboolean ret;
+ ret = FALSE;
#ifdef HAVE_SYSTEMD
if (LOGIND_RUNNING())
ret = gsm_systemd_can_hibernate (logout_dialog->priv->systemd);
+#endif
+#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER)
else
#endif
+#ifdef HAVE_UPOWER
ret = up_client_get_can_hibernate (logout_dialog->priv->up_client);
-
+#endif
return ret;
}
diff --git a/mate-session/gsm-manager.c b/mate-session/gsm-manager.c
index cbe680b..eda565b 100644
--- a/mate-session/gsm-manager.c
+++ b/mate-session/gsm-manager.c
@@ -38,7 +38,9 @@
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
+#ifdef HAVE_UPOWER
#include <upower.h>
+#endif
#include <gtk/gtk.h> /* for logout dialog */
#include <gio/gio.h> /* for gsettings */
@@ -144,9 +146,10 @@ struct GsmManagerPrivate
DBusGProxy *bus_proxy;
DBusGConnection *connection;
-
+#ifdef HAVE_UPOWER
/* Interface with other parts of the system */
UpClient *up_client;
+#endif
};
enum {
@@ -1142,10 +1145,11 @@ manager_perhaps_lock (GsmManager *manager)
static void
manager_attempt_hibernate (GsmManager *manager)
{
+#ifdef HAVE_UPOWER
gboolean can_hibernate;
GError *error;
gboolean ret;
-
+#endif
#ifdef HAVE_SYSTEMD
if (LOGIND_RUNNING()) {
@@ -1158,8 +1162,11 @@ manager_attempt_hibernate (GsmManager *manager)
gsm_systemd_attempt_hibernate (systemd);
}
+#endif
+#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER)
else {
#endif
+#ifdef HAVE_UPOWER
can_hibernate = up_client_get_can_hibernate (manager->priv->up_client);
if (can_hibernate) {
@@ -1174,7 +1181,8 @@ manager_attempt_hibernate (GsmManager *manager)
g_error_free (error);
}
}
-#ifdef HAVE_SYSTEMD
+#endif
+#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER)
}
#endif
}
@@ -1182,10 +1190,11 @@ manager_attempt_hibernate (GsmManager *manager)
static void
manager_attempt_suspend (GsmManager *manager)
{
+#ifdef HAVE_UPOWER
gboolean can_suspend;
GError *error;
gboolean ret;
-
+#endif
#ifdef HAVE_SYSTEMD
if (LOGIND_RUNNING()) {
@@ -1198,8 +1207,11 @@ manager_attempt_suspend (GsmManager *manager)
gsm_systemd_attempt_suspend (systemd);
}
+#endif
+#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER)
else {
#endif
+#ifdef HAVE_UPOWER
can_suspend = up_client_get_can_suspend (manager->priv->up_client);
if (can_suspend) {
@@ -1214,7 +1226,8 @@ manager_attempt_suspend (GsmManager *manager)
g_error_free (error);
}
}
-#ifdef HAVE_SYSTEMD
+#endif
+#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER)
}
#endif
}
@@ -2387,12 +2400,12 @@ gsm_manager_dispose (GObject *object)
g_object_unref (manager->priv->settings_screensaver);
manager->priv->settings_screensaver = NULL;
}
-
+#ifdef HAVE_UPOWER
if (manager->priv->up_client != NULL) {
g_object_unref (manager->priv->up_client);
manager->priv->up_client = NULL;
}
-
+#endif
G_OBJECT_CLASS (gsm_manager_parent_class)->dispose (object);
}
@@ -2599,9 +2612,9 @@ gsm_manager_init (GsmManager *manager)
"status-changed",
G_CALLBACK (on_presence_status_changed),
manager);
-
+#ifdef HAVE_UPOWER
manager->priv->up_client = up_client_new ();
-
+#endif
g_signal_connect (manager->priv->settings_session,
"changed",
G_CALLBACK (on_gsettings_key_changed),
@@ -3270,12 +3283,12 @@ gsm_manager_can_shutdown (GsmManager *manager,
#endif
gboolean can_suspend;
gboolean can_hibernate;
-
+#ifdef HAVE_UPOWER
g_object_get (manager->priv->up_client,
"can-suspend", &can_suspend,
"can-hibernate", &can_hibernate,
NULL);
-
+#endif
g_debug ("GsmManager: CanShutdown called");
g_return_val_if_fail (GSM_IS_MANAGER (manager), FALSE);