Commit 6e595a31 authored by Sébastien Blin's avatar Sébastien Blin Committed by Philippe Gorley

mainwindow: re-link to connectivityChanged.

finish to remove unused code from old LRC models

Change-Id: I4677db795cf43326ffecd44e3b561c98c337ffb4
Gitlab: #984Reviewed-by: Philippe Gorley's avatarPhilippe Gorley <philippe.gorley@savoirfairelinux.com>
parent 5aebd506
......@@ -19,9 +19,9 @@
#include "dbuserrorhandler.h"
#include <glib/gi18n.h>
#include <callmodel.h>
#include <globalinstances.h>
#include "../ring_client.h"
#include <api/lrc.h>
namespace Interfaces {
......@@ -105,7 +105,7 @@ check_connection_cb(GtkWidget *warning_dialog)
gtk_widget_destroy(warning_dialog);
if ((!CallModel::instance().isConnected()) || (!CallModel::instance().isValid())) {
if ((!lrc::api::Lrc::isConnected()) || (!lrc::api::Lrc::dbusIsValid())) {
g_warning("could not reconnect to the daemon");
auto quit_dialog = ring_quitting_dialog();
......
......@@ -42,7 +42,6 @@
#include <api/newcallmodel.h>
#include <api/profile.h>
// Ring client
#include "config.h"
#include "newaccountsettingsview.h"
......@@ -128,6 +127,13 @@ struct RingMainWindowPrivate
gulong notif_accept_call;
gulong notif_decline_call;
gboolean set_top_account_flag = true;
GCancellable *cancellable;
#if USE_LIBNM
/* NetworkManager */
NMClient *nm_client;
NMActiveConnection *primary_connection;
#endif
};
G_DEFINE_TYPE_WITH_PRIVATE(RingMainWindow, ring_main_window, GTK_TYPE_APPLICATION_WINDOW);
......@@ -893,10 +899,77 @@ update_download_folder(RingMainWindow* self)
update_data_transfer(priv->cpp->lrc_->getDataTransferModel(), priv->settings);
}
#if USE_LIBNM
static void
log_connection_info(NMActiveConnection *connection)
{
if (connection) {
g_debug("primary network connection: %s, default: %s",
nm_active_connection_get_uuid(connection),
nm_active_connection_get_default(connection) ? "yes" : "no");
} else {
g_warning("no primary network connection detected, check network settings");
}
}
static void
primary_connection_changed(NMClient *nm, GParamSpec*, RingMainWindow* self)
{
auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
auto connection = nm_client_get_primary_connection(nm);
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;
priv->cpp->lrc_->connectivityChanged();
}
}
static void
nm_client_cb(G_GNUC_UNUSED GObject *source_object, GAsyncResult *result, RingMainWindow* self)
{
auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
GError* error = nullptr;
if (auto nm_client = nm_client_new_finish(result, &error)) {
priv->nm_client = nm_client;
g_debug("NetworkManager client initialized, version: %s\ndaemon running: %s\nnnetworking enabled: %s",
nm_client_get_version(nm_client),
nm_client_get_nm_running(nm_client) ? "yes" : "no",
nm_client_networking_get_enabled(nm_client) ? "yes" : "no");
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), self);
} else {
g_warning("error initializing NetworkManager client: %s", error->message);
g_clear_error(&error);
}
}
#endif /* USE_LIBNM */
void
CppImpl::init()
{
lrc_->getAVModel().deactivateOldVideoModels();
widgets->cancellable = g_cancellable_new();
#if USE_LIBNM
// monitor the network using libnm to notify the daemon about connectivity changes
nm_client_new_async(widgets->cancellable, (GAsyncReadyCallback)nm_client_cb, self);
#endif
smartviewPageNum = gtk_notebook_page_num(GTK_NOTEBOOK(widgets->notebook_contacts),
widgets->scrolled_window_smartview);
......@@ -2147,6 +2220,14 @@ ring_main_window_dispose(GObject *object)
delete priv->notifier;
priv->notifier = nullptr;
// cancel any pending cancellable operations
g_cancellable_cancel(priv->cancellable);
g_object_unref(priv->cancellable);
#if USE_LIBNM
// clear NetworkManager client if it was used
g_clear_object(&priv->nm_client);
#endif
G_OBJECT_CLASS(ring_main_window_parent_class)->dispose(object);
if (priv->general_settings_view) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment