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
This commit is contained in:
parent
49437fd9c3
commit
fa38394401
6 changed files with 570 additions and 400 deletions
|
|
@ -75,8 +75,8 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
def callMenu(self, category, name, menu_type, profile_key):
|
||||
return unicode(self.db_core_iface.callMenu(category, name, menu_type, profile_key))
|
||||
|
||||
def confirmationAnswer(self, id, accepted, data):
|
||||
return self.db_core_iface.confirmationAnswer(id, accepted, data)
|
||||
def confirmationAnswer(self, id, accepted, data, profile):
|
||||
return self.db_core_iface.confirmationAnswer(id, accepted, data, profile)
|
||||
|
||||
def connect(self, profile_key="@DEFAULT@"):
|
||||
return self.db_core_iface.connect(profile_key)
|
||||
|
|
@ -105,8 +105,8 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
def getEntityData(self, jid, keys, profile):
|
||||
return self.db_core_iface.getEntityData(jid, keys, profile)
|
||||
|
||||
def getHistory(self, from_jid, to_jid, limit, between=True, callback=None, errback=None):
|
||||
return self.db_core_iface.getHistory(from_jid, to_jid, limit, between, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
|
||||
def getHistory(self, from_jid, to_jid, limit, between=True, profile="@NONE@", callback=None, errback=None):
|
||||
return self.db_core_iface.getHistory(from_jid, to_jid, limit, between, profile, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
|
||||
|
||||
def getLastResource(self, contact_jid, profile_key="@DEFAULT@"):
|
||||
return unicode(self.db_core_iface.getLastResource(contact_jid, profile_key))
|
||||
|
|
@ -141,8 +141,8 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
def getProfilesList(self, ):
|
||||
return self.db_core_iface.getProfilesList()
|
||||
|
||||
def getProgress(self, id):
|
||||
return self.db_core_iface.getProgress(id)
|
||||
def getProgress(self, id, profile):
|
||||
return self.db_core_iface.getProgress(id, profile)
|
||||
|
||||
def getVersion(self, ):
|
||||
return unicode(self.db_core_iface.getVersion())
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ import sys
|
|||
import os
|
||||
from os.path import abspath, basename, dirname
|
||||
from optparse import OptionParser
|
||||
import pdb
|
||||
from sat.tools.jid import JID
|
||||
import gobject
|
||||
from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService
|
||||
|
|
@ -79,7 +78,7 @@ class JP():
|
|||
print(_(u"Can't connect to SàT backend, are you sure it's launched ?"))
|
||||
import sys
|
||||
sys.exit(1)
|
||||
self.transfer_id = None
|
||||
self.transfer_data = None
|
||||
|
||||
def check_options(self):
|
||||
"""Check command line options"""
|
||||
|
|
@ -242,7 +241,7 @@ class JP():
|
|||
|
||||
for file in self.files:
|
||||
if not os.path.exists(file):
|
||||
error (_("File [%s] doesn't exist !") % file)
|
||||
error (_(u"File [%s] doesn't exist !") % file)
|
||||
exit(1)
|
||||
if not self.options.bz2 and os.path.isdir(file):
|
||||
error (_("[%s] is a dir ! Please send files inside or use compression") % file)
|
||||
|
|
@ -265,11 +264,11 @@ class JP():
|
|||
bz2.close()
|
||||
info(_("OK !"))
|
||||
path = abspath(tmpfile)
|
||||
self.transfer_id = self.bridge.sendFile(full_dest_jid, path, {}, profile_key=self.profile)
|
||||
self.transfer_data = self.bridge.sendFile(full_dest_jid, path, {}, profile_key=self.profile)
|
||||
else:
|
||||
for file in self.files:
|
||||
path = abspath(file)
|
||||
self.transfer_id = self.bridge.sendFile(full_dest_jid, path, {}, profile_key=self.profile) #FIXME: show progress only for last transfer_id
|
||||
self.transfer_data = self.bridge.sendFile(full_dest_jid, path, {}, profile_key=self.profile) #FIXME: show progress only for last transfer_id
|
||||
|
||||
|
||||
def _getFullJid(self, param_jid):
|
||||
|
|
@ -283,8 +282,11 @@ class JP():
|
|||
return param_jid
|
||||
|
||||
|
||||
def askConfirmation(self, type, id, data):
|
||||
def askConfirmation(self, type, confirm_id, data, profile):
|
||||
"""CB used for file transfer, accept files depending on parameters"""
|
||||
if profile != self.profile:
|
||||
debug("Ask confirmation ignored: not our profile")
|
||||
return
|
||||
answer_data={}
|
||||
if type == "FILE_TRANSFER":
|
||||
if not self.options.wait_file:
|
||||
|
|
@ -295,11 +297,11 @@ class JP():
|
|||
answer_data["dest_path"] = os.getcwd()+'/'+data['filename']
|
||||
|
||||
if self.options.force or not os.path.exists(answer_data["dest_path"]):
|
||||
self.bridge.confirmationAnswer(id, True, answer_data)
|
||||
self.bridge.confirmationAnswer(confirm_id, True, answer_data, profile)
|
||||
info(_("Accepted file [%(filename)s] from %(sender)s") % {'filename':data['filename'], 'sender':data['from']})
|
||||
self.transfer_id = id
|
||||
self.transfer_data = confirm_id
|
||||
else:
|
||||
self.bridge.confirmationAnswer(id, False, answer_data)
|
||||
self.bridge.confirmationAnswer(confirm_id, False, answer_data, profile)
|
||||
warning(_("Refused file [%(filename)s] from %(sender)s: a file with the same name already exist") % {'filename':data['filename'], 'sender':data['from']})
|
||||
|
||||
|
||||
|
|
@ -316,14 +318,14 @@ class JP():
|
|||
fifopath = os.path.join(tmp_dir,"pipe_in")
|
||||
answer_data["dest_path"] = fifopath
|
||||
os.mkfifo(fifopath)
|
||||
self.bridge.confirmationAnswer(id, True, answer_data)
|
||||
self.bridge.confirmationAnswer(confirm_id, True, answer_data, profile)
|
||||
with open(fifopath, 'r') as f:
|
||||
shutil.copyfileobj(f, sys.stdout)
|
||||
shutil.rmtree(tmp_dir)
|
||||
self.loop.quit()
|
||||
|
||||
|
||||
def actionResult(self, type, id, data):
|
||||
def actionResult(self, action_type, action_id, data, profile):
|
||||
#FIXME
|
||||
info (_("FIXME: actionResult not implemented"))
|
||||
|
||||
|
|
@ -332,8 +334,9 @@ class JP():
|
|||
self.bridge.register("askConfirmation", self.askConfirmation)
|
||||
|
||||
def progressCB(self):
|
||||
if self.transfer_id:
|
||||
data = self.bridge.getProgress(self.transfer_id)
|
||||
if self.transfer_data:
|
||||
transfer_id = self.transfer_data
|
||||
data = self.bridge.getProgress(transfer_id, self.profile)
|
||||
if data:
|
||||
if not data['position']:
|
||||
data['position'] = '0'
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
import urwid
|
||||
from urwid_satext import sat_widgets
|
||||
from sat.tools.jid import JID
|
||||
|
||||
|
||||
class Progress(urwid.WidgetWrap):
|
||||
|
|
@ -38,47 +37,48 @@ class Progress(urwid.WidgetWrap):
|
|||
main_wid = sat_widgets.FocusFrame(listbox, footer=buttons_wid)
|
||||
urwid.WidgetWrap.__init__(self, main_wid)
|
||||
|
||||
def addProgress(self, id, message):
|
||||
def addProgress(self, progress_id, message):
|
||||
profile = self.host.profile # TODO: manage multiple profiles
|
||||
mess_wid = urwid.Text(message)
|
||||
progr_wid = urwid.ProgressBar('progress_normal', 'progress_complete')
|
||||
column = urwid.Columns([mess_wid, progr_wid])
|
||||
self.progress_dict[id] = {'full':column,'progress':progr_wid,'state':'init'}
|
||||
self.progress_dict[(progress_id, profile)] = {'full':column,'progress':progr_wid,'state':'init'}
|
||||
self.progress_list.append(column)
|
||||
self.progressCB(self.host.loop, (id, message))
|
||||
self.progressCB(self.host.loop, (progress_id, message, profile))
|
||||
|
||||
def progressCB(self, loop, data):
|
||||
id, message = data
|
||||
data = self.host.bridge.getProgress(id)
|
||||
pbar = self.progress_dict[id]['progress']
|
||||
progress_id, message, profile = data
|
||||
data = self.host.bridge.getProgress(progress_id, profile)
|
||||
pbar = self.progress_dict[(progress_id, profile)]['progress'] #FIXME: must manage profiles
|
||||
if data:
|
||||
if self.progress_dict[id]['state'] == 'init':
|
||||
if self.progress_dict[(progress_id, profile)]['state'] == 'init':
|
||||
#first answer, we must construct the bar
|
||||
self.progress_dict[id]['state'] = 'progress'
|
||||
self.progress_dict[(progress_id, profile)]['state'] = 'progress'
|
||||
pbar.done = float(data['size'])
|
||||
|
||||
pbar.set_completion(float(data['position']))
|
||||
self.updateNotBar()
|
||||
else:
|
||||
if self.progress_dict[id]['state'] == 'progress':
|
||||
self.progress_dict[id]['state'] = 'done'
|
||||
if self.progress_dict[(progress_id, profile)]['state'] == 'progress':
|
||||
self.progress_dict[(progress_id, profile)]['state'] = 'done'
|
||||
pbar.set_completion(pbar.done)
|
||||
self.updateNotBar()
|
||||
return
|
||||
|
||||
loop.set_alarm_in(1,self.progressCB, (id, message))
|
||||
loop.set_alarm_in(1,self.progressCB, (progress_id, message, profile))
|
||||
|
||||
def __removeBar(self, id):
|
||||
wid = self.progress_dict[id]['full']
|
||||
def __removeBar(self, progress_id, profile):
|
||||
wid = self.progress_dict[(progress_id, profile)]['full']
|
||||
self.progress_list.remove(wid)
|
||||
del(self.progress_dict[id])
|
||||
del(self.progress_dict[(progress_id, profile)])
|
||||
|
||||
def __onClear(self, button):
|
||||
to_remove = []
|
||||
for id in self.progress_dict:
|
||||
if self.progress_dict[id]['state'] == 'done':
|
||||
to_remove.append(id)
|
||||
for id in to_remove:
|
||||
self.__removeBar(id)
|
||||
for progress_id, profile in self.progress_dict:
|
||||
if self.progress_dict[(progress_id, profile)]['state'] == 'done':
|
||||
to_remove.append((progress_id, profile))
|
||||
for progress_id, profile in to_remove:
|
||||
self.__removeBar(progress_id, profile)
|
||||
self.updateNotBar()
|
||||
|
||||
def updateNotBar(self):
|
||||
|
|
@ -87,8 +87,8 @@ class Progress(urwid.WidgetWrap):
|
|||
return
|
||||
progress = 0
|
||||
nb_bars = 0
|
||||
for id in self.progress_dict:
|
||||
pbar = self.progress_dict[id]['progress']
|
||||
for progress_id, profile in self.progress_dict:
|
||||
pbar = self.progress_dict[(progress_id, profile)]['progress']
|
||||
progress += pbar.current/pbar.done*100
|
||||
nb_bars+=1
|
||||
av_progress = progress/float(nb_bars)
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class QuickApp(object):
|
|||
self.options.profile = self.options.profile.decode('utf-8')
|
||||
return args
|
||||
|
||||
def _getParamError(self):
|
||||
def _getParamError(self, ignore):
|
||||
error(_("Can't get profile parameter"))
|
||||
|
||||
def plug_profile(self, profile_key='@DEFAULT@'):
|
||||
|
|
@ -546,7 +546,7 @@ class QuickApp(object):
|
|||
self.contact_list.setCache(jid, 'avatar', filename)
|
||||
self.contact_list.replace(jid)
|
||||
|
||||
def askConfirmation(self, type, id, data):
|
||||
def askConfirmation(self, type, id, data, profile):
|
||||
raise NotImplementedError
|
||||
|
||||
def actionResult(self, type, id, data):
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ class Chat(wx.Frame, QuickChat):
|
|||
else:
|
||||
full_jid = self.target
|
||||
id = self.host.bridge.sendFile(full_jid, filename, {}, self.host.profile)
|
||||
self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename))
|
||||
self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename), self.host.profile)
|
||||
|
||||
def onStartTarot(self, e):
|
||||
debug (_("Starting Tarot game"))
|
||||
|
|
|
|||
|
|
@ -223,11 +223,13 @@ class MainWindow(wx.Frame, QuickApp):
|
|||
self.tools.Disable()
|
||||
return
|
||||
|
||||
def askConfirmation(self, type, id, data):
|
||||
def askConfirmation(self, confirmation_type, confirmation_id, data, profile):
|
||||
#TODO: refactor this in QuickApp
|
||||
if not self.check_profile(profile):
|
||||
return
|
||||
debug (_("Confirmation asked"))
|
||||
answer_data={}
|
||||
if type == "FILE_TRANSFER":
|
||||
if confirmation_type == "FILE_TRANSFER":
|
||||
debug (_("File transfer confirmation asked"))
|
||||
dlg = wx.MessageDialog(self, _("The contact %(jid)s wants to send you the file %(filename)s\nDo you accept ?") % {'jid':data["from"], 'filename':data["filename"]},
|
||||
_('File Request'),
|
||||
|
|
@ -238,16 +240,16 @@ class MainWindow(wx.Frame, QuickApp):
|
|||
filename = wx.FileSelector(_("Where do you want to save the file ?"), flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
|
||||
if filename:
|
||||
answer_data["dest_path"] = filename
|
||||
self.bridge.confirmationAnswer(id, True, answer_data)
|
||||
self.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename))
|
||||
self.bridge.confirmationAnswer(confirmation_id, True, answer_data, profile)
|
||||
self.waitProgress(confirmation_id, _("File Transfer"), _("Copying %s") % os.path.basename(filename), profile)
|
||||
else:
|
||||
answer = wx.ID_NO
|
||||
if answer==wx.ID_NO:
|
||||
self.bridge.confirmationAnswer(id, False, answer_data)
|
||||
self.bridge.confirmationAnswer(confirmation_id, False, answer_data, profile)
|
||||
|
||||
dlg.Destroy()
|
||||
|
||||
elif type == "YES/NO":
|
||||
elif confirmation_type == "YES/NO":
|
||||
debug (_("Yes/No confirmation asked"))
|
||||
dlg = wx.MessageDialog(self, data["message"],
|
||||
_('Confirmation'),
|
||||
|
|
@ -255,13 +257,15 @@ class MainWindow(wx.Frame, QuickApp):
|
|||
)
|
||||
answer=dlg.ShowModal()
|
||||
if answer==wx.ID_YES:
|
||||
self.bridge.confirmationAnswer(id, True, {})
|
||||
self.bridge.confirmationAnswer(confirmation_id, True, {}, profile)
|
||||
if answer==wx.ID_NO:
|
||||
self.bridge.confirmationAnswer(id, False, {})
|
||||
self.bridge.confirmationAnswer(confirmation_id, False, {}, profile)
|
||||
|
||||
dlg.Destroy()
|
||||
|
||||
def actionResult(self, type, id, data):
|
||||
def actionResult(self, type, id, data, profile):
|
||||
if not self.check_profile(profile):
|
||||
return
|
||||
debug (_("actionResult: type = [%(type)s] id = [%(id)s] data = [%(data)s]") % {'type':type, 'id':id, 'data':data})
|
||||
if not id in self.current_action_ids:
|
||||
debug (_('unknown id, ignoring'))
|
||||
|
|
@ -313,8 +317,8 @@ class MainWindow(wx.Frame, QuickApp):
|
|||
|
||||
|
||||
|
||||
def progressCB(self, id, title, message):
|
||||
data = self.bridge.getProgress(id)
|
||||
def progressCB(self, progress_id, title, message, profile):
|
||||
data = self.bridge.getProgress(progress_id, profile)
|
||||
if data:
|
||||
if not self.pbar:
|
||||
#first answer, we must construct the bar
|
||||
|
|
@ -327,11 +331,11 @@ class MainWindow(wx.Frame, QuickApp):
|
|||
self.pbar.Update(self.pbar.finish_value)
|
||||
return
|
||||
|
||||
wx.CallLater(10, self.progressCB, id, title, message)
|
||||
wx.CallLater(10, self.progressCB, progress_id, title, message, profile)
|
||||
|
||||
def waitProgress (self, id, title, message):
|
||||
def waitProgress (self, progress_id, title, message, profile):
|
||||
self.pbar = None
|
||||
wx.CallLater(10, self.progressCB, id, title, message)
|
||||
wx.CallLater(10, self.progressCB, progress_id, title, message, profile)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue