mirror of
https://github.com/onionshare/onionshare.git
synced 2025-08-06 13:24:24 -04:00
GUI displays "Read Message" button when a receive mode submission includes a message
This commit is contained in:
parent
abf5b05280
commit
34b791abcf
9 changed files with 177 additions and 62 deletions
|
@ -353,6 +353,10 @@ class GuiCommon:
|
|||
color: #666666;
|
||||
font-size: 11px;
|
||||
}""",
|
||||
"receive_message_button": """
|
||||
QPushButton {
|
||||
padding: 5px 10px;
|
||||
}""",
|
||||
# Settings dialog
|
||||
"settings_version": """
|
||||
QLabel {
|
||||
|
|
BIN
desktop/src/onionshare/resources/images/open_message.png
Normal file
BIN
desktop/src/onionshare/resources/images/open_message.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
|
@ -195,5 +195,6 @@
|
|||
"settings_error_bundled_tor_broken": "OnionShare could not connect to Tor:\n{}",
|
||||
"gui_rendezvous_cleanup": "Waiting for Tor circuits to close to be sure your files have successfully transferred.\n\nThis might take a few minutes.",
|
||||
"gui_rendezvous_cleanup_quit_early": "Quit Early",
|
||||
"error_port_not_available": "OnionShare port not available"
|
||||
"error_port_not_available": "OnionShare port not available",
|
||||
"history_receive_read_message_button": "Read Message"
|
||||
}
|
|
@ -447,6 +447,12 @@ class Mode(QtWidgets.QWidget):
|
|||
"""
|
||||
pass
|
||||
|
||||
def handle_request_upload_includes_message(self, event):
|
||||
"""
|
||||
Handle REQUEST_UPLOAD_INCLUDES_MESSAGE event.
|
||||
"""
|
||||
pass
|
||||
|
||||
def handle_request_upload_file_renamed(self, event):
|
||||
"""
|
||||
Handle REQUEST_UPLOAD_FILE_RENAMED event.
|
||||
|
|
|
@ -268,6 +268,66 @@ 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":
|
||||
# try:
|
||||
# # If nautilus is available, open it
|
||||
# subprocess.Popen(["xdg-open", self.dir])
|
||||
# except Exception:
|
||||
# Alert(
|
||||
# self.common,
|
||||
# strings._("gui_open_folder_error").format(abs_filename),
|
||||
# )
|
||||
|
||||
# # macOS
|
||||
# elif self.common.platform == "Darwin":
|
||||
# subprocess.call(["open", "-R", abs_filename])
|
||||
|
||||
# # Windows
|
||||
# elif self.common.platform == "Windows":
|
||||
# subprocess.Popen(["explorer", f"/select,{abs_filename}"])
|
||||
|
||||
|
||||
class ReceiveHistoryItem(HistoryItem):
|
||||
def __init__(self, common, id, content_length):
|
||||
super(ReceiveHistoryItem, self).__init__()
|
||||
|
@ -301,6 +361,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)
|
||||
|
@ -311,6 +374,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()
|
||||
|
@ -319,17 +383,14 @@ 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
|
||||
for each file
|
||||
"""
|
||||
# self.common.log(
|
||||
# "ReceiveHistoryItem",
|
||||
# "update",
|
||||
# f"id={self.id} data[action]={data['action']} files={list(self.files)}",
|
||||
# )
|
||||
|
||||
if data["action"] == "progress":
|
||||
total_uploaded_bytes = 0
|
||||
for filename in data["progress"]:
|
||||
|
@ -572,6 +633,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.
|
||||
|
@ -665,7 +733,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()
|
||||
|
@ -686,6 +754,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.
|
||||
|
|
|
@ -78,27 +78,24 @@ class ReceiveMode(Mode):
|
|||
data_dir_layout.addWidget(data_dir_button)
|
||||
self.mode_settings_widget.mode_specific_layout.addLayout(data_dir_layout)
|
||||
|
||||
# Disable text
|
||||
# Disable text or files
|
||||
self.disable_text_checkbox = self.settings.get("receive", "disable_files")
|
||||
self.disable_text_checkbox = QtWidgets.QCheckBox()
|
||||
self.disable_text_checkbox.clicked.connect(self.disable_text_checkbox_clicked)
|
||||
self.disable_text_checkbox.setText(
|
||||
strings._("mode_settings_receive_disable_text_checkbox")
|
||||
)
|
||||
self.mode_settings_widget.mode_specific_layout.addWidget(
|
||||
self.disable_text_checkbox
|
||||
)
|
||||
|
||||
# Disable files
|
||||
self.disable_files_checkbox = self.settings.get("receive", "disable_files")
|
||||
self.disable_files_checkbox = QtWidgets.QCheckBox()
|
||||
self.disable_files_checkbox.clicked.connect(self.disable_files_checkbox_clicked)
|
||||
self.disable_files_checkbox.setText(
|
||||
strings._("mode_settings_receive_disable_files_checkbox")
|
||||
)
|
||||
self.mode_settings_widget.mode_specific_layout.addWidget(
|
||||
self.disable_files_checkbox
|
||||
)
|
||||
disable_layout = QtWidgets.QHBoxLayout()
|
||||
disable_layout.addWidget(self.disable_text_checkbox)
|
||||
disable_layout.addWidget(self.disable_files_checkbox)
|
||||
disable_layout.addStretch()
|
||||
self.mode_settings_widget.mode_specific_layout.addLayout(disable_layout)
|
||||
|
||||
# Webhook URL
|
||||
webhook_url = self.settings.get("receive", "webhook_url")
|
||||
|
@ -344,8 +341,11 @@ class ReceiveMode(Mode):
|
|||
Handle REQUEST_STARTED event.
|
||||
"""
|
||||
item = ReceiveHistoryItem(
|
||||
self.common, event["data"]["id"], event["data"]["content_length"]
|
||||
self.common,
|
||||
event["data"]["id"],
|
||||
event["data"]["content_length"],
|
||||
)
|
||||
|
||||
self.history.add(event["data"]["id"], item)
|
||||
self.toggle_history.update_indicator(True)
|
||||
self.history.in_progress_count += 1
|
||||
|
@ -365,6 +365,12 @@ class ReceiveMode(Mode):
|
|||
{"action": "progress", "progress": event["data"]["progress"]},
|
||||
)
|
||||
|
||||
def handle_request_upload_includes_message(self, event):
|
||||
"""
|
||||
Handle REQUEST_UPLOAD_INCLUDES_MESSAGE event.
|
||||
"""
|
||||
self.history.includes_message(event["data"]["id"], event["data"]["filename"])
|
||||
|
||||
def handle_request_upload_file_renamed(self, event):
|
||||
"""
|
||||
Handle REQUEST_UPLOAD_FILE_RENAMED event.
|
||||
|
|
|
@ -540,6 +540,9 @@ class Tab(QtWidgets.QWidget):
|
|||
elif event["type"] == Web.REQUEST_CANCELED:
|
||||
mode.handle_request_canceled(event)
|
||||
|
||||
elif event["type"] == Web.REQUEST_UPLOAD_INCLUDES_MESSAGE:
|
||||
mode.handle_request_upload_includes_message(event)
|
||||
|
||||
elif event["type"] == Web.REQUEST_UPLOAD_FILE_RENAMED:
|
||||
mode.handle_request_upload_file_renamed(event)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue