[network-manager-applet/fg/c-e-ethernet-link2] c-e: link negotiation: introduce the link "Ignore" flag



commit bab29f9928df1155d49d62bb667e00527e85a46a
Author: Francesco Giudici <fgiudici redhat com>
Date:   Mon Nov 28 15:57:43 2016 +0100

    c-e: link negotiation: introduce the link "Ignore" flag
    
    In this way it is possible to remove the "Default" value from the Duplex
    and Speed boxes. They will be enabled only when both the autonegotiate
    and ignore options are not selected and will force to select both speed
    and duplex values.
    
    Move also the link negotiation section on bottom.

 src/connection-editor/ce-page-ethernet.ui |  270 ++++++++++++++++------------
 src/connection-editor/page-ethernet.c     |  125 ++++++++------
 2 files changed, 223 insertions(+), 172 deletions(-)
---
diff --git a/src/connection-editor/ce-page-ethernet.ui b/src/connection-editor/ce-page-ethernet.ui
index 11542fc..93c293a 100644
--- a/src/connection-editor/ce-page-ethernet.ui
+++ b/src/connection-editor/ce-page-ethernet.ui
@@ -36,9 +36,6 @@
     </columns>
     <data>
       <row>
-        <col id="0" translatable="yes">Automatic</col>
-      </row>
-      <row>
         <col id="0" translatable="yes">10 Mb/s</col>
       </row>
       <row>
@@ -59,9 +56,6 @@
     </columns>
     <data>
       <row>
-        <col id="0" translatable="yes">Automatic</col>
-      </row>
-      <row>
         <col id="0" translatable="yes">Half</col>
       </row>
       <row>
@@ -110,97 +104,6 @@
       </packing>
     </child>
     <child>
-      <object class="GtkLabel" id="ethernet_speed_label">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="xalign">0</property>
-        <property name="label" translatable="yes">_Speed:</property>
-        <property name="use_underline">True</property>
-       <property name="margin_left">26</property>
-        <property name="mnemonic_widget">ethernet_speed</property>
-      </object>
-      <packing>
-        <property name="top_attach">2</property>
-        <property name="bottom_attach">3</property>
-        <property name="x_options">GTK_FILL</property>
-        <property name="y_options"/>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkComboBox" id="ethernet_speed">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="model">model2</property>
-        <child>
-          <object class="GtkCellRendererText" id="renderer2"/>
-          <attributes>
-            <attribute name="text">0</attribute>
-          </attributes>
-        </child>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="right_attach">2</property>
-        <property name="top_attach">2</property>
-        <property name="bottom_attach">3</property>
-        <property name="y_options"/>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="ethernet_duplex_label">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="xalign">0</property>
-        <property name="label" translatable="yes">_Duplex:</property>
-        <property name="use_underline">True</property>
-       <property name="margin_left">26</property>
-        <property name="mnemonic_widget">ethernet_duplex</property>
-      </object>
-      <packing>
-        <property name="top_attach">3</property>
-        <property name="bottom_attach">4</property>
-        <property name="x_options">GTK_FILL</property>
-        <property name="y_options"/>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkComboBox" id="ethernet_duplex">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="model">model3</property>
-        <child>
-          <object class="GtkCellRendererText" id="renderer3"/>
-          <attributes>
-            <attribute name="text">0</attribute>
-          </attributes>
-        </child>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="right_attach">2</property>
-        <property name="top_attach">3</property>
-        <property name="bottom_attach">4</property>
-        <property name="y_options"/>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkCheckButton" id="ethernet_autonegotiate">
-        <property name="label" translatable="yes">Automatic link negotiation</property>
-        <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="receives_default">False</property>
-        <property name="use_underline">True</property>
-        <property name="draw_indicator">True</property>
-      </object>
-      <packing>
-        <property name="right_attach">2</property>
-        <property name="top_attach">1</property>
-        <property name="bottom_attach">2</property>
-        <property name="x_options">GTK_FILL</property>
-        <property name="y_options"/>
-      </packing>
-    </child>
-    <child>
       <object class="GtkLabel" id="ethernet_device_label">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
