From 4bec79f4944e1222d2f79c7a11668a80da497872 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Fri, 28 Sep 2018 13:43:10 -0700 Subject: [PATCH] Toggle showing uploads and downloads for both share and receive modes --- onionshare_gui/mode.py | 1 + onionshare_gui/onionshare_gui.py | 7 +++++++ onionshare_gui/receive_mode/__init__.py | 28 ++++++++++++++++++++++++- onionshare_gui/share_mode/__init__.py | 19 ++++++++++++++--- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/onionshare_gui/mode.py b/onionshare_gui/mode.py index d91b2e64..6da83318 100644 --- a/onionshare_gui/mode.py +++ b/onionshare_gui/mode.py @@ -36,6 +36,7 @@ class Mode(QtWidgets.QWidget): starting_server_step3 = QtCore.pyqtSignal() starting_server_error = QtCore.pyqtSignal(str) set_server_active = QtCore.pyqtSignal(bool) + adjust_size = QtCore.pyqtSignal() def __init__(self, common, qtapp, app, status_bar, server_status_label, system_tray, filenames=None, local_only=False): super(Mode, self).__init__() diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 79565edd..a95b75c9 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -132,6 +132,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_server_active.connect(self.set_server_active) + self.share_mode.adjust_size.connect(self.adjust_size) # Receive mode self.receive_mode = ReceiveMode(self.common, qtapp, app, self.status_bar, self.server_status_label, self.system_tray, None, self.local_only) @@ -146,6 +147,7 @@ class OnionShareGui(QtWidgets.QMainWindow): self.receive_mode.server_status.url_copied.connect(self.copy_url) self.receive_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth) self.receive_mode.set_server_active.connect(self.set_server_active) + self.receive_mode.adjust_size.connect(self.adjust_size) self.update_mode_switcher() self.update_server_status_indicator() @@ -442,6 +444,11 @@ class OnionShareGui(QtWidgets.QMainWindow): # Disable settings menu action when server is active self.settings_action.setEnabled(not active) + def adjust_size(self): + self.share_mode.adjustSize() + self.receive_mode.adjustSize() + self.adjustSize() + def closeEvent(self, e): self.common.log('OnionShareGui', 'closeEvent') try: diff --git a/onionshare_gui/receive_mode/__init__.py b/onionshare_gui/receive_mode/__init__.py index 80bd9cad..efad618a 100644 --- a/onionshare_gui/receive_mode/__init__.py +++ b/onionshare_gui/receive_mode/__init__.py @@ -63,10 +63,19 @@ class ReceiveMode(Mode): self.update_uploads_completed() self.update_uploads_in_progress() + self.info_toggle_button = QtWidgets.QPushButton() + self.info_toggle_button.setDefault(False) + self.info_toggle_button.setFixedWidth(30) + self.info_toggle_button.setFixedHeight(30) + self.info_toggle_button.setFlat(True) + self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle.png')) ) + self.info_toggle_button.clicked.connect(self.toggle_uploads) + self.info_layout = QtWidgets.QHBoxLayout() self.info_layout.addStretch() self.info_layout.addWidget(self.info_in_progress_uploads_count) self.info_layout.addWidget(self.info_completed_uploads_count) + self.info_layout.addWidget(self.info_toggle_button) self.info_widget = QtWidgets.QWidget() self.info_widget.setLayout(self.info_layout) @@ -226,4 +235,21 @@ class ReceiveMode(Mode): self.info_widget.hide() # Resize window - self.adjustSize() + self.adjust_size.emit() + + def toggle_uploads(self): + """ + Toggle showing and hiding the Uploads widget + """ + self.common.log('ReceiveMode', 'toggle_uploads') + + if self.uploads.isVisible(): + self.uploads.hide() + self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle.png')) ) + self.info_toggle_button.setFlat(True) + else: + self.uploads.show() + self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle_selected.png')) ) + self.info_toggle_button.setFlat(False) + + self.adjust_size.emit() diff --git a/onionshare_gui/share_mode/__init__.py b/onionshare_gui/share_mode/__init__.py index 7e444137..cf33e8b1 100644 --- a/onionshare_gui/share_mode/__init__.py +++ b/onionshare_gui/share_mode/__init__.py @@ -226,7 +226,7 @@ class ShareMode(Mode): Stop the compression thread on cancel """ if self.compress_thread: - self.common.log('OnionShareGui', 'cancel_server: quitting compress thread') + self.common.log('ShareMode', 'cancel_server: quitting compress thread') self.compress_thread.quit() def handle_tor_broke_custom(self): @@ -305,6 +305,8 @@ class ShareMode(Mode): self.info_widget.show() def update_primary_action(self): + self.common.log('ShareMode', 'update_primary_action') + # Show or hide primary action layout file_count = self.file_selection.file_list.count() if file_count > 0: @@ -328,7 +330,7 @@ class ShareMode(Mode): self.info_widget.hide() # Resize window - self.adjustSize() + self.adjust_size.emit() def reset_info_counters(self): """ @@ -366,7 +368,18 @@ class ShareMode(Mode): """ Toggle showing and hiding the Downloads widget """ - pass + self.common.log('ShareMode', 'toggle_downloads') + + if self.downloads.isVisible(): + self.downloads.hide() + self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle.png')) ) + self.info_toggle_button.setFlat(True) + else: + self.downloads.show() + self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle_selected.png')) ) + self.info_toggle_button.setFlat(False) + + self.adjust_size.emit() @staticmethod def _compute_total_size(filenames):