[network-manager-applet/bg/editor-ipv4-addresses-bgo763937: 1/4] editor: preserve old addresses when changing IP method
- From: Beniamino Galvani <bgalvani src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/bg/editor-ipv4-addresses-bgo763937: 1/4] editor: preserve old addresses when changing IP method
- Date: Mon, 12 Sep 2016 13:48:56 +0000 (UTC)
commit bdabfa30a7d6359a4acd4576eb8f5deb6cc6c552
Author: Beniamino Galvani <bgalvani redhat com>
Date: Mon Sep 12 14:11:33 2016 +0200
editor: preserve old addresses when changing IP method
When the user switches from "Manual" to a method with disabled IP
addressing and then back, the address list is lost. Restore it.
src/connection-editor/page-ip4.c | 21 +++++++++++++++++----
src/connection-editor/page-ip6.c | 20 ++++++++++++++++----
2 files changed, 33 insertions(+), 8 deletions(-)
---
diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c
index b457448..4efadd3 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -59,6 +59,7 @@ typedef struct {
GtkButton *addr_delete;
GtkTreeView *addr_list;
GtkCellRenderer *addr_cells[COL_LAST + 1];
+ GtkTreeModel *addr_saved;
/* DNS servers */
GtkWidget *dns_servers_label;
@@ -246,6 +247,7 @@ method_changed (GtkComboBox *combo, gpointer user_data)
gboolean ip4_required_enabled = TRUE;
gboolean method_auto = FALSE;
GtkTreeIter iter;
+ GtkListStore *store;
if (gtk_combo_box_get_active_iter (priv->method, &iter)) {
gtk_tree_model_get (GTK_TREE_MODEL (priv->method_store), &iter,
@@ -268,6 +270,7 @@ method_changed (GtkComboBox *combo, gpointer user_data)
break;
case IP4_METHOD_DISABLED:
addr_enabled = dns_enabled = dhcp_enabled = routes_enabled = ip4_required_enabled = FALSE;
+ break;
default:
break;
}
@@ -285,11 +288,21 @@ method_changed (GtkComboBox *combo, gpointer user_data)
gtk_widget_set_sensitive (GTK_WIDGET (priv->addr_add), addr_enabled);
gtk_widget_set_sensitive (GTK_WIDGET (priv->addr_delete), addr_enabled);
gtk_widget_set_sensitive (GTK_WIDGET (priv->addr_list), addr_enabled);
- if (!addr_enabled) {
- GtkListStore *store;
- store = GTK_LIST_STORE (gtk_tree_view_get_model (priv->addr_list));
- gtk_list_store_clear (store);
+ if (addr_enabled) {
+ if (priv->addr_saved) {
+ /* Restore old entries */
+ gtk_tree_view_set_model (priv->addr_list, priv->addr_saved);
+ g_clear_object (&priv->addr_saved);
+ }
+ } else {
+ if (!priv->addr_saved) {
+ /* Save current entries, set empty list */
+ priv->addr_saved = g_object_ref (gtk_tree_view_get_model (priv->addr_list));
+ store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+ gtk_tree_view_set_model (priv->addr_list, GTK_TREE_MODEL (store));
+ g_object_unref (store);
+ }
}
gtk_widget_set_sensitive (priv->dns_servers_label, dns_enabled);
diff --git a/src/connection-editor/page-ip6.c b/src/connection-editor/page-ip6.c
index 124269e..8564285 100644
--- a/src/connection-editor/page-ip6.c
+++ b/src/connection-editor/page-ip6.c
@@ -58,6 +58,7 @@ typedef struct {
GtkButton *addr_delete;
GtkTreeView *addr_list;
GtkCellRenderer *addr_cells[COL_LAST + 1];
+ GtkTreeModel *addr_saved;
/* DNS servers */
GtkWidget *dns_servers_label;
@@ -246,6 +247,7 @@ method_changed (GtkComboBox *combo, gpointer user_data)
gboolean ip6_required_enabled = TRUE;
gboolean method_auto = FALSE;
GtkTreeIter iter;
+ GtkListStore *store;
if (gtk_combo_box_get_active_iter (priv->method, &iter)) {
gtk_tree_model_get (GTK_TREE_MODEL (priv->method_store), &iter,
@@ -283,11 +285,21 @@ method_changed (GtkComboBox *combo, gpointer user_data)
gtk_widget_set_sensitive (GTK_WIDGET (priv->addr_add), addr_enabled);
gtk_widget_set_sensitive (GTK_WIDGET (priv->addr_delete), addr_enabled);
gtk_widget_set_sensitive (GTK_WIDGET (priv->addr_list), addr_enabled);
- if (!addr_enabled) {
- GtkListStore *store;
- store = GTK_LIST_STORE (gtk_tree_view_get_model (priv->addr_list));
- gtk_list_store_clear (store);
+ if (addr_enabled) {
+ if (priv->addr_saved) {
+ /* Restore old entries */
+ gtk_tree_view_set_model (priv->addr_list, priv->addr_saved);
+ g_clear_object (&priv->addr_saved);
+ }
+ } else {
+ if (!priv->addr_saved) {
+ /* Save current entries, set empty list */
+ priv->addr_saved = g_object_ref (gtk_tree_view_get_model (priv->addr_list));
+ store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+ gtk_tree_view_set_model (priv->addr_list, GTK_TREE_MODEL (store));
+ g_object_unref (store);
+ }
}
gtk_widget_set_sensitive (priv->dns_servers_label, dns_enabled);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]