WIP: Starting to make messages in receive mode work in GUI

This commit is contained in:
Micah Lee 2021-04-28 19:10:26 -04:00
parent 2acdea5229
commit 0de27f9775
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
5 changed files with 62 additions and 7 deletions

View File

@ -53,6 +53,8 @@ class ModeSettings:
"receive": {
"data_dir": self.build_default_receive_data_dir(),
"webhook_url": None,
"disable_text": False,
"disable_files": False,
},
"website": {"disable_csp": False, "filenames": []},
"chat": {"room": "default"},

View File

@ -26,6 +26,17 @@ from datetime import datetime
from flask import Request, request, render_template, make_response, flash, redirect
from werkzeug.utils import secure_filename
"""
Receive mode uses a special flask requests object, ReceiveModeRequest, in
order to keep track of upload progress. Here's what happens when someone
uploads files:
- new ReceiveModeRequest object is created
- creates a directory based on the timestamp
-
"""
class ReceiveModeWeb:
"""
@ -90,18 +101,20 @@ class ReceiveModeWeb:
with open(local_path, "w") as f:
f.write(text_message)
basename = os.path.basename(local_path)
# TODO: possibly change this
# Tell the GUI a message has been uploaded
self.web.add_request(
self.web.REQUEST_UPLOAD_SET_DIR,
request.path,
self.web.REQUEST_STARTED,
local_path,
{
"id": request.history_id,
"filename": basename,
"dir": request.receive_mode_dir,
"content_length": len(text_message),
},
)
self.web.add_request(
self.web.REQUEST_UPLOAD_FINISHED,
local_path,
{"id": request.history_id},
)
self.common.log(
"ReceiveModeWeb",

View File

@ -174,6 +174,8 @@
"mode_settings_share_autostop_sharing_checkbox": "Stop sharing after files have been sent (uncheck to allow downloading individual files)",
"mode_settings_receive_data_dir_label": "Save files to",
"mode_settings_receive_data_dir_browse_button": "Browse",
"mode_settings_receive_disable_text_checkbox": "Disable submitting text",
"mode_settings_receive_disable_files_checkbox": "Disable uploading files",
"mode_settings_receive_webhook_url_checkbox": "Use notification webhook",
"mode_settings_website_disable_csp_checkbox": "Don't send Content Security Policy header (allows your website to use third-party resources)",
"gui_all_modes_transfer_finished_range": "Transferred {} - {}",

View File

@ -453,6 +453,12 @@ class Mode(QtWidgets.QWidget):
"""
pass
def handle_request_upload_message(self, event):
"""
Handle REQUEST_UPLOAD_MESSAGE event.
"""
pass
def handle_request_upload_set_dir(self, event):
"""
Handle REQUEST_UPLOAD_SET_DIR event.

View File

@ -78,6 +78,28 @@ class ReceiveMode(Mode):
data_dir_layout.addWidget(data_dir_button)
self.mode_settings_widget.mode_specific_layout.addLayout(data_dir_layout)
# Disable text
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
)
# Webhook URL
webhook_url = self.settings.get("receive", "webhook_url")
self.webhook_url_checkbox = QtWidgets.QCheckBox()
@ -212,6 +234,16 @@ class ReceiveMode(Mode):
self.data_dir_lineedit.setText(selected_dir)
self.settings.set("receive", "data_dir", selected_dir)
def disable_text_checkbox_clicked(self):
self.settings.set(
"receive", "disable_text", self.disable_text_checkbox.isChecked()
)
def disable_files_checkbox_clicked(self):
self.settings.set(
"receive", "disable_files", self.disable_files_checkbox.isChecked()
)
def webhook_url_checkbox_clicked(self):
if self.webhook_url_checkbox.isChecked():
if self.settings.get("receive", "webhook_url"):