Move server status indicator to the status bar at the bottom

This commit is contained in:
Micah Lee 2018-02-06 19:31:02 -08:00
parent 69fe7f0d98
commit f93ed86283
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
3 changed files with 40 additions and 18 deletions

View file

@ -73,11 +73,15 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.server_status = ServerStatus(self.qtapp, self.app, web, self.file_selection, self.settings)
self.server_status.server_started.connect(self.file_selection.server_started)
self.server_status.server_started.connect(self.start_server)
self.server_status.server_started.connect(self.update_server_status_indicator)
self.server_status.server_stopped.connect(self.file_selection.server_stopped)
self.server_status.server_stopped.connect(self.stop_server)
self.server_status.server_stopped.connect(self.update_server_status_indicator)
self.start_server_finished.connect(self.clear_message)
self.start_server_finished.connect(self.server_status.start_server_finished)
self.start_server_finished.connect(self.update_server_status_indicator)
self.stop_server_finished.connect(self.server_status.stop_server_finished)
self.stop_server_finished.connect(self.update_server_status_indicator)
self.file_selection.file_list.files_updated.connect(self.server_status.update)
self.file_selection.file_list.files_updated.connect(self.update_primary_action)
self.server_status.url_copied.connect(self.copy_url)
@ -109,10 +113,26 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.settings_button.setIcon( QtGui.QIcon(common.get_resource_path('images/settings.png')) )
self.settings_button.clicked.connect(self.open_settings)
# Server status indicator on the status bar
self.server_status_image_stopped = QtGui.QImage(common.get_resource_path('images/server_stopped.png'))
self.server_status_image_working = QtGui.QImage(common.get_resource_path('images/server_working.png'))
self.server_status_image_started = QtGui.QImage(common.get_resource_path('images/server_started.png'))
self.server_status_image_label = QtWidgets.QLabel()
self.server_status_image_label.setFixedWidth(20)
self.server_status_label = QtWidgets.QLabel()
self.server_status_label.setStyleSheet('QLabel { font-style: italic; color: #666666; }')
server_status_indicator_layout = QtWidgets.QHBoxLayout()
server_status_indicator_layout.addWidget(self.server_status_image_label)
server_status_indicator_layout.addWidget(self.server_status_label)
self.server_status_indicator = QtWidgets.QWidget()
self.server_status_indicator.setLayout(server_status_indicator_layout)
self.update_server_status_indicator()
# Status bar
self.status_bar = QtWidgets.QStatusBar()
self.status_bar.setSizeGripEnabled(False)
self.status_bar.setStyleSheet("QStatusBar::item { border: 0px; }")
self.status_bar.addPermanentWidget(self.server_status_indicator)
self.status_bar.addPermanentWidget(self.settings_button)
self.setStatusBar(self.status_bar)
@ -167,6 +187,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.check_for_updates()
def update_primary_action(self):
common.log('OnionShareGui', 'update_primary_action')
# Resize window
self.adjustSize()
@ -176,6 +197,20 @@ class OnionShareGui(QtWidgets.QMainWindow):
else:
self.primary_action.hide()
def update_server_status_indicator(self):
common.log('OnionShareGui', 'update_server_status_indicator')
# Set the status image
if self.server_status.status == self.server_status.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.server_status.status == self.server_status.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.server_status.status == self.server_status.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))
def _initSystemTray(self):
system = common.get_platform()

View file

@ -78,16 +78,8 @@ class ServerStatus(QtWidgets.QWidget):
self.server_shutdown_timeout_container.setLayout(shutdown_timeout_container_layout)
# Server layout
self.status_image_stopped = QtGui.QImage(common.get_resource_path('images/server_stopped.png'))
self.status_image_working = QtGui.QImage(common.get_resource_path('images/server_working.png'))
self.status_image_started = QtGui.QImage(common.get_resource_path('images/server_started.png'))
self.status_image_label = QtWidgets.QLabel()
self.status_image_label.setFixedWidth(30)
self.server_button = QtWidgets.QPushButton()
self.server_button.clicked.connect(self.server_button_clicked)
server_layout = QtWidgets.QHBoxLayout()
server_layout.addWidget(self.status_image_label)
server_layout.addWidget(self.server_button)
# URL layout
url_font = QtGui.QFont()
@ -120,7 +112,7 @@ class ServerStatus(QtWidgets.QWidget):
# Add the widgets
layout = QtWidgets.QVBoxLayout()
layout.addLayout(server_layout)
layout.addWidget(self.server_button)
layout.addLayout(url_layout)
layout.addWidget(self.server_shutdown_timeout_container)
self.setLayout(layout)
@ -155,14 +147,6 @@ class ServerStatus(QtWidgets.QWidget):
"""
Update the GUI elements based on the current state.
"""
# Set the status image
if self.status == self.STATUS_STOPPED:
self.status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.status_image_stopped))
elif self.status == self.STATUS_WORKING:
self.status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.status_image_working))
elif self.status == self.STATUS_STARTED:
self.status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.status_image_started))
# Set the URL fields
if self.status == self.STATUS_STARTED:
self.url_description.show()

View file

@ -136,5 +136,8 @@
"persistent_url_in_use": "This share is using a persistent address",
"gui_url_description": "<b>Anyone</b> with this link can <b>download</b> your files using <b>Tor Browser</b>:",
"gui_url_label": "Your Download Address",
"gui_url_label_one_time": "Your One-Time Download Address"
"gui_url_label_one_time": "Your One-Time Download Address",
"gui_status_indicator_stopped": "Stopped",
"gui_status_indicator_working": "Working...",
"gui_status_indicator_started": "Running"
}