@@ -209,8 +112,8 @@
         <property name="use_underline">True</property>
       </object>
       <packing>
-        <property name="top_attach">4</property>
-        <property name="bottom_attach">5</property>
+        <property name="top_attach">1</property>
+        <property name="bottom_attach">2</property>
         <property name="x_options">GTK_FILL</property>
         <property name="y_options"/>
       </packing>
@@ -226,8 +129,8 @@
       <packing>
         <property name="left_attach">1</property>
         <property name="right_attach">2</property>
-        <property name="top_attach">4</property>
-        <property name="bottom_attach">5</property>
+        <property name="top_attach">1</property>
+        <property name="bottom_attach">2</property>
         <property name="y_options"/>
       </packing>
     </child>
@@ -241,8 +144,8 @@
         <property name="mnemonic_widget">ethernet_cloned_mac</property>
       </object>
       <packing>
-        <property name="top_attach">5</property>
-        <property name="bottom_attach">6</property>
+        <property name="top_attach">2</property>
+        <property name="bottom_attach">3</property>
         <property name="x_options">GTK_FILL</property>
         <property name="y_options"/>
       </packing>
@@ -256,8 +159,8 @@
       <packing>
         <property name="left_attach">1</property>
         <property name="right_attach">2</property>
-        <property name="top_attach">5</property>
-        <property name="bottom_attach">6</property>
+        <property name="top_attach">2</property>
+        <property name="bottom_attach">3</property>
         <property name="y_options"/>
       </packing>
     </child>
@@ -271,8 +174,8 @@
         <property name="mnemonic_widget">ethernet_mtu</property>
       </object>
       <packing>
-        <property name="top_attach">6</property>
-        <property name="bottom_attach">7</property>
+        <property name="top_attach">3</property>
+        <property name="bottom_attach">4</property>
         <property name="x_options">GTK_FILL</property>
         <property name="y_options"/>
       </packing>
@@ -311,8 +214,8 @@
       <packing>
         <property name="left_attach">1</property>
         <property name="right_attach">2</property>
-        <property name="top_attach">6</property>
-        <property name="bottom_attach">7</property>
+        <property name="top_attach">3</property>
+        <property name="bottom_attach">4</property>
         <property name="x_options">GTK_FILL</property>
         <property name="y_options">GTK_FILL</property>
       </packing>
@@ -325,8 +228,8 @@
         <property name="label" translatable="yes">Wake on LAN:</property>
       </object>
       <packing>
-        <property name="top_attach">7</property>
-        <property name="bottom_attach">8</property>
+        <property name="top_attach">4</property>
+        <property name="bottom_attach">5</property>
         <property name="x_options">GTK_FILL</property>
         <property name="y_options"></property>
       </packing>
@@ -451,7 +354,7 @@
             <property name="can_focus">True</property>
             <property name="receives_default">False</property>
             <property name="use_underline">True</property>
-            <property name="xalign">0</property>
+            1<property name="xalign">0</property>
             <property name="draw_indicator">True</property>
           </object>
           <packing>
@@ -463,8 +366,8 @@
       <packing>
         <property name="left_attach">1</property>
         <property name="right_attach">2</property>
-        <property name="top_attach">7</property>
-        <property name="bottom_attach">8</property>
+        <property name="top_attach">4</property>
+        <property name="bottom_attach">5</property>
         <property name="y_options"/>
       </packing>
     </child>
@@ -478,8 +381,8 @@
         <property name="mnemonic_widget">ethernet_wol_passwd</property>
       </object>
       <packing>
-        <property name="top_attach">8</property>
-        <property name="bottom_attach">9</property>
+        <property name="top_attach">5</property>
+        <property name="bottom_attach">6</property>
         <property name="x_options">GTK_FILL</property>
         <property name="y_options"/>
       </packing>
@@ -493,10 +396,145 @@
       <packing>
         <property name="left_attach">1</property>
         <property name="right_attach">2</property>
