[network-manager-applet: 6/7] editor: change properties on IP4/IP6 pages if Wi-Fi mode changes



commit 0294378068e990f8129095e481c5cc2ac8c3b617
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 |    2 +-
 src/connection-editor/page-ip4.c             |   94 ++++++++++++++++++++++++++
 src/connection-editor/page-ip6.c             |   91 +++++++++++++++++++++++++
 src/connection-editor/page-wifi.c            |    5 ++
 4 files changed, 191 insertions(+), 1 deletions(-)
---
diff --git a/src/connection-editor/nm-connection-editor.h b/src/connection-editor/nm-connection-editor.h
index bdbab11..6275baf 100644
--- a/src/connection-editor/nm-connection-editor.h
+++ b/src/connection-editor/nm-connection-editor.h
@@ -79,7 +79,7 @@ typedef struct {
 
 typedef enum {
        /* Add item for inter-page changes here */
-       DUMMY,
+       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 7989a0f..120a2d2 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -54,6 +54,8 @@ typedef struct {
 
        GtkComboBox *method;
        GtkListStore *method_store;
+       int normal_method_idx;
+       int hotspot_method_idx;
 
        /* Addresses */
        GtkWidget *addr_label;
@@ -1385,12 +1387,103 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
        return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
 }
 
+static gboolean
+get_iter_for_method (GtkTreeModel *model, int column, GtkTreeIter *iter)
+{
+       int col;
+
+       if (gtk_tree_model_get_iter_first (model, iter)) {
+               do {
+                       gtk_tree_model_get (model, iter, METHOD_COL_NUM, &col, -1);
+                       if (col == column)
+                               return TRUE;
+               } while (gtk_tree_model_iter_next (model, iter));
+       }
+       return FALSE;
+}
+
+static void
+toggle_method_sensitivity (CEPage *page, int column, gboolean sensitive)
+{
+       CEPageIP4 *self = CE_PAGE_IP4 (page);
+       CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
+       GtkTreeModel *model = GTK_TREE_MODEL (priv->method_store);
+       GtkTreeIter iter;
+
+       if (get_iter_for_method (model, column, &iter))
+               gtk_list_store_set (priv->method_store, &iter, METHOD_COL_ENABLED, sensitive, -1);
+}
+
+static gboolean
+get_method_sensitivity (CEPage *page, int column)
+{
+       CEPageIP4 *self = CE_PAGE_IP4 (page);
+       CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
+       GtkTreeModel *model = GTK_TREE_MODEL (priv->method_store);
+       GtkTreeIter iter;
+       gboolean sensitive = FALSE;
+
+       if (get_iter_for_method (model, column, &iter))
+               gtk_tree_model_get (GTK_TREE_MODEL (priv->method_store), &iter, METHOD_COL_ENABLED, 
&sensitive, -1);
+       return sensitive;
+}
+
+static void
+change_method_combo (CEPage *page, gboolean is_hotspot)
+{
+       CEPageIP4 *self = CE_PAGE_IP4 (page);
+       CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
+
+       /* Store previous active method */
+       if (get_method_sensitivity (page, IP4_METHOD_AUTO))
+               priv->normal_method_idx = gtk_combo_box_get_active (priv->method);
+       else
+               priv->hotspot_method_idx = gtk_combo_box_get_active (priv->method);
+
+       /* Set active method */
+       if (is_hotspot) {
+               if (priv->hotspot_method_idx == -1) {
+                       int method = IP4_METHOD_SHARED;
+                       if (g_strcmp0 (nm_setting_ip_config_get_method (priv->setting),
+                                      NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0)
+                               method = IP4_METHOD_DISABLED;
+                       gtk_combo_box_set_active (priv->method, method);
+               } else
+                       gtk_combo_box_set_active (priv->method, priv->hotspot_method_idx);
+       } else {
+               if (priv->normal_method_idx != -1)
+                       gtk_combo_box_set_active (priv->method, priv->normal_method_idx);
+       }
+
+       toggle_method_sensitivity (page, IP4_METHOD_AUTO, !is_hotspot);
+       toggle_method_sensitivity (page, IP4_METHOD_AUTO_ADDRESSES, !is_hotspot);
+       toggle_method_sensitivity (page, IP4_METHOD_MANUAL, !is_hotspot);
+       toggle_method_sensitivity (page, IP4_METHOD_LINK_LOCAL, !is_hotspot);
+}
+
+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 (page, TRUE);
+               else
+                       change_method_combo (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_method_idx = -1;
+       priv->hotspot_method_idx = -1;
 }
 
 static void
@@ -1421,5 +1514,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 f9ace0d..db95b03 100644
--- a/src/connection-editor/page-ip6.c
+++ b/src/connection-editor/page-ip6.c
@@ -53,6 +53,8 @@ typedef struct {
 
        GtkComboBox *method;
        GtkListStore *method_store;
+       int normal_method_idx;
+       int hotspot_method_idx;
 
        /* Addresses */
        GtkWidget *addr_label;
@@ -1369,12 +1371,100 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
        return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
 }
 
+static gboolean
+get_iter_for_method (GtkTreeModel *model, int column, GtkTreeIter *iter)
+{
+       int col;
+
+       if (gtk_tree_model_get_iter_first (model, iter)) {
+               do {
+                       gtk_tree_model_get (model, iter, METHOD_COL_NUM, &col, -1);
+                       if (col == column)
+                               return TRUE;
+               } while (gtk_tree_model_iter_next (model, iter));
+       }
+       return FALSE;
+}
+
+static void
+toggle_method_sensitivity (CEPage *page, int column, gboolean sensitive)
+{
+       CEPageIP6 *self = CE_PAGE_IP6 (page);
+       CEPageIP6Private *priv = CE_PAGE_IP6_GET_PRIVATE (self);
+       GtkTreeModel *model = GTK_TREE_MODEL (priv->method_store);
+       GtkTreeIter iter;
+
+       if (get_iter_for_method (model, column, &iter))
+               gtk_list_store_set (priv->method_store, &iter, METHOD_COL_ENABLED, sensitive, -1);
+}
+
+static gboolean
+get_method_sensitivity (CEPage *page, int column)
+{
+       CEPageIP6 *self = CE_PAGE_IP6 (page);
+       CEPageIP6Private *priv = CE_PAGE_IP6_GET_PRIVATE (self);
+       GtkTreeModel *model = GTK_TREE_MODEL (priv->method_store);
+       GtkTreeIter iter;
+       gboolean sensitive = FALSE;
+
+       if (get_iter_for_method (model, column, &iter))
+               gtk_tree_model_get (GTK_TREE_MODEL (priv->method_store), &iter, METHOD_COL_ENABLED, 
&sensitive, -1);
+       return sensitive;
+}
+
+static void
+change_method_combo (CEPage *page, gboolean is_hotspot)
+{
+       CEPageIP6 *self = CE_PAGE_IP6 (page);
+       CEPageIP6Private *priv = CE_PAGE_IP6_GET_PRIVATE (self);
+
+       /* Store previous active method */
+       if (get_method_sensitivity (page, IP6_METHOD_AUTO))
+               priv->normal_method_idx = gtk_combo_box_get_active (priv->method);
+       else
+               priv->hotspot_method_idx = gtk_combo_box_get_active (priv->method);
+
+       /* Set active method */
+       if (is_hotspot) {
+               if (priv->hotspot_method_idx != -1)
+                       gtk_combo_box_set_active (priv->method, priv->hotspot_method_idx);
+               else
+                       gtk_combo_box_set_active (priv->method, IP6_METHOD_IGNORE);
+       } else {
+               if (priv->normal_method_idx != -1)
+                       gtk_combo_box_set_active (priv->method, priv->normal_method_idx);
+       }
+
+       toggle_method_sensitivity (page, IP6_METHOD_AUTO, !is_hotspot);
+       toggle_method_sensitivity (page, IP6_METHOD_AUTO_ADDRESSES, !is_hotspot);
+       toggle_method_sensitivity (page, IP6_METHOD_AUTO_DHCP_ONLY, !is_hotspot);
+       toggle_method_sensitivity (page, IP6_METHOD_MANUAL, !is_hotspot);
+       toggle_method_sensitivity (page, IP6_METHOD_LINK_LOCAL, !is_hotspot);
+}
+
+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 (page, TRUE);
+               else
+                       change_method_combo (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_method_idx = -1;
+       priv->hotspot_method_idx = -1;
 }
 
 static void
@@ -1405,5 +1495,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 d9dcb69..63367c6 100644
--- a/src/connection-editor/page-wifi.c
+++ b/src/connection-editor/page-wifi.c
@@ -245,9 +245,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
@@ -260,6 +262,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]