[gnome-control-center] network: Replace the notebook with a stack
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Replace the notebook with a stack
- Date: Tue, 18 Jul 2017 02:42:27 +0000 (UTC)
commit 158591a346579c0a2a7f46a5e534290f65c9a3d1
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Jul 11 13:02:51 2017 -0300
network: Replace the notebook with a stack
The Network panel uses a GtkNotebook internally to manage
the different setup pages of the network devices. While it
does the job, we now have a modern widget for that: GtkStack.
With GtkStack, managing the pages becomes a lot easier and
we gain almost for free the nice transition between pages,
besides of course being a widget that consumes slightly less
resources.
Besides all these gains, using a GtkStack will allow us to
implement the new Wi-Fi panel in a more cohesive manner,
sharing large portions of code and avoiding copy pasta.
This commit then turns the GtkNotebook into a GtkStack, and
renames and adapts the code to reflect that. Fortunately,
the code got actually simpler with the move.
https://bugzilla.gnome.org/show_bug.cgi?id=784818
panels/network/cc-network-panel.c | 70 +++++++++-------------------------
panels/network/net-device-ethernet.c | 10 ++--
panels/network/net-device-mobile.c | 10 ++--
panels/network/net-device-simple.c | 10 ++--
panels/network/net-device-wifi.c | 10 ++--
panels/network/net-object.c | 14 +++----
panels/network/net-object.h | 8 ++--
panels/network/net-proxy.c | 10 ++--
panels/network/net-vpn.c | 10 ++--
panels/network/network.ui | 4 +-
10 files changed, 60 insertions(+), 96 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 27e675a..08ef3e1 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -750,7 +750,6 @@ panel_add_device (CcNetworkPanel *panel, NMDevice *device)
NMDeviceType type;
NetDevice *net_device;
CcNetworkPanelPrivate *priv = panel->priv;
- GtkNotebook *notebook;
GtkSizeGroup *size_group;
GType device_g_type;
const char *udi;
@@ -831,13 +830,12 @@ panel_add_device (CcNetworkPanel *panel, NMDevice *device)
/* add as a panel */
if (device_g_type != NET_TYPE_DEVICE) {
- notebook = GTK_NOTEBOOK (gtk_builder_get_object (panel->priv->builder,
- "notebook_types"));
+ GtkStack *stack;
+
+ stack = GTK_STACK (gtk_builder_get_object (panel->priv->builder, "stack"));
size_group = GTK_SIZE_GROUP (gtk_builder_get_object (panel->priv->builder,
"sizegroup1"));
- net_object_add_to_notebook (NET_OBJECT (net_device),
- notebook,
- size_group);
+ net_object_add_to_stack (NET_OBJECT (net_device), stack, size_group);
}
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
@@ -961,46 +959,25 @@ static void
nm_devices_treeview_clicked_cb (GtkTreeSelection *selection, CcNetworkPanel *panel)
{
CcNetworkPanelPrivate *priv = panel->priv;
- const gchar *id_tmp;
const gchar *needle;
- GList *l;
- GList *panels = NULL;
- GtkNotebook *notebook;
+ GtkStack *stack;
GtkTreeIter iter;
GtkTreeModel *model;
- GtkWidget *widget;
- guint i = 0;
NetObject *object = NULL;
if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
g_debug ("no row selected");
- goto out;
+ return;
}
- /* find the widget in the notebook that matches the object ID */
+ /* find the widget in the stack that matches the object ID */
object = get_selected_object (panel);
needle = net_object_get_id (object);
- notebook = GTK_NOTEBOOK (gtk_builder_get_object (priv->builder,
- "notebook_types"));
- panels = gtk_container_get_children (GTK_CONTAINER (notebook));
- for (l = panels; l != NULL; l = l->next) {
- widget = GTK_WIDGET (l->data);
- id_tmp = g_object_get_data (G_OBJECT (widget), "NetObject::id");
- if (g_strcmp0 (needle, id_tmp) == 0) {
- gtk_notebook_set_current_page (notebook, i);
-
- /* object is deletable? */
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
- "remove_toolbutton"));
- gtk_widget_set_sensitive (widget,
- net_object_get_removable (object));
- break;
- }
- i++;
- }
+ stack = GTK_STACK (gtk_builder_get_object (priv->builder, "stack"));
+
+ gtk_stack_set_visible_child_name (stack, needle);
+
g_object_unref (object);
-out:
- g_list_free (panels);
}
static void
@@ -1009,18 +986,15 @@ panel_add_proxy_device (CcNetworkPanel *panel)
GtkListStore *liststore_devices;
GtkTreeIter iter;
NetProxy *proxy;
- GtkNotebook *notebook;
+ GtkStack *stack;
GtkSizeGroup *size_group;
- /* add proxy to notebook */
+ /* add proxy to stack */
proxy = net_proxy_new ();
- notebook = GTK_NOTEBOOK (gtk_builder_get_object (panel->priv->builder,
- "notebook_types"));
+ stack = GTK_STACK (gtk_builder_get_object (panel->priv->builder, "stack"));
size_group = GTK_SIZE_GROUP (gtk_builder_get_object (panel->priv->builder,
"sizegroup1"));
- net_object_add_to_notebook (NET_OBJECT (proxy),
- notebook,
- size_group);
+ net_object_add_to_stack (NET_OBJECT (proxy), stack, size_group);
/* add proxy to device list */
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
@@ -1174,7 +1148,7 @@ panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection)
GtkTreeIter iter;
NetVpn *net_vpn;
const gchar *id;
- GtkNotebook *notebook;
+ GtkStack *stack;
GtkSizeGroup *size_group;
/* does already exist */
@@ -1194,13 +1168,10 @@ panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection)
G_CALLBACK (object_removed_cb), panel, 0);
/* add as a panel */
- notebook = GTK_NOTEBOOK (gtk_builder_get_object (panel->priv->builder,
- "notebook_types"));
+ stack = GTK_STACK (gtk_builder_get_object (panel->priv->builder, "stack"));
size_group = GTK_SIZE_GROUP (gtk_builder_get_object (panel->priv->builder,
"sizegroup1"));
- net_object_add_to_notebook (NET_OBJECT (net_vpn),
- notebook,
- size_group);
+ net_object_add_to_stack (NET_OBJECT (net_vpn), stack, size_group);
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
"liststore_devices"));
@@ -1434,11 +1405,6 @@ cc_network_panel_init (CcNetworkPanel *panel)
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel));
g_signal_connect_after (toplevel, "map", G_CALLBACK (on_toplevel_map), panel);
- /* hide implementation details */
- widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
- "notebook_types"));
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE);
-
widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
"vbox1"));
gtk_container_add (GTK_CONTAINER (panel), widget);
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index e3ab8b8..7cc0e43 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -53,15 +53,15 @@ device_ethernet_get_speed (NetDeviceSimple *device_simple)
}
static GtkWidget *
-device_ethernet_add_to_notebook (NetObject *object,
- GtkNotebook *notebook,
- GtkSizeGroup *heading_size_group)
+device_ethernet_add_to_stack (NetObject *object,
+ GtkStack *stack,
+ GtkSizeGroup *heading_size_group)
{
NetDeviceEthernet *device = NET_DEVICE_ETHERNET (object);
GtkWidget *vbox;
vbox = GTK_WIDGET (gtk_builder_get_object (device->builder, "vbox6"));
- gtk_notebook_append_page (notebook, vbox, NULL);
+ gtk_stack_add_named (stack, vbox, net_object_get_id (object));
return vbox;
}
@@ -612,7 +612,7 @@ net_device_ethernet_class_init (NetDeviceEthernetClass *klass)
simple_class->get_speed = device_ethernet_get_speed;
obj_class->refresh = device_ethernet_refresh;
- obj_class->add_to_notebook = device_ethernet_add_to_notebook;
+ obj_class->add_to_stack = device_ethernet_add_to_stack;
object_class->constructed = device_ethernet_constructed;
object_class->finalize = device_ethernet_finalize;
}
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index fe83bff..062e4d1 100644
--- a/panels/network/net-device-mobile.c
+++ b/panels/network/net-device-mobile.c
@@ -68,9 +68,9 @@ enum {
G_DEFINE_TYPE (NetDeviceMobile, net_device_mobile, NET_TYPE_DEVICE)
static GtkWidget *
-device_mobile_proxy_add_to_notebook (NetObject *object,
- GtkNotebook *notebook,
- GtkSizeGroup *heading_size_group)
+device_mobile_proxy_add_to_stack (NetObject *object,
+ GtkStack *stack,
+ GtkSizeGroup *heading_size_group)
{
GtkWidget *widget;
NetDeviceMobile *device_mobile = NET_DEVICE_MOBILE (object);
@@ -85,7 +85,7 @@ device_mobile_proxy_add_to_notebook (NetObject *object,
widget = GTK_WIDGET (gtk_builder_get_object (device_mobile->priv->builder,
"vbox7"));
- gtk_notebook_append_page (notebook, widget, NULL);
+ gtk_stack_add_named (stack, widget, net_object_get_id (object));
return widget;
}
@@ -880,7 +880,7 @@ net_device_mobile_class_init (NetDeviceMobileClass *klass)
object_class->constructed = net_device_mobile_constructed;
object_class->get_property = net_device_mobile_get_property;
object_class->set_property = net_device_mobile_set_property;
- parent_class->add_to_notebook = device_mobile_proxy_add_to_notebook;
+ parent_class->add_to_stack = device_mobile_proxy_add_to_stack;
parent_class->refresh = device_mobile_refresh;
g_type_class_add_private (klass, sizeof (NetDeviceMobilePrivate));
diff --git a/panels/network/net-device-simple.c b/panels/network/net-device-simple.c
index 79b6ca3..5fa0ea5 100644
--- a/panels/network/net-device-simple.c
+++ b/panels/network/net-device-simple.c
@@ -42,9 +42,9 @@ struct _NetDeviceSimplePrivate
G_DEFINE_TYPE (NetDeviceSimple, net_device_simple, NET_TYPE_DEVICE)
static GtkWidget *
-device_simple_proxy_add_to_notebook (NetObject *object,
- GtkNotebook *notebook,
- GtkSizeGroup *heading_size_group)
+device_simple_proxy_add_to_stack (NetObject *object,
+ GtkStack *stack,
+ GtkSizeGroup *heading_size_group)
{
GtkWidget *widget;
NetDeviceSimple *device_simple = NET_DEVICE_SIMPLE (object);
@@ -56,7 +56,7 @@ device_simple_proxy_add_to_notebook (NetObject *object,
widget = GTK_WIDGET (gtk_builder_get_object (device_simple->priv->builder,
"vbox6"));
- gtk_notebook_append_page (notebook, widget, NULL);
+ gtk_stack_add_named (stack, widget, net_object_get_id (object));
return widget;
}
@@ -219,7 +219,7 @@ net_device_simple_class_init (NetDeviceSimpleClass *klass)
object_class->finalize = net_device_simple_finalize;
object_class->constructed = net_device_simple_constructed;
- parent_class->add_to_notebook = device_simple_proxy_add_to_notebook;
+ parent_class->add_to_stack = device_simple_proxy_add_to_stack;
parent_class->refresh = device_simple_refresh;
simple_class->get_speed = device_simple_get_speed;
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index 9ac645b..48112f5 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -81,9 +81,9 @@ enum {
};
static GtkWidget *
-device_wifi_proxy_add_to_notebook (NetObject *object,
- GtkNotebook *notebook,
- GtkSizeGroup *heading_size_group)
+device_wifi_proxy_add_to_stack (NetObject *object,
+ GtkStack *stack,
+ GtkSizeGroup *heading_size_group)
{
GtkWidget *widget;
NetDeviceWifi *device_wifi = NET_DEVICE_WIFI (object);
@@ -95,7 +95,7 @@ device_wifi_proxy_add_to_notebook (NetObject *object,
widget = GTK_WIDGET (gtk_builder_get_object (device_wifi->priv->builder,
"notebook_view"));
- gtk_notebook_append_page (notebook, widget, NULL);
+ gtk_stack_add_named (stack, widget, net_object_get_id (object));
return widget;
}
@@ -1547,7 +1547,7 @@ net_device_wifi_class_init (NetDeviceWifiClass *klass)
object_class->finalize = net_device_wifi_finalize;
object_class->constructed = net_device_wifi_constructed;
- parent_class->add_to_notebook = device_wifi_proxy_add_to_notebook;
+ parent_class->add_to_stack = device_wifi_proxy_add_to_stack;
parent_class->refresh = device_wifi_refresh;
parent_class->edit = device_wifi_edit;
diff --git a/panels/network/net-object.c b/panels/network/net-object.c
index ef94523..cb96d5c 100644
--- a/panels/network/net-object.c
+++ b/panels/network/net-object.c
@@ -135,23 +135,21 @@ net_object_get_panel (NetObject *object)
}
GtkWidget *
-net_object_add_to_notebook (NetObject *object,
- GtkNotebook *notebook,
- GtkSizeGroup *heading_size_group)
+net_object_add_to_stack (NetObject *object,
+ GtkStack *stack,
+ GtkSizeGroup *heading_size_group)
{
GtkWidget *widget;
NetObjectClass *klass = NET_OBJECT_GET_CLASS (object);
- if (klass->add_to_notebook != NULL) {
- widget = klass->add_to_notebook (object,
- notebook,
- heading_size_group);
+ if (klass->add_to_stack != NULL) {
+ widget = klass->add_to_stack (object, stack, heading_size_group);
g_object_set_data_full (G_OBJECT (widget),
"NetObject::id",
g_strdup (object->priv->id),
g_free);
return widget;
}
- g_debug ("no klass->add_to_notebook for %s", object->priv->id);
+ g_debug ("no klass->add_to_stack for %s", object->priv->id);
return NULL;
}
diff --git a/panels/network/net-object.h b/panels/network/net-object.h
index 715236b..8d98680 100644
--- a/panels/network/net-object.h
+++ b/panels/network/net-object.h
@@ -54,8 +54,8 @@ struct _NetObjectClass
GObjectClass parent_class;
/* vtable */
- GtkWidget *(*add_to_notebook) (NetObject *object,
- GtkNotebook *notebook,
+ GtkWidget *(*add_to_stack) (NetObject *object,
+ GtkStack *stack,
GtkSizeGroup *heading_size_group);
void (*delete) (NetObject *object);
void (*refresh) (NetObject *object);
@@ -81,8 +81,8 @@ void net_object_emit_removed (NetObject *object)
void net_object_delete (NetObject *object);
void net_object_refresh (NetObject *object);
void net_object_edit (NetObject *object);
-GtkWidget *net_object_add_to_notebook (NetObject *object,
- GtkNotebook *notebook,
+GtkWidget *net_object_add_to_stack (NetObject *object,
+ GtkStack *stack,
GtkSizeGroup *heading_size_group);
gboolean net_object_get_removable (NetObject *object);
void net_object_set_removable (NetObject *object,
diff --git a/panels/network/net-proxy.c b/panels/network/net-proxy.c
index b1a499c..fd4873f 100644
--- a/panels/network/net-proxy.c
+++ b/panels/network/net-proxy.c
@@ -210,9 +210,9 @@ panel_proxy_mode_combo_changed_cb (GtkWidget *widget, NetProxy *proxy)
}
static GtkWidget *
-net_proxy_add_to_notebook (NetObject *object,
- GtkNotebook *notebook,
- GtkSizeGroup *heading_size_group)
+net_proxy_add_to_stack (NetObject *object,
+ GtkStack *stack,
+ GtkSizeGroup *heading_size_group)
{
GtkWidget *widget;
NetProxy *proxy = NET_PROXY (object);
@@ -224,7 +224,7 @@ net_proxy_add_to_notebook (NetObject *object,
widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder,
"grid5"));
- gtk_notebook_append_page (notebook, widget, NULL);
+ gtk_stack_add_named (stack, widget, net_object_get_id (object));
return widget;
}
@@ -247,7 +247,7 @@ net_proxy_class_init (NetProxyClass *klass)
NetObjectClass *parent_class = NET_OBJECT_CLASS (klass);
object_class->finalize = net_proxy_finalize;
- parent_class->add_to_notebook = net_proxy_add_to_notebook;
+ parent_class->add_to_stack = net_proxy_add_to_stack;
g_type_class_add_private (klass, sizeof (NetProxyPrivate));
}
diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c
index 4ed09e3..a2e6905 100644
--- a/panels/network/net-vpn.c
+++ b/panels/network/net-vpn.c
@@ -237,9 +237,9 @@ vpn_proxy_delete (NetObject *object)
}
static GtkWidget *
-vpn_proxy_add_to_notebook (NetObject *object,
- GtkNotebook *notebook,
- GtkSizeGroup *heading_size_group)
+vpn_proxy_add_to_stack (NetObject *object,
+ GtkStack *stack,
+ GtkSizeGroup *heading_size_group)
{
GtkWidget *widget;
NetVpn *vpn = NET_VPN (object);
@@ -251,7 +251,7 @@ vpn_proxy_add_to_notebook (NetObject *object,
widget = GTK_WIDGET (gtk_builder_get_object (vpn->priv->builder,
"vbox9"));
- gtk_notebook_append_page (notebook, widget, NULL);
+ gtk_stack_add_named (stack, widget, net_object_get_id (object));
return widget;
}
@@ -553,7 +553,7 @@ net_vpn_class_init (NetVpnClass *klass)
object_class->set_property = net_vpn_set_property;
object_class->constructed = net_vpn_constructed;
object_class->finalize = net_vpn_finalize;
- parent_class->add_to_notebook = vpn_proxy_add_to_notebook;
+ parent_class->add_to_stack = vpn_proxy_add_to_stack;
parent_class->delete = vpn_proxy_delete;
parent_class->refresh = vpn_proxy_refresh;
parent_class->edit = vpn_proxy_edit;
diff --git a/panels/network/network.ui b/panels/network/network.ui
index e092766..15f41c2 100644
--- a/panels/network/network.ui
+++ b/panels/network/network.ui
@@ -131,10 +131,10 @@
</packing>
</child>
<child>
- <object class="GtkNotebook" id="notebook_types">
+ <object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="show_border">False</property>
+ <property name="transition_type">crossfade</property>
</object>
<packing>
<property name="expand">True</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]