| 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-2007 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 | import sys |
|---|
| 25 | from common import gajim |
|---|
| 26 | |
|---|
| 27 | def device_now_active(self, *args): |
|---|
| 28 | for connection in gajim.connections.itervalues(): |
|---|
| 29 | if gajim.config.get_per('accounts', connection.name, |
|---|
| 30 | 'listen_to_network_manager') and connection.time_to_reconnect: |
|---|
| 31 | connection._reconnect() |
|---|
| 32 | |
|---|
| 33 | def device_no_longer_active(self, *args): |
|---|
| 34 | for connection in gajim.connections.itervalues(): |
|---|
| 35 | if gajim.config.get_per('accounts', connection.name, |
|---|
| 36 | 'listen_to_network_manager') and connection.connected > 1: |
|---|
| 37 | connection._disconnectedReconnCB() |
|---|
| 38 | |
|---|
| 39 | supported = False |
|---|
| 40 | |
|---|
| 41 | if sys.platform == 'darwin': |
|---|
| 42 | supported = True |
|---|
| 43 | else: |
|---|
| 44 | try: |
|---|
| 45 | from common.dbus_support import system_bus |
|---|
| 46 | |
|---|
| 47 | bus = system_bus.SystemBus() |
|---|
| 48 | |
|---|
| 49 | if 'org.freedesktop.NetworkManager' in bus.list_names(): |
|---|
| 50 | supported = True |
|---|
| 51 | bus.add_signal_receiver(device_no_longer_active, |
|---|
| 52 | 'DeviceNoLongerActive', |
|---|
| 53 | 'org.freedesktop.NetworkManager', |
|---|
| 54 | 'org.freedesktop.NetworkManager', |
|---|
| 55 | '/org/freedesktop/NetworkManager') |
|---|
| 56 | |
|---|
| 57 | bus.add_signal_receiver(device_now_active, |
|---|
| 58 | 'DeviceNowActive', |
|---|
| 59 | 'org.freedesktop.NetworkManager', |
|---|
| 60 | 'org.freedesktop.NetworkManager', |
|---|
| 61 | '/org/freedesktop/NetworkManager') |
|---|
| 62 | except Exception: |
|---|
| 63 | pass |
|---|
| 64 | |
|---|
| 65 | # vim: se ts=3: |
|---|