comparison frontends/src/jp/jp @ 538:2c4016921403

core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles - added profile argument to askConfirmation, actionResult, actionResultExt, entityDataUpdated, confirmationAnswer, getProgress - core, frontends: fixed calls/signals according to new bridge API - user of proper profile namespace for progression indicators and dialogs - memory: getParam* now return bool when param type is bool - memory: added getStringParam* to return string instead of typed value - core, memory, storage, quick_frontend: getHistory now manage properly multi-profiles - plugins XEP-0047, XEP-0054, XEP-0065, XEP-0077, XEP-0096; multi-profiles proper handling
author Goffi <goffi@goffi.org>
date Sat, 10 Nov 2012 16:38:16 +0100
parents b7c4bb2c0668
children 3eeb6c865e4d
comparison
equal deleted inserted replaced
537:28cddc96c4ed 538:2c4016921403
51 51
52 import sys 52 import sys
53 import os 53 import os
54 from os.path import abspath, basename, dirname 54 from os.path import abspath, basename, dirname
55 from optparse import OptionParser 55 from optparse import OptionParser
56 import pdb
57 from sat.tools.jid import JID 56 from sat.tools.jid import JID
58 import gobject 57 import gobject
59 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService 58 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService
60 import tarfile 59 import tarfile
61 import tempfile 60 import tempfile
77 self.bridge=DBusBridgeFrontend() 76 self.bridge=DBusBridgeFrontend()
78 except BridgeExceptionNoService: 77 except BridgeExceptionNoService:
79 print(_(u"Can't connect to SàT backend, are you sure it's launched ?")) 78 print(_(u"Can't connect to SàT backend, are you sure it's launched ?"))
80 import sys 79 import sys
81 sys.exit(1) 80 sys.exit(1)
82 self.transfer_id = None 81 self.transfer_data = None
83 82
84 def check_options(self): 83 def check_options(self):
85 """Check command line options""" 84 """Check command line options"""
86 usage=_(""" 85 usage=_("""
87 %prog [options] [FILE1 FILE2 ...] JID 86 %prog [options] [FILE1 FILE2 ...] JID
240 def send_files(self): 239 def send_files(self):
241 """Send files to jabber contact""" 240 """Send files to jabber contact"""
242 241
243 for file in self.files: 242 for file in self.files:
244 if not os.path.exists(file): 243 if not os.path.exists(file):
245 error (_("File [%s] doesn't exist !") % file) 244 error (_(u"File [%s] doesn't exist !") % file)
246 exit(1) 245 exit(1)
247 if not self.options.bz2 and os.path.isdir(file): 246 if not self.options.bz2 and os.path.isdir(file):
248 error (_("[%s] is a dir ! Please send files inside or use compression") % file) 247 error (_("[%s] is a dir ! Please send files inside or use compression") % file)
249 exit(1) 248 exit(1)
250 249
263 info(_("Adding %s"), file) 262 info(_("Adding %s"), file)
264 bz2.add(file) 263 bz2.add(file)
265 bz2.close() 264 bz2.close()
266 info(_("OK !")) 265 info(_("OK !"))
267 path = abspath(tmpfile) 266 path = abspath(tmpfile)
268 self.transfer_id = self.bridge.sendFile(full_dest_jid, path, {}, profile_key=self.profile) 267 self.transfer_data = self.bridge.sendFile(full_dest_jid, path, {}, profile_key=self.profile)
269 else: 268 else:
270 for file in self.files: 269 for file in self.files:
271 path = abspath(file) 270 path = abspath(file)
272 self.transfer_id = self.bridge.sendFile(full_dest_jid, path, {}, profile_key=self.profile) #FIXME: show progress only for last transfer_id 271 self.transfer_data = self.bridge.sendFile(full_dest_jid, path, {}, profile_key=self.profile) #FIXME: show progress only for last transfer_id
273 272
274 273
275 def _getFullJid(self, param_jid): 274 def _getFullJid(self, param_jid):
276 """Return the full jid if possible (add last resource when find a bare jid""" 275 """Return the full jid if possible (add last resource when find a bare jid"""
277 _jid = JID(param_jid) 276 _jid = JID(param_jid)
281 if last_resource: 280 if last_resource:
282 return "%s/%s" % (_jid.short, last_resource) 281 return "%s/%s" % (_jid.short, last_resource)
283 return param_jid 282 return param_jid
284 283
285 284
286 def askConfirmation(self, type, id, data): 285 def askConfirmation(self, type, confirm_id, data, profile):
287 """CB used for file transfer, accept files depending on parameters""" 286 """CB used for file transfer, accept files depending on parameters"""
287 if profile != self.profile:
288 debug("Ask confirmation ignored: not our profile")
289 return
288 answer_data={} 290 answer_data={}
289 if type == "FILE_TRANSFER": 291 if type == "FILE_TRANSFER":
290 if not self.options.wait_file: 292 if not self.options.wait_file:
291 return 293 return
292 if self.dest_jids and not JID(data['from']).short in [JID(_jid).short for _jid in self.dest_jids]: 294 if self.dest_jids and not JID(data['from']).short in [JID(_jid).short for _jid in self.dest_jids]:
293 return #file is not sent by a filtered jid 295 return #file is not sent by a filtered jid
294 296
295 answer_data["dest_path"] = os.getcwd()+'/'+data['filename'] 297 answer_data["dest_path"] = os.getcwd()+'/'+data['filename']
296 298
297 if self.options.force or not os.path.exists(answer_data["dest_path"]): 299 if self.options.force or not os.path.exists(answer_data["dest_path"]):
298 self.bridge.confirmationAnswer(id, True, answer_data) 300 self.bridge.confirmationAnswer(confirm_id, True, answer_data, profile)
299 info(_("Accepted file [%(filename)s] from %(sender)s") % {'filename':data['filename'], 'sender':data['from']}) 301 info(_("Accepted file [%(filename)s] from %(sender)s") % {'filename':data['filename'], 'sender':data['from']})
300 self.transfer_id = id 302 self.transfer_data = confirm_id
301 else: 303 else:
302 self.bridge.confirmationAnswer(id, False, answer_data) 304 self.bridge.confirmationAnswer(confirm_id, False, answer_data, profile)
303 warning(_("Refused file [%(filename)s] from %(sender)s: a file with the same name already exist") % {'filename':data['filename'], 'sender':data['from']}) 305 warning(_("Refused file [%(filename)s] from %(sender)s: a file with the same name already exist") % {'filename':data['filename'], 'sender':data['from']})
304 306
305 307
306 if not self.options.multiple and not self.options.progress: 308 if not self.options.multiple and not self.options.progress:
307 #we just accept one file 309 #we just accept one file
314 316
315 tmp_dir = tempfile.mkdtemp() 317 tmp_dir = tempfile.mkdtemp()
316 fifopath = os.path.join(tmp_dir,"pipe_in") 318 fifopath = os.path.join(tmp_dir,"pipe_in")
317 answer_data["dest_path"] = fifopath 319 answer_data["dest_path"] = fifopath
318 os.mkfifo(fifopath) 320 os.mkfifo(fifopath)
319 self.bridge.confirmationAnswer(id, True, answer_data) 321 self.bridge.confirmationAnswer(confirm_id, True, answer_data, profile)
320 with open(fifopath, 'r') as f: 322 with open(fifopath, 'r') as f:
321 shutil.copyfileobj(f, sys.stdout) 323 shutil.copyfileobj(f, sys.stdout)
322 shutil.rmtree(tmp_dir) 324 shutil.rmtree(tmp_dir)
323 self.loop.quit() 325 self.loop.quit()
324 326
325 327
326 def actionResult(self, type, id, data): 328 def actionResult(self, action_type, action_id, data, profile):
327 #FIXME 329 #FIXME
328 info (_("FIXME: actionResult not implemented")) 330 info (_("FIXME: actionResult not implemented"))
329 331
330 def confirmation_reply(self): 332 def confirmation_reply(self):
331 """Auto reply to confirmations requests""" 333 """Auto reply to confirmations requests"""
332 self.bridge.register("askConfirmation", self.askConfirmation) 334 self.bridge.register("askConfirmation", self.askConfirmation)
333 335
334 def progressCB(self): 336 def progressCB(self):
335 if self.transfer_id: 337 if self.transfer_data:
336 data = self.bridge.getProgress(self.transfer_id) 338 transfer_id = self.transfer_data
339 data = self.bridge.getProgress(transfer_id, self.profile)
337 if data: 340 if data:
338 if not data['position']: 341 if not data['position']:
339 data['position'] = '0' 342 data['position'] = '0'
340 if not self.pbar: 343 if not self.pbar:
341 #first answer, we must construct the bar 344 #first answer, we must construct the bar