frontends: incoming files transfer management:
- quick app: getWaitingConf is used on profile connexion
- primitivus: askConfirmation is now managed, use new 'dir' style of FileDialog
This commit is contained in:
parent
75bb00a0d4
commit
297b439369
7 changed files with 73 additions and 11 deletions
|
|
@ -147,6 +147,9 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
def getVersion(self, ):
|
||||
return unicode(self.db_core_iface.getVersion())
|
||||
|
||||
def getWaitingConf(self, profile_key):
|
||||
return self.db_core_iface.getWaitingConf(profile_key)
|
||||
|
||||
def getWaitingSub(self, profile_key="@DEFAULT@"):
|
||||
return self.db_core_iface.getWaitingSub(profile_key)
|
||||
|
||||
|
|
|
|||
|
|
@ -282,13 +282,13 @@ class JP():
|
|||
return param_jid
|
||||
|
||||
|
||||
def askConfirmation(self, type, confirm_id, data, profile):
|
||||
def askConfirmation(self, confirm_id, confirm_type, 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 confirm_type == "FILE_TRANSFER":
|
||||
if not self.options.wait_file:
|
||||
return
|
||||
if self.dest_jids and not JID(data['from']).short in [JID(_jid).short for _jid in self.dest_jids]:
|
||||
|
|
@ -308,7 +308,7 @@ class JP():
|
|||
if not self.options.multiple and not self.options.progress:
|
||||
#we just accept one file
|
||||
self.loop.quit()
|
||||
elif type == "PIPE_TRANSFER":
|
||||
elif confirm_type == "PIPE_TRANSFER":
|
||||
if not self.options.pipe_in:
|
||||
return
|
||||
if self.dest_jids and not JID(data['from']).short in [JID(_jid).short for _jid in self.dest_jids]:
|
||||
|
|
@ -331,7 +331,12 @@ class JP():
|
|||
|
||||
def confirmation_reply(self):
|
||||
"""Auto reply to confirmations requests"""
|
||||
#we register incoming confirmation
|
||||
self.bridge.register("askConfirmation", self.askConfirmation)
|
||||
|
||||
#and we ask those we have missed
|
||||
for confirm_id, confirm_type, data in self.bridge.getWaitingConf(self.profile):
|
||||
self.askConfirmation(confirm_id, confirm_type, data, self.profile)
|
||||
|
||||
def progressCB(self):
|
||||
if self.transfer_data:
|
||||
|
|
|
|||
|
|
@ -327,5 +327,5 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
|||
full_jid = JID("%s/%s" % (self.target.short, last_resource))
|
||||
else:
|
||||
full_jid = self.target
|
||||
id = self.host.bridge.sendFile(full_jid, filepath, {}, self.host.profile)
|
||||
self.host.addProgress(id,filepath)
|
||||
progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.host.profile)
|
||||
self.host.addProgress(progress_id,filepath)
|
||||
|
|
|
|||
|
|
@ -22,8 +22,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
import urwid
|
||||
from urwid_satext import sat_widgets
|
||||
from urwid_satext.files_management import FileDialog
|
||||
from sat_frontends.quick_frontend.quick_app import QuickApp
|
||||
from sat_frontends.quick_frontend.quick_chat_list import QuickChatList
|
||||
from sat_frontends.quick_frontend.quick_utils import getNewPath
|
||||
from sat_frontends.primitivus.profile_manager import ProfileManager
|
||||
from sat_frontends.primitivus.contact_list import ContactList
|
||||
from sat_frontends.primitivus.chat import Chat
|
||||
|
|
@ -35,6 +37,7 @@ import sat_frontends.primitivus.constants
|
|||
import logging
|
||||
from logging import debug, info, error
|
||||
from sat.tools.jid import JID
|
||||
from os.path import join
|
||||
|
||||
|
||||
### logging configuration FIXME: put this elsewhere ###
|
||||
|
|
@ -394,6 +397,38 @@ class PrimitivusApp(QuickApp):
|
|||
#No notification left, we can hide the bar
|
||||
self.main_widget.footer = self.editBar
|
||||
|
||||
def askConfirmation(self, confirmation_id, confirmation_type, data, profile):
|
||||
if not self.check_profile(profile):
|
||||
return
|
||||
answer_data={}
|
||||
|
||||
def dir_selected_cb(path):
|
||||
dest_path = join(path, data['filename'])
|
||||
answer_data["dest_path"] = getNewPath(dest_path)
|
||||
self.addProgress(confirmation_id, dest_path)
|
||||
accept_cb(None)
|
||||
|
||||
def accept_file_transfer_cb(widget):
|
||||
self.removePopUp()
|
||||
pop_up_widget = FileDialog(dir_selected_cb, refuse_cb, title=_(u"Where do you want to save the file ?"), style=['dir'])
|
||||
self.showPopUp(pop_up_widget)
|
||||
|
||||
def accept_cb(widget):
|
||||
self.removePopUp()
|
||||
self.bridge.confirmationAnswer(confirmation_id, True, answer_data, profile)
|
||||
|
||||
def refuse_cb(widget):
|
||||
self.removePopUp()
|
||||
self.bridge.confirmationAnswer(confirmation_id, False, answer_data, profile)
|
||||
|
||||
if confirmation_type == "FILE_TRANSFER":
|
||||
pop_up_widget = sat_widgets.ConfirmDialog(_("The contact %(jid)s wants to send you the file %(filename)s\nDo you accept ?") % {'jid':data["from"], 'filename':data["filename"]}, no_cb=refuse_cb, yes_cb=accept_file_transfer_cb)
|
||||
self.showPopUp(pop_up_widget)
|
||||
|
||||
elif confirmation_type == "YES/NO":
|
||||
pop_up_widget = sat_widgets.ConfirmDialog(data["message"], no_cb=refuse_cb, yes_cb=accept_cb)
|
||||
self.showPopUp(pop_up_widget)
|
||||
|
||||
def actionResult(self, type, id, data):
|
||||
if not id in self.current_action_ids:
|
||||
debug (_('unknown id, ignoring'))
|
||||
|
|
|
|||
|
|
@ -147,6 +147,10 @@ class QuickApp(object):
|
|||
callback=lambda watched: self.plug_profile_4(watched, autoconnect, profile), errback=self._getParamError)
|
||||
|
||||
def plug_profile_4(self, watched, autoconnect, profile):
|
||||
if autoconnect and not self.bridge.isConnected(profile):
|
||||
#Does the user want autoconnection ?
|
||||
self.bridge.connect(profile)
|
||||
|
||||
self.profiles[profile]['watched'] = watched.split() #TODO: put this in a plugin
|
||||
|
||||
## misc ##
|
||||
|
|
@ -186,10 +190,11 @@ class QuickApp(object):
|
|||
|
||||
for subject_args in self.bridge.getRoomsSubjects(profile):
|
||||
self.roomNewSubject(*subject_args, profile=profile)
|
||||
|
||||
if autoconnect and not self.bridge.isConnected(profile):
|
||||
#Does the user want autoconnection ?
|
||||
self.bridge.connect(profile)
|
||||
|
||||
#Finaly, we get the waiting confirmation requests
|
||||
for confirm_id, confirm_type, data in self.bridge.getWaitingConf(profile):
|
||||
self.askConfirmation(confirm_id, confirm_type, data, profile)
|
||||
|
||||
|
||||
|
||||
def unplug_profile(self, profile):
|
||||
|
|
@ -546,7 +551,7 @@ class QuickApp(object):
|
|||
self.contact_list.setCache(jid, 'avatar', filename)
|
||||
self.contact_list.replace(jid)
|
||||
|
||||
def askConfirmation(self, type, id, data, profile):
|
||||
def askConfirmation(self, confirm_id, confirm_type, data, profile):
|
||||
raise NotImplementedError
|
||||
|
||||
def actionResult(self, type, id, data):
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
from sat.tools.jid import JID
|
||||
from os.path import exists, splitext
|
||||
|
||||
def escapePrivate(ori_jid):
|
||||
"""Escape a private jid"""
|
||||
|
|
@ -31,3 +32,16 @@ def unescapePrivate(escaped_jid):
|
|||
escaped_split = tuple(escaped_jid[len(const_PRIVATE_PREFIX):].split('@'))
|
||||
assert(len(escaped_split) == 3)
|
||||
return JID("%s@%s/%s" % escaped_split)
|
||||
|
||||
def getNewPath(path):
|
||||
""" Check if path exists, and find a non existant path if needed """
|
||||
idx = 2
|
||||
if not exists(path):
|
||||
return path
|
||||
root, ext = splitext(path)
|
||||
while True:
|
||||
new_path = "%s_%d%s" % (root, idx, ext)
|
||||
if not exists(new_path):
|
||||
return new_path
|
||||
idx+=1
|
||||
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ class MainWindow(wx.Frame, QuickApp):
|
|||
self.tools.Disable()
|
||||
return
|
||||
|
||||
def askConfirmation(self, confirmation_type, confirmation_id, data, profile):
|
||||
def askConfirmation(self, confirmation_id, confirmation_type, data, profile):
|
||||
#TODO: refactor this in QuickApp
|
||||
if not self.check_profile(profile):
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in a new issue