mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-27 08:19:41 -05:00
Move MODE_SHARE, MODE_RECEIVE, and MODE_WEBSITE into GuiCommon
This commit is contained in:
parent
bba5286815
commit
e51be47844
@ -24,6 +24,10 @@ class GuiCommon:
|
|||||||
The shared code for all of the OnionShare GUI.
|
The shared code for all of the OnionShare GUI.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
MODE_SHARE = "share"
|
||||||
|
MODE_RECEIVE = "receive"
|
||||||
|
MODE_WEBSITE = "website"
|
||||||
|
|
||||||
def __init__(self, common):
|
def __init__(self, common):
|
||||||
self.common = common
|
self.common = common
|
||||||
|
|
||||||
|
@ -39,10 +39,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
MainWindow is the OnionShare main window, which contains the GUI elements, including all open tabs
|
MainWindow is the OnionShare main window, which contains the GUI elements, including all open tabs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
MODE_SHARE = "share"
|
|
||||||
MODE_RECEIVE = "receive"
|
|
||||||
MODE_WEBSITE = "website"
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, common, onion, qtapp, app, filenames, config=False, local_only=False
|
self, common, onion, qtapp, app, filenames, config=False, local_only=False
|
||||||
):
|
):
|
||||||
@ -58,7 +54,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.app = app
|
self.app = app
|
||||||
self.local_only = local_only
|
self.local_only = local_only
|
||||||
|
|
||||||
self.mode = self.MODE_SHARE
|
self.mode = self.common.gui.MODE_SHARE
|
||||||
|
|
||||||
self.setWindowTitle("OnionShare")
|
self.setWindowTitle("OnionShare")
|
||||||
self.setWindowIcon(
|
self.setWindowIcon(
|
||||||
@ -296,7 +292,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
def update_mode_switcher(self):
|
def update_mode_switcher(self):
|
||||||
# Based on the current mode, switch the mode switcher button styles,
|
# Based on the current mode, switch the mode switcher button styles,
|
||||||
# and show and hide widgets to switch modes
|
# and show and hide widgets to switch modes
|
||||||
if self.mode == self.MODE_SHARE:
|
if self.mode == self.common.gui.MODE_SHARE:
|
||||||
self.share_mode_button.setStyleSheet(
|
self.share_mode_button.setStyleSheet(
|
||||||
self.common.gui.css["mode_switcher_selected_style"]
|
self.common.gui.css["mode_switcher_selected_style"]
|
||||||
)
|
)
|
||||||
@ -310,7 +306,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.receive_mode.hide()
|
self.receive_mode.hide()
|
||||||
self.share_mode.show()
|
self.share_mode.show()
|
||||||
self.website_mode.hide()
|
self.website_mode.hide()
|
||||||
elif self.mode == self.MODE_WEBSITE:
|
elif self.mode == self.common.gui.MODE_WEBSITE:
|
||||||
self.share_mode_button.setStyleSheet(
|
self.share_mode_button.setStyleSheet(
|
||||||
self.common.gui.css["mode_switcher_unselected_style"]
|
self.common.gui.css["mode_switcher_unselected_style"]
|
||||||
)
|
)
|
||||||
@ -342,26 +338,26 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.update_server_status_indicator()
|
self.update_server_status_indicator()
|
||||||
|
|
||||||
def share_mode_clicked(self):
|
def share_mode_clicked(self):
|
||||||
if self.mode != self.MODE_SHARE:
|
if self.mode != self.common.gui.MODE_SHARE:
|
||||||
self.common.log("MainWindow", "share_mode_clicked")
|
self.common.log("MainWindow", "share_mode_clicked")
|
||||||
self.mode = self.MODE_SHARE
|
self.mode = self.common.gui.MODE_SHARE
|
||||||
self.update_mode_switcher()
|
self.update_mode_switcher()
|
||||||
|
|
||||||
def receive_mode_clicked(self):
|
def receive_mode_clicked(self):
|
||||||
if self.mode != self.MODE_RECEIVE:
|
if self.mode != self.common.gui.MODE_RECEIVE:
|
||||||
self.common.log("MainWindow", "receive_mode_clicked")
|
self.common.log("MainWindow", "receive_mode_clicked")
|
||||||
self.mode = self.MODE_RECEIVE
|
self.mode = self.common.gui.MODE_RECEIVE
|
||||||
self.update_mode_switcher()
|
self.update_mode_switcher()
|
||||||
|
|
||||||
def website_mode_clicked(self):
|
def website_mode_clicked(self):
|
||||||
if self.mode != self.MODE_WEBSITE:
|
if self.mode != self.common.gui.MODE_WEBSITE:
|
||||||
self.common.log("MainWindow", "website_mode_clicked")
|
self.common.log("MainWindow", "website_mode_clicked")
|
||||||
self.mode = self.MODE_WEBSITE
|
self.mode = self.common.gui.MODE_WEBSITE
|
||||||
self.update_mode_switcher()
|
self.update_mode_switcher()
|
||||||
|
|
||||||
def update_server_status_indicator(self):
|
def update_server_status_indicator(self):
|
||||||
# Set the status image
|
# Set the status image
|
||||||
if self.mode == self.MODE_SHARE:
|
if self.mode == self.common.gui.MODE_SHARE:
|
||||||
# Share mode
|
# Share mode
|
||||||
if self.share_mode.server_status.status == ServerStatus.STATUS_STOPPED:
|
if self.share_mode.server_status.status == ServerStatus.STATUS_STOPPED:
|
||||||
self.server_status_image_label.setPixmap(
|
self.server_status_image_label.setPixmap(
|
||||||
@ -389,7 +385,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.server_status_label.setText(
|
self.server_status_label.setText(
|
||||||
strings._("gui_status_indicator_share_started")
|
strings._("gui_status_indicator_share_started")
|
||||||
)
|
)
|
||||||
elif self.mode == self.MODE_WEBSITE:
|
elif self.mode == self.common.gui.MODE_WEBSITE:
|
||||||
# Website mode
|
# Website mode
|
||||||
if self.website_mode.server_status.status == ServerStatus.STATUS_STOPPED:
|
if self.website_mode.server_status.status == ServerStatus.STATUS_STOPPED:
|
||||||
self.server_status_image_label.setPixmap(
|
self.server_status_image_label.setPixmap(
|
||||||
@ -591,9 +587,9 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.website_mode.handle_tor_broke()
|
self.website_mode.handle_tor_broke()
|
||||||
|
|
||||||
# Process events from the web object
|
# Process events from the web object
|
||||||
if self.mode == self.MODE_SHARE:
|
if self.mode == self.common.gui.MODE_SHARE:
|
||||||
mode = self.share_mode
|
mode = self.share_mode
|
||||||
elif self.mode == self.MODE_WEBSITE:
|
elif self.mode == self.common.gui.MODE_WEBSITE:
|
||||||
mode = self.website_mode
|
mode = self.website_mode
|
||||||
else:
|
else:
|
||||||
mode = self.receive_mode
|
mode = self.receive_mode
|
||||||
@ -700,11 +696,11 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
"""
|
"""
|
||||||
if active:
|
if active:
|
||||||
self.settings_button.hide()
|
self.settings_button.hide()
|
||||||
if self.mode == self.MODE_SHARE:
|
if self.mode == self.common.gui.MODE_SHARE:
|
||||||
self.share_mode_button.show()
|
self.share_mode_button.show()
|
||||||
self.receive_mode_button.hide()
|
self.receive_mode_button.hide()
|
||||||
self.website_mode_button.hide()
|
self.website_mode_button.hide()
|
||||||
elif self.mode == self.MODE_WEBSITE:
|
elif self.mode == self.common.gui.MODE_WEBSITE:
|
||||||
self.share_mode_button.hide()
|
self.share_mode_button.hide()
|
||||||
self.receive_mode_button.hide()
|
self.receive_mode_button.hide()
|
||||||
self.website_mode_button.show()
|
self.website_mode_button.show()
|
||||||
@ -725,9 +721,9 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.common.log("MainWindow", "closeEvent")
|
self.common.log("MainWindow", "closeEvent")
|
||||||
self.system_tray.hide()
|
self.system_tray.hide()
|
||||||
try:
|
try:
|
||||||
if self.mode == OnionShareGui.MODE_SHARE:
|
if self.mode == self.common.gui.MODE_WEBSITE:
|
||||||
server_status = self.share_mode.server_status
|
server_status = self.share_mode.server_status
|
||||||
if self.mode == OnionShareGui.MODE_WEBSITE:
|
if self.mode == self.common.gui.MODE_WEBSITE:
|
||||||
server_status = self.website_mode.server_status
|
server_status = self.website_mode.server_status
|
||||||
else:
|
else:
|
||||||
server_status = self.receive_mode.server_status
|
server_status = self.receive_mode.server_status
|
||||||
@ -735,7 +731,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.common.log("MainWindow", "closeEvent, opening warning dialog")
|
self.common.log("MainWindow", "closeEvent, opening warning dialog")
|
||||||
dialog = QtWidgets.QMessageBox()
|
dialog = QtWidgets.QMessageBox()
|
||||||
dialog.setWindowTitle(strings._("gui_quit_title"))
|
dialog.setWindowTitle(strings._("gui_quit_title"))
|
||||||
if self.mode == OnionShareGui.MODE_SHARE:
|
if self.mode == self.common.gui.MODE_WEBSITE:
|
||||||
dialog.setText(strings._("gui_share_quit_warning"))
|
dialog.setText(strings._("gui_share_quit_warning"))
|
||||||
else:
|
else:
|
||||||
dialog.setText(strings._("gui_receive_quit_warning"))
|
dialog.setText(strings._("gui_receive_quit_warning"))
|
||||||
|
@ -39,10 +39,6 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
url_copied = QtCore.pyqtSignal()
|
url_copied = QtCore.pyqtSignal()
|
||||||
hidservauth_copied = QtCore.pyqtSignal()
|
hidservauth_copied = QtCore.pyqtSignal()
|
||||||
|
|
||||||
MODE_SHARE = "share"
|
|
||||||
MODE_RECEIVE = "receive"
|
|
||||||
MODE_WEBSITE = "website"
|
|
||||||
|
|
||||||
STATUS_STOPPED = 0
|
STATUS_STOPPED = 0
|
||||||
STATUS_WORKING = 1
|
STATUS_WORKING = 1
|
||||||
STATUS_STARTED = 2
|
STATUS_STARTED = 2
|
||||||
@ -192,8 +188,8 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
"""
|
"""
|
||||||
self.mode = share_mode
|
self.mode = share_mode
|
||||||
|
|
||||||
if (self.mode == ServerStatus.MODE_SHARE) or (
|
if (self.mode == self.common.gui.MODE_SHARE) or (
|
||||||
self.mode == ServerStatus.MODE_WEBSITE
|
self.mode == self.common.gui.MODE_WEBSITE
|
||||||
):
|
):
|
||||||
self.file_selection = file_selection
|
self.file_selection = file_selection
|
||||||
|
|
||||||
@ -248,11 +244,11 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
|
|
||||||
info_image = self.common.get_resource_path("images/info.png")
|
info_image = self.common.get_resource_path("images/info.png")
|
||||||
|
|
||||||
if self.mode == ServerStatus.MODE_SHARE:
|
if self.mode == self.common.gui.MODE_SHARE:
|
||||||
self.url_description.setText(
|
self.url_description.setText(
|
||||||
strings._("gui_share_url_description").format(info_image)
|
strings._("gui_share_url_description").format(info_image)
|
||||||
)
|
)
|
||||||
elif self.mode == ServerStatus.MODE_WEBSITE:
|
elif self.mode == self.common.gui.MODE_WEBSITE:
|
||||||
self.url_description.setText(
|
self.url_description.setText(
|
||||||
strings._("gui_website_url_description").format(info_image)
|
strings._("gui_website_url_description").format(info_image)
|
||||||
)
|
)
|
||||||
@ -263,7 +259,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
|
|
||||||
# Show a Tool Tip explaining the lifecycle of this URL
|
# Show a Tool Tip explaining the lifecycle of this URL
|
||||||
if self.common.settings.get("save_private_key"):
|
if self.common.settings.get("save_private_key"):
|
||||||
if self.mode == ServerStatus.MODE_SHARE and self.common.settings.get(
|
if self.mode == self.common.gui.MODE_SHARE and self.common.settings.get(
|
||||||
"close_after_first_download"
|
"close_after_first_download"
|
||||||
):
|
):
|
||||||
self.url_description.setToolTip(
|
self.url_description.setToolTip(
|
||||||
@ -272,7 +268,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
else:
|
else:
|
||||||
self.url_description.setToolTip(strings._("gui_url_label_persistent"))
|
self.url_description.setToolTip(strings._("gui_url_label_persistent"))
|
||||||
else:
|
else:
|
||||||
if self.mode == ServerStatus.MODE_SHARE and self.common.settings.get(
|
if self.mode == self.common.gui.MODE_SHARE and self.common.settings.get(
|
||||||
"close_after_first_download"
|
"close_after_first_download"
|
||||||
):
|
):
|
||||||
self.url_description.setToolTip(strings._("gui_url_label_onetime"))
|
self.url_description.setToolTip(strings._("gui_url_label_onetime"))
|
||||||
@ -317,12 +313,12 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
|
|
||||||
# Button
|
# Button
|
||||||
if (
|
if (
|
||||||
self.mode == ServerStatus.MODE_SHARE
|
self.mode == self.common.gui.MODE_SHARE
|
||||||
and self.file_selection.get_num_files() == 0
|
and self.file_selection.get_num_files() == 0
|
||||||
):
|
):
|
||||||
self.server_button.hide()
|
self.server_button.hide()
|
||||||
elif (
|
elif (
|
||||||
self.mode == ServerStatus.MODE_WEBSITE
|
self.mode == self.common.gui.MODE_WEBSITE
|
||||||
and self.file_selection.get_num_files() == 0
|
and self.file_selection.get_num_files() == 0
|
||||||
):
|
):
|
||||||
self.server_button.hide()
|
self.server_button.hide()
|
||||||
@ -334,9 +330,9 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
self.common.gui.css["server_status_button_stopped"]
|
self.common.gui.css["server_status_button_stopped"]
|
||||||
)
|
)
|
||||||
self.server_button.setEnabled(True)
|
self.server_button.setEnabled(True)
|
||||||
if self.mode == ServerStatus.MODE_SHARE:
|
if self.mode == self.common.gui.MODE_SHARE:
|
||||||
self.server_button.setText(strings._("gui_share_start_server"))
|
self.server_button.setText(strings._("gui_share_start_server"))
|
||||||
elif self.mode == ServerStatus.MODE_WEBSITE:
|
elif self.mode == self.common.gui.MODE_WEBSITE:
|
||||||
self.server_button.setText(strings._("gui_share_start_server"))
|
self.server_button.setText(strings._("gui_share_start_server"))
|
||||||
else:
|
else:
|
||||||
self.server_button.setText(strings._("gui_receive_start_server"))
|
self.server_button.setText(strings._("gui_receive_start_server"))
|
||||||
@ -350,9 +346,9 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
self.common.gui.css["server_status_button_started"]
|
self.common.gui.css["server_status_button_started"]
|
||||||
)
|
)
|
||||||
self.server_button.setEnabled(True)
|
self.server_button.setEnabled(True)
|
||||||
if self.mode == ServerStatus.MODE_SHARE:
|
if self.mode == self.common.gui.MODE_SHARE:
|
||||||
self.server_button.setText(strings._("gui_share_stop_server"))
|
self.server_button.setText(strings._("gui_share_stop_server"))
|
||||||
elif self.mode == ServerStatus.MODE_WEBSITE:
|
elif self.mode == self.common.gui.MODE_WEBSITE:
|
||||||
self.server_button.setText(strings._("gui_share_stop_server"))
|
self.server_button.setText(strings._("gui_share_stop_server"))
|
||||||
else:
|
else:
|
||||||
self.server_button.setText(strings._("gui_receive_stop_server"))
|
self.server_button.setText(strings._("gui_receive_stop_server"))
|
||||||
|
Loading…
Reference in New Issue
Block a user