diff options
author | Dominique Leuenberger <dimstar@opensuse.org> | 2018-01-18 16:21:57 +0100 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2018-01-26 11:07:59 -0200 |
commit | 5a66372debbc1d4937bf69ad2b9e0007178f6604 (patch) | |
tree | 7c4874becb833b3b83f227f1f0361ce6b7fd2b32 /panels | |
parent | ea83d2370680d369e336787154df9516a253f3de (diff) | |
download | gnome-control-center-5a66372debbc1d4937bf69ad2b9e0007178f6604.tar.gz |
datetime: Allow changing the timezone if polkit says so
As changing the time can have security implications, such as expiring
passwords, while changing the timezone doesn't, it's not unusual to
have a setup where org.freedesktop.timedate1.set-timezone is allowed
while other time-related actions aren't.
Therefore, if org.freedesktop.timedate1.set-timezone is allowed, there's
no reason to require that the user unlocks the panel to enable them to
change the timezone.
https://bugzilla.gnome.org/show_bug.cgi?id=646185
Diffstat (limited to 'panels')
-rw-r--r-- | panels/datetime/cc-datetime-panel.c | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/panels/datetime/cc-datetime-panel.c b/panels/datetime/cc-datetime-panel.c index 306322487..2ea385188 100644 --- a/panels/datetime/cc-datetime-panel.c +++ b/panels/datetime/cc-datetime-panel.c @@ -54,6 +54,7 @@ enum { #define W(x) (GtkWidget*) gtk_builder_get_object (self->builder, x) #define DATETIME_PERMISSION "org.gnome.controlcenter.datetime.configure" +#define DATETIME_TZ_PERMISSION "org.freedesktop.timedate1.set-timezone" #define CLOCK_SCHEMA "org.gnome.desktop.interface" #define CLOCK_FORMAT_KEY "clock-format" @@ -95,6 +96,7 @@ struct _CcDateTimePanel GCancellable *cancellable; GPermission *permission; + GPermission *tz_permission; }; CC_PANEL_REGISTER (CcDateTimePanel, cc_date_time_panel) @@ -131,6 +133,7 @@ cc_date_time_panel_dispose (GObject *object) g_clear_object (&panel->clock_tracker); g_clear_object (&panel->dtm); g_clear_object (&panel->permission); + g_clear_object (&panel->tz_permission); g_clear_object (&panel->clock_settings); g_clear_object (&panel->datetime_settings); g_clear_object (&panel->filechooser_settings); @@ -730,24 +733,24 @@ on_permission_changed (GPermission *permission, gpointer data) { CcDateTimePanel *self = CC_DATE_TIME_PANEL (data); - gboolean allowed, auto_timezone, using_ntp; + gboolean allowed, tz_allowed, auto_timezone, using_ntp; allowed = (self->permission != NULL && g_permission_get_allowed (self->permission)); + tz_allowed = (self->tz_permission != NULL && g_permission_get_allowed (self->tz_permission)); using_ntp = gtk_switch_get_active (GTK_SWITCH (W("network_time_switch"))); auto_timezone = gtk_switch_get_active (GTK_SWITCH (W("auto_timezone_switch"))); /* All the widgets but the lock button and the 24h setting */ gtk_widget_set_sensitive (W("auto-datetime-row"), allowed); - gtk_widget_set_sensitive (W("auto-timezone-row"), allowed); + gtk_widget_set_sensitive (W("auto-timezone-row"), allowed || tz_allowed); gtk_widget_set_sensitive (W("datetime-button"), allowed && !using_ntp); - gtk_widget_set_sensitive (W("timezone-button"), allowed && !auto_timezone); + gtk_widget_set_sensitive (W("timezone-button"), (allowed || tz_allowed) && !auto_timezone); /* Hide the subdialogs if we no longer have permissions */ if (!allowed) - { gtk_widget_hide (GTK_WIDGET (W ("datetime-dialog"))); + if (!allowed && !tz_allowed) gtk_widget_hide (GTK_WIDGET (W ("timezone-dialog"))); - } } static void @@ -835,6 +838,24 @@ run_dialog (CcDateTimePanel *self, } static gboolean +tz_switch_to_row_transform_func (GBinding *binding, + const GValue *source_value, + GValue *target_value, + CcDateTimePanel *self) +{ + gboolean active; + gboolean allowed; + + active = g_value_get_boolean (source_value); + allowed = (self->permission != NULL && g_permission_get_allowed (self->permission)) || + (self->tz_permission != NULL && g_permission_get_allowed (self->tz_permission)); + + g_value_set_boolean (target_value, !active && allowed); + + return TRUE; +} + +static gboolean switch_to_row_transform_func (GBinding *binding, const GValue *source_value, GValue *target_value, @@ -1189,6 +1210,7 @@ cc_date_time_panel_init (CcDateTimePanel *self) /* add the lock button */ self->permission = polkit_permission_new_sync (DATETIME_PERMISSION, NULL, NULL, NULL); + self->tz_permission = polkit_permission_new_sync (DATETIME_TZ_PERMISSION, NULL, NULL, NULL); if (self->permission != NULL) { g_signal_connect (self->permission, "notify", @@ -1226,9 +1248,11 @@ cc_date_time_panel_init (CcDateTimePanel *self) gtk_widget_set_visible (W ("auto-datetime-row"), is_ntp_available (self)); /* Timezone settings */ - bind_switch_to_row (self, - W ("auto_timezone_switch"), - W ("timezone-button")); + g_object_bind_property_full (W ("auto_timezone_switch"), "active", + W ("timezone-button"), "sensitive", + G_BINDING_SYNC_CREATE, + (GBindingTransformFunc) tz_switch_to_row_transform_func, + NULL, self, NULL); self->datetime_settings = g_settings_new (DATETIME_SCHEMA); g_settings_bind (self->datetime_settings, AUTO_TIMEZONE_KEY, |