datetime: check CanNTP when initializing the panel

If the system does not support NTP (as determined by the presence of an
NTP unit in /usr/lib/systemd/ntp-units.d), the Automatic Date & Time row
is intended to be hidden. We respond to changes to timedated's CanNTP
property, but we never account for the initial state of the property,
so we wind up displaying the Automatic Date & Time row even though the
switch is guaranteed to be broken.

Check CanNTP when initializing the panel to fix this.

https://bugzilla.gnome.org/show_bug.cgi?id=732021
This commit is contained in:
Michael Catanzaro 2014-06-21 17:26:46 -05:00
parent 58c1bbc255
commit c8654808c2

View file

@ -743,6 +743,26 @@ change_ntp (GObject *gobject,
queue_set_ntp (self); queue_set_ntp (self);
} }
static gboolean
is_ntp_available (CcDateTimePanel *self)
{
GVariant *value;
gboolean ntp_available = TRUE;
/* We need to access this directly so that we can default to TRUE if
* it is not set.
*/
value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self->priv->dtm), "CanNTP");
if (value)
{
if (g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
ntp_available = g_variant_get_boolean (value);
g_variant_unref (value);
}
return ntp_available;
}
static void static void
on_permission_changed (GPermission *permission, on_permission_changed (GPermission *permission,
GParamSpec *pspec, GParamSpec *pspec,
@ -773,22 +793,7 @@ static void
on_can_ntp_changed (CcDateTimePanel *self) on_can_ntp_changed (CcDateTimePanel *self)
{ {
CcDateTimePanelPrivate *priv = self->priv; CcDateTimePanelPrivate *priv = self->priv;
gboolean ntp_available = TRUE; gtk_widget_set_visible (W ("auto-datetime-row"), is_ntp_available (self));
GVariant *value;
/* We need to access this directly so that we can default to TRUE if
* it is not set.
*/
value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self->priv->dtm), "CanNTP");
if (value)
{
if (g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
ntp_available = g_variant_get_boolean (value);
g_variant_unref (value);
}
gtk_widget_set_visible (W ("auto-datetime-row"),
ntp_available);
} }
static void static void
@ -1281,6 +1286,8 @@ cc_date_time_panel_init (CcDateTimePanel *self)
g_signal_connect (W("network_time_switch"), "notify::active", g_signal_connect (W("network_time_switch"), "notify::active",
G_CALLBACK (change_ntp), self); G_CALLBACK (change_ntp), self);
gtk_widget_set_visible (W ("auto-datetime-row"), is_ntp_available (self));
/* Timezone settings */ /* Timezone settings */
bind_switch_to_row (self, bind_switch_to_row (self,
W ("auto_timezone_switch"), W ("auto_timezone_switch"),