From a1e26cdac16c2b9c3e20c335e265b342e95d6114 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 19 Nov 2020 11:17:22 +1300 Subject: [PATCH 1/4] network: Set transient window from outside NetConnectionEditor constructor --- panels/network/cc-network-panel.c | 5 ++--- .../connection-editor/net-connection-editor.c | 12 ++---------- .../connection-editor/net-connection-editor.h | 3 +-- panels/network/net-device-ethernet.c | 12 ++++-------- panels/network/net-device-wifi.c | 6 ++---- panels/network/net-vpn.c | 8 ++------ 6 files changed, 13 insertions(+), 33 deletions(-) diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c index b87e58b45..0bfd14b72 100644 --- a/panels/network/cc-network-panel.c +++ b/panels/network/cc-network-panel.c @@ -682,10 +682,9 @@ create_connection_cb (GtkWidget *button, CcNetworkPanel *self) { NetConnectionEditor *editor; - GtkWindow *toplevel; - toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))); - editor = net_connection_editor_new (toplevel, NULL, NULL, NULL, self->client); + editor = net_connection_editor_new (NULL, NULL, NULL, self->client); + gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)))); net_connection_editor_run (editor); } diff --git a/panels/network/connection-editor/net-connection-editor.c b/panels/network/connection-editor/net-connection-editor.c index b231caf53..4233d7393 100644 --- a/panels/network/connection-editor/net-connection-editor.c +++ b/panels/network/connection-editor/net-connection-editor.c @@ -59,7 +59,6 @@ struct _NetConnectionEditor GtkNotebook *notebook; GtkStack *toplevel_stack; - GtkWidget *parent_window; NMClient *client; NMDevice *device; @@ -199,7 +198,6 @@ net_connection_editor_finalize (GObject *object) g_clear_object (&self->connection); g_clear_object (&self->orig_connection); - g_clear_object (&self->parent_window); g_clear_object (&self->device); g_clear_object (&self->client); g_clear_object (&self->ap); @@ -250,7 +248,7 @@ net_connection_editor_error_dialog (NetConnectionEditor *self, if (gtk_widget_is_visible (GTK_WIDGET (self))) parent = GTK_WINDOW (self); else - parent = GTK_WINDOW (self->parent_window); + parent = gtk_window_get_transient_for (GTK_WINDOW (self)); dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, @@ -786,8 +784,7 @@ permission_changed (NetConnectionEditor *self, } NetConnectionEditor * -net_connection_editor_new (GtkWindow *parent_window, - NMConnection *connection, +net_connection_editor_new (NMConnection *connection, NMDevice *device, NMAccessPoint *ap, NMClient *client) @@ -799,11 +796,6 @@ net_connection_editor_new (GtkWindow *parent_window, "use-header-bar", 1, NULL); - if (parent_window) { - self->parent_window = GTK_WIDGET (g_object_ref (parent_window)); - gtk_window_set_transient_for (GTK_WINDOW (self), - parent_window); - } if (ap) self->ap = g_object_ref (ap); if (device) diff --git a/panels/network/connection-editor/net-connection-editor.h b/panels/network/connection-editor/net-connection-editor.h index ba4bf34cb..c8132e39e 100644 --- a/panels/network/connection-editor/net-connection-editor.h +++ b/panels/network/connection-editor/net-connection-editor.h @@ -28,8 +28,7 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (NetConnectionEditor, net_connection_editor, NET, CONNECTION_EDITOR, GtkDialog) -NetConnectionEditor *net_connection_editor_new (GtkWindow *parent_window, - NMConnection *connection, +NetConnectionEditor *net_connection_editor_new (NMConnection *connection, NMDevice *device, NMAccessPoint *ap, NMClient *client); diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c index 0f652e309..ac019f684 100644 --- a/panels/network/net-device-ethernet.c +++ b/panels/network/net-device-ethernet.c @@ -217,15 +217,13 @@ show_details (NetDeviceEthernet *self, GtkButton *button, const gchar *title) { GtkWidget *row; NMConnection *connection; - GtkWidget *window; NetConnectionEditor *editor; - window = gtk_widget_get_toplevel (GTK_WIDGET (self)); - row = g_object_get_data (G_OBJECT (button), "row"); connection = NM_CONNECTION (g_object_get_data (G_OBJECT (row), "connection")); - editor = net_connection_editor_new (GTK_WINDOW (window), connection, self->device, NULL, self->client); + editor = net_connection_editor_new (connection, self->device, NULL, self->client); + gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)))); if (title) net_connection_editor_set_title (editor, title); g_signal_connect_object (editor, "done", G_CALLBACK (editor_done), self, G_CONNECT_SWAPPED); @@ -391,7 +389,6 @@ add_profile_button_clicked_cb (NetDeviceEthernet *self) g_autofree gchar *uuid = NULL; g_autofree gchar *id = NULL; NetConnectionEditor *editor; - GtkWidget *window; const GPtrArray *connections; connection = nm_simple_connection_new (); @@ -412,9 +409,8 @@ add_profile_button_clicked_cb (NetDeviceEthernet *self) nm_connection_add_setting (connection, nm_setting_wired_new ()); - window = gtk_widget_get_toplevel (GTK_WIDGET (self)); - - editor = net_connection_editor_new (GTK_WINDOW (window), connection, self->device, NULL, self->client); + editor = net_connection_editor_new (connection, self->device, NULL, self->client); + gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)))); g_signal_connect_object (editor, "done", G_CALLBACK (editor_done), self, G_CONNECT_SWAPPED); net_connection_editor_run (editor); } diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c index 7f2de4c7f..8d262fd80 100644 --- a/panels/network/net-device-wifi.c +++ b/panels/network/net-device-wifi.c @@ -967,15 +967,13 @@ show_details_for_row (NetDeviceWifi *self, CcWifiConnectionRow *row, CcWifiConne { NMConnection *connection; NMAccessPoint *ap; - GtkWidget *window; NetConnectionEditor *editor; - window = gtk_widget_get_toplevel (GTK_WIDGET (row)); - connection = cc_wifi_connection_row_get_connection (row); ap = cc_wifi_connection_row_best_access_point (row); - editor = net_connection_editor_new (GTK_WINDOW (window), connection, self->device, ap, self->client); + editor = net_connection_editor_new (connection, self->device, ap, self->client); + gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (row)))); net_connection_editor_run (editor); } diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c index 89c5777be..a1b8821ba 100644 --- a/panels/network/net-vpn.c +++ b/panels/network/net-vpn.c @@ -150,15 +150,11 @@ editor_done (NetVpn *self) static void edit_connection (NetVpn *self) { - GtkWidget *window; NetConnectionEditor *editor; g_autofree gchar *title = NULL; - window = gtk_widget_get_toplevel (GTK_WIDGET (self)); - - editor = net_connection_editor_new (GTK_WINDOW (window), - self->connection, - NULL, NULL, self->client); + editor = net_connection_editor_new (self->connection, NULL, NULL, self->client); + gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)))); title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (self->connection)); net_connection_editor_set_title (editor, title); -- GitLab From 8ded3d956fb58ee8861acd685dca6600a491a001 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 19 Nov 2020 11:43:16 +1300 Subject: [PATCH 2/4] network: Show spinner instead of delaying dialog It's better to respond to the user immediately rather than delay the window opening. --- panels/network/cc-network-panel.c | 2 +- .../connection-editor/connection-editor.ui | 6 ++++++ .../connection-editor/net-connection-editor.c | 15 +-------------- .../connection-editor/net-connection-editor.h | 1 - panels/network/net-device-ethernet.c | 4 ++-- panels/network/net-device-wifi.c | 2 +- panels/network/net-vpn.c | 2 +- 7 files changed, 12 insertions(+), 20 deletions(-) diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c index 0bfd14b72..01b164ea0 100644 --- a/panels/network/cc-network-panel.c +++ b/panels/network/cc-network-panel.c @@ -685,7 +685,7 @@ create_connection_cb (GtkWidget *button, editor = net_connection_editor_new (NULL, NULL, NULL, self->client); gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)))); - net_connection_editor_run (editor); + gtk_window_present (GTK_WINDOW (editor)); } static void diff --git a/panels/network/connection-editor/connection-editor.ui b/panels/network/connection-editor/connection-editor.ui index 17a096f86..746e86b1c 100644 --- a/panels/network/connection-editor/connection-editor.ui +++ b/panels/network/connection-editor/connection-editor.ui @@ -43,6 +43,12 @@ True True + + + True + True + + True diff --git a/panels/network/connection-editor/net-connection-editor.c b/panels/network/connection-editor/net-connection-editor.c index 4233d7393..0e8ae890f 100644 --- a/panels/network/connection-editor/net-connection-editor.c +++ b/panels/network/connection-editor/net-connection-editor.c @@ -74,7 +74,6 @@ struct _NetConnectionEditor NMClientPermissionResult can_modify; gboolean title_set; - gboolean show_when_initialized; }; G_DEFINE_TYPE (NetConnectionEditor, net_connection_editor, GTK_TYPE_DIALOG) @@ -396,11 +395,9 @@ recheck_initialization (NetConnectionEditor *self) if (!editor_is_initialized (self)) return; + gtk_stack_set_visible_child (self->toplevel_stack, GTK_WIDGET (self->notebook)); gtk_notebook_set_current_page (self->notebook, 0); - if (self->show_when_initialized) - gtk_window_present (GTK_WINDOW (self)); - g_idle_add (idle_validate, self); } @@ -814,16 +811,6 @@ net_connection_editor_new (NMConnection *connection, return self; } -void -net_connection_editor_run (NetConnectionEditor *self) -{ - if (!editor_is_initialized (self)) { - self->show_when_initialized = TRUE; - return; - } - gtk_window_present (GTK_WINDOW (self)); -} - static void forgotten_cb (GObject *source_object, GAsyncResult *res, diff --git a/panels/network/connection-editor/net-connection-editor.h b/panels/network/connection-editor/net-connection-editor.h index c8132e39e..cbd197f9f 100644 --- a/panels/network/connection-editor/net-connection-editor.h +++ b/panels/network/connection-editor/net-connection-editor.h @@ -34,7 +34,6 @@ NetConnectionEditor *net_connection_editor_new (NMConnection *connectio NMClient *client); void net_connection_editor_set_title (NetConnectionEditor *editor, const gchar *title); -void net_connection_editor_run (NetConnectionEditor *editor); void net_connection_editor_forget (NetConnectionEditor *editor); G_END_DECLS diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c index ac019f684..73adb62fc 100644 --- a/panels/network/net-device-ethernet.c +++ b/panels/network/net-device-ethernet.c @@ -227,7 +227,7 @@ show_details (NetDeviceEthernet *self, GtkButton *button, const gchar *title) if (title) net_connection_editor_set_title (editor, title); g_signal_connect_object (editor, "done", G_CALLBACK (editor_done), self, G_CONNECT_SWAPPED); - net_connection_editor_run (editor); + gtk_window_present (GTK_WINDOW (editor)); } static void @@ -412,7 +412,7 @@ add_profile_button_clicked_cb (NetDeviceEthernet *self) editor = net_connection_editor_new (connection, self->device, NULL, self->client); gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)))); g_signal_connect_object (editor, "done", G_CALLBACK (editor_done), self, G_CONNECT_SWAPPED); - net_connection_editor_run (editor); + gtk_window_present (GTK_WINDOW (editor)); } static void diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c index 8d262fd80..69fe2e122 100644 --- a/panels/network/net-device-wifi.c +++ b/panels/network/net-device-wifi.c @@ -974,7 +974,7 @@ show_details_for_row (NetDeviceWifi *self, CcWifiConnectionRow *row, CcWifiConne editor = net_connection_editor_new (connection, self->device, ap, self->client); gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (row)))); - net_connection_editor_run (editor); + gtk_window_present (GTK_WINDOW (editor)); } static void diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c index a1b8821ba..44400662b 100644 --- a/panels/network/net-vpn.c +++ b/panels/network/net-vpn.c @@ -159,7 +159,7 @@ edit_connection (NetVpn *self) net_connection_editor_set_title (editor, title); g_signal_connect_object (editor, "done", G_CALLBACK (editor_done), self, G_CONNECT_SWAPPED); - net_connection_editor_run (editor); + gtk_window_present (GTK_WINDOW (editor)); } static void -- GitLab From 362548fbd1f985b022a09efe39f092f58ce1bf43 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 19 Nov 2020 11:51:45 +1300 Subject: [PATCH 3/4] network: Don't explicitly disconnect signals that are automatically disconnected. --- panels/network/connection-editor/net-connection-editor.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/panels/network/connection-editor/net-connection-editor.c b/panels/network/connection-editor/net-connection-editor.c index 0e8ae890f..bcdf4c765 100644 --- a/panels/network/connection-editor/net-connection-editor.c +++ b/panels/network/connection-editor/net-connection-editor.c @@ -190,10 +190,6 @@ static void net_connection_editor_finalize (GObject *object) { NetConnectionEditor *self = NET_CONNECTION_EDITOR (object); - GSList *l; - - for (l = self->pages; l != NULL; l = l->next) - g_signal_handlers_disconnect_by_func (l->data, page_changed, self); g_clear_object (&self->connection); g_clear_object (&self->orig_connection); -- GitLab From aef13948ebdce93080686f0f99573e470e7d1b7f Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 19 Nov 2020 11:50:48 +1300 Subject: [PATCH 4/4] network: Remove duplicate list We can just iterate over the GtkNotebook - no need to mantain a list of pages. --- .../connection-editor/net-connection-editor.c | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/panels/network/connection-editor/net-connection-editor.c b/panels/network/connection-editor/net-connection-editor.c index bcdf4c765..505b8ee25 100644 --- a/panels/network/connection-editor/net-connection-editor.c +++ b/panels/network/connection-editor/net-connection-editor.c @@ -69,7 +69,6 @@ struct _NetConnectionEditor NMAccessPoint *ap; GSList *initializing_pages; - GSList *pages; NMClientPermissionResult can_modify; @@ -324,7 +323,7 @@ update_sensitivity (NetConnectionEditor *self) { NMSettingConnection *sc; gboolean sensitive; - GSList *l; + GList *pages; if (!editor_is_initialized (self)) return; @@ -337,29 +336,34 @@ update_sensitivity (NetConnectionEditor *self) sensitive = self->can_modify; } - for (l = self->pages; l; l = l->next) - gtk_widget_set_sensitive (GTK_WIDGET (l->data), sensitive); + pages = gtk_container_get_children (GTK_CONTAINER (self->notebook)); + for (GList *l = pages; l; l = l->next) { + CEPage *page = l->data; + gtk_widget_set_sensitive (GTK_WIDGET (page), sensitive); + } } static void validate (NetConnectionEditor *self) { gboolean valid = FALSE; - GSList *l; + GList *pages; if (!editor_is_initialized (self)) goto done; valid = TRUE; - for (l = self->pages; l; l = l->next) { + pages = gtk_container_get_children (GTK_CONTAINER (self->notebook)); + for (GList *l = pages; l; l = l->next) { + CEPage *page = l->data; g_autoptr(GError) error = NULL; - if (!ce_page_validate (CE_PAGE (l->data), self->connection, &error)) { + if (!ce_page_validate (page, self->connection, &error)) { valid = FALSE; if (error) { - g_debug ("Invalid setting %s: %s", ce_page_get_title (CE_PAGE (l->data)), error->message); + g_debug ("Invalid setting %s: %s", ce_page_get_title (page), error->message); } else { - g_debug ("Invalid setting %s", ce_page_get_title (CE_PAGE (l->data))); + g_debug ("Invalid setting %s", ce_page_get_title (page)); } } } @@ -420,7 +424,6 @@ page_initialized (NetConnectionEditor *self, GError *error, CEPage *page) gtk_notebook_insert_page (self->notebook, GTK_WIDGET (page), label, i); self->initializing_pages = g_slist_remove (self->initializing_pages, page); - self->pages = g_slist_append (self->pages, page); recheck_initialization (self); } -- GitLab