From e8004084fbb25e197fb56df648ec00d13fcbc910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 12 Nov 2017 23:24:10 +0100 Subject: [PATCH] Use Gio.NetworkMonitor for reconnecting - This uses also NetworkManager, but also other more low level interfaces on linux - This should work cross-platform - Leave network_watcher.py for now, because it shows how to use the Gtk dbus interface --- gajim/features_window.py | 8 -------- gajim/gui_interface.py | 25 +++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/gajim/features_window.py b/gajim/features_window.py index d43300bbf..17ffd8307 100644 --- a/gajim/features_window.py +++ b/gajim/features_window.py @@ -57,10 +57,6 @@ class FeaturesWindow: _('Ability to encrypting chat messages with OpenPGP.'), _('Requires gpg and python-gnupg (http://code.google.com/p/python-gnupg/).'), _('Requires gpg.exe in PATH.')), - _('Network-Watcher'): (self.network_watcher_available, - _('Autodetection of network status.'), - _('Requires gnome-network-manager'), - _('Feature not available under Windows.')), _('Password encryption'): (self.some_keyring_available, _('Passwords can be stored securely and not just in plaintext.'), _('Requires libsecret and a provider (such as GNOME Keyring and KSecretService).'), @@ -157,10 +153,6 @@ class FeaturesWindow: def gpg_available(self): return app.HAVE_GPG - def network_watcher_available(self): - from gajim import network_watcher - return network_watcher.supported - def some_keyring_available(self): if os.name == 'nt': return True diff --git a/gajim/gui_interface.py b/gajim/gui_interface.py index 6b221494a..91072e42d 100644 --- a/gajim/gui_interface.py +++ b/gajim/gui_interface.py @@ -44,6 +44,7 @@ import hashlib from gi.repository import Gtk from gi.repository import GdkPixbuf from gi.repository import GLib +from gi.repository import Gio try: from PIL import Image @@ -2553,6 +2554,23 @@ class Interface: view.updateNamespace({'gajim': app}) app.ipython_window = window + def network_status_changed(self, monitor, connected): + if connected == self.network_state: + # This callback gets called a lot from GTK with the + # same state, not only on change. + return + self.network_state = connected + if connected: + for connection in app.connections.values(): + if connection.connected <= 0: + log.info('Connect %s', connection.name) + connection.reconnect() + else: + for connection in app.connections.values(): + if connection.connected > 1: + log.info('Disconnect %s', connection.name) + connection.disconnectedReconnCB() + def run(self, application): if app.config.get('trayicon') != 'never': self.show_systray() @@ -2773,8 +2791,6 @@ class Interface: self.remote_ctrl = None - from gajim import network_watcher - if dbus_support.supported: from gajim import upower_listener from gajim import logind_listener @@ -2876,6 +2892,11 @@ class Interface: self.music_track_changed_signal = None + self.network_monitor = Gio.NetworkMonitor.get_default() + self.network_monitor.connect('network-changed', + self.network_status_changed) + self.network_state = self.network_monitor.get_network_available() + class PassphraseRequest: def __init__(self, keyid):