Merge branch 'networkmonitor' into 'master'

Use Gio.NetworkMonitor for reconnecting

See merge request gajim/gajim!149
This commit is contained in:
Philipp Hörist 2017-11-18 22:09:35 +01:00
commit f7bb9c8a33
2 changed files with 23 additions and 10 deletions

View File

@ -57,10 +57,6 @@ class FeaturesWindow:
_('Ability to encrypting chat messages with OpenPGP.'), _('Ability to encrypting chat messages with OpenPGP.'),
_('Requires gpg and python-gnupg (http://code.google.com/p/python-gnupg/).'), _('Requires gpg and python-gnupg (http://code.google.com/p/python-gnupg/).'),
_('Requires gpg.exe in PATH.')), _('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, _('Password encryption'): (self.some_keyring_available,
_('Passwords can be stored securely and not just in plaintext.'), _('Passwords can be stored securely and not just in plaintext.'),
_('Requires libsecret and a provider (such as GNOME Keyring and KSecretService).'), _('Requires libsecret and a provider (such as GNOME Keyring and KSecretService).'),
@ -157,10 +153,6 @@ class FeaturesWindow:
def gpg_available(self): def gpg_available(self):
return app.HAVE_GPG return app.HAVE_GPG
def network_watcher_available(self):
from gajim import network_watcher
return network_watcher.supported
def some_keyring_available(self): def some_keyring_available(self):
if os.name == 'nt': if os.name == 'nt':
return True return True

View File

@ -44,6 +44,7 @@ import hashlib
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf
from gi.repository import GLib from gi.repository import GLib
from gi.repository import Gio
try: try:
from PIL import Image from PIL import Image
@ -2558,6 +2559,23 @@ class Interface:
view.updateNamespace({'gajim': app}) view.updateNamespace({'gajim': app})
app.ipython_window = window 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): def run(self, application):
if app.config.get('trayicon') != 'never': if app.config.get('trayicon') != 'never':
self.show_systray() self.show_systray()
@ -2779,8 +2797,6 @@ class Interface:
self.remote_ctrl = None self.remote_ctrl = None
from gajim import network_watcher
if dbus_support.supported: if dbus_support.supported:
from gajim import upower_listener from gajim import upower_listener
from gajim import logind_listener from gajim import logind_listener
@ -2882,6 +2898,11 @@ class Interface:
self.music_track_changed_signal = None 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: class PassphraseRequest:
def __init__(self, keyid): def __init__(self, keyid):