[gnome-control-center] network: Move widget code into GtkBuilder



commit f335ed420f96f558b5b167583303c203b3b501b0
Author: Robert Ancell <robert ancell canonical com>
Date:   Thu Oct 24 20:45:05 2019 +1300

    network: Move widget code into GtkBuilder

 panels/network/net-device-ethernet.c | 20 ++++++++------------
 panels/network/net-device-mobile.c   | 11 -----------
 panels/network/network-ethernet.ui   |  7 +++++++
 panels/network/network-mobile.ui     |  6 ++++++
 4 files changed, 21 insertions(+), 23 deletions(-)
---
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index 8a7bb4796..2177657a5 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -39,6 +39,7 @@ struct _NetDeviceEthernet
 {
         GtkBox             parent;
 
+        GtkListBox        *connection_list;
         GtkButton         *details_button;
         GtkFrame          *details_frame;
         HdyActionRow      *details_row;
@@ -48,7 +49,6 @@ struct _NetDeviceEthernet
 
         NMClient          *client;
         NMDevice          *device;
-        GtkListBox        *list;
         gboolean           updating_device;
         GHashTable        *connections;
 };
@@ -324,7 +324,7 @@ add_row (NetDeviceEthernet *self, NMConnection *connection)
 
         g_object_set_data (G_OBJECT (row), "connection", connection);
 
-        gtk_container_add (GTK_CONTAINER (self->list), row);
+        gtk_container_add (GTK_CONTAINER (self->connection_list), row);
 }
 
 static void
@@ -342,9 +342,9 @@ populate_ui (NetDeviceEthernet *self)
         NMConnection *connection;
         gint n_connections;
 
-        children = gtk_container_get_children (GTK_CONTAINER (self->list));
+        children = gtk_container_get_children (GTK_CONTAINER (self->connection_list));
         for (c = children; c; c = c->next) {
-                gtk_container_remove (GTK_CONTAINER (self->list), c->data);
+                gtk_container_remove (GTK_CONTAINER (self->connection_list), c->data);
         }
         g_list_free (children);
 
@@ -443,7 +443,7 @@ device_off_switch_changed_cb (NetDeviceEthernet *self)
 }
 
 static void
-connection_activated (NetDeviceEthernet *self, GtkListBoxRow *row)
+connection_list_row_activated_cb (NetDeviceEthernet *self, GtkListBoxRow *row)
 {
         NMConnection *connection;
 
@@ -481,6 +481,7 @@ net_device_ethernet_class_init (NetDeviceEthernetClass *klass)
 
         gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/network/network-ethernet.ui");
 
+        gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, connection_list);
         gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, details_button);
         gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, details_frame);
         gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, details_row);
@@ -488,6 +489,7 @@ net_device_ethernet_class_init (NetDeviceEthernetClass *klass)
         gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, device_off_switch);
         gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, scrolled_window);
 
+        gtk_widget_class_bind_template_callback (widget_class, connection_list_row_activated_cb);
         gtk_widget_class_bind_template_callback (widget_class, device_off_switch_changed_cb);
         gtk_widget_class_bind_template_callback (widget_class, details_button_clicked_cb);
         gtk_widget_class_bind_template_callback (widget_class, add_profile_button_clicked_cb);
@@ -500,13 +502,7 @@ net_device_ethernet_init (NetDeviceEthernet *self)
 
         self->connections = g_hash_table_new (NULL, NULL);
 
-        self->list = GTK_LIST_BOX (gtk_list_box_new ());
-        gtk_list_box_set_selection_mode (self->list, GTK_SELECTION_NONE);
-        gtk_list_box_set_header_func (self->list, cc_list_box_update_header_func, NULL, NULL);
-        gtk_container_add (GTK_CONTAINER (self->scrolled_window), GTK_WIDGET (self->list));
-        g_signal_connect_swapped (self->list, "row-activated",
-                                  G_CALLBACK (connection_activated), self);
-        gtk_widget_show (GTK_WIDGET (self->list));
+        gtk_list_box_set_header_func (self->connection_list, cc_list_box_update_header_func, NULL, NULL);
 }
 
 NetDeviceEthernet *
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index 536a37468..1bc1fb8dc 100644
--- a/panels/network/net-device-mobile.c
+++ b/panels/network/net-device-mobile.c
@@ -770,21 +770,10 @@ net_device_mobile_class_init (NetDeviceMobileClass *klass)
 static void
 net_device_mobile_init (NetDeviceMobile *self)
 {
-        GtkCellRenderer *renderer;
-
         gtk_widget_init_template (GTK_WIDGET (self));
 
         self->cancellable = g_cancellable_new ();
 
-        /* setup mobile combobox model */
-        renderer = gtk_cell_renderer_text_new ();
-        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self->network_combo),
-                                    renderer,
-                                    FALSE);
-        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self->network_combo), renderer,
-                                        "text", COLUMN_TITLE,
-                                        NULL);
-
         gtk_widget_set_visible (GTK_WIDGET (self->options_button), g_find_program_in_path 
("nm-connection-editor") != NULL);
 }
 
diff --git a/panels/network/network-ethernet.ui b/panels/network/network-ethernet.ui
index f5063158d..183633dc7 100644
--- a/panels/network/network-ethernet.ui
+++ b/panels/network/network-ethernet.ui
@@ -55,6 +55,13 @@
             <property name="hscrollbar_policy">never</property>
             <property name="vscrollbar_policy">never</property>
             <property name="shadow_type">in</property>
+            <child>
+              <object class="GtkListBox" id="connection_list">
+                <property name="visible">True</property>
+                <property name="selection-mode">none</property>
+                <signal name="row-activated" handler="connection_list_row_activated_cb" 
object="NetDeviceEthernet" swapped="yes"/>
+              </object>
+            </child>
           </object>
         </child>
 
diff --git a/panels/network/network-mobile.ui b/panels/network/network-mobile.ui
index bc13dc44b..fa1ad59cc 100644
--- a/panels/network/network-mobile.ui
+++ b/panels/network/network-mobile.ui
@@ -268,6 +268,12 @@
                 <property name="model">mobile_connections_list_store</property>
                 <property name="entry_text_column">1</property>
                 <signal name="changed" handler="network_combo_changed_cb" object="NetDeviceMobile" 
swapped="yes"/>
+                <child>
+                  <object class="GtkCellRendererText"/>
+                  <attributes>
+                    <attribute name="text">1</attribute>
+                  </attributes>
+                </child>
               </object>
               <packing>
                 <property name="left_attach">1</property>


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