This commit is contained in:
N0\A
2025-10-24 19:16:16 +02:00
parent 9b20fa745e
commit 25eaad1491
2 changed files with 60 additions and 2 deletions

View File

@@ -43,7 +43,7 @@ class DuktoProtocol:
self.on_receive_request: Optional[Callable[[str, int, int], bool]] = None self.on_receive_request: Optional[Callable[[str, int, int], bool]] = None
self.on_receive_start: Optional[Callable[[str], None]] = None self.on_receive_start: Optional[Callable[[str], None]] = None
self.on_receive_complete: Optional[Callable[[List[str], int], None]] = None self.on_receive_complete: Optional[Callable[[List[str], int], None]] = None
self.on_receive_text: Optional[Callable[[str, int], None]] = None self.on_receive_text: Optional[Callable[[str, str, int], None]] = None
self.on_send_complete: Optional[Callable[[List[str]], None]] = None self.on_send_complete: Optional[Callable[[List[str]], None]] = None
self.on_transfer_progress: Optional[Callable[[int, int], None]] = None self.on_transfer_progress: Optional[Callable[[int, int], None]] = None
self.on_error: Optional[Callable[[str], None]] = None self.on_error: Optional[Callable[[str], None]] = None
@@ -322,7 +322,7 @@ class DuktoProtocol:
if receiving_text: if receiving_text:
text = text_data.decode('utf-8') text = text_data.decode('utf-8')
if self.on_receive_text: if self.on_receive_text:
self.on_receive_text(text, total_size) self.on_receive_text(sender_ip, text, total_size)
else: else:
if self.on_receive_complete: if self.on_receive_complete:
self.on_receive_complete(received_files, total_size) self.on_receive_complete(received_files, total_size)

58
main.py
View File

@@ -346,6 +346,50 @@ class ReceiveConfirmationDialog(QtWidgets.QDialog):
self.setLayout(layout) self.setLayout(layout)
class ShowTextDialog(QtWidgets.QDialog):
def __init__(self, text, sender_ip, parent=None):
super().__init__(parent)
self.setWindowTitle("Received Text")
self.setMinimumSize(400, 300)
layout = QtWidgets.QVBoxLayout()
# Info label
info_label = QtWidgets.QLabel(f"Received text from {sender_ip}:")
layout.addWidget(info_label)
# Text display
self.text_edit = QtWidgets.QTextEdit()
self.text_edit.setPlainText(text)
self.text_edit.setReadOnly(True)
layout.addWidget(self.text_edit)
# Buttons
button_layout = QtWidgets.QHBoxLayout()
self.copy_button = QtWidgets.QPushButton("Copy to Clipboard")
self.copy_button.clicked.connect(self.copy_to_clipboard)
close_button = QtWidgets.QPushButton("Close")
close_button.clicked.connect(self.accept)
button_layout.addStretch()
button_layout.addWidget(self.copy_button)
button_layout.addWidget(close_button)
layout.addLayout(button_layout)
self.setLayout(layout)
def copy_to_clipboard(self):
clipboard = QtWidgets.QApplication.clipboard()
clipboard.setText(self.text_edit.toPlainText())
self.copy_button.setText("Copied!")
timer = QtCore.QTimer(self)
timer.setSingleShot(True)
timer.timeout.connect(lambda: self.copy_button.setText("Copy to Clipboard"))
timer.start(2000)
class MainWindow(QtWidgets.QMainWindow): class MainWindow(QtWidgets.QMainWindow):
show_menu_signal = QtCore.Signal() show_menu_signal = QtCore.Signal()
@@ -376,6 +420,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.super_menu = super_menu self.super_menu = super_menu
self.dukto_handler = dukto_handler self.dukto_handler = dukto_handler
self.dukto_handler.on_receive_request = self.handle_receive_request self.dukto_handler.on_receive_request = self.handle_receive_request
self.dukto_handler.on_receive_text = self.handle_receive_text
self.receive_confirmation_event = threading.Event() self.receive_confirmation_event = threading.Event()
self.receive_confirmation_result = [False] self.receive_confirmation_result = [False]
@@ -573,6 +618,19 @@ class MainWindow(QtWidgets.QMainWindow):
self.receive_confirmation_event.wait() self.receive_confirmation_event.wait()
return self.receive_confirmation_result[0] return self.receive_confirmation_result[0]
@QtCore.Slot(str, str, int)
def show_text_dialog(self, sender_ip, text, total_size):
dialog = ShowTextDialog(text, sender_ip, self)
dialog.exec()
def handle_receive_text(self, sender_ip, text, total_size):
QtCore.QMetaObject.invokeMethod(
self, "show_text_dialog", QtCore.Qt.QueuedConnection, #type: ignore
QtCore.Q_ARG(str, sender_ip),
QtCore.Q_ARG(str, text),
QtCore.Q_ARG(int, total_size),
)
def restart_application(self): def restart_application(self):
presence.end() presence.end()
self.dukto_handler.shutdown() self.dukto_handler.shutdown()