prevent calling extra connectivityChanged

The NMClient seems to always emit an extra notify::primary-connection
signal on startup which resulted in always calling connectivityChanged
and so reloading the accounts in the daemon for no reason.

We save the NMActiveConnection pointer to make sure it has really changed.

Change-Id: I8ee920c0f12e0e599bde37a2a0adf2a36561a75b
Tuleap: #1097
diff --git a/src/ring_client.cpp b/src/ring_client.cpp
index f56b768..39f28a4 100644
--- a/src/ring_client.cpp
+++ b/src/ring_client.cpp
@@ -113,6 +113,7 @@
 #if USE_LIBNM
     /* NetworkManager */
     NMClient *nm_client;
+    NMActiveConnection *primary_connection;
 #endif
 
     /* notifications */
@@ -394,12 +395,19 @@
 }
 
 static void
-primary_connection_changed(NMClient *nm)
+primary_connection_changed(NMClient *nm,  GParamSpec*, RingClient *self)
 {
+    auto priv = RING_CLIENT_GET_PRIVATE(self);
     auto connection = nm_client_get_primary_connection(nm);
-    log_connection_info(connection);
 
-    AccountModel::instance().slotConnectivityChanged();
+    if (priv->primary_connection != connection) {
+        /* make sure the connection really changed
+         * on client start it seems to always emit the notify::primary-connection signal though it
+         * hasn't changed */
+        log_connection_info(connection);
+        priv->primary_connection = connection;
+        AccountModel::instance().slotConnectivityChanged();
+    }
 }
 
 static void
@@ -417,13 +425,14 @@
 
         auto connection = nm_client_get_primary_connection(nm_client);
         log_connection_info(connection);
+        priv->primary_connection = connection;
 
         /* We monitor the primary connection and notify the daemon to re-load its connections
          * (accounts, UPnP, ...) when it changes. For example, on most systems, if we have an
          * ethernet connection and then also connect to wifi, the primary connection will not change;
          * however it will change in the opposite case because an ethernet connection is preferred.
          */
-        g_signal_connect(nm_client, "notify::primary-connection", G_CALLBACK(primary_connection_changed), nullptr);
+        g_signal_connect(nm_client, "notify::primary-connection", G_CALLBACK(primary_connection_changed), self);
 
     } else {
         g_warning("error initializing NetworkManager client: %s", error->message);