[gnome-video-arcade] Bug 622933 - Migrate from dbus-glib to GDBus
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-video-arcade] Bug 622933 - Migrate from dbus-glib to GDBus
- Date: Sun, 15 May 2011 22:20:07 +0000 (UTC)
commit 35e340b23a91df6d75331382b7ddfe1143540ac6
Author: Matthew Barnes <mbarnes redhat com>
Date: Sun May 15 14:48:19 2011 -0400
Bug 622933 - Migrate from dbus-glib to GDBus
Introduces GvaScreenSaver, based on TotemScrsaver.
configure.ac | 23 +-
docs/reference/Makefile.am | 8 +-
docs/reference/gnome-video-arcade-docs.sgml | 2 +-
docs/reference/gnome-video-arcade-sections.txt | 29 ++-
docs/reference/gnome-video-arcade.types | 2 +
docs/reference/tmpl/gva-dbus.sgml | 42 --
docs/reference/tmpl/gva-screen-saver.sgml | 76 ++++
docs/reference/tmpl/gva-ui.sgml | 8 +
src/Makefile.am | 17 +-
src/gva-dbus.c | 124 ------
src/gva-dbus.h | 41 --
src/gva-screen-saver.c | 494 ++++++++++++++++++++++++
src/gva-screen-saver.h | 86 ++++
src/gva-ui.c | 104 +++--
src/gva-ui.h | 1 +
src/main.c | 10 +-
16 files changed, 764 insertions(+), 303 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0aad8ed..88fc95b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,7 @@ AC_SUBST(abs_top_builddir)
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
# Dependencies
-GLIB_MODULES="glib-2.0 >= 2.28"
+GLIB_MODULES="glib-2.0 gio-2.0 >= 2.28"
PKG_CHECK_MODULES(GLIB, $GLIB_MODULES)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
@@ -47,26 +47,6 @@ AC_SUBST(SQLITE_LIBS)
GDS_MODULES="gsettings-desktop-schemas"
PKG_CHECK_MODULES(GSETTINGS_DESKTOP_SCHEMAS, $GDS_MODULES)
-# --with-dbus=[yes|no]
-DBUS_CFLAGS=
-DBUS_LIBS=
-AC_ARG_WITH([dbus],
- [AC_HELP_STRING([--with-dbus],
- [use D-Bus for better desktop integration [default=yes]])],
- with_dbus="$withval", with_dbus="yes")
-if test "$with_dbus" = "yes"; then
-DBUS_MODULES="dbus-glib-1" # minimum version?
-PKG_CHECK_MODULES(DBUS, $DBUS_MODULES)
-AC_DEFINE_UNQUOTED(HAVE_DBUS, 1,
- [Define to 1 if you are using GLib bindings for D-Bus])
-else
-DBUS_CFLAGS=
-DBUS_LIBS=
-fi
-AM_CONDITIONAL(HAVE_DBUS, test $with_dbus = yes)
-AC_SUBST(DBUS_CFLAGS)
-AC_SUBST(DBUS_LIBS)
-
# --with-gstreamer=[yes|no]
AC_ARG_WITH([gstreamer],
[AC_HELP_STRING([--with-gstreamer],
@@ -231,7 +211,6 @@ echo " MAME Program : $MAME_PROGRAM"
echo " Category File : $with_category"
echo " History File : $with_history"
echo " NPlayers File : $with_nplayers"
-echo " Use D-Bus : $with_dbus"
echo " Use GStreamer : $with_gstreamer"
echo " Use libwnck : $with_wnck"
echo
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index dc77475..a3fd3f9 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -74,7 +74,6 @@ INCLUDES= \
-I$(top_srcdir)/src \
-I$(top_builddir) \
-I$(top_builddir)/src \
- $(DBUS_CFLAGS) \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
$(GIT_CFLAGS) \
@@ -82,10 +81,6 @@ INCLUDES= \
$(SQLITE_CFLAGS) \
$(WNCK_CFLAGS)
-if HAVE_DBUS
-DBUS_OBJECTS = $(top_builddir)/src/gva-dbus.o
-endif
-
GTKDOC_LIBS= \
$(top_builddir)/src/gva-audit.o \
$(top_builddir)/src/gva-categories.o \
@@ -108,14 +103,13 @@ GTKDOC_LIBS= \
$(top_builddir)/src/gva-preferences.o \
$(top_builddir)/src/gva-process.o \
$(top_builddir)/src/gva-properties.o \
+ $(top_builddir)/src/gva-screen-saver.o \
$(top_builddir)/src/gva-time.o \
$(top_builddir)/src/gva-tree-view.o \
$(top_builddir)/src/gva-ui.o \
$(top_builddir)/src/gva-util.o \
$(top_builddir)/src/gva-wnck.o \
$(top_builddir)/src/@MAME_BACKEND@ \
- $(DBUS_OBJECTS) \
- $(DBUS_LIBS) \
$(GLIB_LIBS) \
$(GTK_LIBS) \
$(GIT_LIBS) \
diff --git a/docs/reference/gnome-video-arcade-docs.sgml b/docs/reference/gnome-video-arcade-docs.sgml
index 0675353..3bd7d71 100644
--- a/docs/reference/gnome-video-arcade-docs.sgml
+++ b/docs/reference/gnome-video-arcade-docs.sgml
@@ -25,7 +25,6 @@
<xi:include href="xml/gva-categories.xml"/>
<xi:include href="xml/gva-columns.xml"/>
<xi:include href="xml/gva-db.xml"/>
- <xi:include href="xml/gva-dbus.xml"/>
<xi:include href="xml/gva-error.xml"/>
<xi:include href="xml/gva-favorites.xml"/>
<xi:include href="xml/gva-history.xml"/>
@@ -47,6 +46,7 @@
<xi:include href="xml/gva-music-button.xml"/>
<xi:include href="xml/gva-mute-button.xml"/>
<xi:include href="xml/gva-process.xml"/>
+ <xi:include href="xml/gva-screen-saver.xml"/>
</chapter>
<xi:include href="database-schema.xml"/>
diff --git a/docs/reference/gnome-video-arcade-sections.txt b/docs/reference/gnome-video-arcade-sections.txt
index 660fcb5..dcfacf8 100644
--- a/docs/reference/gnome-video-arcade-sections.txt
+++ b/docs/reference/gnome-video-arcade-sections.txt
@@ -87,12 +87,6 @@ gva_db_set_error
</SECTION>
<SECTION>
-<FILE>gva-dbus</FILE>
-gva_dbus_init
-gva_dbus_inhibit_screen_saver
-</SECTION>
-
-<SECTION>
<FILE>gva-error</FILE>
GVA_ERROR
GVA_SQLITE_ERROR
@@ -374,6 +368,28 @@ gva_properties_window_state_event_cb
</SECTION>
<SECTION>
+<FILE>gva-screen-saver</FILE>
+<TITLE>GvaScreenSaver</TITLE>
+GvaScreenSaver
+gva_screen_saver_new
+gva_screen_saver_enable
+gva_screen_saver_disable
+gva_screen_saver_get_reason
+gva_screen_saver_set_reason
+<SUBSECTION Standard>
+GVA_SCREEN_SAVER
+GVA_IS_SCREEN_SAVER
+GVA_TYPE_SCREEN_SAVER
+GVA_SCREEN_SAVER_CLASS
+GVA_IS_SCREEN_SAVER_CLASS
+GVA_SCREEN_SAVER_GET_CLASS
+GvaScreenSaverClass
+<SUBSECTION Private>
+GvaScreenSaverPrivate
+gva_screen_saver_get_type
+</SECTION>
+
+<SECTION>
<FILE>gva-tree-view</FILE>
gva_tree_view_init
gva_tree_view_lookup
@@ -433,6 +449,7 @@ gva_ui_get_managed_widget
gva_ui_add_column_actions
gva_ui_lock
gva_ui_unlock
+gva_ui_init
<SUBSECTION Private>
GVA_WIDGET_AUDIT_SAVE_BUTTON
GVA_WIDGET_AUDIT_TREE_VIEW
diff --git a/docs/reference/gnome-video-arcade.types b/docs/reference/gnome-video-arcade.types
index 7d004bf..ea3c307 100644
--- a/docs/reference/gnome-video-arcade.types
+++ b/docs/reference/gnome-video-arcade.types
@@ -6,6 +6,7 @@
#include <gva-music-button.h>
#include <gva-mute-button.h>
#include <gva-process.h>
+#include <gva-screen-saver.h>
#include <gva-time.h>
gva_cell_renderer_pixbuf_get_type
@@ -16,4 +17,5 @@ gva_mame_process_get_type
gva_music_button_get_type
gva_mute_button_get_type
gva_process_get_type
+gva_screen_saver_get_type
gva_time_get_type
diff --git a/docs/reference/tmpl/gva-screen-saver.sgml b/docs/reference/tmpl/gva-screen-saver.sgml
new file mode 100644
index 0000000..25fa414
--- /dev/null
+++ b/docs/reference/tmpl/gva-screen-saver.sgml
@@ -0,0 +1,76 @@
+<!-- ##### SECTION Title ##### -->
+GvaScreenSaver
+
+<!-- ##### SECTION Short_Description ##### -->
+
+
+<!-- ##### SECTION Long_Description ##### -->
+<para>
+
+</para>
+
+<!-- ##### SECTION See_Also ##### -->
+<para>
+
+</para>
+
+<!-- ##### SECTION Stability_Level ##### -->
+
+
+<!-- ##### SECTION Image ##### -->
+
+
+<!-- ##### STRUCT GvaScreenSaver ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### ARG GvaScreenSaver:reason ##### -->
+<para>
+
+</para>
+
+<!-- ##### FUNCTION gva_screen_saver_new ##### -->
+<para>
+
+</para>
+
+ void:
+ Returns:
+
+
+<!-- ##### FUNCTION gva_screen_saver_enable ##### -->
+<para>
+
+</para>
+
+ screen_saver:
+
+
+<!-- ##### FUNCTION gva_screen_saver_disable ##### -->
+<para>
+
+</para>
+
+ screen_saver:
+
+
+<!-- ##### FUNCTION gva_screen_saver_get_reason ##### -->
+<para>
+
+</para>
+
+ screen_saver:
+ Returns:
+
+
+<!-- ##### FUNCTION gva_screen_saver_set_reason ##### -->
+<para>
+
+</para>
+
+ screen_saver:
+ reason:
+
+
diff --git a/docs/reference/tmpl/gva-ui.sgml b/docs/reference/tmpl/gva-ui.sgml
index 49a6df6..d4862ce 100644
--- a/docs/reference/tmpl/gva-ui.sgml
+++ b/docs/reference/tmpl/gva-ui.sgml
@@ -232,3 +232,11 @@
@void:
+<!-- ##### FUNCTION gva_ui_init ##### -->
+<para>
+
+</para>
+
+ void:
+
+
diff --git a/src/Makefile.am b/src/Makefile.am
index 4c803b7..84dc7ea 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,7 +4,7 @@ bin_PROGRAMS = gnome-video-arcade
AM_CFLAGS = \
-Wall \
- @DBUS_CFLAGS@ @GLIB_CFLAGS@ @GTK_CFLAGS@ @GIT_CFLAGS@ \
+ @GLIB_CFLAGS@ @GTK_CFLAGS@ @GIT_CFLAGS@ \
@GSTREAMER_CFLAGS@ @SQLITE_CFLAGS@ @WNCK_CFLAGS@
AM_CPPFLAGS = \
@@ -15,12 +15,6 @@ AM_CPPFLAGS = \
AM_LDFLAGS = \
-export-dynamic
-if HAVE_DBUS
-DBUS_SOURCES = \
- gva-dbus.c \
- gva-dbus.h
-endif
-
gnome_video_arcade_SOURCES = \
gva-audit.c \
gva-audit.h \
@@ -64,8 +58,10 @@ gnome_video_arcade_SOURCES = \
gva-preferences.h \
gva-process.c \
gva-process.h \
- gva-properties.h \
gva-properties.c \
+ gva-properties.h \
+ gva-screen-saver.c \
+ gva-screen-saver.h \
gva-time.c \
gva-time.h \
gva-tree-view.c \
@@ -76,7 +72,6 @@ gnome_video_arcade_SOURCES = \
gva-util.h \
gva-wnck.c \
gva-wnck.h \
- $(DBUS_SOURCES) \
main.c
EXTRA_gnome_video_arcade_SOURCES = \
@@ -84,8 +79,8 @@ EXTRA_gnome_video_arcade_SOURCES = \
gva-mame-xmame.c
gnome_video_arcade_LDADD = \
- @DBUS_LIBS@ @GLIB_LIBS@ @GTK_LIBS@ \
- @GIT_LIBS@ @GSTREAMER_LIBS@ @MAME_BACKEND@ \
+ @GLIB_LIBS@ @GTK_LIBS@ @GIT_LIBS@ \
+ @GSTREAMER_LIBS@ @MAME_BACKEND@ \
@SQLITE_LIBS@ @WNCK_LIBS@
gnome_video_arcade_DEPENDENCIES = \
diff --git a/src/gva-screen-saver.c b/src/gva-screen-saver.c
new file mode 100644
index 0000000..0772191
--- /dev/null
+++ b/src/gva-screen-saver.c
@@ -0,0 +1,494 @@
+/* Copyright 2007-2011 Matthew Barnes
+ *
+ * This file is part of GNOME Video Arcade.
+ *
+ * Based on totem-scrsaver.c by Bastien Nocera.
+ *
+ * GNOME Video Arcade 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 3 of
+ * the License, or (at your option) any later version.
+ *
+ * GNOME Video Arcade 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <gdk/gdk.h>
+
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h>
+#include <X11/keysym.h>
+#endif /* GDK_WINDOWING_X11 */
+
+#include "gva-screen-saver.h"
+
+#define SCREEN_SAVER_SERVICE "org.gnome.ScreenSaver"
+#define SCREEN_SAVER_PATH "/org/gnome/ScreenSaver"
+#define SCREEN_SAVER_INTERFACE "org.gnome.ScreenSaver"
+
+#define GVA_SCREEN_SAVER_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), GVA_TYPE_SCREEN_SAVER, GvaScreenSaverPrivate))
+
+struct GvaScreenSaverPrivate
+{
+ gboolean disabled;
+ gchar *reason;
+
+ GDBusProxy *gss_proxy;
+ gboolean have_screen_saver_dbus;
+ guint32 cookie;
+
+ /* To save the X11 screen saver info */
+ gint timeout;
+ gint interval;
+ gint prefer_blanking;
+ gint allow_exposures;
+};
+
+enum
+{
+ PROP_0,
+ PROP_REASON
+};
+
+G_DEFINE_TYPE (GvaScreenSaver, gva_screen_saver, G_TYPE_OBJECT)
+
+static gboolean
+screen_saver_is_running_dbus (GvaScreenSaver *screen_saver)
+{
+ return screen_saver->priv->have_screen_saver_dbus;
+}
+
+static void
+screen_saver_inhibit_cb (GDBusProxy *proxy,
+ GAsyncResult *result,
+ GvaScreenSaver *screen_saver)
+{
+ GVariant *value;
+ GError *error = NULL;
+
+ value = g_dbus_proxy_call_finish (proxy, result, &error);
+
+ if (value != NULL)
+ {
+ guint32 cookie = 0;
+
+ /* save the cookie */
+ if (g_variant_is_of_type (value, G_VARIANT_TYPE ("(u)")))
+ g_variant_get (value, "(u)", &cookie);
+ screen_saver->priv->cookie = cookie;
+ g_variant_unref (value);
+ }
+ else
+ {
+ g_return_if_fail (error != NULL);
+ g_warning (
+ "Problem inhibiting the screen saver: %s",
+ error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (screen_saver);
+}
+
+static void
+screen_saver_uninhibit_cb (GDBusProxy *proxy,
+ GAsyncResult *result,
+ GvaScreenSaver *screen_saver)
+{
+ GVariant *value;
+ GError *error = NULL;
+
+ value = g_dbus_proxy_call_finish (proxy, result, &error);
+
+ if (value != NULL)
+ {
+ /* Clear the cookie. */
+ screen_saver->priv->cookie = 0;
+ g_variant_unref (value);
+ }
+ else
+ {
+ g_return_if_fail (error != NULL);
+ g_warning (
+ "Problem uninhibiting the screen saver: %s",
+ error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (screen_saver);
+}
+
+static void
+screen_saver_inhibit_dbus (GvaScreenSaver *screen_saver,
+ gboolean inhibit)
+{
+ GDBusProxy *proxy;
+
+ if (!screen_saver->priv->have_screen_saver_dbus)
+ return;
+
+ proxy = screen_saver->priv->gss_proxy;
+
+ if (inhibit) {
+ g_return_if_fail (screen_saver->priv->reason != NULL);
+ g_dbus_proxy_call (
+ proxy,
+ "Inhibit",
+ g_variant_new (
+ "(ss)",
+ g_get_application_name (),
+ screen_saver->priv->reason),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ -1,
+ NULL,
+ (GAsyncReadyCallback) screen_saver_inhibit_cb,
+ g_object_ref (screen_saver));
+ } else {
+ g_dbus_proxy_call (
+ proxy,
+ "UnInhibit",
+ g_variant_new ("(u)", screen_saver->priv->cookie),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ -1,
+ NULL,
+ (GAsyncReadyCallback) screen_saver_uninhibit_cb,
+ g_object_ref (screen_saver));
+ }
+}
+
+static void
+screen_saver_enable_dbus (GvaScreenSaver *screen_saver)
+{
+ screen_saver_inhibit_dbus (screen_saver, FALSE);
+}
+
+static void
+screen_saver_disable_dbus (GvaScreenSaver *screen_saver)
+{
+ screen_saver_inhibit_dbus (screen_saver, TRUE);
+}
+
+static void
+screen_saver_update_dbus_presence (GvaScreenSaver *screen_saver)
+{
+ GDBusProxy *proxy;
+ gchar *name_owner;
+
+ proxy = screen_saver->priv->gss_proxy;
+ name_owner = g_dbus_proxy_get_name_owner (proxy);
+
+ if (name_owner != NULL)
+ {
+ screen_saver->priv->have_screen_saver_dbus = TRUE;
+ g_free (name_owner);
+
+ /* Screen saver just appeared, or reappeared. */
+ if (screen_saver->priv->reason != NULL)
+ screen_saver_disable_dbus (screen_saver);
+ }
+ else
+ {
+ screen_saver->priv->have_screen_saver_dbus = FALSE;
+ }
+}
+
+static void
+screen_saver_dbus_owner_changed_cb (GDBusProxy *proxy,
+ GParamSpec *pspec,
+ GvaScreenSaver *screen_saver)
+{
+ screen_saver_update_dbus_presence (screen_saver);
+}
+
+static void
+screen_saver_dbus_proxy_new_cb (GObject *source,
+ GAsyncResult *result,
+ GvaScreenSaver *screen_saver)
+{
+ GDBusProxy *proxy;
+
+ proxy = g_dbus_proxy_new_for_bus_finish (result, NULL);
+
+ if (proxy == NULL)
+ return;
+
+ g_signal_connect (
+ proxy, "notify::g-name-owner",
+ G_CALLBACK (screen_saver_dbus_owner_changed_cb),
+ screen_saver);
+
+ screen_saver->priv->gss_proxy = proxy;
+
+ screen_saver_update_dbus_presence (screen_saver);
+}
+
+#ifdef GDK_WINDOWING_X11
+static void
+screen_saver_enable_x11 (GvaScreenSaver *screen_saver)
+{
+ GdkDisplay *display;
+
+ display = gdk_display_get_default ();
+
+ XLockDisplay (GDK_DISPLAY_XDISPLAY (display));
+ XSetScreenSaver (
+ GDK_DISPLAY_XDISPLAY (display),
+ screen_saver->priv->timeout,
+ screen_saver->priv->interval,
+ screen_saver->priv->prefer_blanking,
+ screen_saver->priv->allow_exposures);
+ XUnlockDisplay (GDK_DISPLAY_XDISPLAY (display));
+}
+
+static void
+screen_saver_disable_x11 (GvaScreenSaver *screen_saver)
+{
+ GdkDisplay *display;
+
+ display = gdk_display_get_default ();
+
+ XLockDisplay (GDK_DISPLAY_XDISPLAY (display));
+ XGetScreenSaver (
+ GDK_DISPLAY_XDISPLAY (display),
+ &screen_saver->priv->timeout,
+ &screen_saver->priv->interval,
+ &screen_saver->priv->prefer_blanking,
+ &screen_saver->priv->allow_exposures);
+ XSetScreenSaver (
+ GDK_DISPLAY_XDISPLAY (display), 0, 0,
+ DontPreferBlanking, DontAllowExposures);
+ XUnlockDisplay (GDK_DISPLAY_XDISPLAY (display));
+}
+#endif
+
+static void
+screen_saver_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id)
+ {
+ case PROP_REASON:
+ gva_screen_saver_set_reason (
+ GVA_SCREEN_SAVER (object),
+ g_value_get_string (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+screen_saver_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id)
+ {
+ case PROP_REASON:
+ g_value_set_string (
+ value, gva_screen_saver_get_reason (
+ GVA_SCREEN_SAVER (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+screen_saver_dispose (GObject *object)
+{
+ GvaScreenSaverPrivate *priv;
+
+ priv = GVA_SCREEN_SAVER_GET_PRIVATE (object);
+
+ if (priv->gss_proxy != NULL)
+ {
+ g_object_unref (priv->gss_proxy);
+ priv->gss_proxy = NULL;
+ }
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (gva_screen_saver_parent_class)->dispose (object);
+}
+
+static void
+screen_saver_finalize (GObject *object)
+{
+ GvaScreenSaverPrivate *priv;
+
+ priv = GVA_SCREEN_SAVER_GET_PRIVATE (object);
+
+ g_free (priv->reason);
+
+ /* Chain up to parent's finalize() method. */
+ G_OBJECT_CLASS (gva_screen_saver_parent_class)->finalize (object);
+}
+
+static void
+gva_screen_saver_class_init (GvaScreenSaverClass *class)
+{
+ GObjectClass *object_class;
+
+ g_type_class_add_private (class, sizeof (GvaScreenSaverPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = screen_saver_set_property;
+ object_class->get_property = screen_saver_get_property;
+ object_class->dispose = screen_saver_dispose;
+ object_class->finalize = screen_saver_finalize;
+
+ /**
+ * GvaScreenSaver:reason
+ *
+ * The reason for disabling the screen saver.
+ **/
+ g_object_class_install_property (
+ object_class,
+ PROP_REASON,
+ g_param_spec_string (
+ "reason",
+ NULL,
+ NULL,
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+gva_screen_saver_init (GvaScreenSaver *screen_saver)
+{
+ screen_saver->priv = GVA_SCREEN_SAVER_GET_PRIVATE (screen_saver);
+
+ g_dbus_proxy_new_for_bus (
+ G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ SCREEN_SAVER_SERVICE,
+ SCREEN_SAVER_PATH,
+ SCREEN_SAVER_INTERFACE,
+ NULL, (GAsyncReadyCallback)
+ screen_saver_dbus_proxy_new_cb,
+ screen_saver);
+}
+
+/**
+ * gva_screen_saver_new:
+ *
+ * Creates a #GvaScreenSaver object.
+ *
+ * If the GNOME screen saver is running, it uses its D-Bus interface
+ * to inhibit the screen saver; otherwise it falls back to using the
+ * X screen saver functionality for this.
+ *
+ * Returns: a newly created #GvaScreenSaver
+ */
+GvaScreenSaver *
+gva_screen_saver_new (void)
+{
+ return g_object_new (GVA_TYPE_SCREEN_SAVER, NULL);
+}
+
+/**
+ * gva_screen_saver_disable:
+ * @screen_saver: a #GvaScreenSaver
+ *
+ * Disables the screen saver.
+ **/
+void
+gva_screen_saver_disable (GvaScreenSaver *screen_saver)
+{
+ g_return_if_fail (GVA_IS_SCREEN_SAVER (screen_saver));
+
+ if (screen_saver->priv->disabled != FALSE)
+ return;
+
+ screen_saver->priv->disabled = TRUE;
+
+ if (screen_saver_is_running_dbus (screen_saver))
+ screen_saver_disable_dbus (screen_saver);
+ else
+#ifdef GDK_WINDOWING_X11
+ screen_saver_disable_x11 (screen_saver);
+#else
+#warning Unimplemented
+ {}
+#endif
+}
+
+/**
+ * gva_screen_saver_enable:
+ * @screen_saver: a #GvaScreenSaver
+ *
+ * Enables the screen saver.
+ **/
+void
+gva_screen_saver_enable (GvaScreenSaver *screen_saver)
+{
+ g_return_if_fail (GVA_IS_SCREEN_SAVER (screen_saver));
+
+ if (screen_saver->priv->disabled == FALSE)
+ return;
+
+ screen_saver->priv->disabled = FALSE;
+
+ if (screen_saver_is_running_dbus (screen_saver))
+ screen_saver_enable_dbus (screen_saver);
+ else
+#ifdef GDK_WINDOWING_X11
+ screen_saver_enable_x11 (screen_saver);
+#else
+#warning Unimplemented
+ {}
+#endif
+}
+
+/**
+ * gva_screen_saver_get_reason:
+ * @screen_saver: a #GvaScreenSaver
+ *
+ * Returns the reason for disabling the screen saver.
+ *
+ * Returns: the reason for disabling the screen saver
+ **/
+const gchar *
+gva_screen_saver_get_reason (GvaScreenSaver *screen_saver)
+{
+ g_return_val_if_fail (GVA_IS_SCREEN_SAVER (screen_saver), NULL);
+
+ return screen_saver->priv->reason;
+}
+
+/**
+ * gva_screen_saver_set_reason:
+ * @screen_saver: a #GvaScreenSaver
+ * @reason: the reason for disabling the screen saver
+ *
+ * Sets the reason for disabling the screen saver. This string is passed
+ * to the "org.gnome.ScreenSaver" D-Bus interface on subsequent calls to
+ * gva_screen_saver_disable().
+ **/
+void
+gva_screen_saver_set_reason (GvaScreenSaver *screen_saver,
+ const gchar *reason)
+{
+ g_return_if_fail (GVA_IS_SCREEN_SAVER (screen_saver));
+
+ g_free (screen_saver->priv->reason);
+ screen_saver->priv->reason = g_strdup (reason);
+
+ g_object_notify (G_OBJECT (screen_saver), "reason");
+}
diff --git a/src/gva-screen-saver.h b/src/gva-screen-saver.h
new file mode 100644
index 0000000..0a7fb32
--- /dev/null
+++ b/src/gva-screen-saver.h
@@ -0,0 +1,86 @@
+/* Copyright 2007-2011 Matthew Barnes
+ *
+ * This file is part of GNOME Video Arcade.
+ *
+ * Based on totem-scrsaver.h by Bastien Nocera.
+ *
+ * GNOME Video Arcade 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 3 of
+ * the License, or (at your option) any later version.
+ *
+ * GNOME Video Arcade 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * SECTION: gva-screen-saver
+ * @short_description: Inhibit the screen saver
+ *
+ * #GvaScreenSaver inhibits the screen saver from starting while running a
+ * game in full-screen mode. It prefers the "org.gnome.ScreenSaver" D-Bus
+ * interface, but can also make calls to Xlib directly.
+ **/
+
+#ifndef GVA_SCREEN_SAVER_H
+#define GVA_SCREEN_SAVER_H
+
+#include <glib-object.h>
+
+#define GVA_TYPE_SCREEN_SAVER \
+ (gva_screen_saver_get_type ())
+#define GVA_SCREEN_SAVER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), GVA_TYPE_SCREEN_SAVER, GvaScreenSaver))
+#define GVA_SCREEN_SAVER_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), GVA_TYPE_SCREEN_SAVER, GvaScreenSaverClass))
+#define GVA_IS_SCREEN_SAVER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), GVA_TYPE_SCREEN_SAVER))
+#define GVA_IS_SCREEN_SAVER_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), GVA_TYPE_SCREEN_SAVER))
+#define GVA_SCREEN_SAVER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), GVA_TYPE_SCREEN_SAVER, GvaScreenSaverClass))
+
+G_BEGIN_DECLS
+
+typedef struct _GvaScreenSaver GvaScreenSaver;
+typedef struct _GvaScreenSaverClass GvaScreenSaverClass;
+typedef struct _GvaScreenSaverPrivate GvaScreenSaverPrivate;
+
+/**
+ * GvaScreenSaver:
+ *
+ * Contains only private data that should be read and manipulated using the
+ * functions below.
+ **/
+struct _GvaScreenSaver
+{
+ GObject parent;
+ GvaScreenSaverPrivate *priv;
+};
+
+struct _GvaScreenSaverClass
+{
+ GObjectClass parent_class;
+};
+
+GType gva_screen_saver_get_type (void) G_GNUC_CONST;
+GvaScreenSaver *gva_screen_saver_new (void);
+void gva_screen_saver_enable (GvaScreenSaver *screen_saver);
+void gva_screen_saver_disable (GvaScreenSaver *screen_saver);
+const gchar * gva_screen_saver_get_reason (GvaScreenSaver *screen_saver);
+void gva_screen_saver_set_reason (GvaScreenSaver *screen_saver,
+ const gchar *reason);
+
+G_END_DECLS
+
+#endif /* GVA_SCREEN_SAVER_H */
diff --git a/src/gva-ui.c b/src/gva-ui.c
index ef1e21c..6c1f732 100644
--- a/src/gva-ui.c
+++ b/src/gva-ui.c
@@ -31,14 +31,11 @@
#include "gva-play-back.h"
#include "gva-preferences.h"
#include "gva-process.h"
+#include "gva-screen-saver.h"
#include "gva-tree-view.h"
#include "gva-util.h"
#include "gva-wnck.h"
-#ifdef HAVE_DBUS
-#include "gva-dbus.h"
-#endif
-
#define SQL_INSERT_LASTPLAYED \
"INSERT INTO lastplayed VALUES ('%s', %" G_GINT64_FORMAT ")"
@@ -48,6 +45,7 @@
static GtkBuilder *builder = NULL;
static GtkUIManager *manager = NULL;
static gboolean initialized = FALSE;
+static GvaScreenSaver *screen_saver = NULL;
/* About Dialog Information */
static const gchar *authors[] =
@@ -447,22 +445,27 @@ gva_action_play_back_cb (GtkAction *action)
process = gva_mame_playback_game (name, inpname, &error);
gva_error_handle (&error);
-#ifdef HAVE_DBUS
if (process != NULL)
{
- const gchar *reason;
-
- /* Translators: This is passed through D-Bus as the
- * reason to inhibit GNOME screen saver. */
- reason = _("Watching a fullscreen game");
- gva_dbus_inhibit_screen_saver (process, reason, &error);
- gva_error_handle (&error);
- }
-#endif
+ if (gva_preferences_get_full_screen ())
+ {
+ const gchar *reason;
+
+ /* Translators: This is passed through D-Bus as
+ * the reason to inhibit GNOME screen saver. */
+ reason = _("Watching a fullscreen game");
+ gva_screen_saver_set_reason (screen_saver, reason);
+ gva_screen_saver_disable (screen_saver);
+
+ g_signal_connect_data (
+ process, "exited",
+ G_CALLBACK (gva_screen_saver_enable),
+ screen_saver, (GClosureNotify) NULL,
+ G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+ }
- if (process != NULL)
- {
gva_wnck_listen_for_new_window (process, name);
+
g_signal_connect_after (
process, "exited",
G_CALLBACK (log_lastplayed), g_strdup (name));
@@ -545,22 +548,27 @@ gva_action_record_cb (GtkAction *action)
process = gva_mame_record_game (name, inpname, &error);
gva_error_handle (&error);
-#ifdef HAVE_DBUS
if (process != NULL)
{
- const gchar *reason;
+ if (gva_preferences_get_full_screen ())
+ {
+ const gchar *reason;
+
+ /* Translators: This is passed through D-Bus as
+ * the reason to inhibit GNOME screen saver. */
+ reason = _("Recording a fullscreen game");
+ gva_screen_saver_set_reason (screen_saver, reason);
+ gva_screen_saver_disable (screen_saver);
+
+ g_signal_connect_data (
+ process, "exited",
+ G_CALLBACK (gva_screen_saver_enable),
+ screen_saver, (GClosureNotify) NULL,
+ G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+ }
- /* Translators: This is passed through D-Bus as the
- * reason to inhibit GNOME screen saver. */
- reason = _("Recording a fullscreen game");
- gva_dbus_inhibit_screen_saver (process, reason, &error);
- gva_error_handle (&error);
- }
-#endif
-
- if (process != NULL)
- {
gva_wnck_listen_for_new_window (process, name);
+
g_signal_connect_after (
process, "exited",
G_CALLBACK (log_lastplayed), g_strdup (name));
@@ -684,22 +692,27 @@ gva_action_start_cb (GtkAction *action)
process = gva_mame_run_game (name, &error);
gva_error_handle (&error);
-#ifdef HAVE_DBUS
if (process != NULL)
{
- const gchar *reason;
+ if (gva_preferences_get_full_screen ())
+ {
+ const gchar *reason;
+
+ /* Translators: This is passed through D-Bus as the
+ * reason to inhibit GNOME screen saver. */
+ reason = _("Playing a fullscreen game");
+ gva_screen_saver_set_reason (screen_saver, reason);
+ gva_screen_saver_disable (screen_saver);
+
+ g_signal_connect_data (
+ process, "exited",
+ G_CALLBACK (gva_screen_saver_enable),
+ screen_saver, (GClosureNotify) NULL,
+ G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+ }
- /* Translators: This is passed through D-Bus as the
- * reason to inhibit GNOME screen saver. */
- reason = _("Playing a fullscreen game");
- gva_dbus_inhibit_screen_saver (process, reason, &error);
- gva_error_handle (&error);
- }
-#endif
-
- if (process != NULL)
- {
gva_wnck_listen_for_new_window (process, name);
+
g_signal_connect_after (
process, "exited",
G_CALLBACK (log_lastplayed), g_strdup (name));
@@ -1000,3 +1013,14 @@ gva_ui_unlock (void)
gtk_action_group_set_sensitive (action_group, TRUE);
gtk_widget_set_sensitive (GVA_WIDGET_MAIN_TREE_VIEW, TRUE);
}
+
+/**
+ * gva_ui_init:
+ *
+ * Initializes the screen saver inhibitor.
+ **/
+void
+gva_ui_init (void)
+{
+ screen_saver = gva_screen_saver_new ();
+}
diff --git a/src/gva-ui.h b/src/gva-ui.h
index 7533b3e..d7117ad 100644
--- a/src/gva-ui.h
+++ b/src/gva-ui.h
@@ -190,6 +190,7 @@ GtkWidget * gva_ui_get_managed_widget (const gchar *widget_path);
void gva_ui_add_column_actions (GtkTreeView *view);
void gva_ui_lock (void);
void gva_ui_unlock (void);
+void gva_ui_init (void);
/* GtkAction callbacks */
diff --git a/src/main.c b/src/main.c
index 66376a7..66743e0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -39,10 +39,6 @@
#include "gva-ui.h"
#include "gva-util.h"
-#ifdef HAVE_DBUS
-#include "gva-dbus.h"
-#endif
-
#define APPLICATION_ID "org.gnome.VideoArcade"
#define SQL_COUNT_ROMS \
@@ -395,6 +391,7 @@ main (gint argc, gchar **argv)
gva_play_back_init ();
gva_preferences_init ();
gva_properties_init ();
+ gva_ui_init ();
gva_categories_init (&error);
gva_error_handle (&error);
@@ -405,11 +402,6 @@ main (gint argc, gchar **argv)
gva_nplayers_init (&error);
gva_error_handle (&error);
-#ifdef HAVE_DBUS
- gva_dbus_init (&error);
- gva_error_handle (&error);
-#endif
-
g_idle_add ((GSourceFunc) start, NULL);
g_idle_add ((GSourceFunc) setup_file_monitors, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]