[gnome-settings-daemon] datetime: Avoid popping up polkit password prompts



commit 35888bd19ae530c90f3a6021d513b81879e4b571
Author: Kalev Lember <kalevlember gmail com>
Date:   Wed Aug 28 08:38:46 2013 +0200

    datetime: Avoid popping up polkit password prompts
    
    Check if we have permissions to set the timezone. If we don't, just
    avoid changing the system TZ on location changes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706979

 configure.ac                            |    3 +++
 plugins/datetime/Makefile.am            |    3 +++
 plugins/datetime/gsd-timezone-monitor.c |   21 +++++++++++++++++++++
 3 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 47710ef..fd57732 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,6 +54,7 @@ PA_REQUIRED_VERSION=2.0
 LIBWACOM_REQUIRED_VERSION=0.7
 LIBRSVG_REQUIRED_VERSION=2.36.2
 PANGO_REQUIRED_VERSION=1.20.0
+POLKIT_REQUIRED_VERSION=0.103
 UPOWER_REQUIRED_VERSION=0.9.11
 IBUS_REQUIRED_VERSION=1.4.99
 GSETTINGS_DESKTOP_SCHEMAS_REQUIRED_VERSION=3.7.2.1
@@ -251,6 +252,8 @@ dnl ---------------------------------------------------------------------------
 AC_CHECK_LIBM
 AC_SUBST(LIBM)
 
+PKG_CHECK_MODULES(DATETIME, polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION)
+
 dnl ---------------------------------------------------------------------------
 dnl - wacom (disabled for s390/s390x and non Linux platforms)
 dnl ---------------------------------------------------------------------------
diff --git a/plugins/datetime/Makefile.am b/plugins/datetime/Makefile.am
index f8cdbe2..c2b41c8 100644
--- a/plugins/datetime/Makefile.am
+++ b/plugins/datetime/Makefile.am
@@ -50,6 +50,7 @@ gsd_test_datetime_CFLAGS =                                    \
 gsd_test_datetime_LDADD =                                      \
        $(top_builddir)/gnome-settings-daemon/libgsd.la         \
        $(top_builddir)/plugins/common/libcommon.la             \
+       $(DATETIME_LIBS)                                        \
        $(LIBM)                                                 \
        $(SETTINGS_PLUGIN_LIBS)
 
@@ -74,6 +75,7 @@ libdatetime_la_CPPFLAGS =                                     \
        $(AM_CPPFLAGS)
 
 libdatetime_la_CFLAGS =                        \
+       $(DATETIME_CFLAGS)              \
        $(PLUGIN_CFLAGS)                \
        $(SETTINGS_PLUGIN_CFLAGS)       \
        $(AM_CFLAGS)
@@ -82,6 +84,7 @@ libdatetime_la_LDFLAGS = \
        $(GSD_PLUGIN_LDFLAGS)
 
 libdatetime_la_LIBADD = \
+       $(DATETIME_LIBS)                                                \
        $(LIBM) \
        $(SETTINGS_PLUGIN_LIBS)
 
diff --git a/plugins/datetime/gsd-timezone-monitor.c b/plugins/datetime/gsd-timezone-monitor.c
index f283d69..73a88ae 100644
--- a/plugins/datetime/gsd-timezone-monitor.c
+++ b/plugins/datetime/gsd-timezone-monitor.c
@@ -27,10 +27,14 @@
 #include "tz.h"
 
 #include <math.h>
+#include <polkit/polkit.h>
+
+#define SET_TIMEZONE_PERMISSION "org.freedesktop.timedate1.set-timezone"
 
 typedef struct
 {
         GCancellable *cancellable;
+        GPermission *permission;
         GeoclueClient *geoclue_client;
         GeoclueManager *geoclue_manager;
         Timedate1 *dtm;
@@ -313,6 +317,7 @@ gsd_timezone_monitor_finalize (GObject *obj)
         g_clear_object (&priv->dtm);
         g_clear_object (&priv->geoclue_client);
         g_clear_object (&priv->geoclue_manager);
+        g_clear_object (&priv->permission);
         g_clear_pointer (&priv->current_timezone, g_free);
         g_clear_pointer (&priv->tzdb, tz_db_free);
 
@@ -335,6 +340,22 @@ gsd_timezone_monitor_init (GsdTimezoneMonitor *self)
 
         g_debug ("Starting timezone monitor");
 
+        priv->permission = polkit_permission_new_sync (SET_TIMEZONE_PERMISSION,
+                                                       NULL, NULL,
+                                                       &error);
+        if (priv->permission == NULL) {
+                g_warning ("Could not get '%s' permission: %s",
+                           SET_TIMEZONE_PERMISSION,
+                           error->message);
+                g_error_free (error);
+                return;
+        }
+
+        if (!g_permission_get_allowed (priv->permission)) {
+                g_debug ("No permission to set timezone");
+                return;
+        }
+
         priv->cancellable = g_cancellable_new ();
         priv->dtm = timedate1_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
                                                       G_DBUS_PROXY_FLAGS_NONE,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]