]> www.fi.muni.cz Git - evince.git/commitdiff
[shell] Remove DBUS conditionals from TotemScrsaver
authorChristian Persch <chpe@gnome.org>
Thu, 13 May 2010 12:59:18 +0000 (14:59 +0200)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Tue, 25 May 2010 07:38:31 +0000 (09:38 +0200)
Now that GDBus is in GIO, there's no need to conditionally compile this
code. Just allow passing %NULL for @connection in totem_scrsaver_new()
to disable using DBUS to inhibit the screensaver.

cut-n-paste/totem-screensaver/totem-scrsaver.c
cut-n-paste/totem-screensaver/totem-scrsaver.h
shell/ev-application.c

index 1a9159f4bf05018ba8dacf9c91e9a091fe47b1aa..88ac99352d3f4c05c8264f922a66f4d11f769ed7 100644 (file)
 #endif /* HAVE_XTEST */
 #endif /* GDK_WINDOWING_X11 */
 
-#ifdef ENABLE_DBUS
+#include "totem-scrsaver.h"
+
 #define GS_SERVICE   "org.gnome.ScreenSaver"
 #define GS_PATH      "/org/gnome/ScreenSaver"
 #define GS_INTERFACE "org.gnome.ScreenSaver"
-#endif /* ENABLE_DBUS */
-
-#include "totem-scrsaver.h"
 
 #define XSCREENSAVER_MIN_TIMEOUT 60
 
@@ -53,12 +51,10 @@ struct TotemScrsaverPrivate {
        /* Whether the screensaver is disabled */
        gboolean disabled;
 
-#ifdef ENABLE_DBUS
         GDBusConnection *connection;
         gboolean have_screensaver_dbus;
         guint watch_id;
        guint32 cookie;
-#endif /* ENABLE_DBUS */
 
        /* To save the screensaver info */
        int timeout;
@@ -72,23 +68,23 @@ struct TotemScrsaverPrivate {
        gboolean have_xtest;
 };
 
+enum {
+        PROP_0,
+        PROP_CONNECTION
+};
+
 G_DEFINE_TYPE(TotemScrsaver, totem_scrsaver, G_TYPE_OBJECT)
 
 static gboolean
 screensaver_is_running_dbus (TotemScrsaver *scr)
 {
-#ifdef ENABLE_DBUS
-        return scr->priv->connection != NULL;
-#else
-       return FALSE;
-#endif /* ENABLE_DBUS */
+        return scr->priv->have_screensaver_dbus;
 }
 
 static void
 screensaver_inhibit_dbus (TotemScrsaver *scr,
                          gboolean       inhibit)
 {
-#ifdef ENABLE_DBUS
         TotemScrsaverPrivate *priv = scr->priv;
        GError *error = NULL;
         GVariant *value;
@@ -170,7 +166,6 @@ screensaver_inhibit_dbus (TotemScrsaver *scr,
                        g_error_free (error);
                }
        }
-#endif /* ENABLE_DBUS */
 }
 
 static void
@@ -185,7 +180,6 @@ screensaver_disable_dbus (TotemScrsaver *scr)
        screensaver_inhibit_dbus (scr, TRUE);
 }
 
-#ifdef ENABLE_DBUS
 static void
 screensaver_dbus_appeared_cb (GDBusConnection *connection,
                               const char      *name,
@@ -212,32 +206,18 @@ screensaver_dbus_disappeared_cb (GDBusConnection *connection,
 
         priv->have_screensaver_dbus = FALSE;
 }
-#endif
 
 static void
-screensaver_init_dbus (TotemScrsaver *scr)
+screensaver_finalize_dbus (TotemScrsaver *scr)
 {
-#ifdef ENABLE_DBUS
         TotemScrsaverPrivate *priv = scr->priv;
 
-        priv->watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
-                                                GS_SERVICE,
-                                                G_BUS_NAME_WATCHER_FLAGS_NONE,
-                                                screensaver_dbus_appeared_cb,
-                                                screensaver_dbus_disappeared_cb,
-                                                scr, NULL);
-#endif /* ENABLE_DBUS */
-}
+        if (priv->connection == NULL)
+                return;
 
-static void
-screensaver_finalize_dbus (TotemScrsaver *scr)
-{
-#ifdef ENABLE_DBUS
-        g_bus_unwatch_name (scr->priv->watch_id);
+        g_bus_unwatch_name (priv->watch_id);
 
-        if (scr->priv->connection != NULL)
-                g_object_unref (scr->priv->connection);
-#endif /* ENABLE_DBUS */
+        g_object_unref (priv->connection);
 }
 
 #ifdef GDK_WINDOWING_X11
