[gnome-control-center] datetime: Add "Network Time" switch



commit de270ce6b4d61ff6c4882cf5a9202018142650eb
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Dec 9 17:09:38 2010 +0000

    datetime: Add "Network Time" switch
    
    And disable the date/time switches when turning NTP on/off.

 panels/datetime/cc-datetime-panel.c |   45 +++++++++++++++++++++++++-
 panels/datetime/datetime.ui         |   59 +++++++++++++++++++++++-----------
 2 files changed, 83 insertions(+), 21 deletions(-)
---
diff --git a/panels/datetime/cc-datetime-panel.c b/panels/datetime/cc-datetime-panel.c
index 3aa16dd..7f5be76 100644
--- a/panels/datetime/cc-datetime-panel.c
+++ b/panels/datetime/cc-datetime-panel.c
@@ -262,6 +262,17 @@ set_timezone_cb (CcDateTimePanel *self,
 }
 
 static void
+set_using_ntp_cb (CcDateTimePanel *self,
+                  GError          *error)
+{
+  /* TODO: display any error in a user friendly way */
+  if (error)
+    {
+      g_warning ("Could not set system to use NTP: %s", error->message);
+    }
+}
+
+static void
 apply_button_clicked_cb (GtkButton       *button,
                          CcDateTimePanel *self)
 {
@@ -269,6 +280,7 @@ apply_button_clicked_cb (GtkButton       *button,
   guint mon, y, d;
   time_t unixtime;
   GDateTime *old_date;
+  gboolean using_ntp;
 
   old_date = priv->date;
 
@@ -290,6 +302,9 @@ apply_button_clicked_cb (GtkButton       *button,
     {
       set_system_timezone_async (priv->current_location->zone, (GFunc) set_timezone_cb, self, NULL);
     }
+
+  using_ntp = gtk_switch_get_active (GTK_SWITCH (W("network_time_switch")));
+  set_using_ntp_async (using_ntp, (GFunc) set_using_ntp_cb, self, NULL);
 }
 
 static void
@@ -529,6 +544,16 @@ city_changed_cb (GtkComboBox     *box,
 }
 
 static void
+update_widget_state_for_ntp (CcDateTimePanel *panel,
+                             gboolean         using_ntp)
+{
+  CcDateTimePanelPrivate *priv = panel->priv;
+
+  gtk_widget_set_sensitive (W("table1"), !using_ntp);
+  gtk_widget_set_sensitive (W("table2"), !using_ntp);
+}
+
+static void
 month_year_changed (GtkWidget       *widget,
                     CcDateTimePanel *panel)
 {
@@ -593,6 +618,14 @@ change_time (GtkButton       *button,
 }
 
 static void
+change_ntp (GObject    *gobject,
+            GParamSpec *pspec,
+            gpointer    user_data)
+{
+  update_widget_state_for_ntp (user_data, gtk_switch_get_active (GTK_SWITCH (gobject)));
+}
+
+static void
 cc_date_time_panel_init (CcDateTimePanel *self)
 {
   CcDateTimePanelPrivate *priv;
@@ -606,6 +639,7 @@ cc_date_time_panel_init (CcDateTimePanel *self)
   GtkTreeModelFilter *city_modelfilter;
   GtkTreeModelSort *city_modelsort;
   guint i, num_days;
+  gboolean using_ntp;
   int ret;
 
   priv = self->priv = DATE_TIME_PANEL_PRIVATE (self);
@@ -623,11 +657,18 @@ cc_date_time_panel_init (CcDateTimePanel *self)
       return;
     }
 
+  /* set up network time button */
+  using_ntp = get_using_ntp ();
+  gtk_switch_set_active (GTK_SWITCH (W("network_time_switch")), using_ntp);
+  update_widget_state_for_ntp (self, using_ntp);
+  g_signal_connect (W("network_time_switch"), "notify::active",
+                    G_CALLBACK (change_ntp), self);
+
   /* set up time editing widgets */
   for (i = 0; i < G_N_ELEMENTS (buttons); i++)
     {
-      g_signal_connect (W(buttons[i]), "clicked", G_CALLBACK (change_time),
-                        self);
+      g_signal_connect (W(buttons[i]), "clicked",
+                        G_CALLBACK (change_time), self);
     }
 
   /* set up date editing widgets */
diff --git a/panels/datetime/datetime.ui b/panels/datetime/datetime.ui
index a59ef85..240bea8 100644
--- a/panels/datetime/datetime.ui
+++ b/panels/datetime/datetime.ui
@@ -13,7 +13,40 @@
         <child>
           <object class="GtkVBox" id="hbox">
             <property name="visible">True</property>
-            <property name="orientation">vertical</property>
+	    <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkHBox" id="hbox2">
+                <property name="visible">True</property>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label3">
+                    <property name="visible">True</property>
+                    <property name="xalign">1</property>
+                    <property name="label" translatable="yes">Network Time</property>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSwitch" id="network_time_switch">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                  </object>
+                  <packing>
+                    <property name="position">2</property>
+                    <property name="expand">False</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="position">0</property>
+                <property name="padding">6</property>
+              </packing>
+            </child>
             <child>
               <object class="GtkHBox" id="vbox">
                 <property name="visible">True</property>
@@ -110,18 +143,6 @@
                     <property name="visible">True</property>
                     <property name="orientation">vertical</property>
                     <child>
-                      <object class="GtkCheckButton" id="check_auto_update">
-                        <property name="label" translatable="yes">Set time automatically</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="draw_indicator">True</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
                       <object class="GtkAlignment" id="alignment2">
                         <property name="visible">True</property>
                         <property name="xscale">0</property>
@@ -314,7 +335,7 @@
                       <packing>
                         <property name="expand">False</property>
                         <property name="padding">12</property>
-                        <property name="position">1</property>
+                        <property name="position">0</property>
                       </packing>
                     </child>
                     <child>
@@ -328,7 +349,7 @@
                       </object>
                       <packing>
                         <property name="expand">False</property>
-                        <property name="position">3</property>
+                        <property name="position">2</property>
                       </packing>
                     </child>
                     <child>
@@ -342,7 +363,7 @@
                       </object>
                       <packing>
                         <property name="expand">False</property>
-                        <property name="position">4</property>
+                        <property name="position">3</property>
                       </packing>
                     </child>
                     <child>
@@ -391,7 +412,7 @@
                       <packing>
                         <property name="expand">False</property>
                         <property name="padding">12</property>
-                        <property name="position">2</property>
+                        <property name="position">1</property>
                       </packing>
                     </child>
                   </object>
@@ -402,7 +423,7 @@
                 </child>
               </object>
               <packing>
-                <property name="position">0</property>
+                <property name="position">1</property>
               </packing>
             </child>
             <child>
@@ -426,7 +447,7 @@
               </object>
               <packing>
                 <property name="expand">False</property>
-                <property name="position">1</property>
+                <property name="position">2</property>
               </packing>
             </child>
           </object>



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