comparison frontends/src/quick_frontend/quick_app.py @ 414:f6f94e21c642

Quick frontend: use of asyncGetParamA when pluging profile
author Goffi <goffi@goffi.org>
date Tue, 01 Nov 2011 22:52:36 +0100
parents 10b4f577d0c0
children c243f4cb2ad9
comparison
equal deleted inserted replaced
413:dd4caab17008 414:f6f94e21c642
109 (self.options, args) = parser.parse_args() 109 (self.options, args) = parser.parse_args()
110 if self.options.profile: 110 if self.options.profile:
111 self.options.profile = self.options.profile.decode('utf-8') 111 self.options.profile = self.options.profile.decode('utf-8')
112 return args 112 return args
113 113
114 def _getParamError(self):
115 error(_("Can't get profile parameter"))
116
114 def plug_profile(self, profile_key='@DEFAULT@'): 117 def plug_profile(self, profile_key='@DEFAULT@'):
115 """Tell application which profile must be used""" 118 """Tell application which profile must be used"""
116 if self.single_profile and self.profiles: 119 if self.single_profile and self.profiles:
117 error(_('There is already one profile plugged (we are in single profile mode) !')) 120 error(_('There is already one profile plugged (we are in single profile mode) !'))
118 return 121 return
126 self.profiles[profile]={} 129 self.profiles[profile]={}
127 if self.single_profile: 130 if self.single_profile:
128 self.profile = profile 131 self.profile = profile
129 132
130 ###now we get the essential params### 133 ###now we get the essential params###
131 self.profiles[profile]['whoami']=JID(self.bridge.getParamA("JabberID","Connection", profile_key=profile)) 134 self.bridge.asyncGetParamA("JabberID","Connection", profile_key=profile,
132 autoconnect = self.bridge.getParamA("autoconnect","Connection", profile_key=profile) == "true" 135 callback=lambda _jid: self.plug_profile_2(_jid, profile), errback=self._getParamError)
133 self.profiles[profile]['watched']=self.bridge.getParamA("Watched", "Misc", profile_key=profile).split() #TODO: put this in a plugin 136
137 def plug_profile_2(self, _jid, profile):
138 self.profiles[profile]['whoami'] = JID(_jid)
139 self.bridge.asyncGetParamA("autoconnect","Connection", profile_key=profile,
140 callback=lambda value: self.plug_profile_3(value=="true", profile), errback=self._getParamError)
141
142 def plug_profile_3(self, autoconnect, profile):
143 self.bridge.asyncGetParamA("Watched", "Misc", profile_key=profile,
144 callback=lambda watched: self.plug_profile_4(watched, autoconnect, profile), errback=self._getParamError)
145
146 def plug_profile_4(self, watched, autoconnect, profile):
147 self.profiles[profile]['watched'] = watched.split() #TODO: put this in a plugin
134 148
135 ## misc ## 149 ## misc ##
136 self.profiles[profile]['onlineContact'] = set() #FIXME: temporary 150 self.profiles[profile]['onlineContact'] = set() #FIXME: temporary
137 151
138 #TODO: gof: manage multi-profiles here 152 #TODO: gof: manage multi-profiles here
164 self.roomJoined(*room_args, profile=profile) 178 self.roomJoined(*room_args, profile=profile)
165 179
166 for subject_args in self.bridge.getRoomsSubjectss(profile): 180 for subject_args in self.bridge.getRoomsSubjectss(profile):
167 self.roomNewSubject(*subject_args, profile=profile) 181 self.roomNewSubject(*subject_args, profile=profile)
168 182
169 if autoconnect and not self.bridge.isConnected(profile_key): 183 if autoconnect and not self.bridge.isConnected(profile):
170 #Does the user want autoconnection ? 184 #Does the user want autoconnection ?
171 self.bridge.connect(profile_key) 185 self.bridge.connect(profile)
172 186
173 187
174 def unplug_profile(self, profile): 188 def unplug_profile(self, profile):
175 """Tell the application to not follow anymore the profile""" 189 """Tell the application to not follow anymore the profile"""
176 if not profile in self.profiles: 190 if not profile in self.profiles:
507 521
508 def onExit(self): 522 def onExit(self):
509 """Must be called when the frontend is terminating""" 523 """Must be called when the frontend is terminating"""
510 #TODO: mange multi-profile here 524 #TODO: mange multi-profile here
511 try: 525 try:
512 autodisconnect = self.bridge.getParamA("autodisconnect","Connection", profile_key=self.profile) == "true" 526 if self.bridge.isConnected(self.profile):
513 if autodisconnect and self.bridge.isConnected(self.profile): 527 if self.bridge.getParamA("autodisconnect","Connection", profile_key=self.profile) == "true":
514 #Does the user want autodisconnection ? 528 #The user wants autodisconnection
515 self.bridge.disconnect(self.profile) 529 self.bridge.disconnect(self.profile)
516 except: 530 except:
517 pass 531 pass