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
This commit is contained in:
parent
c37ce6fcb4
commit
158591a346
10 changed files with 59 additions and 95 deletions
|
@ -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);
|
||||
stack = GTK_STACK (gtk_builder_get_object (priv->builder, "stack"));
|
||||
|
||||
gtk_stack_set_visible_child_name (stack, needle);
|
||||
|
||||
/* 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++;
|
||||
}
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue