[network-manager-applet/jk/master-as-ifname-rh1083186] editor: only change slave master properties if a new slave was added



commit 0f90a8308b5a7d968f259a4893babc40e58311c5
Author: Jiří Klimeš <jklimes redhat com>
Date:   Mon Mar 16 15:50:02 2015 +0100

    editor: only change slave master properties if a new slave was added
    
    It is to ensure we don't change the master properties in existing connections,
    when a user just edits something else.

 src/connection-editor/page-master.c |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)
---
diff --git a/src/connection-editor/page-master.c b/src/connection-editor/page-master.c
index 1d1590c..9f8d84a 100644
--- a/src/connection-editor/page-master.c
+++ b/src/connection-editor/page-master.c
@@ -44,6 +44,8 @@ typedef struct {
        GtkTreeModel *connections_model;
        GtkButton *add, *edit, *delete;
 
+       GHashTable *new_slaves;  /* track whether some slave(s) were added */
+
 } CEPageMasterPrivate;
 
 enum {
@@ -112,6 +114,8 @@ dispose (GObject *object)
                } while (gtk_tree_model_iter_next (priv->connections_model, &iter));
        }
 
+       g_hash_table_destroy (priv->new_slaves);
+
        G_OBJECT_CLASS (ce_page_master_parent_class)->dispose (object);
 }
 
@@ -343,6 +347,14 @@ connections_selection_changed_cb (GtkTreeSelection *selection, gpointer user_dat
 static void
 add_response_cb (NMConnectionEditor *editor, GtkResponseType response, gpointer user_data)
 {
+       CEPageMaster *self = user_data;
+       CEPageMasterPrivate *priv = CE_PAGE_MASTER_GET_PRIVATE (self);
+       const char *uuid;
+
+       if (response == GTK_RESPONSE_OK) {
+               uuid = nm_connection_get_uuid (editor->connection);
+               g_hash_table_add (priv->new_slaves, g_strdup (uuid));
+       }
        g_object_unref (editor);
 }
 
@@ -474,6 +486,20 @@ connection_double_clicked_cb (GtkTreeView *tree_view,
 }
 
 static void
+delete_result_cb (NMRemoteConnection *connection,
+                  gboolean deleted,
+                  gpointer user_data)
+{
+       CEPageMaster *self = user_data;
+       CEPageMasterPrivate *priv = CE_PAGE_MASTER_GET_PRIVATE (self);
+
+       if (deleted) {
+               g_hash_table_remove (priv->new_slaves,
+                                    nm_connection_get_uuid (NM_CONNECTION (connection)));
+       }
+}
+
+static void
 delete_clicked (GtkButton *button, gpointer user_data)
 {
        CEPageMaster *self = user_data;
@@ -484,7 +510,7 @@ delete_clicked (GtkButton *button, gpointer user_data)
        if (!connection)
                return;
 
-       delete_connection (priv->toplevel, connection, NULL, NULL);
+       delete_connection (priv->toplevel, connection, delete_result_cb, self);
 }
 
 static void
@@ -601,6 +627,10 @@ last_update (CEPage *page, NMConnection *connection, GError **error)
        NMSettingConnection *s_con;
        GtkTreeIter iter;
 
+       /* No new slave added - leave master property as it is. */
+       if (g_hash_table_size (priv->new_slaves) == 0)
+               return TRUE;
+
        /*
         * Set master property of all slaves to be the interface name.
         * Even if UUID has the advantage of being stable and thus easier to use,
@@ -629,6 +659,9 @@ last_update (CEPage *page, NMConnection *connection, GError **error)
 static void
 ce_page_master_init (CEPageMaster *self)
 {
+       CEPageMasterPrivate *priv = CE_PAGE_MASTER_GET_PRIVATE (self);
+
+       priv->new_slaves = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 }
 
 static void


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