I saw that a patch for Network Manager support went into SVN today.  I
thought that I'd share the patch that I've been using for a while as
well...

Jeff
Index: src/gajim.py
===================================================================
--- src/gajim.py	(revision 7284)
+++ src/gajim.py	(working copy)
@@ -1930,6 +1930,12 @@
 		else:
 			self.remote_ctrl = None
 
+		if gajim.config.get('networkmanager_support'):
+			try:
+				import networkmanager_support
+			except:
+				pass
+			
 		self.show_vcard_when_connect = []
 
 		path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps/gajim.png')
Index: src/common/dbus_support.py
===================================================================
--- src/common/dbus_support.py	(revision 7284)
+++ src/common/dbus_support.py	(working copy)
@@ -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):
@@ -93,7 +124,6 @@
 		gajim.log.debug(str(e))
 		return None
 
-
 def get_notifications_interface():
 	'''Returns the notifications interface.'''
 	return get_interface('org.freedesktop.Notifications',
Index: src/common/config.py
===================================================================
--- src/common/config.py	(revision 7284)
+++ src/common/config.py	(working copy)
@@ -150,6 +150,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.')],
Index: src/networkmanager_support.py
===================================================================
--- src/networkmanager_support.py	(revision 0)
+++ src/networkmanager_support.py	(revision 0)
@@ -0,0 +1,32 @@
+
+from common import gajim
+
+def device_no_longer_active(self, *args):
+    print 'device_no_longer_active', args
+    count = 0
+    for connection in gajim.connections.itervalues():
+        connection.change_status('offline', 'Network disconnected...')
+	    
+def device_now_active(self, *args):
+    print 'device_now_active', args
+    for connection in gajim.connections.itervalues():
+        connection.change_status('online', 'Network connected...')
+
+from common.dbus_support import system_bus
+import dbus
+import dbus.glib
+import dbus.service
+
+bus = system_bus.SystemBus()
+    
+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')

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Gajim-devel mailing list
Gajim-devel@gajim.org
https://lists.gajim.org/cgi-bin/listinfo/gajim-devel

Reply via email to