Mercurial > libervia-desktop-kivy
comparison src/cagou/plugins/plugin_wid_chat.py @ 88:3dc526bb4a5a
upload: plugin android gallery, first draft:
- added "external" key in PLUGIN_INFO which indicate that a plugin doesn't create a widget when set to True
- callback and cancel_cb method in UploadMenu now use a cleaning_cb arguments which can be None. If set, the callback will be called without argument once the file is uploaded
- the AndroidGallery plugin looks for images on Android, then save the content to a temporary file an upload it, then clean the file. This plugin is only active on android platform.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 25 Dec 2016 22:53:50 +0100 |
parents | c711be670ecd |
children | 9a6121722669 |
comparison
equal
deleted
inserted
replaced
87:17094a075fd2 | 88:3dc526bb4a5a |
---|---|
594 ) | 594 ) |
595 input_widget.text = '' | 595 input_widget.text = '' |
596 | 596 |
597 def onProgressFinished(self, progress_id, metadata, profile): | 597 def onProgressFinished(self, progress_id, metadata, profile): |
598 try: | 598 try: |
599 callback = self._waiting_pids.pop(progress_id) | 599 callback, cleaning_cb = self._waiting_pids.pop(progress_id) |
600 except KeyError: | 600 except KeyError: |
601 return | 601 return |
602 if cleaning_cb is not None: | |
603 cleaning_cb() | |
602 callback(metadata, profile) | 604 callback(metadata, profile) |
603 | 605 |
604 def onProgressError(self, progress_id, err_msg, profile): | 606 def onProgressError(self, progress_id, err_msg, profile): |
605 try: | 607 try: |
606 del self._waiting_pids[progress_id] | 608 dummy, cleaning_cb = self._waiting_pids[progress_id] |
607 except KeyError: | 609 except KeyError: |
608 return | 610 return |
611 else: | |
612 del self._waiting_pids[progress_id] | |
613 if cleaning_cb is not None: | |
614 cleaning_cb() | |
609 # TODO: display message to user | 615 # TODO: display message to user |
610 log.warning(u"Can't upload file: {}".format(err_msg)) | 616 log.warning(u"Can't upload file: {}".format(err_msg)) |
611 | 617 |
612 def fileUploadDone(self, metadata, profile): | 618 def fileUploadDone(self, metadata, profile): |
613 log.debug("file uploaded: {}".format(metadata)) | 619 log.debug("file uploaded: {}".format(metadata)) |
616 {'': metadata['url']}, | 622 {'': metadata['url']}, |
617 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, | 623 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, |
618 profile_key=profile | 624 profile_key=profile |
619 ) | 625 ) |
620 | 626 |
621 def fileUploadCb(self, progress_data): | 627 def fileUploadCb(self, progress_data, cleaning_cb): |
622 try: | 628 try: |
623 progress_id = progress_data['progress'] | 629 progress_id = progress_data['progress'] |
624 except KeyError: | 630 except KeyError: |
625 xmlui = progress_data['xmlui'] | 631 xmlui = progress_data['xmlui'] |
626 G.host.showUI(xmlui) | 632 G.host.showUI(xmlui) |
627 else: | 633 else: |
628 self._waiting_pids[progress_id] = self.fileUploadDone | 634 self._waiting_pids[progress_id] = (self.fileUploadDone, cleaning_cb) |
629 | 635 |
630 def onUploadOK(self, file_path): | 636 def onUploadOK(self, file_path, cleaning_cb): |
631 G.host.bridge.fileUpload( | 637 G.host.bridge.fileUpload( |
632 file_path, | 638 file_path, |
633 "", | 639 "", |
634 "", | 640 "", |
635 {"ignore_tls_errors": C.BOOL_TRUE}, # FIXME: should not be the default | 641 {"ignore_tls_errors": C.BOOL_TRUE}, # FIXME: should not be the default |
636 self.profile, | 642 self.profile, |
637 callback = self.fileUploadCb | 643 callback = lambda progress_data: self.fileUploadCb(progress_data, cleaning_cb) |
638 ) | 644 ) |
639 | 645 |
640 def _mucJoinCb(self, joined_data): | 646 def _mucJoinCb(self, joined_data): |
641 joined, room_jid_s, occupants, user_nick, subject, profile = joined_data | 647 joined, room_jid_s, occupants, user_nick, subject, profile = joined_data |
642 self.host.mucRoomJoinedHandler(*joined_data[1:]) | 648 self.host.mucRoomJoinedHandler(*joined_data[1:]) |