Add custom title to GUI

This commit is contained in:
Micah Lee 2021-04-13 18:06:29 -04:00
parent 1543bb38d2
commit 3c85a8dae1
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
7 changed files with 64 additions and 0 deletions

View File

@ -165,6 +165,7 @@
"gui_quit_warning_cancel": "Cancel",
"mode_settings_advanced_toggle_show": "Show advanced settings",
"mode_settings_advanced_toggle_hide": "Hide advanced settings",
"mode_settings_title_label": "Title",
"mode_settings_persistent_checkbox": "Save this tab, and automatically open it when I open OnionShare",
"mode_settings_public_checkbox": "Don't use a password",
"mode_settings_autostart_timer_checkbox": "Start onion service at scheduled time",

View File

@ -68,6 +68,11 @@ class ChatMode(Mode):
self.image = QtWidgets.QWidget()
self.image.setLayout(image_layout)
# Set title placeholder
self.mode_settings_widget.title_lineedit.setPlaceholderText(
strings._("gui_tab_name_chat")
)
# Server status
self.server_status.set_mode("chat")
self.server_status.server_started_finished.connect(self.update_primary_action)

View File

@ -39,6 +39,16 @@ class ModeSettingsWidget(QtWidgets.QWidget):
# Downstream Mode need to fill in this layout with its settings
self.mode_specific_layout = QtWidgets.QVBoxLayout()
# Title
title_label = QtWidgets.QLabel(strings._("mode_settings_title_label"))
self.title_lineedit = QtWidgets.QLineEdit()
self.title_lineedit.editingFinished.connect(self.title_editing_finished)
if self.settings.get("general", "title"):
self.title_lineedit.setText(self.settings.get("general", "title"))
title_layout = QtWidgets.QHBoxLayout()
title_layout.addWidget(title_label)
title_layout.addWidget(self.title_lineedit)
# Persistent
self.persistent_checkbox = QtWidgets.QCheckBox()
self.persistent_checkbox.clicked.connect(self.persistent_checkbox_clicked)
@ -162,6 +172,7 @@ class ModeSettingsWidget(QtWidgets.QWidget):
layout = QtWidgets.QVBoxLayout()
layout.addLayout(self.mode_specific_layout)
layout.addLayout(title_layout)
layout.addWidget(self.persistent_checkbox)
layout.addWidget(self.public_checkbox)
layout.addWidget(self.advanced_widget)
@ -203,6 +214,34 @@ class ModeSettingsWidget(QtWidgets.QWidget):
self.legacy_checkbox.hide()
self.client_auth_checkbox.hide()
def title_editing_finished(self):
if self.title_lineedit.text() == "":
self.settings.set("general", "title", None)
if self.tab.mode == self.common.gui.MODE_SHARE:
self.tab.change_title.emit(
self.tab.tab_id, strings._("gui_tab_name_share")
)
elif self.tab.mode == self.common.gui.MODE_RECEIVE:
self.tab.change_title.emit(
self.tab.tab_id, strings._("gui_tab_name_receive")
)
elif self.tab.mode == self.common.gui.MODE_WEBSITE:
self.tab.change_title.emit(
self.tab.tab_id, strings._("gui_tab_name_website")
)
elif self.tab.mode == self.common.gui.MODE_CHAT:
self.tab.change_title.emit(
self.tab.tab_id, strings._("gui_tab_name_chat")
)
elif self.tab_mode == None:
pass
else:
self.settings.set("general", "title", self.title_lineedit.text())
shortened_title = self.title_lineedit.text()
if len(shortened_title) > 11:
shortened_title = shortened_title[:10] + "..."
self.tab.change_title.emit(self.tab.tab_id, shortened_title)
def persistent_checkbox_clicked(self):
self.settings.set("persistent", "enabled", self.persistent_checkbox.isChecked())
self.settings.set("persistent", "mode", self.tab.mode)

View File

@ -106,6 +106,11 @@ class ReceiveMode(Mode):
self.hide_webhook_url()
self.mode_settings_widget.mode_specific_layout.addLayout(webhook_url_layout)
# Set title placeholder
self.mode_settings_widget.title_lineedit.setPlaceholderText(
strings._("gui_tab_name_receive")
)
# Server status
self.server_status.set_mode("receive")
self.server_status.server_started_finished.connect(self.update_primary_action)

View File

@ -77,6 +77,11 @@ class ShareMode(Mode):
for filename in self.filenames:
self.file_selection.file_list.add_file(filename)
# Set title placeholder
self.mode_settings_widget.title_lineedit.setPlaceholderText(
strings._("gui_tab_name_share")
)
# Server status
self.server_status.set_mode("share", self.file_selection)
self.server_status.server_started.connect(self.file_selection.server_started)

View File

@ -77,6 +77,11 @@ class WebsiteMode(Mode):
for filename in self.filenames:
self.file_selection.file_list.add_file(filename)
# Set title placeholder
self.mode_settings_widget.title_lineedit.setPlaceholderText(
strings._("gui_tab_name_website")
)
# Server status
self.server_status.set_mode("website", self.file_selection)
self.server_status.server_started.connect(self.file_selection.server_started)

View File

@ -176,6 +176,10 @@ class TabWidget(QtWidgets.QTabWidget):
)
tab.init(mode_settings)
# Make sure the title is set
tab.get_mode().mode_settings_widget.title_editing_finished()
# If it's persistent, set the persistent image in the tab
self.change_persistent(tab.tab_id, tab.settings.get("persistent", "enabled"))