Author: sb Date: 2006-10-21 02:49:30 +0200 (Sat, 21 Oct 2006) New Revision: 7305
Modified: trunk/src/common/config.py trunk/src/common/dbus_support.py trunk/src/gajim.py trunk/src/network_manager_listener.py trunk/src/roster_window.py Log: fix #860, add patch from <jeff at ocjtech.us>, add per account options, (options are in ACE only)
Modified: trunk/src/common/config.py =================================================================== --- trunk/src/common/config.py 2006-10-20 23:19:57 UTC (rev 7304) +++ trunk/src/common/config.py 2006-10-21 00:49:30 UTC (rev 7305) @@ -151,6 +151,7 @@ 'always_english_wikipedia': [opt_bool, False], 'always_english_wiktionary': [opt_bool, True], 'remote_control': [opt_bool, True, _('If checked, Gajim can be controlled remotely using gajim-remote.'), True], + 'networkmanager_support': [opt_bool, True, _('If checked, listen for DBus signals from NetworkManager and change the status of your Jabber connections based upon the status of your network connection.'), True], 'chat_state_notifications': [opt_str, 'all'], # 'all', 'composing_only', 'disabled' 'autodetect_browser_mailer': [opt_bool, False, '', True], 'print_ichat_every_foo_minutes': [opt_int, 5, _('When not printing time for every message (print_time==sometimes), print it every x minutes.')], @@ -263,6 +264,7 @@ 'msgwin-y-position': [opt_int, -1], # Default is to let the wm decide 'msgwin-width': [opt_int, 480], 'msgwin-height': [opt_int, 440], + 'listen_to_network_manager' : [opt_bool, True], 'is_zeroconf': [opt_bool, False], 'zeroconf_first_name': [ opt_str, '', '', True ], 'zeroconf_last_name': [ opt_str, '', '', True ],
Modified: trunk/src/common/dbus_support.py =================================================================== --- trunk/src/common/dbus_support.py 2006-10-20 23:19:57 UTC (rev 7304) +++ trunk/src/common/dbus_support.py 2006-10-21 00:49:30 UTC (rev 7305) @@ -34,6 +34,37 @@ print _('D-Bus python bindings are missing in this computer') print _('D-Bus capabilities of Gajim cannot be used')
+class SystemBus: + '''A Singleton for the DBus SystemBus''' + def __init__(self): + self.system_bus = None + + def SystemBus(self): + if not supported: + raise exceptions.DbusNotSupported + + if not self.present(): + raise exceptions.SystemBusNotPresent + return self.system_bus + + def bus(self): + return self.SystemBus() + + def present(self): + if not supported: + return False + if self.system_bus is None: + try: + self.system_bus = dbus.SystemBus() + except dbus.dbus_bindings.DBusException: + self.system_bus = None + return False + if self.system_bus is None: + return False + return True + +system_bus = SystemBus() + class SessionBus: '''A Singleton for the D-Bus SessionBus''' def __init__(self):
Modified: trunk/src/gajim.py =================================================================== --- trunk/src/gajim.py 2006-10-20 23:19:57 UTC (rev 7304) +++ trunk/src/gajim.py 2006-10-21 00:49:30 UTC (rev 7305) @@ -1430,7 +1430,8 @@ status = gajim.connections[account].status gajim.connections[account].username = new_name gajim.connections[account].change_status(status, '') - + else: + gajim.connections[account].change_status('offline','')
def read_sleepy(self): '''Check idle status and change that status if needed''' @@ -1937,6 +1938,12 @@ else: self.remote_ctrl = None
+ if gajim.config.get('networkmanager_support'): + try: + import network_manager_listener + except ImportError: + pass + self.show_vcard_when_connect = []
path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps/gajim.png')
Modified: trunk/src/network_manager_listener.py =================================================================== --- trunk/src/network_manager_listener.py 2006-10-20 23:19:57 UTC (rev 7304) +++ trunk/src/network_manager_listener.py 2006-10-21 00:49:30 UTC (rev 7305) @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- ## network_manager_listener.py +## Copyright (C) 2006 Jeffrey C. Ollie <jeff at ocjtech.us> +## Copyright (C) 2006 Stefan Bethge <stefan at lanpartei.de> ## -## 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. @@ -13,22 +13,35 @@ ## GNU General Public License for more details. ##
+from common import gajim + +def device_now_active(self, *args): + for connection in gajim.connections.itervalues(): + if gajim.config.get_per('accounts', connection.name, 'listen_to_network_manager'): + connection.change_status('online', '') + +def device_no_longer_active(self, *args): + for connection in gajim.connections.itervalues(): + if gajim.config.get_per('accounts', connection.name, 'listen_to_network_manager'): + connection.change_status('offline', '') + + +from common.dbus_support import system_bus + import dbus import dbus.glib
-NM_OBJ_PATH = '/org/freedesktop/NetworkManager' -NM_INTERFACE = 'org.freedesktop.NetworkManager' -NM_SERVICE = 'org.freedesktop.NetworkManager' +bus = system_bus.SystemBus()
-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) +bus.add_signal_receiver(device_no_longer_active, + 'DeviceNoLongerActive', + 'org.freedesktop.NetworkManager', + 'org.freedesktop.NetworkManager', + '/org/freedesktop/NetworkManager')
- self._devices = self._nm_iface.getDevices() +bus.add_signal_receiver(device_now_active, + 'DeviceNowActive', + 'org.freedesktop.NetworkManager', + 'org.freedesktop.NetworkManager', + '/org/freedesktop/NetworkManager')
- self._nm_iface.connect_to_signal('DeviceNowActive', - nm_activated_CB) - self._nm_iface.connect_to_signal('DeviceNoLongerActive', - nm_deactivated_CB)
Modified: trunk/src/roster_window.py =================================================================== --- trunk/src/roster_window.py 2006-10-20 23:19:57 UTC (rev 7304) +++ trunk/src/roster_window.py 2006-10-21 00:49:30 UTC (rev 7305) @@ -48,10 +48,6 @@ 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) @@ -3121,8 +3117,9 @@ gajim.last_message_time[account][ctrl.get_full_jid()] = 0 win.set_active_tab(fjid, account) if gajim.connections[account].is_zeroconf and \ - gajim.connections[account].status in ('offline', 'invisible'): + gajim.connections[account].status in ('offline', 'invisible') win.get_control(fjid, account).got_disconnected() + win.window.present()
def on_roster_treeview_row_activated(self, widget, path, col = 0): @@ -4176,18 +4173,3 @@ if len(gajim.connections) == 0: # if we have no account gajim.interface.instances['account_creation_wizard'] = \ config.AccountCreationWizardWindow() - - try: - nm_listener = NetworkManagerListener(self.nm_activated_CB, - self.nm_deactivated_CB) - except: - print >> sys.stderr, _('Network Manager support not available') - - 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', '') -