[gnome-control-center/wip/networking2: 19/36] network: Redo IPv4 address section
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/networking2: 19/36] network: Redo IPv4 address section
- Date: Mon, 7 Jan 2013 05:15:48 +0000 (UTC)
commit 316ed6b9bbee1754e4ad0a2497ec65ef8361f170
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jan 6 16:16:46 2013 -0500
network: Redo IPv4 address section
Hide the address list entirely unless the mode is manual.
Turn the + row into an inline toolbar. Make the delete buttons
insensitive if there's only one row. Based on review feedback.
panels/network/connection-editor/ce-page-ip4.c | 71 ++++++++++++++++++++----
1 files changed, 59 insertions(+), 12 deletions(-)
---
diff --git a/panels/network/connection-editor/ce-page-ip4.c b/panels/network/connection-editor/ce-page-ip4.c
index 5cdb080..1053166 100644
--- a/panels/network/connection-editor/ce-page-ip4.c
+++ b/panels/network/connection-editor/ce-page-ip4.c
@@ -53,6 +53,7 @@ method_changed (GtkComboBox *combo, CEPageIP4 *page)
gboolean dns_enabled;
gboolean routes_enabled;
guint method;
+ GtkWidget *widget;
method = gtk_combo_box_get_active (combo);
switch (method) {
@@ -74,7 +75,8 @@ method_changed (GtkComboBox *combo, CEPageIP4 *page)
break;
}
- gtk_widget_set_sensitive (page->address_list, addr_enabled);
+ widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section"));
+ gtk_widget_set_visible (widget, addr_enabled);
gtk_widget_set_sensitive (page->dns_list, dns_enabled);
gtk_widget_set_sensitive (page->routes_list, routes_enabled);
gtk_widget_set_sensitive (page->never_default, routes_enabled);
@@ -100,6 +102,32 @@ update_separator (GtkWidget **separator,
}
static void
+update_address_row_sensitivity (CEPageIP4 *page)
+{
+ GList *children, *l;
+ gint rows = 0;
+
+ children = gtk_container_get_children (GTK_CONTAINER (page->address_list));
+ for (l = children; l; l = l->next) {
+ GtkWidget *row = l->data;
+ GtkWidget *button;
+
+ button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button"));
+ if (button != NULL)
+ rows++;
+ }
+ for (l = children; l; l = l->next) {
+ GtkWidget *row = l->data;
+ GtkWidget *button;
+
+ button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button"));
+ if (button != NULL)
+ gtk_widget_set_sensitive (button, rows > 1);
+ }
+ g_list_free (children);
+}
+
+static void
remove_row (GtkButton *button, CEPageIP4 *page)
{
GtkWidget *row;
@@ -111,6 +139,8 @@ remove_row (GtkButton *button, CEPageIP4 *page)
gtk_container_remove (GTK_CONTAINER (list), row);
ce_page_changed (CE_PAGE (page));
+
+ update_address_row_sensitivity (page);
}
static gint
@@ -186,6 +216,7 @@ add_address_row (CEPageIP4 *page,
image = gtk_image_new_from_icon_name ("user-trash-symbolic", GTK_ICON_SIZE_MENU);
gtk_button_set_image (GTK_BUTTON (delete_button), image);
gtk_grid_attach (GTK_GRID (row), delete_button, 3, 2, 1, 1);
+ g_object_set_data (G_OBJECT (row), "delete-button", delete_button);
gtk_widget_set_margin_left (row, 10);
gtk_widget_set_margin_right (row, 10);
@@ -194,6 +225,8 @@ add_address_row (CEPageIP4 *page,
gtk_widget_set_halign (row, GTK_ALIGN_FILL);
gtk_widget_show_all (row);
gtk_container_add (GTK_CONTAINER (page->address_list), row);
+
+ update_address_row_sensitivity (page);
}
static void
@@ -208,9 +241,12 @@ add_address_section (CEPageIP4 *page)
GtkWidget *widget;
GtkWidget *frame;
GtkWidget *list;
- GtkWidget *row;
GtkWidget *button;
GtkWidget *image;
+ GtkWidget *toolbar;
+ GtkToolItem *item;
+ GtkStyleContext *context;
+ GtkWidget *box;
gint i;
widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section"));
@@ -222,20 +258,29 @@ add_address_section (CEPageIP4 *page)
egg_list_box_set_separator_funcs (EGG_LIST_BOX (list), update_separator, NULL, NULL);
egg_list_box_set_sort_func (EGG_LIST_BOX (list), sort_first_last, NULL, NULL);
gtk_container_add (GTK_CONTAINER (frame), list);
- row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- g_object_set_data (G_OBJECT (row), "last", GINT_TO_POINTER (TRUE));
+
+ toolbar = gtk_toolbar_new ();
+ gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
+ gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_MENU);
+ context = gtk_widget_get_style_context (toolbar);
+ gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_INLINE_TOOLBAR);
+ gtk_container_add (GTK_CONTAINER (widget), toolbar);
+
+ item = gtk_separator_tool_item_new ();
+ gtk_tool_item_set_expand (item, TRUE);
+ gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item), FALSE);
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (item), 0);
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ item = gtk_tool_item_new ();
+ gtk_container_add (GTK_CONTAINER (item), box);
button = gtk_button_new ();
g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_empty_address_row), page);
image = gtk_image_new_from_icon_name ("list-add-symbolic", GTK_ICON_SIZE_MENU);
gtk_button_set_image (GTK_BUTTON (button), image);
- gtk_widget_set_margin_top (button, 10);
- gtk_widget_set_margin_bottom (button, 10);
- gtk_widget_set_margin_left (button, 10);
- gtk_widget_set_margin_right (button, 10);
- gtk_widget_set_halign (button, GTK_ALIGN_END);
- gtk_box_pack_start (GTK_BOX (row), button, TRUE, TRUE, 0);
- gtk_container_add (GTK_CONTAINER (list), row);
- gtk_widget_show_all (frame);
+ gtk_container_add (GTK_CONTAINER (box), button);
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (item), 1);
for (i = 0; i < nm_setting_ip4_config_get_num_addresses (page->setting); i++) {
NMIP4Address *addr;
@@ -261,6 +306,8 @@ add_address_section (CEPageIP4 *page)
}
if (nm_setting_ip4_config_get_num_addresses (page->setting) == 0)
add_empty_address_row (page);
+
+ gtk_widget_show_all (widget);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]