[gnome-control-center/wip/networking2: 20/36] network: Redo dns and routes sections



commit b8ff90e97eb2a4f7d86c50f887c338153d56649c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 6 16:38:53 2013 -0500

    network: Redo dns and routes sections
    
    Move the automatic switches out of the lists, desensitize delete
    buttons for the last item, and switch to inline toolbars for the
    add button. Also use 'Server' as the label for DNS servers.
    Based on review feedback.

 panels/network/connection-editor/ce-page-ip4.c |  148 ++++++++----------------
 panels/network/connection-editor/ip4-page.ui   |  101 ++++++++++++++--
 2 files changed, 135 insertions(+), 114 deletions(-)
---
diff --git a/panels/network/connection-editor/ce-page-ip4.c b/panels/network/connection-editor/ce-page-ip4.c
index ac639be..9bc1c7c 100644
--- a/panels/network/connection-editor/ce-page-ip4.c
+++ b/panels/network/connection-editor/ce-page-ip4.c
@@ -102,12 +102,12 @@ update_separator (GtkWidget **separator,
 }
 
 static void
-update_address_row_sensitivity (CEPageIP4 *page)
+update_row_sensitivity (CEPageIP4 *page, GtkWidget *list)
 {
         GList *children, *l;
         gint rows = 0;
 
-        children = gtk_container_get_children (GTK_CONTAINER (page->address_list));
+        children = gtk_container_get_children (GTK_CONTAINER (list));
         for (l = children; l; l = l->next) {
                 GtkWidget *row = l->data;
                 GtkWidget *button;
@@ -140,7 +140,7 @@ remove_row (GtkButton *button, CEPageIP4 *page)
 
         ce_page_changed (CE_PAGE (page));
 
-        update_address_row_sensitivity (page);
+        update_row_sensitivity (page, list);
 }
 
 static gint
@@ -226,7 +226,7 @@ add_address_row (CEPageIP4   *page,
         gtk_widget_show_all (row);
         gtk_container_add (GTK_CONTAINER (page->address_list), row);
 
-        update_address_row_sensitivity (page);
+        update_row_sensitivity (page, page->address_list);
 }
 
 static void
@@ -236,28 +236,14 @@ add_empty_address_row (CEPageIP4 *page)
 }
 
 static void
-add_address_section (CEPageIP4 *page)
+add_section_toolbar (CEPageIP4 *page, GtkWidget *section, GCallback add_cb)
 {
-        GtkWidget *widget;
-        GtkWidget *frame;
-        GtkWidget *list;
-        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"));
-
-        frame = gtk_frame_new (NULL);
-        gtk_container_add (GTK_CONTAINER (widget), frame);
-        page->address_list = list = GTK_WIDGET (egg_list_box_new ());
-        egg_list_box_set_selection_mode (EGG_LIST_BOX (list), GTK_SELECTION_NONE);
-        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);
+        GtkWidget *button;
+        GtkWidget *image;
 
         toolbar = gtk_toolbar_new ();
         gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
@@ -265,7 +251,7 @@ add_address_section (CEPageIP4 *page)
         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);
+        gtk_container_add (GTK_CONTAINER (section), toolbar);
 
         item = gtk_separator_tool_item_new ();
         gtk_tool_item_set_expand (item, TRUE);
@@ -276,11 +262,32 @@ add_address_section (CEPageIP4 *page)
         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);
+        g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_cb), page);
         image = gtk_image_new_from_icon_name ("list-add-symbolic", GTK_ICON_SIZE_MENU);
         gtk_button_set_image (GTK_BUTTON (button), image);
         gtk_container_add (GTK_CONTAINER (box), button);
         gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (item), 1);
