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

Commits:

7 changed files:

Changes:

  • src/common/config.py
    ... ... @@ -193,7 +193,6 @@ class Config:
    193 193
                 'always_english_wikipedia': [opt_bool, False],
    
    194 194
                 'always_english_wiktionary': [opt_bool, True],
    
    195 195
                 'remote_control': [opt_bool, False, _('If checked, Gajim can be controlled remotely using gajim-remote.'), True],
    
    196
    -            'networkmanager_support': [opt_bool, True, _('If True, listen to D-Bus signals from NetworkManager and change the status of accounts (provided they do not have listen_to_network_manager set to False and they sync with global status) based upon the status of the network connection.'), True],
    
    197 196
                 'outgoing_chat_state_notifications': [opt_str, 'all', _('Sent chat state notifications. Can be one of all, composing_only, disabled.')],
    
    198 197
                 'displayed_chat_state_notifications': [opt_str, 'all', _('Displayed chat state notifications in chat windows. Can be one of all, composing_only, disabled.')],
    
    199 198
                 'autodetect_browser_mailer': [opt_bool, True, '', True],
    
    ... ... @@ -387,7 +386,6 @@ class Config:
    387 386
                         'msgwin-y-position': [opt_int, -1], # Default is to let the wm decide
    
    388 387
                         'msgwin-width': [opt_int, 480],
    
    389 388
                         'msgwin-height': [opt_int, 440],
    
    390
    -                    'listen_to_network_manager': [opt_bool, True],
    
    391 389
                         'is_zeroconf': [opt_bool, False],
    
    392 390
                         'last_status': [opt_str, 'online'],
    
    393 391
                         'last_status_msg': [opt_str, ''],
    

  • src/common/connection.py
    ... ... @@ -198,7 +198,7 @@ class CommonConnection:
    198 198
             """
    
    199 199
             gajim.ged.raise_event(event, self.name, data)
    
    200 200
     
    
    201
    -    def _reconnect(self):
    
    201
    +    def reconnect(self):
    
    202 202
             """
    
    203 203
             To be implemented by derivated classes
    
    204 204
             """
    
    ... ... @@ -849,7 +849,7 @@ class Connection(CommonConnection, ConnectionHandlers):
    849 849
         def check_jid(self, jid):
    
    850 850
             return helpers.parse_jid(jid)
    
    851 851
     
    
    852
    -    def _reconnect(self):
    
    852
    +    def reconnect(self):
    
    853 853
             # Do not try to reco while we are already trying
    
    854 854
             self.time_to_reconnect = None
    
    855 855
             if self.connected < 2: # connection failed
    
    ... ... @@ -894,7 +894,7 @@ class Connection(CommonConnection, ConnectionHandlers):
    894 894
                 gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
    
    895 895
                                         show=gajim.SHOW_LIST[self.connected]))
    
    896 896
     
    
    897
    -    def _disconnectedReconnCB(self):
    
    897
    +    def disconnectedReconnCB(self):
    
    898 898
             """
    
    899 899
             Called when we are disconnected
    
    900 900
             """
    
    ... ... @@ -914,7 +914,7 @@ class Connection(CommonConnection, ConnectionHandlers):
    914 914
                         show='error'))
    
    915 915
                 if self.connection:
    
    916 916
                     self.connection.UnregisterDisconnectHandler(
    
    917
    -                    self._disconnectedReconnCB)
    
    917
    +                    self.disconnectedReconnCB)
    
    918 918
                 self.disconnect()
    
    919 919
                 if gajim.config.get_per('accounts', self.name, 'autoreconnect'):
    
    920 920
                     self.connected = -1
    
    ... ... @@ -925,7 +925,7 @@ class Connection(CommonConnection, ConnectionHandlers):
    925 925
                         self.status = gajim.status_before_autoaway[self.name]
    
    926 926
                         gajim.status_before_autoaway[self.name] = ''
    
    927 927
                         self.old_show = 'online'
    
    928
    -                # this check has moved from _reconnect method
    
    928
    +                # this check has moved from reconnect method
    
    929 929
                     # do exponential backoff until less than 5 minutes
    
    930 930
                     if self.retrycount < 2 or self.last_time_to_reconnect is None:
    
    931 931
                         self.last_time_to_reconnect = 5
    
    ... ... @@ -1242,7 +1242,7 @@ class Connection(CommonConnection, ConnectionHandlers):
    1242 1242
                         self._connection_lost()
    
    1243 1243
                 else:
    
    1244 1244
                     # try reconnect if connection has failed before auth to server
    
    1245
    -                self._disconnectedReconnCB()
    
    1245
    +                self.disconnectedReconnCB()
    
    1246 1246
     
    
    1247 1247
         def connect_to_next_type(self, retry=False):
    
    1248 1248
             if self.redirected:
    
    ... ... @@ -1409,7 +1409,7 @@ class Connection(CommonConnection, ConnectionHandlers):
    1409 1409
             self.connected_hostname = self._current_host['host']
    
    1410 1410
             self.on_connect_failure = None
    
    1411 1411
             con.UnregisterDisconnectHandler(self._on_disconnected)
    
    1412
    -        con.RegisterDisconnectHandler(self._disconnectedReconnCB)
    
    1412
    +        con.RegisterDisconnectHandler(self.disconnectedReconnCB)
    
    1413 1413
             log.debug('Connected to server %s:%s with %s' % (
    
    1414 1414
                     self._current_host['host'], self._current_host['port'], con_type))
    
    1415 1415
     
    
    ... ... @@ -3038,7 +3038,7 @@ class Connection(CommonConnection, ConnectionHandlers):
    3038 3038
             if self.awaiting_xmpp_ping_id:
    
    3039 3039
                 # We haven't got the pong in time, disco and reconnect
    
    3040 3040
                 log.warning("No reply received for keepalive ping. Reconnecting.")
    
    3041
    -            self._disconnectedReconnCB()
    
    3041
    +            self.disconnectedReconnCB()
    
    3042 3042
     
    
    3043 3043
         def _reconnect_alarm(self):
    
    3044 3044
             if not gajim.config.get_per('accounts', self.name, 'active'):
    
    ... ... @@ -3046,7 +3046,7 @@ class Connection(CommonConnection, ConnectionHandlers):
    3046 3046
                 return
    
    3047 3047
             if self.time_to_reconnect:
    
    3048 3048
                 if self.connected < 2:
    
    3049
    -                self._reconnect()
    
    3049
    +                self.reconnect()
    
    3050 3050
                 else:
    
    3051 3051
                     self.time_to_reconnect = None
    
    3052 3052
     
    

  • src/common/zeroconf/connection_zeroconf.py
    ... ... @@ -120,7 +120,7 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
    120 120
         def check_jid(self, jid):
    
    121 121
             return jid
    
    122 122
     
    
    123
    -    def _reconnect(self):
    
    123
    +    def reconnect(self):
    
    124 124
             # Do not try to reco while we are already trying
    
    125 125
             self.time_to_reconnect = None
    
    126 126
             gajim.log.debug('reconnect')
    
    ... ... @@ -163,7 +163,7 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
    163 163
             gajim.nec.push_incoming_event(ZeroconfPresenceReceivedEvent(
    
    164 164
                 None, conn=self, fjid=jid, show='offline', status=''))
    
    165 165
     
    
    166
    -    def _disconnectedReconnCB(self):
    
    166
    +    def disconnectedReconnCB(self):
    
    167 167
             """
    
    168 168
             Called when we are disconnected. Comes from network manager for example
    
    169 169
             we don't try to reconnect, network manager will tell us when we can
    

  • src/features_window.py
    ... ... @@ -61,9 +61,9 @@ class FeaturesWindow:
    61 61
                     _('Ability to encrypting chat messages with OpenPGP.'),
    
    62 62
                     _('Requires gpg and python-gnupg (http://code.google.com/p/python-gnupg/).'),
    
    63 63
                     _('Requires gpg.exe in PATH.')),
    
    64
    -            _('Network-manager'): (self.network_manager_available,
    
    64
    +            _('Network-Watcher'): (self.network_watcher_available,
    
    65 65
                     _('Autodetection of network status.'),
    
    66
    -                _('Requires gnome-network-manager and python-dbus.'),
    
    66
    +                _('Requires gnome-network-manager'),
    
    67 67
                     _('Feature not available under Windows.')),
    
    68 68
                 _('Password encryption'): (self.some_keyring_available,
    
    69 69
                     _('Passwords can be stored securely and not just in plaintext.'),
    
    ... ... @@ -178,11 +178,9 @@ class FeaturesWindow:
    178 178
         def gpg_available(self):
    
    179 179
             return gajim.HAVE_GPG
    
    180 180
     
    
    181
    -    def network_manager_available(self):
    
    182
    -        if os.name == 'nt':
    
    183
    -            return False
    
    184
    -        import network_manager_listener
    
    185
    -        return network_manager_listener.supported
    
    181
    +    def network_watcher_available(self):
    
    182
    +        import network_watcher
    
    183
    +        return network_watcher.supported
    
    186 184
     
    
    187 185
         def some_keyring_available(self):
    
    188 186
             if os.name == 'nt':
    

  • src/gui_interface.py
    ... ... @@ -2973,9 +2973,7 @@ class Interface:
    2973 2973
     
    
    2974 2974
             self.remote_ctrl = None
    
    2975 2975
     
    
    2976
    -        if gajim.config.get('networkmanager_support') and \
    
    2977
    -        dbus_support.supported:
    
    2978
    -            import network_manager_listener
    
    2976
    +        import network_watcher
    
    2979 2977
     
    
    2980 2978
             if dbus_support.supported:
    
    2981 2979
                 import upower_listener
    

  • src/network_manager_listener.py deleted
    1
    -# -*- coding: utf-8 -*-
    
    2
    -## src/network_manager_listener.py
    
    3
    -##
    
    4
    -## Copyright (C) 2006 Jeffrey C. Ollie <jeff AT ocjtech.us>
    
    5
    -##                    Nikos Kouremenos <kourem AT gmail.com>
    
    6
    -##                    Stefan Bethge <stefan AT lanpartei.de>
    
    7
    -## Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org>
    
    8
    -##
    
    9
    -## This file is part of Gajim.
    
    10
    -##
    
    11
    -## Gajim is free software; you can redistribute it and/or modify
    
    12
    -## it under the terms of the GNU General Public License as published
    
    13
    -## by the Free Software Foundation; version 3 only.
    
    14
    -##
    
    15
    -## Gajim is distributed in the hope that it will be useful,
    
    16
    -## but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    17
    -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    
    18
    -## GNU General Public License for more details.
    
    19
    -##
    
    20
    -## You should have received a copy of the GNU General Public License
    
    21
    -## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    22
    -##
    
    23
    -
    
    24
    -from common import gajim
    
    25
    -
    
    26
    -
    
    27
    -def device_now_active(self, *args):
    
    28
    -    """
    
    29
    -    For Network Manager 0.6
    
    30
    -    """
    
    31
    -    for connection in gajim.connections.values():
    
    32
    -        if gajim.config.get_per('accounts', connection.name,
    
    33
    -        'listen_to_network_manager') and connection.time_to_reconnect:
    
    34
    -            connection._reconnect()
    
    35
    -
    
    36
    -def device_no_longer_active(self, *args):
    
    37
    -    """
    
    38
    -    For Network Manager 0.6
    
    39
    -    """
    
    40
    -    for connection in gajim.connections.values():
    
    41
    -        if gajim.config.get_per('accounts', connection.name,
    
    42
    -        'listen_to_network_manager') and connection.connected > 1:
    
    43
    -            connection._disconnectedReconnCB()
    
    44
    -
    
    45
    -def state_changed(state):
    
    46
    -    """
    
    47
    -    For Network Manager 0.7 - 0.9
    
    48
    -    """
    
    49
    -    if state == 70:
    
    50
    -        for connection in gajim.connections.values():
    
    51
    -            if gajim.config.get_per('accounts', connection.name,
    
    52
    -            'listen_to_network_manager') and connection.time_to_reconnect:
    
    53
    -                connection._reconnect()
    
    54
    -    else:
    
    55
    -        for connection in gajim.connections.values():
    
    56
    -            if gajim.config.get_per('accounts', connection.name,
    
    57
    -            'listen_to_network_manager') and connection.connected > 1:
    
    58
    -                connection._disconnectedReconnCB()
    
    59
    -
    
    60
    -supported = False
    
    61
    -
    
    62
    -from common import dbus_support
    
    63
    -
    
    64
    -if dbus_support.supported:
    
    65
    -    import dbus
    
    66
    -
    
    67
    -    try:
    
    68
    -        from common.dbus_support import system_bus
    
    69
    -
    
    70
    -        bus = system_bus.bus()
    
    71
    -
    
    72
    -        if 'org.freedesktop.NetworkManager' in bus.list_names():
    
    73
    -            nm_object = bus.get_object('org.freedesktop.NetworkManager',
    
    74
    -                    '/org/freedesktop/NetworkManager')
    
    75
    -            props = dbus.Interface(nm_object, "org.freedesktop.DBus.Properties")
    
    76
    -            bus.add_signal_receiver(state_changed,
    
    77
    -                    'StateChanged',
    
    78
    -                    'org.freedesktop.NetworkManager',
    
    79
    -                    'org.freedesktop.NetworkManager',
    
    80
    -                    '/org/freedesktop/NetworkManager')
    
    81
    -            supported = True
    
    82
    -
    
    83
    -    except dbus.DBusException:
    
    84
    -        try:
    
    85
    -            if 'org.freedesktop.NetworkManager' in bus.list_names():
    
    86
    -                supported = True
    
    87
    -
    
    88
    -                bus.add_signal_receiver(device_no_longer_active,
    
    89
    -                        'DeviceNoLongerActive',
    
    90
    -                        'org.freedesktop.NetworkManager',
    
    91
    -                        'org.freedesktop.NetworkManager',
    
    92
    -                        '/org/freedesktop/NetworkManager')
    
    93
    -
    
    94
    -                bus.add_signal_receiver(device_now_active,
    
    95
    -                        'DeviceNowActive',
    
    96
    -                        'org.freedesktop.NetworkManager',
    
    97
    -                        'org.freedesktop.NetworkManager',
    
    98
    -                        '/org/freedesktop/NetworkManager')
    
    99
    -        except Exception:
    
    100
    -            pass

  • src/network_watcher.py
    1
    +# -*- coding: utf-8 -*-
    
    2
    +## src/network_watcher.py
    
    3
    +##
    
    4
    +## Copyright (C) 2017 Philipp Hoerist <philipp AT hoerist.com>
    
    5
    +##
    
    6
    +## This file is part of Gajim.
    
    7
    +##
    
    8
    +## Gajim is free software; you can redistribute it and/or modify
    
    9
    +## it under the terms of the GNU General Public License as published
    
    10
    +## by the Free Software Foundation; version 3 only.
    
    11
    +##
    
    12
    +## Gajim is distributed in the hope that it will be useful,
    
    13
    +## but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14
    +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    
    15
    +## GNU General Public License for more details.
    
    16
    +##
    
    17
    +## You should have received a copy of the GNU General Public License
    
    18
    +## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    19
    +##
    
    20
    +
    
    21
    +
    
    22
    +import logging
    
    23
    +
    
    24
    +from gi.repository import Gio, GLib
    
    25
    +
    
    26
    +from common import gajim
    
    27
    +
    
    28
    +log = logging.getLogger('gajim.network_watcher')
    
    29
    +
    
    30
    +
    
    31
    +supported = False
    
    32
    +
    
    33
    +
    
    34
    +def watch_name(name):
    
    35
    +    Gio.bus_watch_name(
    
    36
    +        Gio.BusType.SYSTEM,
    
    37
    +        name,
    
    38
    +        Gio.BusNameWatcherFlags.NONE,
    
    39
    +        appeared,
    
    40
    +        None)
    
    41
    +
    
    42
    +
    
    43
    +def signal_received(connection, sender_name, object_path,
    
    44
    +                    interface_name, signal_name, parameters, *user_data):
    
    45
    +    connected = None
    
    46
    +    log.info('Signal received: %s - %s', interface_name, parameters)
    
    47
    +    if interface_name == 'org.freedesktop.NetworkManager':
    
    48
    +        # https://people.freedesktop.org/~lkundrak/nm-docs/nm-dbus-types.html
    
    49
    +        connected = parameters[0] == 70
    
    50
    +    if connected is not None:
    
    51
    +        GLib.timeout_add_seconds(
    
    52
    +            2, update_connection_state,
    
    53
    +            connected)
    
    54
    +
    
    55
    +
    
    56
    +def appeared(connection, name, name_owner, *user_data):
    
    57
    +    global supported
    
    58
    +    supported = True
    
    59
    +    log.info('%s appeared', name)
    
    60
    +    if name == 'org.freedesktop.NetworkManager':
    
    61
    +        connection.signal_subscribe(
    
    62
    +            'org.freedesktop.NetworkManager',
    
    63
    +            None,
    
    64
    +            'StateChanged',
    
    65
    +            '/org/freedesktop/NetworkManager',
    
    66
    +            None,
    
    67
    +            Gio.DBusSignalFlags.NONE,
    
    68
    +            signal_received,
    
    69
    +            None)
    
    70
    +
    
    71
    +
    
    72
    +def update_connection_state(connected):
    
    73
    +    if connected:
    
    74
    +        for connection in gajim.connections.values():
    
    75
    +            log.info('Connect %s', connection.name)
    
    76
    +            connection.reconnect()
    
    77
    +    else:
    
    78
    +        for connection in gajim.connections.values():
    
    79
    +            if connection.connected > 1:
    
    80
    +                log.info('Disconnect %s', connection.name)
    
    81
    +                connection.disconnectedReconnCB()
    
    82
    +
    
    83
    +
    
    84
    +watch_name('org.freedesktop.NetworkManager')