diff options
Diffstat (limited to 'desktop/src/onionshare/tab/mode/history.py')
-rw-r--r-- | desktop/src/onionshare/tab/mode/history.py | 88 |
1 files changed, 86 insertions, 2 deletions
diff --git a/desktop/src/onionshare/tab/mode/history.py b/desktop/src/onionshare/tab/mode/history.py index 45e37c75..091905f7 100644 --- a/desktop/src/onionshare/tab/mode/history.py +++ b/desktop/src/onionshare/tab/mode/history.py @@ -148,6 +148,7 @@ class ShareHistoryItem(HistoryItem): # Change the label self.label.setText(self.get_finished_label_text(self.started_dt)) + self.label.setStyleSheet(self.common.gui.css["history_default_label"]) self.status = HistoryItem.STATUS_FINISHED else: @@ -253,7 +254,7 @@ class ReceiveHistoryItemFile(QtWidgets.QWidget): try: # If nautilus is available, open it subprocess.Popen(["xdg-open", self.dir]) - except: + except Exception: Alert( self.common, strings._("gui_open_folder_error").format(abs_filename), @@ -268,6 +269,60 @@ class ReceiveHistoryItemFile(QtWidgets.QWidget): subprocess.Popen(["explorer", f"/select,{abs_filename}"]) +class ReceiveHistoryItemMessage(QtWidgets.QWidget): + def __init__( + self, + common, + ): + super(ReceiveHistoryItemMessage, self).__init__() + self.common = common + self.filename = None + + # Read message button + message_pixmap = QtGui.QPixmap.fromImage( + QtGui.QImage(GuiCommon.get_resource_path("images/open_message.png")) + ) + message_icon = QtGui.QIcon(message_pixmap) + self.message_button = QtWidgets.QPushButton( + strings._("history_receive_read_message_button") + ) + self.message_button.setStyleSheet(self.common.gui.css["receive_message_button"]) + self.message_button.clicked.connect(self.open_message) + self.message_button.setIcon(message_icon) + self.message_button.setIconSize(message_pixmap.rect().size()) + + # Layouts + layout = QtWidgets.QHBoxLayout() + layout.addWidget(self.message_button) + layout.addStretch() + self.setLayout(layout) + + self.hide() + + def set_filename(self, new_filename): + self.filename = new_filename + self.show() + + def open_message(self): + """ + Open the message in the operating system's default text editor + """ + self.common.log("ReceiveHistoryItemMessage", "open_message", self.filename) + + # Linux + if self.common.platform == "Linux" or self.common.platform == "BSD": + # If nautilus is available, open it + subprocess.Popen(["xdg-open", self.filename]) + + # macOS + elif self.common.platform == "Darwin": + subprocess.call(["open", self.filename]) + + # Windows + elif self.common.platform == "Windows": + subprocess.Popen(["notepad", self.filename]) + + class ReceiveHistoryItem(HistoryItem): def __init__(self, common, id, content_length): super(ReceiveHistoryItem, self).__init__() @@ -277,6 +332,12 @@ class ReceiveHistoryItem(HistoryItem): self.started = datetime.now() self.status = HistoryItem.STATUS_STARTED + self.common.log( + "ReceiveHistoryItem", + "__init__", + f"id={self.id} content_length={self.content_length}", + ) + # Label self.label = QtWidgets.QLabel( strings._("gui_all_modes_transfer_started").format( @@ -295,6 +356,9 @@ class ReceiveHistoryItem(HistoryItem): self.common.gui.css["downloads_uploads_progress_bar"] ) + # The message widget, if a message was included + self.message = ReceiveHistoryItemMessage(self.common) + # This layout contains file widgets self.files_layout = QtWidgets.QVBoxLayout() self.files_layout.setContentsMargins(0, 0, 0, 0) @@ -305,6 +369,7 @@ class ReceiveHistoryItem(HistoryItem): # Layout layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label) + layout.addWidget(self.message) layout.addWidget(self.progress_bar) layout.addWidget(files_widget) layout.addStretch() @@ -313,6 +378,9 @@ class ReceiveHistoryItem(HistoryItem): # We're also making a dictionary of file widgets, to make them easier to access self.files = {} + def includes_message(self, message_filename): + self.message.set_filename(message_filename) + def update(self, data): """ Using the progress from Web, update the progress bar and file size labels @@ -372,6 +440,7 @@ class ReceiveHistoryItem(HistoryItem): # Change the label self.label.setText(self.get_finished_label_text(self.started)) + self.label.setStyleSheet(self.common.gui.css["history_default_label"]) elif data["action"] == "canceled": # Change the status @@ -412,6 +481,7 @@ class IndividualFileHistoryItem(HistoryItem): self.common.gui.css["history_individual_file_timestamp_label"] ) self.path_label = QtWidgets.QLabel(self.path) + self.path_label.setStyleSheet(self.common.gui.css["history_default_label"]) self.status_code_label = QtWidgets.QLabel() # Progress bar @@ -560,6 +630,13 @@ class HistoryItemList(QtWidgets.QScrollArea): if id in self.items: self.items[id].cancel() + def includes_message(self, id, message_filename): + """ + Show message button for receive mode + """ + if id in self.items: + self.items[id].includes_message(message_filename) + def reset(self): """ Reset all items, emptying the list. Override this method. @@ -637,6 +714,7 @@ class History(QtWidgets.QWidget): self.not_empty_layout.addLayout(header_layout) self.not_empty_layout.addWidget(self.item_list) self.not_empty = QtWidgets.QWidget() + self.not_empty.setStyleSheet(self.common.gui.css["downloads_uploads_not_empty"]) self.not_empty.setLayout(self.not_empty_layout) # Layout @@ -653,7 +731,7 @@ class History(QtWidgets.QWidget): """ Add a new item. """ - self.common.log("History", "add", f"id: {id}, item: {item}") + self.common.log("History", "add", f"id: {id}") # Hide empty, show not empty self.empty.hide() @@ -674,6 +752,12 @@ class History(QtWidgets.QWidget): """ self.item_list.cancel(id) + def includes_message(self, id, message_filename): + """ + Show the message button + """ + self.item_list.includes_message(id, message_filename) + def reset(self): """ Reset all items. |