+}
+
+static void
+add_address_section (CEPageIP4 *page)
+{
+        GtkWidget *widget;
+        GtkWidget *frame;
+        GtkWidget *list;
+        gint i;
+
+        widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section"));
+
+        frame = gtk_frame_new (NULL);
+        gtk_container_add (GTK_CONTAINER (widget), frame);
+        page->address_list = list = GTK_WIDGET (egg_list_box_new ());
+        egg_list_box_set_selection_mode (EGG_LIST_BOX (list), GTK_SELECTION_NONE);
+        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);
+
+        add_section_toolbar (page, widget, G_CALLBACK (add_empty_address_row));
 
         for (i = 0; i < nm_setting_ip4_config_get_num_addresses (page->setting); i++) {
                 NMIP4Address *addr;
@@ -320,7 +327,7 @@ add_dns_row (CEPageIP4   *page,
         GtkWidget *image;
 
         row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-        widget = gtk_label_new (_("Address"));
+        widget = gtk_label_new (_("Server"));
         gtk_misc_set_alignment (GTK_MISC (widget), 1, 0.5);
         gtk_box_pack_start (GTK_BOX (row), widget, FALSE, FALSE, 0);
         widget = gtk_entry_new ();
@@ -337,6 +344,7 @@ add_dns_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_box_pack_start (GTK_BOX (row), delete_button, FALSE, FALSE, 0);
+        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);
@@ -345,6 +353,8 @@ add_dns_row (CEPageIP4   *page,
         gtk_widget_set_halign (row, GTK_ALIGN_FILL);
         gtk_widget_show_all (row);
         gtk_container_add (GTK_CONTAINER (page->dns_list), row);
+
+        update_row_sensitivity (page, page->dns_list);
 }
 
 static void
@@ -359,9 +369,6 @@ add_dns_section (CEPageIP4 *page)
         GtkWidget *widget;
         GtkWidget *frame;
         GtkWidget *list;
-        GtkWidget *row;
-        GtkWidget *button;
-        GtkWidget *image;
         gint i;
 
         widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "dns_section"));
@@ -373,43 +380,10 @@ add_dns_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), "first", GINT_TO_POINTER (TRUE));
-        widget = gtk_label_new (_("Automatic"));
-        gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
-        gtk_widget_set_margin_top (widget, 10);
-        gtk_widget_set_margin_bottom (widget, 10);
-        gtk_widget_set_margin_left (widget, 10);
-        gtk_widget_set_margin_right (widget, 10);
-        gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
-        gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
-        gtk_box_pack_start (GTK_BOX (row), widget, FALSE, FALSE, 0);
-        widget = gtk_switch_new ();
-        page->auto_dns = GTK_SWITCH (widget);
+        page->auto_dns = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_dns_switch"));
         gtk_switch_set_active (page->auto_dns, !nm_setting_ip4_config_get_ignore_auto_dns (page->setting));
-        gtk_widget_set_margin_top (widget, 10);
-        gtk_widget_set_margin_bottom (widget, 10);
-        gtk_widget_set_margin_left (widget, 10);
-        gtk_widget_set_margin_right (widget, 10);
-        gtk_widget_set_halign (widget, GTK_ALIGN_END);
-        gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
-        gtk_box_pack_start (GTK_BOX (row), widget, TRUE, TRUE, 0);
-        gtk_container_add (GTK_CONTAINER (list), row);
 
-        row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-        g_object_set_data (G_OBJECT (row), "last", GINT_TO_POINTER (TRUE));
-        button = gtk_button_new ();
-        g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_empty_dns_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);
+        add_section_toolbar (page, widget, G_CALLBACK (add_empty_dns_row));
 
         for (i = 0; i < nm_setting_ip4_config_get_num_dns (page->setting); i++) {
                 struct in_addr tmp_addr;
@@ -422,6 +396,8 @@ add_dns_section (CEPageIP4 *page)
         }
         if (nm_setting_ip4_config_get_num_dns (page->setting) == 0)
                 add_empty_dns_row (page);
+
+        gtk_widget_show_all (widget);
 }
 
 static void
@@ -493,6 +469,7 @@ add_route_row (CEPageIP4   *page,
         gtk_widget_set_halign (delete_button, GTK_ALIGN_CENTER);
         gtk_widget_set_valign (delete_button, GTK_ALIGN_CENTER);
         gtk_grid_attach (GTK_GRID (row), delete_button, 3, 1, 1, 4);
+        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);
@@ -502,6 +479,8 @@ add_route_row (CEPageIP4   *page,
 
         gtk_widget_show_all (row);
         gtk_container_add (GTK_CONTAINER (page->routes_list), row);
+
+        update_row_sensitivity (page, page->routes_list);
 }
 
 static void
