[network-manager-netbook] Restore combo box for IP method selection



commit 97ec964123a6ca7c5ad18c1db1f3719b08cf7c9e
Author: Tambet Ingo <tambet gmail com>
Date:   Thu Mar 4 16:15:46 2010 -0400

    Restore combo box for IP method selection
    
    Had to replace it with toggle buttons because Moblin panel applets couldn't
    have child X windows (required by GtkComboBox). Now that it's fixed, we
    can use a combo box again.

 src/nmn-connection-details.c |   87 ++++++++++++++++++++---------------------
 1 files changed, 42 insertions(+), 45 deletions(-)
---
diff --git a/src/nmn-connection-details.c b/src/nmn-connection-details.c
index 5953b8c..1ec89f5 100644
--- a/src/nmn-connection-details.c
+++ b/src/nmn-connection-details.c
@@ -38,9 +38,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
 #define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), NMN_TYPE_CONNECTION_DETAILS, NmnConnectionDetailsPrivate))
 
 typedef struct {
-    GtkWidget *method_auto;
-    GtkWidget *method_manual;
-    GtkWidget *method_link_local;
+    GtkWidget *connect_method;
 
     GtkWidget *address;
     GtkWidget *netmask;
@@ -54,6 +52,12 @@ typedef struct {
     gboolean disposed;
 } NmnConnectionDetailsPrivate;
 
+enum {
+    CONNECT_METHOD_DHCP = 0,
+    CONNECT_METHOD_MANUAL = 1,
+    CONNECT_METHOD_LINK_LOCAL = 2
+};
+
 NmnConnectionDetails *
 nmn_connection_details_new (void)
 {
@@ -68,12 +72,11 @@ editable_changed (NmnConnectionDetails *self,
     gboolean entries_enabled;
 
     priv->editable = editable;
-    gtk_widget_set_sensitive (priv->method_auto, editable);
-    gtk_widget_set_sensitive (priv->method_manual, editable);
-    gtk_widget_set_sensitive (priv->method_link_local, editable);
+
+    gtk_widget_set_sensitive (priv->connect_method, editable);
 
     if (editable)
-        entries_enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->method_manual));
+        entries_enabled = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->connect_method)) == CONNECT_METHOD_MANUAL;
     else
         entries_enabled = FALSE;
 
@@ -85,8 +88,8 @@ editable_changed (NmnConnectionDetails *self,
 }
 
 static void
-radio_toggled (GtkToggleButton *toggle,
-               gpointer user_data)
+connect_method_changed (GtkComboBox *combo,
+                        gpointer user_data)
 {
     NmnConnectionDetails *self = NMN_CONNECTION_DETAILS (user_data);
 
@@ -129,15 +132,15 @@ nmn_connection_details_set_data (NmnConnectionDetails *self,
 
         method = nm_setting_ip4_config_get_method (setting);
         if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO))
-            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->method_auto), TRUE);
+            gtk_combo_box_set_active (GTK_COMBO_BOX (priv->connect_method), CONNECT_METHOD_DHCP);
         else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
-            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->method_manual), TRUE);
+            gtk_combo_box_set_active (GTK_COMBO_BOX (priv->connect_method), CONNECT_METHOD_MANUAL);
         else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
-            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->method_link_local), TRUE);
+            gtk_combo_box_set_active (GTK_COMBO_BOX (priv->connect_method), CONNECT_METHOD_LINK_LOCAL);
         else
             g_assert_not_reached ();
     } else
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->method_auto), TRUE);
+        gtk_combo_box_set_active (GTK_COMBO_BOX (priv->connect_method), CONNECT_METHOD_DHCP);
 
     /* We're editable when we're not connected, ie, when
        the active IP4 config is not present */
