]> www.fi.muni.cz Git - evince.git/commitdiff
Remove hard-coded reason in totem-scrsaver
authorBastien Nocera <hadess@hadess.net>
Sat, 12 Jun 2010 16:09:13 +0000 (17:09 +0100)
committerBastien Nocera <hadess@hadess.net>
Sun, 13 Jun 2010 11:09:35 +0000 (12:09 +0100)
We should now be able to share it between totem and evince
without changes.

https://bugzilla.gnome.org/show_bug.cgi?id=621386

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

index 09cbe59dba82bda3347fd76828a88d43c935c842..8622079a5cb61f5a176a1e1738c7d08f511dc70c 100644 (file)
 
 #define XSCREENSAVER_MIN_TIMEOUT 60
 
+enum {
+       PROP_0,
+       PROP_REASON
+};
+
 static void totem_scrsaver_finalize   (GObject *object);
 
 struct TotemScrsaverPrivate {
        /* Whether the screensaver is disabled */
        gboolean disabled;
+       /* The reason for the inhibition */
+       char *reason;
 
        GDBusProxy *gs_proxy;
         gboolean have_screensaver_dbus;
@@ -93,12 +100,13 @@ on_inhibit_cb (GObject      *source_object,
        if (!value) {
                if (!scr->priv->old_dbus_api &&
                    g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
+                       g_return_if_fail (scr->priv->reason != NULL);
                        /* try the old API */
                        scr->priv->old_dbus_api = TRUE;
                        g_dbus_proxy_call (proxy,
                                           "InhibitActivation",
                                           g_variant_new ("(s)",
-                                                         _("Running in presentation mode")),
+                                                         scr->priv->reason),
                                           G_DBUS_CALL_FLAGS_NO_AUTO_START,
                                           -1,
                                           NULL,
@@ -169,11 +177,12 @@ screensaver_inhibit_dbus (TotemScrsaver *scr,
        scr->priv->old_dbus_api = FALSE;
 
        if (inhibit) {
+               g_return_if_fail (scr->priv->reason != NULL);
                g_dbus_proxy_call (priv->gs_proxy,
                                   "Inhibit",
                                   g_variant_new ("(ss)",
-                                                 "Evince",
-                                                 _("Running in presentation mode")),
+                                                 g_get_application_name (),
+                                                 scr->priv->reason),
                                   G_DBUS_CALL_FLAGS_NO_AUTO_START,
                                   -1,
                                   NULL,
@@ -380,6 +389,47 @@ screensaver_finalize_x11 (TotemScrsaver *scr)
 }
 #endif
 
+static void
+totem_scrsaver_get_property (GObject *object,
+                            guint property_id,
+                            GValue *value,
+                            GParamSpec *pspec)
+{
+       TotemScrsaver *scr;
+
+       scr = TOTEM_SCRSAVER (object);
+
+       switch (property_id)
+       {
+       case PROP_REASON:
+               g_value_set_string (value, scr->priv->reason);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+       }
+}
+
+static void
+totem_scrsaver_set_property (GObject *object,
+                            guint property_id,
+                            const GValue *value,
+                            GParamSpec *pspec)
+{
+       TotemScrsaver *scr;
+
+       scr = TOTEM_SCRSAVER (object);
+
+       switch (property_id)
+       {
+       case PROP_REASON:
+               g_free (scr->priv->reason);
+               scr->priv->reason = g_value_dup_string (value);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+       }
+}
+
 static void
 totem_scrsaver_class_init (TotemScrsaverClass *klass)
 {
@@ -387,7 +437,14 @@ totem_scrsaver_class_init (TotemScrsaverClass *klass)
 
        g_type_class_add_private (klass, sizeof (TotemScrsaverPrivate));
 
+       object_class->set_property = totem_scrsaver_set_property;
+       object_class->get_property = totem_scrsaver_get_property;
        object_class->finalize = totem_scrsaver_finalize;
+
+       g_object_class_install_property (object_class, PROP_REASON,
+                                        g_param_spec_string ("reason", NULL, NULL,
+                                                             NULL, G_PARAM_READWRITE));
+
 }
 
 /**
@@ -454,7 +511,7 @@ totem_scrsaver_enable (TotemScrsaver *scr)
 
        if (screensaver_is_running_dbus (scr) != FALSE)
                screensaver_enable_dbus (scr);
-       else 
+       else
 #ifdef GDK_WINDOWING_X11
                screensaver_enable_x11 (scr);
 #else
@@ -482,6 +539,8 @@ totem_scrsaver_finalize (GObject *object)
 {
        TotemScrsaver *scr = TOTEM_SCRSAVER (object);
 
+       g_free (scr->priv->reason);
+
        screensaver_finalize_dbus (scr);
 #ifdef GDK_WINDOWING_X11
        screensaver_finalize_x11 (scr);
index b29a39c7848d6077c5a69ad3ddde861578a11dfa..f3301c8ea0fc80dd9419e17998c926c1dc52b7f0 100644 (file)
@@ -42,7 +42,7 @@ struct TotemScrsaver {
 };
 
 struct TotemScrsaverClass {
-       GObjectClass parent_class; 
+       GObjectClass parent_class;
 };
 
 GType totem_scrsaver_get_type          (void) G_GNUC_CONST;
index 5c0bd3802ba8db0526384fb8d3ca38ea1af121ac..30f231377add87bc83edcd903ee4716b4fa701fe 100644 (file)
@@ -1014,6 +1014,9 @@ ev_application_init (EvApplication *ev_application)
 #endif /* ENABLE_DBUS */
 
        ev_application->scr_saver = totem_scrsaver_new ();
+       g_object_set (ev_application->scr_saver,
+                     "reason", _("Running in presentation mode"),
+                     NULL);
 }
 
 gboolean