+        <property name="top_attach">5</property>
+        <property name="bottom_attach">6</property>
+        <property name="y_options"/>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="ethernet_speed_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <property name="label" translatable="yes">_Speed:</property>
+        <property name="use_underline">True</property>
+       <property name="margin_left">26</property>
+        <property name="mnemonic_widget">ethernet_speed</property>
+      </object>
+      <packing>
+        <property name="top_attach">7</property>
+        <property name="bottom_attach">8</property>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options"/>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkComboBox" id="ethernet_speed">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="tooltip_text" translatable="yes">Speed value for static link negotiation. It is 
required only when "Ignore" and "Auto" options are not selected.</property>
+        <property name="model">model2</property>
+        <child>
+          <object class="GtkCellRendererText" id="renderer2"/>
+          <attributes>
+            <attribute name="text">0</attribute>
+          </attributes>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="right_attach">2</property>
+        <property name="top_attach">7</property>
+        <property name="bottom_attach">8</property>
+        <property name="y_options"/>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="ethernet_duplex_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <property name="label" translatable="yes">_Duplex:</property>
+        <property name="use_underline">True</property>
+       <property name="margin_left">26</property>
+        <property name="mnemonic_widget">ethernet_duplex</property>
+      </object>
+      <packing>
+        <property name="top_attach">8</property>
+        <property name="bottom_attach">9</property>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options"/>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkComboBox" id="ethernet_duplex">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="tooltip_text" translatable="yes">Duplex value for static link negotiation. It is 
required only when "Ignore" and "Auto" options are not selected.</property>
+        <property name="model">model3</property>
+        <child>
+          <object class="GtkCellRendererText" id="renderer3"/>
+          <attributes>
+            <attribute name="text">0</attribute>
+          </attributes>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="right_attach">2</property>
         <property name="top_attach">8</property>
         <property name="bottom_attach">9</property>
         <property name="y_options"/>
       </packing>
     </child>
+    <child>
+      <object class="GtkLabel" id="ethernet_linkneg_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <property name="label" translatable="yes">Link negotiation:</property>
+        <property name="use_underline">True</property>
+      </object>
+      <packing>
+        <property name="top_attach">6</property>
+        <property name="bottom_attach">7</property>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options"/>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkGrid" id="grid_link">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="resize_mode">immediate</property>
+        <property name="column_spacing">12</property>
+        <child>
+          <object class="GtkCheckButton" id="ethernet_autonegotiate">
+            <property name="label" translatable="yes">_Auto</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="margin_right">12</property>
+            <property name="use_underline">True</property>
+            <property name="draw_indicator">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="ethernet_skipneg">
+            <property name="label" translatable="yes">_Ignore</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="use_underline">True</property>
+            <property name="draw_indicator">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="right_attach">2</property>
+        <property name="top_attach">6</property>
+        <property name="bottom_attach">7</property>
+        <property name="y_options"/>
+      </packing>
+    </child>
   </object>
 </interface>
diff --git a/src/connection-editor/page-ethernet.c b/src/connection-editor/page-ethernet.c
index 63f9d64..2a102c5 100644
--- a/src/connection-editor/page-ethernet.c
+++ b/src/connection-editor/page-ethernet.c
@@ -39,7 +39,7 @@ typedef struct {
        GtkComboBox *port;
        GtkComboBox *speed;
        GtkComboBox *duplex;
-       GtkToggleButton *autonegotiate;
+       GtkToggleButton *link_auto, *link_ignore;
        GtkSpinButton *mtu;
        GtkToggleButton *wol_default, *wol_ignore, *wol_phy, *wol_unicast, *wol_multicast,
                        *wol_broadcast, *wol_arp, *wol_magic;
@@ -53,15 +53,13 @@ typedef struct {
 #define PORT_BNC      3
 #define PORT_MII      4
 
-#define SPEED_DEFAULT 0
-#define SPEED_10      1
-#define SPEED_100     2
-#define SPEED_1000    3
-#define SPEED_10000   4
+#define SPEED_10      0
+#define SPEED_100     1
+#define SPEED_1000    2
+#define SPEED_10000   3
 
-#define DUPLEX_DEFAULT 0
-#define DUPLEX_HALF    1
-#define DUPLEX_FULL    2
+#define DUPLEX_HALF    0
+#define DUPLEX_FULL    1
 
 static void
 ethernet_private_init (CEPageEthernet *self)
@@ -93,7 +91,8 @@ ethernet_private_init (CEPageEthernet *self)
        priv->port = GTK_COMBO_BOX (gtk_builder_get_object (builder, "ethernet_port"));
        priv->speed = GTK_COMBO_BOX (gtk_builder_get_object (builder, "ethernet_speed"));
        priv->duplex = GTK_COMBO_BOX (gtk_builder_get_object (builder, "ethernet_duplex"));
-       priv->autonegotiate = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "ethernet_autonegotiate"));
+       priv->link_auto = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "ethernet_autonegotiate"));
+       priv->link_ignore = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "ethernet_skipneg"));
        priv->mtu = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "ethernet_mtu"));
        priv->wol_default = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "wol_default"));
        priv->wol_ignore = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "wol_ignore"));
