[kupfer: 19/20] gajim: +check for running gajim



commit 57581a3e86d1cb9105421a621daa6d00f9097867
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date:   Wed Oct 7 08:22:36 2009 +0200

    gajim: +check for running gajim
    
    Before get dbus object check is gajim running.
    Force start gajim on change global status (except change to 'offline')

 kupfer/plugin/gajim.py |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/kupfer/plugin/gajim.py b/kupfer/plugin/gajim.py
index 9e50d93..0e46e04 100644
--- a/kupfer/plugin/gajim.py
+++ b/kupfer/plugin/gajim.py
@@ -26,14 +26,20 @@ _STATUSES = {
 }
 
 
-def _create_dbus_connection():
-	''' Create dbus connection to Gajim '''
+def _create_dbus_connection(activate=False):
+	''' Create dbus connection to Gajim 
+		@activate: true=starts gajim if not running
+	'''
 	interface = None
 	sbus = dbus.SessionBus()
 	try:
-		obj = sbus.get_object('org.gajim.dbus', '/org/gajim/dbus/RemoteObject')
-		if obj:
-			interface = dbus.Interface(obj, 'org.gajim.dbus.RemoteInterface')
+		#check for running gajim (code from note.py)
+		proxy_obj = sbus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
+		dbus_iface = dbus.Interface(proxy_obj, 'org.freedesktop.DBus')
+		if activate or dbus_iface.NameHasOwner('org.gajim.dbus'):
+			obj = sbus.get_object('org.gajim.dbus', '/org/gajim/dbus/RemoteObject')
+			if obj:
+				interface = dbus.Interface(obj, 'org.gajim.dbus.RemoteInterface')
 
 	except dbus.exceptions.DBusException, err:
 		pretty.print_debug(err)
@@ -87,7 +93,7 @@ class ChangeStatus(Action):
 		Action.__init__(self, _('Change Gajim global Status...'))
 
 	def activate(self, leaf, iobj):
-		interface = _create_dbus_connection()
+		interface = _create_dbus_connection((iobj.object != 'offline'))
 		if interface:
 			interface.change_status(iobj.object, '', '')
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]