Mercurial > libervia-desktop-kivy
comparison src/cagou/plugins/plugin_wid_chat.py @ 86:c711be670ecd
core, chat: upload plugin system:
- extented plugin system so it's not only used with main widget. It is also used for upload widgets and can be extended more
- plugin file name is used to detect the type: plugin_wid_* for main widgets, plugin_upload_* for upload widget plugins
- a new UploadMenu class allows to easily add an upload button which will use loaded plugins
- plugin_info can now specify a list of allowed platforms in "platforms" key
- file upload in chat has been moved to a plugin
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 25 Dec 2016 16:41:21 +0100 |
parents | 46d962910801 |
children | 3dc526bb4a5a |
comparison
equal
deleted
inserted
replaced
85:c2a7234d13d2 | 86:c711be670ecd |
---|---|
23 from sat.core.i18n import _ | 23 from sat.core.i18n import _ |
24 from cagou.core.constants import Const as C | 24 from cagou.core.constants import Const as C |
25 from kivy.uix.boxlayout import BoxLayout | 25 from kivy.uix.boxlayout import BoxLayout |
26 from kivy.uix.gridlayout import GridLayout | 26 from kivy.uix.gridlayout import GridLayout |
27 from kivy.uix.stacklayout import StackLayout | 27 from kivy.uix.stacklayout import StackLayout |
28 from kivy.uix.scrollview import ScrollView | |
29 from kivy.uix.textinput import TextInput | 28 from kivy.uix.textinput import TextInput |
30 from kivy.uix.label import Label | 29 from kivy.uix.label import Label |
31 from kivy.uix.image import AsyncImage | 30 from kivy.uix.image import AsyncImage |
32 from kivy.metrics import dp | 31 from kivy.metrics import dp |
33 from kivy.utils import escape_markup | 32 from kivy.utils import escape_markup |
546 | 545 |
547 class MessagesWidget(GridLayout): | 546 class MessagesWidget(GridLayout): |
548 pass | 547 pass |
549 | 548 |
550 | 549 |
551 class FileUploader(BoxLayout): | |
552 | |
553 def __init__(self, parent_chat, **kwargs): | |
554 self.parent_chat = parent_chat | |
555 super(FileUploader, self).__init__(orientation='vertical', **kwargs) | |
556 | |
557 | |
558 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): | 550 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): |
559 message_input = properties.ObjectProperty() | 551 message_input = properties.ObjectProperty() |
552 messages_widget = properties.ObjectProperty() | |
560 | 553 |
561 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None): | 554 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None): |
562 quick_chat.QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles) | 555 quick_chat.QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles) |
563 cagou_widget.CagouWidget.__init__(self) | 556 cagou_widget.CagouWidget.__init__(self) |
564 self.header_input.hint_text = u"{}".format(target) | 557 self.header_input.hint_text = u"{}".format(target) |
565 scroll_view = ScrollView(size_hint=(1,0.8), scroll_y=0, do_scroll_x=False) | |
566 self.messages_widget = MessagesWidget() | |
567 scroll_view.add_widget(self.messages_widget) | |
568 self.add_widget(scroll_view) | |
569 self.add_widget(MessageInputBox()) | |
570 self.host.addListener('progressError', self.onProgressError, profiles) | 558 self.host.addListener('progressError', self.onProgressError, profiles) |
571 self.host.addListener('progressFinished', self.onProgressFinished, profiles) | 559 self.host.addListener('progressFinished', self.onProgressFinished, profiles) |
572 self._waiting_pids = {} # waiting progress ids | 560 self._waiting_pids = {} # waiting progress ids |
573 self.postInit() | 561 self.postInit() |
574 | 562 |
619 except KeyError: | 607 except KeyError: |
620 return | 608 return |
621 # TODO: display message to user | 609 # TODO: display message to user |
622 log.warning(u"Can't upload file: {}".format(err_msg)) | 610 log.warning(u"Can't upload file: {}".format(err_msg)) |
623 | 611 |
624 def onUploadButton(self): | |
625 G.host.showExtraUI(FileUploader(self)) | |
626 | |
627 def fileUploadDone(self, metadata, profile): | 612 def fileUploadDone(self, metadata, profile): |
628 log.debug("file uploaded: {}".format(metadata)) | 613 log.debug("file uploaded: {}".format(metadata)) |
629 G.host.messageSend( | 614 G.host.messageSend( |
630 self.target, | 615 self.target, |
631 {'': metadata['url']}, | 616 {'': metadata['url']}, |
640 xmlui = progress_data['xmlui'] | 625 xmlui = progress_data['xmlui'] |
641 G.host.showUI(xmlui) | 626 G.host.showUI(xmlui) |
642 else: | 627 else: |
643 self._waiting_pids[progress_id] = self.fileUploadDone | 628 self._waiting_pids[progress_id] = self.fileUploadDone |
644 | 629 |
645 def onUploadOK(self, file_chooser): | 630 def onUploadOK(self, file_path): |
646 if file_chooser.selection: | 631 G.host.bridge.fileUpload( |
647 file_path = file_chooser.selection[0] | 632 file_path, |
648 G.host.bridge.fileUpload( | 633 "", |
649 file_path, | 634 "", |
650 "", | 635 {"ignore_tls_errors": C.BOOL_TRUE}, # FIXME: should not be the default |
651 "", | 636 self.profile, |
652 {"ignore_tls_errors": C.BOOL_TRUE}, # FIXME: should not be the default | 637 callback = self.fileUploadCb |
653 self.profile, | 638 ) |
654 callback = self.fileUploadCb | |
655 ) | |
656 G.host.closeUI() | |
657 | |
658 def onUploadCancel(self, file_chooser): | |
659 G.host.closeUI() | |
660 | 639 |
661 def _mucJoinCb(self, joined_data): | 640 def _mucJoinCb(self, joined_data): |
662 joined, room_jid_s, occupants, user_nick, subject, profile = joined_data | 641 joined, room_jid_s, occupants, user_nick, subject, profile = joined_data |
663 self.host.mucRoomJoinedHandler(*joined_data[1:]) | 642 self.host.mucRoomJoinedHandler(*joined_data[1:]) |
664 jid_ = jid.JID(room_jid_s) | 643 jid_ = jid.JID(room_jid_s) |