Port Network Watcher to Gio API
This commit is contained in:
parent
fe3a5a4aee
commit
1840ff235e
|
@ -193,7 +193,6 @@ class Config:
|
||||||
'always_english_wikipedia': [opt_bool, False],
|
'always_english_wikipedia': [opt_bool, False],
|
||||||
'always_english_wiktionary': [opt_bool, True],
|
'always_english_wiktionary': [opt_bool, True],
|
||||||
'remote_control': [opt_bool, False, _('If checked, Gajim can be controlled remotely using gajim-remote.'), True],
|
'remote_control': [opt_bool, False, _('If checked, Gajim can be controlled remotely using gajim-remote.'), True],
|
||||||
'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],
|
|
||||||
'outgoing_chat_state_notifications': [opt_str, 'all', _('Sent chat state notifications. Can be one of all, composing_only, disabled.')],
|
'outgoing_chat_state_notifications': [opt_str, 'all', _('Sent chat state notifications. Can be one of all, composing_only, disabled.')],
|
||||||
'displayed_chat_state_notifications': [opt_str, 'all', _('Displayed chat state notifications in chat windows. Can be one of all, composing_only, disabled.')],
|
'displayed_chat_state_notifications': [opt_str, 'all', _('Displayed chat state notifications in chat windows. Can be one of all, composing_only, disabled.')],
|
||||||
'autodetect_browser_mailer': [opt_bool, True, '', True],
|
'autodetect_browser_mailer': [opt_bool, True, '', True],
|
||||||
|
@ -387,7 +386,6 @@ class Config:
|
||||||
'msgwin-y-position': [opt_int, -1], # Default is to let the wm decide
|
'msgwin-y-position': [opt_int, -1], # Default is to let the wm decide
|
||||||
'msgwin-width': [opt_int, 480],
|
'msgwin-width': [opt_int, 480],
|
||||||
'msgwin-height': [opt_int, 440],
|
'msgwin-height': [opt_int, 440],
|
||||||
'listen_to_network_manager': [opt_bool, True],
|
|
||||||
'is_zeroconf': [opt_bool, False],
|
'is_zeroconf': [opt_bool, False],
|
||||||
'last_status': [opt_str, 'online'],
|
'last_status': [opt_str, 'online'],
|
||||||
'last_status_msg': [opt_str, ''],
|
'last_status_msg': [opt_str, ''],
|
||||||
|
|
|
@ -61,9 +61,9 @@ 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-manager'): (self.network_manager_available,
|
_('Network-Watcher'): (self.network_watcher_available,
|
||||||
_('Autodetection of network status.'),
|
_('Autodetection of network status.'),
|
||||||
_('Requires gnome-network-manager and python-dbus.'),
|
_('Requires gnome-network-manager'),
|
||||||
_('Feature not available under Windows.')),
|
_('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.'),
|
||||||
|
@ -178,11 +178,9 @@ class FeaturesWindow:
|
||||||
def gpg_available(self):
|
def gpg_available(self):
|
||||||
return gajim.HAVE_GPG
|
return gajim.HAVE_GPG
|
||||||
|
|
||||||
def network_manager_available(self):
|
def network_watcher_available(self):
|
||||||
if os.name == 'nt':
|
import network_watcher
|
||||||
return False
|
return network_watcher.supported
|
||||||
import network_manager_listener
|
|
||||||
return network_manager_listener.supported
|
|
||||||
|
|
||||||
def some_keyring_available(self):
|
def some_keyring_available(self):
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
|
|
|
@ -2966,9 +2966,7 @@ class Interface:
|
||||||
|
|
||||||
self.remote_ctrl = None
|
self.remote_ctrl = None
|
||||||
|
|
||||||
if gajim.config.get('networkmanager_support') and \
|
import network_watcher
|
||||||
dbus_support.supported:
|
|
||||||
import network_manager_listener
|
|
||||||
|
|
||||||
if dbus_support.supported:
|
if dbus_support.supported:
|
||||||
import upower_listener
|
import upower_listener
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
## src/network_manager_listener.py
|
|
||||||
##
|
|
||||||
## Copyright (C) 2006 Jeffrey C. Ollie <jeff AT ocjtech.us>
|
|
||||||
## Nikos Kouremenos <kourem AT gmail.com>
|
|
||||||
## Stefan Bethge <stefan AT lanpartei.de>
|
|
||||||
## Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
||||||
##
|
|
||||||
## This file is part of Gajim.
|
|
||||||
##
|
|
||||||
## Gajim is free software; you can redistribute it and/or modify
|
|
||||||
## it under the terms of the GNU General Public License as published
|
|
||||||
## by the Free Software Foundation; version 3 only.
|
|
||||||
##
|
|
||||||
## Gajim is distributed in the hope that it will be useful,
|
|
||||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
## GNU General Public License for more details.
|
|
||||||
##
|
|
||||||
## You should have received a copy of the GNU General Public License
|
|
||||||
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
##
|
|
||||||
|
|
||||||
from common import gajim
|
|
||||||
|
|
||||||
|
|
||||||
def device_now_active(self, *args):
|
|
||||||
"""
|
|
||||||
For Network Manager 0.6
|
|
||||||
"""
|
|
||||||
for connection in gajim.connections.values():
|
|
||||||
if gajim.config.get_per('accounts', connection.name,
|
|
||||||
'listen_to_network_manager') and connection.time_to_reconnect:
|
|
||||||
connection._reconnect()
|
|
||||||
|
|
||||||
def device_no_longer_active(self, *args):
|
|
||||||
"""
|
|
||||||
For Network Manager 0.6
|
|
||||||
"""
|
|
||||||
for connection in gajim.connections.values():
|
|
||||||
if gajim.config.get_per('accounts', connection.name,
|
|
||||||
'listen_to_network_manager') and connection.connected > 1:
|
|
||||||
connection._disconnectedReconnCB()
|
|
||||||
|
|
||||||
def state_changed(state):
|
|
||||||
"""
|
|
||||||
For Network Manager 0.7 - 0.9
|
|
||||||
"""
|
|
||||||
if state == 70:
|
|
||||||
for connection in gajim.connections.values():
|
|
||||||
if gajim.config.get_per('accounts', connection.name,
|
|
||||||
'listen_to_network_manager') and connection.time_to_reconnect:
|
|
||||||
connection._reconnect()
|
|
||||||
else:
|
|
||||||
for connection in gajim.connections.values():
|
|
||||||
if gajim.config.get_per('accounts', connection.name,
|
|
||||||
'listen_to_network_manager') and connection.connected > 1:
|
|
||||||
connection._disconnectedReconnCB()
|
|
||||||
|
|
||||||
supported = False
|
|
||||||
|
|
||||||
from common import dbus_support
|
|
||||||
|
|
||||||
if dbus_support.supported:
|
|
||||||
import dbus
|
|
||||||
|
|
||||||
try:
|
|
||||||
from common.dbus_support import system_bus
|
|
||||||
|
|
||||||
bus = system_bus.bus()
|
|
||||||
|
|
||||||
if 'org.freedesktop.NetworkManager' in bus.list_names():
|
|
||||||
nm_object = bus.get_object('org.freedesktop.NetworkManager',
|
|
||||||
'/org/freedesktop/NetworkManager')
|
|
||||||
props = dbus.Interface(nm_object, "org.freedesktop.DBus.Properties")
|
|
||||||
bus.add_signal_receiver(state_changed,
|
|
||||||
'StateChanged',
|
|
||||||
'org.freedesktop.NetworkManager',
|
|
||||||
'org.freedesktop.NetworkManager',
|
|
||||||
'/org/freedesktop/NetworkManager')
|
|
||||||
supported = True
|
|
||||||
|
|
||||||
except dbus.DBusException:
|
|
||||||
try:
|
|
||||||
if 'org.freedesktop.NetworkManager' in bus.list_names():
|
|
||||||
supported = True
|
|
||||||
|
|
||||||
bus.add_signal_receiver(device_no_longer_active,
|
|
||||||
'DeviceNoLongerActive',
|
|
||||||
'org.freedesktop.NetworkManager',
|
|
||||||
'org.freedesktop.NetworkManager',
|
|
||||||
'/org/freedesktop/NetworkManager')
|
|
||||||
|
|
||||||
bus.add_signal_receiver(device_now_active,
|
|
||||||
'DeviceNowActive',
|
|
||||||
'org.freedesktop.NetworkManager',
|
|
||||||
'org.freedesktop.NetworkManager',
|
|
||||||
'/org/freedesktop/NetworkManager')
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
## src/network_watcher.py
|
||||||
|
##
|
||||||
|
## Copyright (C) 2017 Philipp Hoerist <philipp AT hoerist.com>
|
||||||
|
##
|
||||||
|
## This file is part of Gajim.
|
||||||
|
##
|
||||||
|
## Gajim is free software; you can redistribute it and/or modify
|
||||||
|
## it under the terms of the GNU General Public License as published
|
||||||
|
## by the Free Software Foundation; version 3 only.
|
||||||
|
##
|
||||||
|
## Gajim is distributed in the hope that it will be useful,
|
||||||
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
## GNU General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from gi.repository import Gio, GLib
|
||||||
|
|
||||||
|
from common import gajim
|
||||||
|
|
||||||
|
log = logging.getLogger('gajim.network_watcher')
|
||||||
|
|
||||||
|
|
||||||
|
supported = False
|
||||||
|
|
||||||
|
|
||||||
|
def watch_name(name):
|
||||||
|
Gio.bus_watch_name(
|
||||||
|
Gio.BusType.SYSTEM,
|
||||||
|
name,
|
||||||
|
Gio.BusNameWatcherFlags.NONE,
|
||||||
|
appeared,
|
||||||
|
None)
|
||||||
|
|
||||||
|
|
||||||
|
def signal_received(connection, sender_name, object_path,
|
||||||
|
interface_name, signal_name, parameters, *user_data):
|
||||||
|
connected = None
|
||||||
|
log.info('Signal received: %s - %s', interface_name, parameters)
|
||||||
|
if interface_name == 'org.freedesktop.NetworkManager':
|
||||||
|
# https://people.freedesktop.org/~lkundrak/nm-docs/nm-dbus-types.html
|
||||||
|
connected = parameters[0] == 70
|
||||||
|
if connected is not None:
|
||||||
|
GLib.timeout_add_seconds(
|
||||||
|
2, update_connection_state,
|
||||||
|
connected)
|
||||||
|
|
||||||
|
|
||||||
|
def appeared(connection, name, name_owner, *user_data):
|
||||||
|
global supported
|
||||||
|
supported = True
|
||||||
|
log.info('%s appeared', name)
|
||||||
|
if name == 'org.freedesktop.NetworkManager':
|
||||||
|
connection.signal_subscribe(
|
||||||
|
'org.freedesktop.NetworkManager',
|
||||||
|
None,
|
||||||
|
'StateChanged',
|
||||||
|
'/org/freedesktop/NetworkManager',
|
||||||
|
None,
|
||||||
|
Gio.DBusSignalFlags.NONE,
|
||||||
|
signal_received,
|
||||||
|
None)
|
||||||
|
|
||||||
|
|
||||||
|
def update_connection_state(connected):
|
||||||
|
if connected:
|
||||||
|
for connection in gajim.connections.values():
|
||||||
|
log.info('Connect %s', connection.name)
|
||||||
|
connection.reconnect()
|
||||||
|
else:
|
||||||
|
for connection in gajim.connections.values():
|
||||||
|
if connection.connected > 1:
|
||||||
|
log.info('Disconnect %s', connection.name)
|
||||||
|
connection.disconnectedReconnCB()
|
||||||
|
|
||||||
|
|
||||||
|
watch_name('org.freedesktop.NetworkManager')
|
Loading…
Reference in New Issue