add simple implementation of network manager awareness

(should find a better place) - see #860
This commit is contained in:
Stefan Bethge 2006-10-17 22:15:20 +00:00
parent f3b6fa94e9
commit 8cf6f4c7c2
2 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
## network_manager_listener.py
##
## Copyright (C) 2006 Stefan Bethge <stefan@lanpartei.de>
##
## This program 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 2 only.
##
## This program 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.
##
import dbus
import dbus.glib
NM_OBJ_PATH = "/org/freedesktop/NetworkManager"
NM_INTERFACE = "org.freedesktop.NetworkManager"
NM_SERVICE = "org.freedesktop.NetworkManager"
class NetworkManagerListener:
def __init__(self, nm_activated_CB, nm_deactivated_CB):
sys_bus = dbus.SystemBus()
proxy_obj = sys_bus.get_object(NM_SERVICE, NM_OBJ_PATH)
self._nm_iface = dbus.Interface(proxy_obj, NM_INTERFACE)
self._devices = self._nm_iface.getDevices()
self._nm_iface.connect_to_signal('DeviceNowActive', nm_activated_CB)
self._nm_iface.connect_to_signal('DeviceNoLongerActive', nm_deactivated_CB)

View File

@ -47,6 +47,10 @@ from common import dbus_support
if dbus_support.supported:
from music_track_listener import MusicTrackListener
from common import dbus_support
if dbus_support.supported:
from network_manager_listener import NetworkManagerListener
#(icon, name, type, jid, account, editable, second pixbuf)
(
C_IMG, # image to show state (online, new message etc)
@ -4169,3 +4173,13 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
gajim.interface.instances['account_creation_wizard'] = \
config.AccountCreationWizardWindow()
nm_listener = NetworkManagerListener(self.nm_activated_CB, self.nm_deactivated_CB)
def nm_activated_CB(self, dev, net):
for acc in gajim.contacts.get_accounts():
gajim.interface.roster.send_status(acc, 'online', '')
def nm_deactivated_CB(self, dev):
for acc in gajim.contacts.get_accounts():
gajim.interface.roster.send_status(acc, 'offline', '')