comparison frontends/src/quick_frontend/quick_app.py @ 1117:6053fb8a6466

quick_frontend: fixes an issue with the profile in the signal handler
author souliane <souliane@mailoo.org>
date Thu, 21 Aug 2014 22:46:57 +0200
parents a096b8579a3c
children 75025461141f
comparison
equal deleted inserted replaced
1116:ee450d7c88a7 1117:6053fb8a6466
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 import sys 21 import sys
22 from sat.core.log import getLogger 22 from sat.core.log import getLogger
23 log = getLogger(__name__) 23 log = getLogger(__name__)
24 from sat.tools.jid import JID 24 from sat.tools.jid import JID
25 from sat_frontends.bridge.DBus import DBusBridgeFrontend 25 from sat_frontends.bridge.DBus import DBusBridgeFrontend
26 from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError 26 from sat.core import exceptions
27 from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate 27 from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
28 from optparse import OptionParser 28 from optparse import OptionParser
29 29
30 from sat_frontends.quick_frontend.constants import Const as C 30 from sat_frontends.quick_frontend.constants import Const as C
31 31
39 self.check_options() 39 self.check_options()
40 40
41 ## bridge ## 41 ## bridge ##
42 try: 42 try:
43 self.bridge = DBusBridgeFrontend() 43 self.bridge = DBusBridgeFrontend()
44 except BridgeExceptionNoService: 44 except exceptions.BridgeExceptionNoService:
45 print(_(u"Can't connect to SàT backend, are you sure it's launched ?")) 45 print(_(u"Can't connect to SàT backend, are you sure it's launched ?"))
46 sys.exit(1) 46 sys.exit(1)
47 except BridgeInitError: 47 except exceptions.BridgeInitError:
48 print(_(u"Can't init bridge")) 48 print(_(u"Can't init bridge"))
49 sys.exit(1) 49 sys.exit(1)
50 self.registerSignal("connected") 50 self.registerSignal("connected")
51 self.registerSignal("disconnected") 51 self.registerSignal("disconnected")
52 self.registerSignal("newContact") 52 self.registerSignal("newContact")
86 86
87 self.current_action_ids = set() 87 self.current_action_ids = set()
88 self.current_action_ids_cb = {} 88 self.current_action_ids_cb = {}
89 self.media_dir = self.bridge.getConfig('', 'media_dir') 89 self.media_dir = self.bridge.getConfig('', 'media_dir')
90 90
91 def registerSignal(self, functionName, handler=None, iface="core"): 91 def registerSignal(self, functionName, handler=None, iface="core", with_profile=True):
92 """Register a handler for a signal 92 """Register a handler for a signal
93 93
94 @param functionName: name of the signal to handle 94 @param functionName (str): name of the signal to handle
95 @param handler: method to call when the signal arrive, None for calling an automaticaly named handler (functionName + 'Handler') 95 @param handler (instancemethod): method to call when the signal arrive, None for calling an automatically named handler (functionName + 'Handler')
96 @param iface: interface of the bridge to use 96 @param iface (str): interface of the bridge to use ('core' or 'plugin')
97 97 @param with_profile (boolean): True if the signal concerns a specific profile, in that case the profile name has to be passed by the caller
98 """ 98 """
99 if handler is None: 99 if handler is None:
100 handler = getattr(self, "%s%s" % (functionName, 'Handler')) 100 handler = getattr(self, "%s%s" % (functionName, 'Handler'))
101 if not with_profile:
102 self.bridge.register(functionName, handler, iface)
103 return
104
101 def signalReceived(*args, **kwargs): 105 def signalReceived(*args, **kwargs):
102 profile = kwargs.get('profile', None) 106 profile = kwargs.get('profile')
107 if profile is None:
108 if not args:
109 raise exceptions.ProfileNotSetError
110 profile = args[-1]
103 if profile is not None and not self.check_profile(profile): 111 if profile is not None and not self.check_profile(profile):
104 return # we ignore signal for profiles we don't manage 112 return # we ignore signal for profiles we don't manage
105 handler(*args, **kwargs) 113 handler(*args, **kwargs)
106 self.bridge.register(functionName, signalReceived, iface) 114 self.bridge.register(functionName, signalReceived, iface)
107 115
108 def check_profile(self, profile): 116 def check_profile(self, profile):
109 """Tell if the profile is currently followed by the application""" 117 """Tell if the profile is currently followed by the application"""
563 self.contact_list.replace(jid) 571 self.contact_list.replace(jid)
564 572
565 def askConfirmationHandler(self, confirm_id, confirm_type, data, profile): 573 def askConfirmationHandler(self, confirm_id, confirm_type, data, profile):
566 raise NotImplementedError 574 raise NotImplementedError
567 575
568 def actionResultHandler(self, type, id, data): 576 def actionResultHandler(self, type, id, data, profile):
569 raise NotImplementedError 577 raise NotImplementedError
570 578
571 def launchAction(self, callback_id, data=None, profile_key="@NONE@"): 579 def launchAction(self, callback_id, data=None, profile_key="@NONE@"):
572 """ Launch a dynamic action 580 """ Launch a dynamic action
573 @param callback_id: id of the action to launch 581 @param callback_id: id of the action to launch