@@ -285,17 +288,20 @@ ui_to_setting (NmnConnectionDetails *self,
                GSList **dns_list)
 {
     NmnConnectionDetailsPrivate *priv = GET_PRIVATE (self);
+    int active;
     gboolean success = FALSE;
 
-    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->method_auto))) {
+    active = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->connect_method));
+
+    if (active == CONNECT_METHOD_DHCP) {
         *method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
         *address = NULL;
         success = TRUE;
-    } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->method_link_local))) {
+    } else if (active == CONNECT_METHOD_LINK_LOCAL) {
         *method = NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL;
         *address = NULL;
         success = TRUE;
-    } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->method_manual))) {
+    } else {
         struct in_addr tmp_addr  = { 0 };
         guint32 prefix;
 
@@ -319,8 +325,7 @@ ui_to_setting (NmnConnectionDetails *self,
         *method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
 
         success = TRUE;
-    } else
-        g_assert_not_reached ();
+    }
 
  out:
     if (!success && *address) {
@@ -466,7 +471,7 @@ nmn_connection_details_init (NmnConnectionDetails *details)
     GtkTextBuffer *buffer;
 
     g_object_set (details,
-                  "n-rows", 8,
+                  "n-rows", 6,
                   "n-columns", 2,
                   "homogeneous", FALSE,
                   "row-spacing", 6,
@@ -479,66 +484,58 @@ nmn_connection_details_init (NmnConnectionDetails *details)
     w = aligned_label_new (_("Connect by:"));
     gtk_table_attach_defaults (table, w, 0, 1, 0, 1);
 
-    priv->method_auto = gtk_radio_button_new_with_label (NULL, _("DHCP"));
-    gtk_table_attach_defaults (table, priv->method_auto, 1, 2, 0, 1);
-    g_signal_connect (priv->method_auto, "toggled", G_CALLBACK (radio_toggled), details);
-    g_signal_connect_swapped (priv->method_auto, "toggled", G_CALLBACK (stuff_changed), details);
-
-    priv->method_manual = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (priv->method_auto), _("Manual"));
-    gtk_table_attach_defaults (table, priv->method_manual, 1, 2, 1, 2);
-    g_signal_connect (priv->method_manual, "toggled", G_CALLBACK (radio_toggled), details);
-    g_signal_connect_swapped (priv->method_manual, "toggled", G_CALLBACK (stuff_changed), details);
-
-    priv->method_link_local = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (priv->method_auto), _("Link Local"));
-    gtk_table_attach_defaults (table, priv->method_link_local, 1, 2, 2, 3);
-    g_signal_connect (priv->method_link_local, "toggled", G_CALLBACK (radio_toggled), details);
-    g_signal_connect_swapped (priv->method_link_local, "toggled", G_CALLBACK (stuff_changed), details);
-
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->method_auto), TRUE);
+    w = gtk_combo_box_new_text ();
+    gtk_combo_box_append_text (GTK_COMBO_BOX (w), _("DHCP"));
+    gtk_combo_box_append_text (GTK_COMBO_BOX (w), _("Manual"));
+    gtk_combo_box_append_text (GTK_COMBO_BOX (w), _("Link Local"));
+    gtk_combo_box_set_active (GTK_COMBO_BOX (w), 0);
+    g_signal_connect (w, "changed", G_CALLBACK (connect_method_changed), details);
+    gtk_table_attach_defaults (table, w, 1, 2, 0, 1);
+    priv->connect_method = w;
 
     /* Address */
     w = aligned_label_new (_("IP Address:"));
-    gtk_table_attach_defaults (table, w, 0, 1, 3, 4);
+    gtk_table_attach_defaults (table, w, 0, 1, 1, 2);
 
     priv->address = gtk_entry_new ();
-    gtk_table_attach_defaults (table, priv->address, 1, 2, 3, 4);
+    gtk_table_attach_defaults (table, priv->address, 1, 2, 1, 2);
     g_signal_connect (priv->address, "insert-text", G_CALLBACK (ip_filter_cb), NULL);
     g_signal_connect_swapped (priv->address, "changed", G_CALLBACK (stuff_changed), details);
 
     /* Netmask */
     w = aligned_label_new (_("Subnet mask:"));
-    gtk_table_attach_defaults (table, w, 0, 1, 4, 5);
+    gtk_table_attach_defaults (table, w, 0, 1, 2, 3);
 
     priv->netmask = gtk_entry_new ();
-    gtk_table_attach_defaults (table, priv->netmask, 1, 2, 4, 5);
+    gtk_table_attach_defaults (table, priv->netmask, 1, 2, 2, 3);
     g_signal_connect (priv->netmask, "insert-text", G_CALLBACK (ip_filter_cb), NULL);
     g_signal_connect_swapped (priv->netmask, "changed", G_CALLBACK (stuff_changed), details);
 
     /* Gateway */
     w = aligned_label_new (_("Router:"));
-    gtk_table_attach_defaults (table, w, 0, 1, 5, 6);
+    gtk_table_attach_defaults (table, w, 0, 1, 3, 4);
 
     priv->gateway = gtk_entry_new ();
-    gtk_table_attach_defaults (table, priv->gateway, 1, 2, 5, 6);
+    gtk_table_attach_defaults (table, priv->gateway, 1, 2, 3, 4);
     g_signal_connect (priv->gateway, "insert-text", G_CALLBACK (ip_filter_cb), NULL);
     g_signal_connect_swapped (priv->gateway, "changed", G_CALLBACK (stuff_changed), details);
 
     /* DNS */
     w = aligned_label_new (_("DNS:"));
-    gtk_table_attach_defaults (table, w, 0, 1, 6, 7);
+    gtk_table_attach_defaults (table, w, 0, 1, 4, 5);
 
     priv->dns = gtk_text_view_new ();
-    gtk_table_attach_defaults (table, priv->dns, 1, 2, 6, 7);
+    gtk_table_attach_defaults (table, priv->dns, 1, 2, 4, 5);
     buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->dns));
     g_signal_connect (buffer, "insert-text", G_CALLBACK (dns_filter_cb), NULL);
     g_signal_connect_swapped (buffer, "changed", G_CALLBACK (stuff_changed), details);
 
     /* Hardware address */
     w = aligned_label_new (_("Your MAC address:"));
-    gtk_table_attach_defaults (table, w, 0, 1, 7, 8);
+    gtk_table_attach_defaults (table, w, 0, 1, 5, 6);
 
     priv->hw_address = aligned_label_new (NULL);
-    gtk_table_attach_defaults (table, priv->hw_address, 1, 2, 7, 8);
+    gtk_table_attach_defaults (table, priv->hw_address, 1, 2, 5, 6);
 
     editable_changed (details, TRUE);
     stuff_changed (details);



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