@@ -120,16 +119,18 @@ link_special_toggled_cb (GtkWidget *widget, gpointer user_data)
        CEPageEthernet *self = CE_PAGE_ETHERNET (user_data);
        CEPageEthernetPrivate *priv = CE_PAGE_ETHERNET_GET_PRIVATE (self);
        gboolean enabled;
+       GtkWidget *other;
 
-       enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+       if (widget == GTK_WIDGET (priv->link_auto))
+               other = GTK_WIDGET (priv->link_ignore);
+       else
+               other = GTK_WIDGET (priv->link_auto);
 
-       if (enabled) {
-               gtk_combo_box_set_active (priv->speed, SPEED_DEFAULT);
-               gtk_combo_box_set_active (priv->duplex, DUPLEX_DEFAULT);
-       }
+       enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
 
        gtk_widget_set_sensitive (GTK_WIDGET (priv->speed), !enabled);
        gtk_widget_set_sensitive (GTK_WIDGET (priv->duplex), !enabled);
+       gtk_widget_set_sensitive (other, !enabled);
 
        stuff_changed (NULL, self);
 }
@@ -182,11 +183,13 @@ populate_ui (CEPageEthernet *self)
 {
        CEPageEthernetPrivate *priv = CE_PAGE_ETHERNET_GET_PRIVATE (self);
        NMSettingWired *setting = priv->setting;
+       gboolean autoneg;
        const char *port;
+       guint32 speed;
        const char *duplex;
        int port_idx = PORT_DEFAULT;
-       int speed_idx;
-       int duplex_idx = DUPLEX_DEFAULT;
+       int speed_idx = SPEED_100;
+       int duplex_idx = DUPLEX_FULL;
        int mtu_def;
        const char *s_mac, *s_ifname, *s_wol_passwd;
        NMSettingWiredWakeOnLan wol;
@@ -206,7 +209,8 @@ populate_ui (CEPageEthernet *self)
        gtk_combo_box_set_active (priv->port, port_idx);
 
        /* Speed */
-       switch (nm_setting_wired_get_speed (setting)) {
+       speed = nm_setting_wired_get_speed (setting);
+       switch (speed) {
        case 10:
                speed_idx = SPEED_10;
                break;
@@ -219,9 +223,6 @@ populate_ui (CEPageEthernet *self)
        case 10000:
                speed_idx = SPEED_10000;
                break;
-       default:
-               speed_idx = SPEED_DEFAULT;
-               break;
        }
        gtk_combo_box_set_active (priv->speed, speed_idx);
 
@@ -235,9 +236,10 @@ populate_ui (CEPageEthernet *self)
        }
        gtk_combo_box_set_active (priv->duplex, duplex_idx);
 
-       /* Autonegotiate */
-       gtk_toggle_button_set_active (priv->autonegotiate,
-                                     nm_setting_wired_get_auto_negotiate (setting));
+       /* Autonegotiate & Link ignore */
+       autoneg = nm_setting_wired_get_auto_negotiate (setting);
+       gtk_toggle_button_set_active (priv->link_auto, autoneg);
+       gtk_toggle_button_set_active (priv->link_ignore, (!autoneg && !speed && !duplex));
 
        /* Device ifname/MAC */
        s_ifname = nm_connection_get_interface_name (CE_PAGE (self)->connection);
@@ -303,8 +305,12 @@ finish_setup (CEPageEthernet *self, gpointer unused, GError *error, gpointer use
 
        populate_ui (self);
 
-       g_signal_connect (priv->autonegotiate, "toggled", G_CALLBACK (link_special_toggled_cb), self);
-       link_special_toggled_cb (GTK_WIDGET (priv->autonegotiate), self);
+       g_signal_connect (priv->link_auto, "toggled", G_CALLBACK (link_special_toggled_cb), self);
+       g_signal_connect (priv->link_ignore, "toggled", G_CALLBACK (link_special_toggled_cb), self);
+       if (gtk_toggle_button_get_active (priv->link_auto))
+               link_special_toggled_cb (GTK_WIDGET (priv->link_auto), self);
+       else
+               link_special_toggled_cb (GTK_WIDGET (priv->link_ignore), self);
        g_signal_connect (priv->port, "changed", G_CALLBACK (stuff_changed), self);
        g_signal_connect (priv->speed, "changed", G_CALLBACK (stuff_changed), self);
        g_signal_connect (priv->duplex, "changed", G_CALLBACK (stuff_changed), self);
@@ -413,36 +419,43 @@ ui_to_setting (CEPageEthernet *self)
                break;
        }
 
-       /* Speed */
-       switch (gtk_combo_box_get_active (priv->speed)) {
-       case SPEED_10:
-               speed = 10;
-               break;
-       case SPEED_100:
-               speed = 100;
-               break;
-       case SPEED_1000:
-               speed = 1000;
-               break;
-       case SPEED_10000:
-               speed = 10000;
-               break;
-       default:
+       /* Speed & Duplex */
+       if (   gtk_toggle_button_get_active (priv->link_ignore)
+           || gtk_toggle_button_get_active (priv->link_auto)) {
                speed = 0;
-               break;
-       }
-
-       /* Duplex */
-       switch (gtk_combo_box_get_active (priv->duplex)) {
-       case DUPLEX_HALF:
-               duplex = "half";
-               break;
-       case DUPLEX_FULL:
-               duplex = "full";
-               break;
-       default:
                duplex = NULL;
-               break;
+       } else {
+               switch (gtk_combo_box_get_active (priv->speed)) {
+               case SPEED_10:
+                       speed = 10;
+                       break;
+               case SPEED_100:
+                       speed = 100;
+                       break;
+               case SPEED_1000:
+                       speed = 1000;
+                       break;
+               case SPEED_10000:
+                       speed = 10000;
+                       break;
+               default:
+                       g_warn_if_reached();
+                       speed = 0;
+                       break;
+               }
+
+               switch (gtk_combo_box_get_active (priv->duplex)) {
+               case DUPLEX_HALF:
+                       duplex = "half";
+                       break;
+               case DUPLEX_FULL:
+                       duplex = "full";
+                       break;
+               default:
+                       g_warn_if_reached();
+                       duplex = NULL;
+                       break;
+               }
        }
 
        entry = gtk_bin_get_child (GTK_BIN (priv->device_combo));
@@ -481,8 +494,8 @@ ui_to_setting (CEPageEthernet *self)
                      NM_SETTING_WIRED_CLONED_MAC_ADDRESS, cloned_mac && *cloned_mac ? cloned_mac : NULL,
                      NM_SETTING_WIRED_PORT, port,
                      NM_SETTING_WIRED_SPEED, speed,
-                     NM_SETTING_WIRED_DUPLEX, duplex ? : NULL,
-                     NM_SETTING_WIRED_AUTO_NEGOTIATE, gtk_toggle_button_get_active (priv->autonegotiate),
+                     NM_SETTING_WIRED_DUPLEX, duplex,
+                     NM_SETTING_WIRED_AUTO_NEGOTIATE, gtk_toggle_button_get_active (priv->link_auto),
                      NM_SETTING_WIRED_WAKE_ON_LAN, wol,
                      NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, wol_passwd && *wol_passwd ? wol_passwd : NULL,
                      NULL);


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