[gnome-control-center/wip/every-detail-matters-round1: 11/13] wifi: Show a spinner when scanning for new access points



commit dc42daab99045439e7412cf4b0f7e9c81d3050cf
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jun 14 14:03:46 2019 -0300

    wifi: Show a spinner when scanning for new access points
    
    The spinner was already present in the UI file! It just needs
    minor cleanups (such as moving the bottom margin from the label
    to the parent box) and binding the widget to the structure.
    
    We need to monitor which device is visible since the Wi-Fi panel
    deals with multiple Wi-Fi devices as well.
    
    Fixes https://gitlab.gnome.org/GNOME/gnome-control-center/issues/551

 panels/network/cc-wifi-panel.c  | 32 ++++++++++++++++++++++++++++++++
 panels/network/cc-wifi-panel.ui |  4 +++-
 2 files changed, 35 insertions(+), 1 deletion(-)
---
diff --git a/panels/network/cc-wifi-panel.c b/panels/network/cc-wifi-panel.c
index 63aa3dc58..3dec9a85f 100644
--- a/panels/network/cc-wifi-panel.c
+++ b/panels/network/cc-wifi-panel.c
@@ -53,12 +53,14 @@ struct _CcWifiPanel
   GtkStack           *header_stack;
   GtkStack           *main_stack;
   GtkSizeGroup       *sizegroup;
+  GtkWidget          *spinner;
   GtkStack           *stack;
 
   NMClient           *client;
 
   GPtrArray          *devices;
 
+  GBinding           *spinner_binding;
   GCancellable       *cancellable;
 
   /* Command-line arguments */
@@ -546,6 +548,34 @@ rfkill_switch_notify_activate_cb (GtkSwitch   *rfkill_switch,
                      NULL);
 }
 
+static void
+on_stack_visible_child_changed_cb (GtkStack    *stack,
+                                   GParamSpec  *pspec,
+                                   CcWifiPanel *self)
+{
+  const gchar *visible_device_id = NULL;
+  guint i;
+
+  /* Remove previous bindings */
+  g_clear_pointer (&self->spinner_binding, g_binding_unbind);
+
+  visible_device_id = gtk_stack_get_visible_child_name (stack);
+  for (i = 0; i < self->devices->len; i++)
+    {
+      NetObject *object = g_ptr_array_index (self->devices, i);
+
+      if (g_strcmp0 (net_object_get_id (object), visible_device_id) == 0)
+        {
+          self->spinner_binding = g_object_bind_property (object,
+                                                          "scanning",
+                                                          self->spinner,
+                                                          "active",
+                                                          G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
+          break;
+        }
+    }
+}
+
 /* Overrides */
 
 static const gchar *
@@ -687,9 +717,11 @@ cc_wifi_panel_class_init (CcWifiPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcWifiPanel, rfkill_switch);
   gtk_widget_class_bind_template_child (widget_class, CcWifiPanel, rfkill_widget);
   gtk_widget_class_bind_template_child (widget_class, CcWifiPanel, sizegroup);
+  gtk_widget_class_bind_template_child (widget_class, CcWifiPanel, spinner);
   gtk_widget_class_bind_template_child (widget_class, CcWifiPanel, stack);
 
   gtk_widget_class_bind_template_callback (widget_class, rfkill_switch_notify_activate_cb);
+  gtk_widget_class_bind_template_callback (widget_class, on_stack_visible_child_changed_cb);
 
   g_object_class_override_property (object_class, PROP_PARAMETERS, "parameters");
 }
diff --git a/panels/network/cc-wifi-panel.ui b/panels/network/cc-wifi-panel.ui
index 8dd3570ce..8b86098ac 100644
--- a/panels/network/cc-wifi-panel.ui
+++ b/panels/network/cc-wifi-panel.ui
@@ -220,12 +220,12 @@
                             <property name="hexpand">True</property>
                             <property name="halign">start</property>
                             <property name="spacing">6</property>
+                            <property name="margin_bottom">12</property>
                             <child>
                               <object class="GtkLabel">
                                 <property name="visible">True</property>
                                 <property name="label" translatable="yes">Visible Networks</property>
                                 <property name="xalign">0.0</property>
-                                <property name="margin_bottom">12</property>
                                 <attributes>
                                   <attribute name="weight" value="bold"/>
                                 </attributes>
@@ -233,6 +233,7 @@
                             </child>
                             <child>
                               <object class="GtkSpinner" id="spinner">
+                                <property name="visible">True</property>
                                 <property name="hexpand">True</property>
                               </object>
                             </child>
@@ -253,6 +254,7 @@
                                 <property name="hexpand">True</property>
                                 <property name="vexpand">True</property>
                                 <property name="transition_type">crossfade</property>
+                                <signal name="notify::visible-child-name" 
handler="on_stack_visible_child_changed_cb" object="CcWifiPanel" swapped="no" />
                               </object>
                             </child>
                           </object>


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