Philipp Hörist pushed to branch master at gajim / gajim

Commits:
e8004084 by Philipp Hörist at 2017-11-12T23:53:03+01:00
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

- - - - -
f7bb9c8a by Philipp Hörist at 2017-11-18T22:09:35+01:00
Merge branch 'networkmonitor' into 'master'

Use Gio.NetworkMonitor for reconnecting

See merge request gajim/gajim!149
- - - - -


2 changed files:

- gajim/features_window.py
- gajim/gui_interface.py


Changes:

=====================================
gajim/features_window.py
=====================================
--- 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


=====================================
gajim/gui_interface.py
=====================================
--- 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
@@ -2558,6 +2559,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()
@@ -2779,8 +2797,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
@@ -2882,6 +2898,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):



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/compare/639f0db1646ae5515f29996b8c7387b6296965a5...f7bb9c8a3303b3be3a1f21257056119a5fae631f

---
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/compare/639f0db1646ae5515f29996b8c7387b6296965a5...f7bb9c8a3303b3be3a1f21257056119a5fae631f
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to