From 0294378068e990f8129095e481c5cc2ac8c3b617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Fri, 2 Oct 2015 12:49:49 +0200 Subject: 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/page-ip4.c | 94 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'src/connection-editor/page-ip4.c') diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c index 7989a0fd..120a2d22 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; } -- cgit v1.2.1