fixed messages caching and drag n drop
This commit is contained in:
parent
a4ceeccfd8
commit
5e788a543d
3 changed files with 12 additions and 8 deletions
|
@ -66,7 +66,6 @@ class Message:
|
||||||
message_id = property(get_message_id)
|
message_id = property(get_message_id)
|
||||||
|
|
||||||
def get_widget(self, *args):
|
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
|
return self._widget
|
||||||
|
|
|
@ -37,7 +37,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
self._toxes = toxes
|
self._toxes = toxes
|
||||||
self._messenger = messenger
|
self._messenger = messenger
|
||||||
self._contacts_manager.active_contact_changed.add_callback(self._new_contact_selected)
|
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()
|
self.update_gc_invites_button_state()
|
||||||
|
|
||||||
|
|
|
@ -12,15 +12,16 @@ class MessageArea(QtWidgets.QPlainTextEdit):
|
||||||
|
|
||||||
def __init__(self, parent, form):
|
def __init__(self, parent, form):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._messenger = self._contacts_manager = None
|
self._messenger = self._contacts_manager = self._file_transfer_handler = None
|
||||||
self.parent = form
|
self.parent = form
|
||||||
self.setAcceptDrops(True)
|
self.setAcceptDrops(True)
|
||||||
self._timer = QtCore.QTimer(self)
|
self._timer = QtCore.QTimer(self)
|
||||||
self._timer.timeout.connect(lambda: self._messenger.send_typing(False))
|
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._messenger = messenger
|
||||||
self._contacts_manager = contacts_manager
|
self._contacts_manager = contacts_manager
|
||||||
|
self._file_transfer_handler = file_transfer_handler
|
||||||
|
|
||||||
def keyPressEvent(self, event):
|
def keyPressEvent(self, event):
|
||||||
if event.matches(QtGui.QKeySequence.Paste):
|
if event.matches(QtGui.QKeySequence.Paste):
|
||||||
|
@ -84,16 +85,20 @@ class MessageArea(QtWidgets.QPlainTextEdit):
|
||||||
def pasteEvent(self, text=None):
|
def pasteEvent(self, text=None):
|
||||||
text = text or QtWidgets.QApplication.clipboard().text()
|
text = text or QtWidgets.QApplication.clipboard().text()
|
||||||
if text.startswith('file://'):
|
if text.startswith('file://'):
|
||||||
file_name = self.parse_file_name(text)
|
if not self._contacts_manager.is_active_a_friend():
|
||||||
self.parent.profile.send_file(file_name)
|
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:
|
else:
|
||||||
self.insertPlainText(text)
|
self.insertPlainText(text)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_file_name(file_name):
|
def _parse_file_path(file_name):
|
||||||
if file_name.endswith('\r\n'):
|
if file_name.endswith('\r\n'):
|
||||||
file_name = file_name[:-2]
|
file_name = file_name[:-2]
|
||||||
file_name = urllib.parse.unquote(file_name)
|
file_name = urllib.parse.unquote(file_name)
|
||||||
|
|
||||||
return file_name[8 if util.get_platform() == 'Windows' else 7:]
|
return file_name[8 if util.get_platform() == 'Windows' else 7:]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue