From 5e788a543d2d3219549db403156ee5ffb54e92cc Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 30 Aug 2018 00:36:07 +0300 Subject: [PATCH] fixed messages caching and drag n drop --- toxygen/messenger/messages.py | 3 +-- toxygen/ui/main_screen.py | 2 +- toxygen/ui/main_screen_widgets.py | 15 ++++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/toxygen/messenger/messages.py b/toxygen/messenger/messages.py index d5882b8..e777c4b 100644 --- a/toxygen/messenger/messages.py +++ b/toxygen/messenger/messages.py @@ -66,8 +66,7 @@ class Message: message_id = property(get_message_id) def get_widget(self, *args): - if self._widget is None: - self._widget = self._create_widget(*args) + self._widget = self._create_widget(*args) return self._widget diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index c89f811..96b2b9e 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -37,7 +37,7 @@ class MainWindow(QtWidgets.QMainWindow): self._toxes = toxes self._messenger = messenger self._contacts_manager.active_contact_changed.add_callback(self._new_contact_selected) - self.messageEdit.set_dependencies(messenger, contacts_manager) + self.messageEdit.set_dependencies(messenger, contacts_manager, file_transfer_handler) self.update_gc_invites_button_state() diff --git a/toxygen/ui/main_screen_widgets.py b/toxygen/ui/main_screen_widgets.py index 8b7bf52..a2d7526 100644 --- a/toxygen/ui/main_screen_widgets.py +++ b/toxygen/ui/main_screen_widgets.py @@ -12,15 +12,16 @@ class MessageArea(QtWidgets.QPlainTextEdit): def __init__(self, parent, form): super().__init__(parent) - self._messenger = self._contacts_manager = None + self._messenger = self._contacts_manager = self._file_transfer_handler = None self.parent = form self.setAcceptDrops(True) self._timer = QtCore.QTimer(self) self._timer.timeout.connect(lambda: self._messenger.send_typing(False)) - def set_dependencies(self, messenger, contacts_manager): + def set_dependencies(self, messenger, contacts_manager, file_transfer_handler): self._messenger = messenger self._contacts_manager = contacts_manager + self._file_transfer_handler = file_transfer_handler def keyPressEvent(self, event): if event.matches(QtGui.QKeySequence.Paste): @@ -84,16 +85,20 @@ class MessageArea(QtWidgets.QPlainTextEdit): def pasteEvent(self, text=None): text = text or QtWidgets.QApplication.clipboard().text() if text.startswith('file://'): - file_name = self.parse_file_name(text) - self.parent.profile.send_file(file_name) + if not self._contacts_manager.is_active_a_friend(): + return + friend_number = self._contacts_manager.get_active_number() + file_path = self._parse_file_path(text) + self._file_transfer_handler.send_file(file_path, friend_number) else: self.insertPlainText(text) @staticmethod - def parse_file_name(file_name): + def _parse_file_path(file_name): if file_name.endswith('\r\n'): file_name = file_name[:-2] file_name = urllib.parse.unquote(file_name) + return file_name[8 if util.get_platform() == 'Windows' else 7:]