2006-10-18 00:15:20 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## 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-2007 Yann Leboulanger <asterix AT lagaule.org>
|
2006-10-18 00:15:20 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2006-10-18 00:15:20 +02:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2006-10-18 00:15:20 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2006-10-18 00:15:20 +02:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2006-10-18 00:15:20 +02:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2006-10-18 00:15:20 +02:00
|
|
|
|
2007-11-14 20:47:52 +01:00
|
|
|
import sys
|
2006-10-21 02:49:30 +02:00
|
|
|
from common import gajim
|
|
|
|
|
2009-06-13 20:31:40 +02:00
|
|
|
|
2006-10-21 02:49:30 +02:00
|
|
|
def device_now_active(self, *args):
|
2009-02-14 11:07:31 +01:00
|
|
|
'''For Network Manager 0.6'''
|
2006-10-21 02:49:30 +02:00
|
|
|
for connection in gajim.connections.itervalues():
|
2006-12-26 15:56:28 +01:00
|
|
|
if gajim.config.get_per('accounts', connection.name,
|
|
|
|
'listen_to_network_manager') and connection.time_to_reconnect:
|
|
|
|
connection._reconnect()
|
2006-10-21 02:49:30 +02:00
|
|
|
|
|
|
|
def device_no_longer_active(self, *args):
|
2009-02-14 11:07:31 +01:00
|
|
|
'''For Network Manager 0.6'''
|
2006-10-21 02:49:30 +02:00
|
|
|
for connection in gajim.connections.itervalues():
|
2006-12-26 15:56:28 +01:00
|
|
|
if gajim.config.get_per('accounts', connection.name,
|
|
|
|
'listen_to_network_manager') and connection.connected > 1:
|
|
|
|
connection._disconnectedReconnCB()
|
2006-10-21 02:49:30 +02:00
|
|
|
|
2009-06-15 21:00:14 +02:00
|
|
|
def state_changed(state):
|
2009-02-14 11:07:31 +01:00
|
|
|
'''For Network Manager 0.7'''
|
2009-06-15 21:00:14 +02:00
|
|
|
if props.Get("org.freedesktop.NetworkManager", "State") == 3:
|
|
|
|
for connection in gajim.connections.itervalues():
|
|
|
|
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.itervalues():
|
|
|
|
if gajim.config.get_per('accounts', connection.name,
|
|
|
|
'listen_to_network_manager') and connection.connected > 1:
|
2009-02-14 11:07:31 +01:00
|
|
|
connection._disconnectedReconnCB()
|
|
|
|
|
2007-06-26 22:59:30 +02:00
|
|
|
supported = False
|
|
|
|
|
2009-06-13 20:31:40 +02:00
|
|
|
from common import dbus_support
|
|
|
|
|
2009-06-15 21:34:38 +02:00
|
|
|
if dbus_support.supported:
|
2009-06-13 20:31:40 +02:00
|
|
|
import dbus
|
|
|
|
import dbus.glib
|
2009-06-15 21:00:14 +02:00
|
|
|
|
|
|
|
try:
|
2007-11-14 20:47:52 +01:00
|
|
|
from common.dbus_support import system_bus
|
|
|
|
|
2009-02-14 11:07:31 +01:00
|
|
|
bus = system_bus.bus()
|
2007-11-14 20:47:52 +01:00
|
|
|
|
|
|
|
if 'org.freedesktop.NetworkManager' in bus.list_names():
|
2009-06-15 21:00:14 +02:00
|
|
|
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',
|
2009-02-14 11:07:31 +01:00
|
|
|
'/org/freedesktop/NetworkManager')
|
2007-11-14 20:47:52 +01:00
|
|
|
supported = True
|
2009-06-15 21:00:14 +02:00
|
|
|
|
2009-06-13 20:31:40 +02:00
|
|
|
except dbus.DBusException:
|
2009-02-14 11:07:31 +01:00
|
|
|
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
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2008-08-15 05:20:23 +02:00
|
|
|
# vim: se ts=3:
|