[network-manager-applet/jk/wifi-ap-mode-bgo755663: 4/4] editor: change properties on IP4/IP6 pages if Wi-Fi mode changes



commit 72feeccf88292e59d2eeb7a0c3e5aae152004021
Author: Jiří Klimeš <jklimes redhat com>
Date:   Fri Oct 2 12:49:49 2015 +0200

    editor: change properties on IP4/IP6 pages if Wi-Fi mode changes
    
    For AP (hotspot) mode, the IPv4 page needs to change method to Shared,
    and the IPv6 mode should be disabled because we don't yet run IPv6 Prefix
    Delegation and router advertisements on the shared interface.

 src/connection-editor/nm-connection-editor.h |    1 +
 src/connection-editor/page-ip4.c             |   74 ++++++++++++++++++++++++++
 src/connection-editor/page-ip6.c             |   66 +++++++++++++++++++++++
 src/connection-editor/page-wifi.c            |    5 ++
 4 files changed, 146 insertions(+), 0 deletions(-)
---
diff --git a/src/connection-editor/nm-connection-editor.h b/src/connection-editor/nm-connection-editor.h
index 5636cc5..498e073 100644
--- a/src/connection-editor/nm-connection-editor.h
+++ b/src/connection-editor/nm-connection-editor.h
@@ -80,6 +80,7 @@ typedef struct {
 
 typedef enum {
        /* Add item for inter-page changes here */
+       INTER_PAGE_CHANGE_WIFI_MODE = 1,
 } InterPageChangeType;
 
 GType               nm_connection_editor_get_type (void);
diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c
index 4c5574e..df915e8 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -64,6 +64,9 @@ typedef struct {
 
        GtkComboBox *method;
        GtkListStore *method_store;
+       GtkListStore *normal_methods, *hotspot_methods;
+       int normal_methods_idx;
+       int hotspot_methods_idx;
 
        /* Addresses */
        GtkWidget *addr_label;
@@ -1231,11 +1234,81 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
 }
 
 static void
+change_method_combo_store (CEPage *page, gboolean is_hotspot)
+{
+       CEPageIP4 *self = CE_PAGE_IP4 (page);
+       CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
+       GtkTreeIter iter;
+
+       if (G_UNLIKELY (!priv->normal_methods)) {
+               priv->normal_methods = priv->method_store;
+       }
+       if (G_UNLIKELY (!priv->hotspot_methods)) {
+               priv->hotspot_methods = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_UINT);
+               gtk_list_store_append (priv->hotspot_methods, &iter);
+               gtk_list_store_set (priv->hotspot_methods, &iter,
+                                   METHOD_COL_NAME, _("Shared to other computers"),
+                                   METHOD_COL_NUM, IP4_METHOD_SHARED,
+                                   -1);
+               gtk_list_store_append (priv->hotspot_methods, &iter);
+               gtk_list_store_set (priv->hotspot_methods, &iter,
+                                   METHOD_COL_NAME, _("Disabled"),
+                                   METHOD_COL_NUM, IP4_METHOD_DISABLED,
+                                   -1);
+       }
+
+       /* Store previous active metdod */
+       if (priv->method_store == priv->normal_methods)
+               priv->normal_methods_idx = gtk_combo_box_get_active (priv->method);
+       if (priv->method_store == priv->hotspot_methods)
+               priv->hotspot_methods_idx = gtk_combo_box_get_active (priv->method);
+
+       /* Change methods combo */
+       if (is_hotspot)
+               priv->method_store = priv->hotspot_methods;
+       else
+               priv->method_store = priv->normal_methods;
+       gtk_combo_box_set_model (priv->method, GTK_TREE_MODEL (priv->method_store));
+
+       /* Set active metheod */
+       if (is_hotspot) {
+               if (priv->hotspot_methods_idx == -1) {
+                       int method = 0;
+                       if (g_strcmp0 (nm_setting_ip4_config_get_method (priv->setting),
+                                      NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0)
+                               method = 1;
+                       gtk_combo_box_set_active (priv->method, method);
+               } else
+                       gtk_combo_box_set_active (priv->method, priv->hotspot_methods_idx);
+       } else {
+               if (priv->normal_methods_idx != -1)
+                       gtk_combo_box_set_active (priv->method, priv->normal_methods_idx);
+       }
+}
+
+static gboolean
+inter_page_change (CEPage *page)
+{
+       gpointer wifi_mode_ap;
+
+       if (nm_connection_editor_inter_page_get_value (page->editor, INTER_PAGE_CHANGE_WIFI_MODE, 
&wifi_mode_ap)) {
+               /* For Wi-Fi AP mode restrict IPv4 methods to shared and disabled */
+               if (GPOINTER_TO_UINT (wifi_mode_ap))
+                       change_method_combo_store (page, TRUE);
+               else
+                       change_method_combo_store (page, FALSE);
+       }
+       return TRUE;
+}
+
+static void
 ce_page_ip4_init (CEPageIP4 *self)
 {
        CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
 
        priv->last_column = -1;
+       priv->normal_methods_idx = -1;
+       priv->hotspot_methods_idx = -1;
 }
 
 static void
@@ -1266,5 +1339,6 @@ ce_page_ip4_class_init (CEPageIP4Class *ip4_class)
 
        /* virtual methods */
        parent_class->ce_page_validate_v = ce_page_validate_v;
+       parent_class->inter_page_change = inter_page_change;
        object_class->dispose = dispose;
 }
