[gnome-control-center] network: Use AdwActionRow and GtkListBox for vpn list
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Use AdwActionRow and GtkListBox for vpn list
- Date: Fri, 4 Feb 2022 18:01:46 +0000 (UTC)
commit de16d7bb394514fc950111b407826c6a896c8fd2
Author: Christopher Davis <christopherdavis gnome org>
Date: Thu Jan 27 04:08:58 2022 -0800
network: Use AdwActionRow and GtkListBox for vpn list
Previously the widget was using a hack to show
separators and had a row nested in a listbox,
nested in a box. Instead of having a custom setup
to work around not haveing a listbox, we can use a
listbox.
See: https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1587
panels/network/cc-network-panel.c | 22 ++++--------
panels/network/cc-network-panel.ui | 17 ++++++---
panels/network/net-vpn.c | 18 ++--------
panels/network/net-vpn.h | 7 ++--
panels/network/network-vpn.ui | 74 +++++++++-----------------------------
5 files changed, 41 insertions(+), 97 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 1bf09e8a8..f7b019742 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -71,6 +71,7 @@ struct _CcNetworkPanel
GtkWidget *box_wired;
GtkWidget *container_bluetooth;
GtkWidget *empty_listbox;
+ GtkWidget *vpn_stack;
/* wireless dialog stuff */
CmdlineOperation arg_operation;
@@ -350,23 +351,11 @@ handle_argv (CcNetworkPanel *self)
g_debug ("Could not handle argv operation, no matching device yet?");
}
-/* HACK: this function is basically a workaround. We don't have a single
- * listbox in the VPN section, thus we need to track the separators and the
- * stub row manually.
- */
static void
update_vpn_section (CcNetworkPanel *self)
{
- guint i, n_vpns;
-
- for (i = 0, n_vpns = 0; i < self->vpns->len; i++) {
- NetVpn *vpn = g_ptr_array_index (self->vpns, i);
-
- net_vpn_set_show_separator (vpn, n_vpns > 0);
- n_vpns++;
- }
-
- gtk_widget_set_visible (self->empty_listbox, n_vpns == 0);
+ gtk_stack_set_visible_child (GTK_STACK (self->vpn_stack),
+ self->vpns->len == 0 ? self->empty_listbox : self->box_vpn);
}
static void
@@ -611,7 +600,7 @@ panel_add_vpn_device (CcNetworkPanel *self, NMConnection *connection)
}
net_vpn = net_vpn_new (self->client, connection);
- gtk_box_append (GTK_BOX (self->box_vpn), GTK_WIDGET (net_vpn));
+ gtk_list_box_append (GTK_LIST_BOX (self->box_vpn), GTK_WIDGET (net_vpn));
/* store in the devices array */
g_ptr_array_add (self->vpns, net_vpn);
@@ -653,7 +642,7 @@ client_connection_removed_cb (CcNetworkPanel *self, NMConnection *connection)
NetVpn *vpn = g_ptr_array_index (self->vpns, i);
if (net_vpn_get_connection (vpn) == connection) {
g_ptr_array_remove (self->vpns, vpn);
- gtk_box_remove (GTK_BOX (self->box_vpn), GTK_WIDGET (vpn));
+ gtk_list_box_remove (GTK_LIST_BOX (self->box_vpn), GTK_WIDGET (vpn));
update_vpn_section (self);
return;
}
@@ -745,6 +734,7 @@ cc_network_panel_class_init (CcNetworkPanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcNetworkPanel, box_wired);
gtk_widget_class_bind_template_child (widget_class, CcNetworkPanel, container_bluetooth);
gtk_widget_class_bind_template_child (widget_class, CcNetworkPanel, empty_listbox);
+ gtk_widget_class_bind_template_child (widget_class, CcNetworkPanel, vpn_stack);
gtk_widget_class_bind_template_callback (widget_class, create_connection_cb);
}
diff --git a/panels/network/cc-network-panel.ui b/panels/network/cc-network-panel.ui
index a3647fdde..53d0215d8 100644
--- a/panels/network/cc-network-panel.ui
+++ b/panels/network/cc-network-panel.ui
@@ -90,11 +90,20 @@
</child>
<child>
- <object class="GtkBox" id="box_vpn">
- <property name="orientation">vertical</property>
-
- <!-- "Not set up" row -->
+ <object class="GtkStack" id="vpn_stack">
+ <child>
+ <object class="GtkListBox" id="box_vpn">
+ <property name="selection_mode">none</property>
+ <accessibility>
+ <property name="label" translatable="yes">VPN</property>
+ </accessibility>
+ <style>
+ <class name="boxed-list" />
+ </style>
+ </object>
+ </child>
<child>
+ <!-- "Not set up" row -->
<object class="GtkListBox" id="empty_listbox">
<property name="selection_mode">none</property>
<style>
diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c
index 3e2c84745..d1bd8fd41 100644
--- a/panels/network/net-vpn.c
+++ b/panels/network/net-vpn.c
@@ -33,12 +33,10 @@
struct _NetVpn
{
- GtkBox parent;
+ AdwActionRow parent;
GtkBox *box;
- GtkLabel *device_label;
GtkSwitch *device_off_switch;
- GtkSeparator *separator;
NMClient *client;
NMConnection *connection;
@@ -46,7 +44,7 @@ struct _NetVpn
gboolean updating_device;
};
-G_DEFINE_TYPE (NetVpn, net_vpn, GTK_TYPE_BOX)
+G_DEFINE_TYPE (NetVpn, net_vpn, ADW_TYPE_ACTION_ROW)
static void
nm_device_refresh_vpn_ui (NetVpn *self)
@@ -63,7 +61,7 @@ nm_device_refresh_vpn_ui (NetVpn *self)
* vpn connections in the device list.
*/
title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (self->connection));
- gtk_label_set_label (self->device_label, title);
+ adw_preferences_row_set_title (ADW_PREFERENCES_ROW (self), title);
if (self->active_connection) {
g_signal_handlers_disconnect_by_func (self->active_connection,
@@ -189,9 +187,7 @@ net_vpn_class_init (NetVpnClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/network/network-vpn.ui");
- gtk_widget_class_bind_template_child (widget_class, NetVpn, device_label);
gtk_widget_class_bind_template_child (widget_class, NetVpn, device_off_switch);
- gtk_widget_class_bind_template_child (widget_class, NetVpn, separator);
gtk_widget_class_bind_template_callback (widget_class, device_off_toggled);
gtk_widget_class_bind_template_callback (widget_class, edit_connection);
@@ -234,11 +230,3 @@ net_vpn_get_connection (NetVpn *self)
g_return_val_if_fail (NET_IS_VPN (self), NULL);
return self->connection;
}
-
-void
-net_vpn_set_show_separator (NetVpn *self,
- gboolean show_separator)
-{
- g_return_if_fail (NET_IS_VPN (self));
- gtk_widget_set_visible (GTK_WIDGET (self->separator), show_separator);
-}
diff --git a/panels/network/net-vpn.h b/panels/network/net-vpn.h
index ea334be30..183545814 100644
--- a/panels/network/net-vpn.h
+++ b/panels/network/net-vpn.h
@@ -21,20 +21,17 @@
#pragma once
+#include <adwaita.h>
#include <gtk/gtk.h>
#include <NetworkManager.h>
G_BEGIN_DECLS
-G_DECLARE_FINAL_TYPE (NetVpn, net_vpn, NET, VPN, GtkBox)
+G_DECLARE_FINAL_TYPE (NetVpn, net_vpn, NET, VPN, AdwActionRow)
NetVpn *net_vpn_new (NMClient *client,
NMConnection *connection);
NMConnection *net_vpn_get_connection (NetVpn *vpn);
-
-void net_vpn_set_show_separator (NetVpn *vpn,
- gboolean show_separator);
-
G_END_DECLS
diff --git a/panels/network/network-vpn.ui b/panels/network/network-vpn.ui
index 6bd0a2b04..85f6171c7 100644
--- a/panels/network/network-vpn.ui
+++ b/panels/network/network-vpn.ui
@@ -1,65 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
- <template class="NetVpn" parent="GtkBox">
- <property name="hexpand">True</property>
- <property name="orientation">vertical</property>
-
- <!-- HACK: a separator above the row, since we don't have a real listbox widget in the panel -->
- <child>
- <object class="GtkSeparator" id="separator">
- <property name="orientation">horizontal</property>
+ <template class="NetVpn" parent="AdwActionRow">
+ <property name="activatable-widget">device_off_switch</property>
+ <child type="suffix">
+ <object class="GtkSwitch" id="device_off_switch">
+ <property name="valign">center</property>
+ <signal name="notify::active" handler="device_off_toggled" object="NetVpn" swapped="yes"/>
+ <accessibility>
+ <property name="label" translatable="yes">Turn VPN connection off</property>
+ </accessibility>
</object>
</child>
-
- <!-- Main listbox -->
- <child>
- <object class="GtkListBox">
- <property name="selection_mode">none</property>
- <style>
- <class name="boxed-list" />
- </style>
- <child>
- <object class="GtkListBoxRow">
- <property name="activatable">False</property>
- <child>
- <object class="GtkBox">
- <property name="valign">start</property>
- <property name="margin_top">8</property>
- <property name="margin_bottom">8</property>
- <property name="margin_start">12</property>
- <property name="margin_end">12</property>
- <property name="spacing">12</property>
- <child>
- <object class="GtkLabel" id="device_label">
- <property name="xalign">0</property>
- <property name="ellipsize">end</property>
- <property name="hexpand">True</property>
- </object>
- </child>
- <child>
- <object class="GtkSwitch" id="device_off_switch">
- <property name="halign">end</property>
- <property name="valign">center</property>
- <signal name="notify::active" handler="device_off_toggled" object="NetVpn"
swapped="yes"/>
- <accessibility>
- <property name="label" translatable="yes">Turn VPN connection off</property>
- </accessibility>
- </object>
- </child>
- <child>
- <object class="GtkButton" id="options_button">
- <property name="icon_name">emblem-system-symbolic</property>
- <signal name="clicked" handler="edit_connection" object="NetVpn" swapped="yes"/>
- <accessibility>
- <property name="label" translatable="yes">Options…</property>
- </accessibility>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
+ <child type="suffix">
+ <object class="GtkButton" id="options_button">
+ <property name="valign">center</property>
+ <property name="icon_name">emblem-system-symbolic</property>
+ <signal name="clicked" handler="edit_connection" object="NetVpn" swapped="yes"/>
+ <accessibility>
+ <property name="label" translatable="yes">Options…</property>
+ </accessibility>
</object>
</child>
</template>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]