From e1b88ba90318b464c9c435fc46b11e05fed617ba Mon Sep 17 00:00:00 2001 From: rbuj Date: Fri, 8 Jan 2021 00:55:14 +0100 Subject: netspeed-preferences: move device list to class properties --- netspeed/src/netspeed-preferences.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'netspeed/src/netspeed-preferences.c') diff --git a/netspeed/src/netspeed-preferences.c b/netspeed/src/netspeed-preferences.c index 401a9de8..18fc3221 100644 --- a/netspeed/src/netspeed-preferences.c +++ b/netspeed/src/netspeed-preferences.c @@ -38,6 +38,8 @@ struct _NetspeedPreferences GtkWidget *show_icon_checkbutton; GtkWidget *show_quality_icon_checkbutton; GtkWidget *change_icon_checkbutton; + + GList *devices; }; typedef enum @@ -112,11 +114,9 @@ static void on_network_device_combo_changed (GtkComboBox *combo, NetspeedPreferences *preferences) { - GList *devices; - int i, active; + gint active; gboolean old_auto_change_device, auto_change_device; - devices = g_object_get_data (G_OBJECT (combo), "devices"); active = gtk_combo_box_get_active (combo); g_assert (active > -1); @@ -128,16 +128,15 @@ on_network_device_combo_changed (GtkComboBox *combo, auto_change_device = TRUE; } else { const gchar *current_device_name; + const gchar *selected_device_name; current_device_name = netspeed_applet_get_current_device_name (preferences->netspeed); auto_change_device = FALSE; - for (i = 1; i < active; i++) { - devices = g_list_next (devices); - } - if (!devices || !g_strcmp0 (devices->data, current_device_name)) + selected_device_name = g_list_nth_data (preferences->devices, (guint) (active - 1)); + if (!g_strcmp0 (selected_device_name, current_device_name)) return; g_settings_set_string (preferences->settings, - "device", devices->data); + "device", selected_device_name); } if (old_auto_change_device != auto_change_device) g_settings_set_boolean (preferences->settings, @@ -147,10 +146,9 @@ on_network_device_combo_changed (GtkComboBox *combo, static void netspeed_preferences_finalize (GObject *object) { - NetspeedPreferences *self = NETSPEED_PREFERENCES (object); - g_signal_handlers_disconnect_by_func (self->network_device_combo, - on_network_device_combo_changed, - self); + NetspeedPreferences *preferences = NETSPEED_PREFERENCES (object); + + free_devices_list (preferences->devices); G_OBJECT_CLASS (netspeed_preferences_parent_class)->finalize (object); } @@ -187,16 +185,10 @@ netspeed_preferences_class_init (NetspeedPreferencesClass *klass) gtk_widget_class_bind_template_callback (widget_class, on_network_device_combo_changed); } -static void -free_devices (gpointer data) -{ - g_list_free_full (data, g_free); -} - static void fill_device_combo (NetspeedPreferences *preferences, GSettings *settings) { - GList *ptr, *devices; + GList *ptr; int i, active = -1; const gchar *current_device_name; gboolean auto_change_device; @@ -204,7 +196,7 @@ fill_device_combo (NetspeedPreferences *preferences, GSettings *settings) /* Default means device with default route set */ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (preferences->network_device_combo), _("Default")); - ptr = devices = get_available_devices (); + ptr = preferences->devices = get_available_devices (); current_device_name = netspeed_applet_get_current_device_name (preferences->netspeed); auto_change_device = g_settings_get_boolean (settings, "auto-change-device"); for (i = 0; ptr; ptr = g_list_next (ptr)) { @@ -217,8 +209,6 @@ fill_device_combo (NetspeedPreferences *preferences, GSettings *settings) if (active < 0 || auto_change_device) active = 0; gtk_combo_box_set_active (GTK_COMBO_BOX (preferences->network_device_combo), active); - g_object_set_data_full (G_OBJECT (preferences->network_device_combo), "devices", - devices, free_devices); } GtkWidget * -- cgit v1.2.1