diff --git a/src/connection-editor/page-ip6.c b/src/connection-editor/page-ip6.c
index eb252e3..7aca8fa 100644
--- a/src/connection-editor/page-ip6.c
+++ b/src/connection-editor/page-ip6.c
@@ -63,6 +63,9 @@ typedef struct {
 
        GtkComboBox *method;
        GtkListStore *method_store;
+       GtkListStore *normal_methods, *hotspot_methods;
+       int normal_methods_idx;
+       int hotspot_methods_idx;
 
        /* Addresses */
        GtkWidget *addr_label;
@@ -1218,11 +1221,73 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
 }
 
 static void
+change_method_combo_store (CEPage *page, gboolean is_hotspot)
+{
+       CEPageIP6 *self = CE_PAGE_IP6 (page);
+       CEPageIP6Private *priv = CE_PAGE_IP6_GET_PRIVATE (self);
+       GtkTreeIter iter;
+
+       if (G_UNLIKELY (!priv->normal_methods)) {
+               priv->normal_methods = priv->method_store;
+       }
+       if (G_UNLIKELY (!priv->hotspot_methods)) {
+               priv->hotspot_methods = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_BOOLEAN);
+               gtk_list_store_append (priv->hotspot_methods, &iter);
+               gtk_list_store_set (priv->hotspot_methods, &iter,
+                                   METHOD_COL_NAME, _("Ignore"),
+                                   METHOD_COL_NUM, IP6_METHOD_IGNORE,
+                                   METHOD_COL_ENABLED, TRUE,
+                                   -1);
+       }
+
+       /* Store previous active metdod */
+       if (priv->method_store == priv->normal_methods)
+               priv->normal_methods_idx = gtk_combo_box_get_active (priv->method);
+       if (priv->method_store == priv->hotspot_methods)
+               priv->hotspot_methods_idx = gtk_combo_box_get_active (priv->method);
+
+       /* Change methods combo */
+       if (is_hotspot)
+               priv->method_store = priv->hotspot_methods;
+       else
+               priv->method_store = priv->normal_methods;
+       gtk_combo_box_set_model (priv->method, GTK_TREE_MODEL (priv->method_store));
+
+       /* Set active metheod */
+       if (is_hotspot) {
+               if (priv->hotspot_methods_idx != -1)
+                       gtk_combo_box_set_active (priv->method, priv->hotspot_methods_idx);
+               else
+                       gtk_combo_box_set_active (priv->method, 0);
+       } else {
+               if (priv->normal_methods_idx != -1)
+                       gtk_combo_box_set_active (priv->method, priv->normal_methods_idx);
+       }
+}
+
+static gboolean
+inter_page_change (CEPage *page)
+{
+       gpointer wifi_mode_ap;
+
+       if (nm_connection_editor_inter_page_get_value (page->editor, INTER_PAGE_CHANGE_WIFI_MODE, 
&wifi_mode_ap)) {
+               /* For Wi-Fi AP mode restrict IPv6 methods to ignore */
+               if (GPOINTER_TO_UINT (wifi_mode_ap))
+                       change_method_combo_store (page, TRUE);
+               else
+                       change_method_combo_store (page, FALSE);
+       }
+       return TRUE;
+}
+
+static void
 ce_page_ip6_init (CEPageIP6 *self)
 {
        CEPageIP6Private *priv = CE_PAGE_IP6_GET_PRIVATE (self);
 
        priv->last_column = -1;
+       priv->normal_methods_idx = -1;
+       priv->hotspot_methods_idx = -1;
 }
 
 static void
@@ -1253,5 +1318,6 @@ ce_page_ip6_class_init (CEPageIP6Class *ip6_class)
 
        /* virtual methods */
        parent_class->ce_page_validate_v = ce_page_validate_v;
+       parent_class->inter_page_change = inter_page_change;
        object_class->dispose = dispose;
 }
diff --git a/src/connection-editor/page-wifi.c b/src/connection-editor/page-wifi.c
index cbcd3b0..aa4ea28 100644
--- a/src/connection-editor/page-wifi.c
+++ b/src/connection-editor/page-wifi.c
@@ -248,9 +248,11 @@ mode_combo_changed_cb (GtkComboBox *combo,
        GtkWidget *widget_band_label, *widget_chan_label, *widget_bssid_label;
        gboolean show_freq = FALSE;
        gboolean show_bssid = TRUE;
+       gboolean hotspot = FALSE;
 
        switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) {
        case 1: /* hotspot */
+               hotspot = TRUE;
        case 2: /* adhoc */
                /* BSSID is random and is created by kernel for Ad-Hoc networks
                 * http://lxr.linux.no/linux+v3.7.6/net/mac80211/ibss.c#L685
@@ -263,6 +265,9 @@ mode_combo_changed_cb (GtkComboBox *combo,
                show_freq = FALSE;
                break;
        }
+       nm_connection_editor_inter_page_set_value (parent->editor,
+                                                  INTER_PAGE_CHANGE_WIFI_MODE,
+                                                  GUINT_TO_POINTER (hotspot));
 
        widget_band_label = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_band_label"));
        widget_chan_label = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_channel_label"));


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