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
This commit is contained in:
		
							parent
							
								
									5236693df9
								
							
						
					
					
						commit
						e8004084fb
					
				
					 2 changed files with 23 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue