Add ServerStatus to ReceiveMode, and update the server status indicator to have receive statuses too

This commit is contained in:
Micah Lee 2018-04-25 09:46:49 -07:00
parent 10581b1421
commit 2fc4330ee4
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
5 changed files with 59 additions and 19 deletions

View file

@ -29,6 +29,7 @@ from .tor_connection_dialog import TorConnectionDialog
from .settings_dialog import SettingsDialog
from .widgets import Alert
from .update_checker import UpdateThread
from .server_status import ServerStatus
class OnionShareGui(QtWidgets.QMainWindow):
"""
@ -167,7 +168,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.share_mode.server_status.url_copied.connect(self.copy_url)
self.share_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth)
self.share_mode.set_share_server_active.connect(self.set_share_server_active)
self.receive_mode = ReceiveMode(self.common)
self.receive_mode = ReceiveMode(self.common, qtapp, app, web, self.status_bar, self.server_share_status_label, self.system_tray)
self.update_mode_switcher()
self.update_server_status_indicator()
@ -224,6 +225,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.share_mode.hide()
self.receive_mode.show()
self.update_server_status_indicator()
self.adjustSize();
def share_mode_clicked(self):
@ -237,21 +239,30 @@ class OnionShareGui(QtWidgets.QMainWindow):
def update_server_status_indicator(self):
self.common.log('OnionShareGui', 'update_server_status_indicator')
# Share mode
# Set the status image
if self.mode == self.MODE_SHARE:
# Set the status image
if self.share_mode.server_status.status == self.share_mode.server_status.STATUS_STOPPED:
# Share mode
if self.share_mode.server_status.status == ServerStatus.STATUS_STOPPED:
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_stopped))
self.server_status_label.setText(strings._('gui_status_indicator_stopped', True))
elif self.share_mode.server_status.status == self.share_mode.server_status.STATUS_WORKING:
self.server_status_label.setText(strings._('gui_status_indicator_share_stopped', True))
elif self.share_mode.server_status.status == ServerStatus.STATUS_WORKING:
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_working))
self.server_status_label.setText(strings._('gui_status_indicator_working', True))
elif self.share_mode.server_status.status == self.share_mode.server_status.STATUS_STARTED:
self.server_status_label.setText(strings._('gui_status_indicator_share_working', True))
elif self.share_mode.server_status.status == ServerStatus.STATUS_STARTED:
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_started))
self.server_status_label.setText(strings._('gui_status_indicator_started', True))
self.server_status_label.setText(strings._('gui_status_indicator_share_started', True))
else:
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_stopped))
self.server_status_label.setText(strings._('gui_status_indicator_stopped', True))
# Receive mode
if self.receive_mode.server_status.status == ServerStatus.STATUS_STOPPED:
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_stopped))
self.server_status_label.setText(strings._('gui_status_indicator_receive_stopped', True))
elif self.receive_mode.server_status.status == ServerStatus.STATUS_WORKING:
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_working))
self.server_status_label.setText(strings._('gui_status_indicator_receive_working', True))
elif self.receive_mode.server_status.status == ServerStatus.STATUS_STARTED:
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_started))
self.server_status_label.setText(strings._('gui_status_indicator_receive_started', True))
def stop_server_finished(self):
# When the server stopped, cleanup the ephemeral onion service

View file

@ -21,13 +21,36 @@ from PyQt5 import QtCore, QtWidgets, QtGui
from onionshare import strings
from ..server_status import ServerStatus
class ReceiveMode(QtWidgets.QWidget):
"""
Parts of the main window UI for receiving files.
"""
def __init__(self, common):
def __init__(self, common, qtapp, app, web, status_bar, server_share_status_label, system_tray):
super(ReceiveMode, self).__init__()
self.common = common
self.qtapp = qtapp
self.app = app
self.web = web
self.status_bar = status_bar
self.server_share_status_label = server_share_status_label
self.system_tray = system_tray
# Server status
self.server_status = ServerStatus(self.common, self.qtapp, self.app, self.web)
# Primary action layout
primary_action_layout = QtWidgets.QVBoxLayout()
primary_action_layout.addWidget(self.server_status)
self.primary_action = QtWidgets.QWidget()
self.primary_action.setLayout(primary_action_layout)
# Layout
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.primary_action)
self.setLayout(layout)
def timer_callback(self):
"""

View file

@ -22,7 +22,7 @@ from PyQt5 import QtCore, QtWidgets, QtGui
from onionshare import strings
from ..widgets import Alert
from .widgets import Alert
class ServerStatus(QtWidgets.QWidget):
"""
@ -39,7 +39,7 @@ class ServerStatus(QtWidgets.QWidget):
STATUS_WORKING = 1
STATUS_STARTED = 2
def __init__(self, common, qtapp, app, web, file_selection):
def __init__(self, common, qtapp, app, web, file_selection=None):
super(ServerStatus, self).__init__()
self.common = common
@ -49,6 +49,8 @@ class ServerStatus(QtWidgets.QWidget):
self.qtapp = qtapp
self.app = app
self.web = web
# Only used in share mode
self.file_selection = file_selection
# Shutdown timeout layout
@ -172,7 +174,8 @@ class ServerStatus(QtWidgets.QWidget):
button_stopped_style = 'QPushButton { background-color: #5fa416; color: #ffffff; padding: 10px; border: 0; border-radius: 5px; }'
button_working_style = 'QPushButton { background-color: #4c8211; color: #ffffff; padding: 10px; border: 0; border-radius: 5px; font-style: italic; }'
button_started_style = 'QPushButton { background-color: #d0011b; color: #ffffff; padding: 10px; border: 0; border-radius: 5px; }'
if self.file_selection.get_num_files() == 0:
if self.file_selection and self.file_selection.get_num_files() == 0:
self.server_button.hide()
else:
self.server_button.show()

View file

@ -27,8 +27,8 @@ from onionshare.common import Common, ShutdownTimer
from onionshare.onion import *
from .file_selection import FileSelection
from .server_status import ServerStatus
from .downloads import Downloads
from ..server_status import ServerStatus
from ..onion_thread import OnionThread
from ..widgets import Alert

View file

@ -151,9 +151,12 @@
"gui_url_label_stay_open": "This share will not expire automatically unless a timer is set.",
"gui_url_label_onetime": "This share will expire after the first download",
"gui_url_label_onetime_and_persistent": "This share will expire after the first download<br><br>Every share will have the same address (to use one-time addresses, disable persistence in the Settings)",
"gui_status_indicator_stopped": "Ready to Share",
"gui_status_indicator_working": "Starting…",
"gui_status_indicator_started": "Sharing",
"gui_status_indicator_share_stopped": "Ready to Share",
"gui_status_indicator_share_working": "Starting…",
"gui_status_indicator_share_started": "Sharing",
"gui_status_indicator_receive_stopped": "Ready to Receive",
"gui_status_indicator_receive_working": "Starting…",
"gui_status_indicator_receive_started": "Receiving",
"gui_file_info": "{} Files, {}",
"gui_file_info_single": "{} File, {}",
"info_in_progress_downloads_tooltip": "{} download(s) in progress",