# HG changeset patch # User Goffi # Date 1352921835 -3600 # Node ID 3eeb6c865e4ded164c7eee34960da52e86a9f4fb # Parent 8b116fa42a3195f894ed148d94f678efcb0a4999 frontends: incoming files transfer management: - quick app: getWaitingConf is used on profile connexion - primitivus: askConfirmation is now managed, use new 'dir' style of FileDialog diff -r 8b116fa42a31 -r 3eeb6c865e4d frontends/src/bridge/DBus.py --- a/frontends/src/bridge/DBus.py Wed Nov 14 20:24:28 2012 +0100 +++ b/frontends/src/bridge/DBus.py Wed Nov 14 20:37:15 2012 +0100 @@ -147,6 +147,9 @@ 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) diff -r 8b116fa42a31 -r 3eeb6c865e4d frontends/src/jp/jp --- a/frontends/src/jp/jp Wed Nov 14 20:24:28 2012 +0100 +++ b/frontends/src/jp/jp Wed Nov 14 20:37:15 2012 +0100 @@ -282,13 +282,13 @@ 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 @@ 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 @@ 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: diff -r 8b116fa42a31 -r 3eeb6c865e4d frontends/src/primitivus/chat.py --- a/frontends/src/primitivus/chat.py Wed Nov 14 20:24:28 2012 +0100 +++ b/frontends/src/primitivus/chat.py Wed Nov 14 20:37:15 2012 +0100 @@ -327,5 +327,5 @@ 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) diff -r 8b116fa42a31 -r 3eeb6c865e4d frontends/src/primitivus/primitivus --- a/frontends/src/primitivus/primitivus Wed Nov 14 20:24:28 2012 +0100 +++ b/frontends/src/primitivus/primitivus Wed Nov 14 20:37:15 2012 +0100 @@ -22,8 +22,10 @@ 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 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 @@ #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')) diff -r 8b116fa42a31 -r 3eeb6c865e4d frontends/src/quick_frontend/quick_app.py --- a/frontends/src/quick_frontend/quick_app.py Wed Nov 14 20:24:28 2012 +0100 +++ b/frontends/src/quick_frontend/quick_app.py Wed Nov 14 20:37:15 2012 +0100 @@ -147,6 +147,10 @@ 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 @@ 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 @@ 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): diff -r 8b116fa42a31 -r 3eeb6c865e4d frontends/src/quick_frontend/quick_utils.py --- a/frontends/src/quick_frontend/quick_utils.py Wed Nov 14 20:24:28 2012 +0100 +++ b/frontends/src/quick_frontend/quick_utils.py Wed Nov 14 20:37:15 2012 +0100 @@ -20,6 +20,7 @@ """ from sat.tools.jid import JID +from os.path import exists, splitext def escapePrivate(ori_jid): """Escape a private jid""" @@ -31,3 +32,16 @@ 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 + diff -r 8b116fa42a31 -r 3eeb6c865e4d frontends/src/wix/main_window.py --- a/frontends/src/wix/main_window.py Wed Nov 14 20:24:28 2012 +0100 +++ b/frontends/src/wix/main_window.py Wed Nov 14 20:37:15 2012 +0100 @@ -223,7 +223,7 @@ 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