[gnome-control-center] network: Remove two common functions that are more simply done inside the few cases that use them



commit 3c32ee72ea175c1655253ca3507f52fb9b766a1a
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Oct 1 12:50:30 2019 +1300

    network: Remove two common functions that are more simply done inside the few cases that use them
    
    The existing code relied on using GtkBuilder, which will no longer work when we
    switch to GtkTemplate.

 panels/network/net-device-ethernet.c |  8 ++++++--
 panels/network/net-device-mobile.c   |  5 ++++-
 panels/network/net-device-wifi.c     |  6 +++++-
 panels/network/panel-common.c        | 34 +++-------------------------------
 panels/network/panel-common.h        |  9 +--------
 5 files changed, 19 insertions(+), 43 deletions(-)
---
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index 7a43f4fcd..e4239891b 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -23,7 +23,8 @@
 
 #include <glib-object.h>
 #include <glib/gi18n.h>
-
+#define HANDY_USE_UNSTABLE_API
+#include <handy.h>
 #include <NetworkManager.h>
 
 #include "panel-common.h"
@@ -204,6 +205,7 @@ device_ethernet_refresh_ui (NetDeviceEthernet *device)
         NMDeviceState state;
         GtkWidget *widget;
         g_autofree gchar *speed = NULL;
+        g_autofree gchar *status = NULL;
 
         nm_device = net_device_get_nm_device (NET_DEVICE (device));
 
@@ -221,7 +223,9 @@ device_ethernet_refresh_ui (NetDeviceEthernet *device)
 
         if (state != NM_DEVICE_STATE_UNAVAILABLE)
                 speed = net_device_simple_get_speed (NET_DEVICE_SIMPLE (device));
-        panel_set_device_row_status (device->builder, "details_row", nm_device, speed);
+        widget = GTK_WIDGET (gtk_builder_get_object (device->builder, "details_row"));
+        status = panel_device_status_to_localized_string (nm_device, speed);
+        hdy_action_row_set_title (HDY_ACTION_ROW (widget), status);
 
         populate_ui (device);
 }
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index 69868a371..96e9ff229 100644
--- a/panels/network/net-device-mobile.c
+++ b/panels/network/net-device-mobile.c
@@ -374,6 +374,7 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *device_mobile)
         NMClient *client;
         NMDeviceModemCapabilities caps;
         NMDevice *nm_device;
+        g_autofree gchar *status = NULL;
 
         nm_device = net_device_get_nm_device (NET_DEVICE (device_mobile));
 
@@ -388,7 +389,9 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *device_mobile)
         mobilebb_enabled_toggled (client, NULL, device_mobile);
 
         /* set device state, with status */
-        panel_set_device_status (device_mobile->builder, "label_status", nm_device, NULL);
+        widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->builder, "label_status"));
+        status = panel_device_status_to_localized_string (nm_device, NULL);
+        gtk_label_set_label (GTK_LABEL (widget), status);
 
         /* sensitive for other connection types if the device is currently connected */
         widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->builder,
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index 9efed8cc6..f8a1b689a 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -491,6 +491,8 @@ nm_device_wifi_refresh_ui (NetDeviceWifi *device_wifi)
         NMAccessPoint *ap;
         NMConnection *connection;
         GtkWidget *dialog;
+        GtkWidget *widget;
+        g_autofree gchar *status = NULL;
 
         if (device_is_hotspot (device_wifi)) {
                 nm_device_wifi_refresh_hotspot (device_wifi);
@@ -585,7 +587,9 @@ nm_device_wifi_refresh_ui (NetDeviceWifi *device_wifi)
         else
                 panel_set_device_widget_details (device_wifi->builder, "last_used", NULL);
 
-        panel_set_device_status (device_wifi->builder, "heading_status", nm_device, NULL);
+        widget = GTK_WIDGET (gtk_builder_get_object (device_wifi->builder, "heading_status"));
+        status = panel_device_status_to_localized_string (nm_device, NULL);
+        gtk_label_set_label (GTK_LABEL (widget), status);
 
         /* update list of APs */
         show_wifi_list (device_wifi);
diff --git a/panels/network/panel-common.c b/panels/network/panel-common.c
index 34c0b24c8..022243c39 100644
--- a/panels/network/panel-common.c
+++ b/panels/network/panel-common.c
@@ -269,9 +269,9 @@ device_state_reason_to_localized_string (NMDevice *device)
         return value;
 }
 
-static gchar *
-device_status_to_localized_string (NMDevice *nm_device,
-                                   const gchar *speed)
+gchar *
+panel_device_status_to_localized_string (NMDevice *nm_device,
+                                         const gchar *speed)
 {
         NMDeviceState state;
         GString *string;
@@ -314,34 +314,6 @@ device_status_to_localized_string (NMDevice *nm_device,
         return g_string_free (string, FALSE);
 }
 
-void
-panel_set_device_status (GtkBuilder *builder,
-                         const gchar *label_name,
-                         NMDevice *nm_device,
-                         const gchar *speed)
-{
-        GtkLabel *label;
-        g_autofree gchar *status = NULL;
-
-        label = GTK_LABEL (gtk_builder_get_object (builder, label_name));
-        status = device_status_to_localized_string (nm_device, speed);
-        gtk_label_set_label (label, status);
-}
-
-void
-panel_set_device_row_status (GtkBuilder  *builder,
-                             const gchar *row_name,
-                             NMDevice    *nm_device,
-                             const gchar *speed)
-{
-        HdyActionRow *row;
-        g_autofree gchar *status = NULL;
-
-        row = HDY_ACTION_ROW (gtk_builder_get_object (builder, row_name));
-        status = device_status_to_localized_string (nm_device, speed);
-        hdy_action_row_set_title (row, status);
-}
-
 gboolean
 panel_set_device_widget_details (GtkBuilder *builder,
                                  const gchar *widget_suffix,
diff --git a/panels/network/panel-common.h b/panels/network/panel-common.h
index 6a68533a7..4f0631bc1 100644
--- a/panels/network/panel-common.h
+++ b/panels/network/panel-common.h
@@ -21,19 +21,12 @@
 
 #pragma once
 
-#include <glib-object.h>
 #include <NetworkManager.h>
 #include <gtk/gtk.h>
 
 G_BEGIN_DECLS
 
-void             panel_set_device_status                       (GtkBuilder *builder,
-                                                                const gchar *label_name,
-                                                                NMDevice *nm_device,
-                                                                const gchar *speed);
-void             panel_set_device_row_status                   (GtkBuilder *builder,
-                                                                const gchar *row_name,
-                                                                NMDevice *nm_device,
+gchar           *panel_device_status_to_localized_string       (NMDevice *nm_device,
                                                                 const gchar *speed);
 gboolean         panel_set_device_widget_details               (GtkBuilder *builder,
                                                                 const gchar *widget_suffix,


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