@@ -516,9 +495,6 @@ add_routes_section (CEPageIP4 *page)
         GtkWidget *widget;
         GtkWidget *frame;
         GtkWidget *list;
-        GtkWidget *row;
-        GtkWidget *button;
-        GtkWidget *image;
         gint i;
 
         widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_section"));
@@ -530,42 +506,10 @@ add_routes_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), "first", GINT_TO_POINTER (TRUE));
-        widget = gtk_label_new (_("Automatic"));
-        gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
-        gtk_widget_set_margin_top (widget, 10);
-        gtk_widget_set_margin_bottom (widget, 10);
-        gtk_widget_set_margin_left (widget, 10);
-        gtk_widget_set_margin_right (widget, 10);
-        gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
-        gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
-        gtk_box_pack_start (GTK_BOX (row), widget, FALSE, FALSE, 0);
-        widget = gtk_switch_new ();
-        page->auto_routes = GTK_SWITCH (widget);
-        gtk_switch_set_active (GTK_SWITCH (widget), !nm_setting_ip4_config_get_ignore_auto_routes (page->setting));
-        gtk_widget_set_margin_top (widget, 10);
-        gtk_widget_set_margin_bottom (widget, 10);
-        gtk_widget_set_margin_left (widget, 10);
-        gtk_widget_set_margin_right (widget, 10);
-        gtk_widget_set_halign (widget, GTK_ALIGN_END);
-        gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
-        gtk_box_pack_start (GTK_BOX (row), widget, TRUE, TRUE, 0);
-        gtk_container_add (GTK_CONTAINER (list), row);
-        row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-        g_object_set_data (G_OBJECT (row), "last", GINT_TO_POINTER (TRUE));
-        button = gtk_button_new ();
-        g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_empty_route_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);
+        page->auto_routes = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_routes_switch"));
+        gtk_switch_set_active (page->auto_routes, !nm_setting_ip4_config_get_ignore_auto_routes (page->setting));
+
+        add_section_toolbar (page, widget, G_CALLBACK (add_empty_route_row));
 
         for (i = 0; i < nm_setting_ip4_config_get_num_routes (page->setting); i++) {
                 NMIP4Route *route;
@@ -592,6 +536,8 @@ add_routes_section (CEPageIP4 *page)
         }
         if (nm_setting_ip4_config_get_num_routes (page->setting) == 0)
                 add_empty_route_row (page);
+
+        gtk_widget_show_all (widget);
 }
 
 static void
diff --git a/panels/network/connection-editor/ip4-page.ui b/panels/network/connection-editor/ip4-page.ui
index e5a46ab..c6dd152 100644
--- a/panels/network/connection-editor/ip4-page.ui
+++ b/panels/network/connection-editor/ip4-page.ui
@@ -125,16 +125,54 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="heading_dns">
+                  <object class="GtkBox" id="box1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="margin_top">24</property>
                     <property name="margin_bottom">6</property>
-                    <property name="xalign">0</property>
-                    <property name="label" translatable="yes">DNS</property>
-                    <attributes>
-                      <attribute name="weight" value="bold"/>
-                    </attributes>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkLabel" id="heading_dns">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">DNS</property>
+                        <attributes>
+                          <attribute name="weight" value="bold"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">Automatic</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkSwitch" id="auto_dns_switch">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="halign">end</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
                     <property name="expand">False</property>
@@ -158,16 +196,53 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="heading_routes">
+                  <object class="GtkBox" id="box3">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="margin_top">24</property>
-                    <property name="margin_bottom">6</property>
-                    <property name="xalign">0</property>
-                    <property name="label" translatable="yes">Routes</property>
-                    <attributes>
-                      <attribute name="weight" value="bold"/>
-                    </attributes>
+                    <property name="margin_bottom">5</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkLabel" id="heading_routes">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Routes</property>
+                        <attributes>
+                          <attribute name="weight" value="bold"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">Automatic</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkSwitch" id="auto_routes_switch">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
                     <property name="expand">False</property>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]