@@ -355,19 +335,15 @@ screensaver_finalize_x11 (TotemScrsaver *scr)
 }
 #endif
 
-#ifdef ENABLE_DBUS
-
-enum {
-        PROP_0,
-        PROP_CONNECTION
-};
-
 static void
 totem_scrsaver_constructed (GObject *object)
 {
         TotemScrsaver *scr = TOTEM_SCRSAVER (object);
         TotemScrsaverPrivate *priv = scr->priv;
 
+        if (priv->connection == NULL)
+                return;
+
         priv->watch_id = g_bus_watch_name_on_connection (priv->connection,
                                                          GS_SERVICE,
                                                          G_BUS_NAME_WATCHER_FLAGS_NONE,
@@ -395,14 +371,15 @@ totem_scrsaver_set_property (GObject      *object,
        }
 }
 
-#endif /* ENABLE_DBUS */
-
 static void
 totem_scrsaver_class_init (TotemScrsaverClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-#ifdef ENABLE_DBUS
+        object_class->set_property = totem_scrsaver_set_property;
+        object_class->constructed = totem_scrsaver_constructed;
+       object_class->finalize = totem_scrsaver_finalize;
+
        g_object_class_install_property (object_class,
                                         PROP_CONNECTION,
                                         g_param_spec_object ("connection", NULL, NULL,
@@ -410,24 +387,24 @@ totem_scrsaver_class_init (TotemScrsaverClass *klass)
                                                              G_PARAM_WRITABLE |
                                                               G_PARAM_CONSTRUCT_ONLY |
                                                               G_PARAM_STATIC_STRINGS));
-        object_class->set_property = totem_scrsaver_set_property;
-        object_class->constructed = totem_scrsaver_constructed;
-#endif
-
-       object_class->finalize = totem_scrsaver_finalize;
 }
 
+/**
+ * totem_scrsaver_new:
+ * @connection: (allow-none): a #GDBusConnection, or %NULL
+ *
+ * Creates a #TotemScrsaver object. If @connection is non-%NULL,
+ * and the GNOME screen saver is running, it uses its DBUS interface to
+ * inhibit the screensaver; otherwise it falls back to using the X
+ * screensaver functionality for this.
+ *
+ * Returns: a newly created #TotemScrsaver
+ */
 TotemScrsaver *
-#ifdef ENABLE_DBUS
 totem_scrsaver_new (GDBusConnection *connection)
-#else
-totem_scrsaver_new (void)
-#endif
 {
        return g_object_new (TOTEM_TYPE_SCRSAVER,
-#ifdef ENABLE_DBUS
                              "connection", connection,
-#endif
                              NULL);
 }
 
@@ -436,7 +413,6 @@ totem_scrsaver_init (TotemScrsaver *scr)
 {
        scr->priv = G_TYPE_INSTANCE_GET_PRIVATE (scr, TOTEM_TYPE_SCRSAVER, TotemScrsaverPrivate);
 
-       screensaver_init_dbus (scr);
 #ifdef GDK_WINDOWING_X11
        screensaver_init_x11 (scr);
 #else
index d175896bef639bee74b30c5833a2490d8e505841..b9a5606d20b834c342be7758647abccf6561553f 100644 (file)
 #define TOTEM_SCRSAVER_H
 
 #include <glib.h>
-#include <glib-object.h>
-#ifdef ENABLE_DBUS
 #include <gio/gio.h>
-#endif
 
 G_BEGIN_DECLS
 
@@ -50,11 +47,7 @@ struct TotemScrsaverClass {
 };
 
 GType totem_scrsaver_get_type          (void);
-#ifdef ENABLE_DBUS
-TotemScrsaver *totem_scrsaver_new      (GDBusConnection *connection);
-#else
-TotemScrsaver *totem_scrsaver_new      (void);
-#endif
+TotemScrsaver *totem_scrsaver_new       (GDBusConnection *connection);
 void totem_scrsaver_enable             (TotemScrsaver *scr);
 void totem_scrsaver_disable            (TotemScrsaver *scr);
 void totem_scrsaver_set_state          (TotemScrsaver *scr,
index 191c6fb94274356955bc322aa5552b36bb9ac206..de2ef3d7053c2871270f30677e4fdab958597e50 100644 (file)
@@ -891,7 +891,7 @@ ev_application_init (EvApplication *ev_application)
        ev_application->scr_saver = totem_scrsaver_new (ev_application->connection);
 }
 #else
-        ev_application->scr_saver = totem_scrsaver_new ();
+        ev_application->scr_saver = totem_scrsaver_new (NULL);
 #endif /* ENABLE_DBUS */
 }