From bc573209d9be256822bee00dec6c1376ee197a98 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 7 Oct 2018 18:09:02 -0700 Subject: [PATCH] Delete Info widget, and move completed and in progress widgets into the header of history --- onionshare_gui/mode/history.py | 68 ++++++++-- onionshare_gui/mode/share_mode/__init__.py | 40 +++--- onionshare_gui/mode/share_mode/info.py | 149 --------------------- share/locale/en.json | 4 +- 4 files changed, 72 insertions(+), 189 deletions(-) delete mode 100644 onionshare_gui/mode/share_mode/info.py diff --git a/onionshare_gui/mode/history.py b/onionshare_gui/mode/history.py index 31b4a646..a28340a4 100644 --- a/onionshare_gui/mode/history.py +++ b/onionshare_gui/mode/history.py @@ -179,6 +179,30 @@ class History(QtWidgets.QWidget): self.setMinimumWidth(350) + # In progress and completed counters + self.in_progress_count = 0 + self.completed_count = 0 + + # In progress and completed labels + self.in_progress_label = QtWidgets.QLabel() + self.in_progress_label.setStyleSheet(self.common.css['mode_info_label']) + self.completed_label = QtWidgets.QLabel() + self.completed_label.setStyleSheet(self.common.css['mode_info_label']) + + # Header + self.header_label = QtWidgets.QLabel(header_text) + self.header_label.setStyleSheet(self.common.css['downloads_uploads_label']) + clear_button = QtWidgets.QPushButton(strings._('gui_clear_history', True)) + clear_button.setStyleSheet(self.common.css['downloads_uploads_clear']) + clear_button.setFlat(True) + clear_button.clicked.connect(self.reset) + header_layout = QtWidgets.QHBoxLayout() + header_layout.addWidget(self.header_label) + header_layout.addStretch() + header_layout.addWidget(self.in_progress_label) + header_layout.addWidget(self.completed_label) + header_layout.addWidget(clear_button) + # When there are no items self.empty_image = QtWidgets.QLabel() self.empty_image.setAlignment(QtCore.Qt.AlignCenter) @@ -195,22 +219,9 @@ class History(QtWidgets.QWidget): self.empty.setStyleSheet(self.common.css['downloads_uploads_empty']) self.empty.setLayout(empty_layout) - # Header - self.header_label = QtWidgets.QLabel(header_text) - self.header_label.setStyleSheet(self.common.css['downloads_uploads_label']) - clear_button = QtWidgets.QPushButton(strings._('gui_clear_history', True)) - clear_button.setStyleSheet(self.common.css['downloads_uploads_clear']) - clear_button.setFlat(True) - clear_button.clicked.connect(self.reset) - header_layout = QtWidgets.QHBoxLayout() - header_layout.addWidget(self.header_label) - header_layout.addStretch() - header_layout.addWidget(clear_button) - # When there are items self.item_list = HistoryItemList(self.common) self.not_empty_layout = QtWidgets.QVBoxLayout() - self.not_empty_layout.addLayout(header_layout) self.not_empty_layout.addWidget(self.item_list) self.not_empty = QtWidgets.QWidget() self.not_empty.setLayout(self.not_empty_layout) @@ -218,12 +229,15 @@ class History(QtWidgets.QWidget): # Layout layout = QtWidgets.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) + layout.addLayout(header_layout) layout.addWidget(self.empty) layout.addWidget(self.not_empty) self.setLayout(layout) # Reset once at the beginning self.reset() + self.update_completed() + self.update_in_progress() def add(self, id, item): """ @@ -261,6 +275,34 @@ class History(QtWidgets.QWidget): self.not_empty.hide() self.empty.show() + # Reset counters + self.completed_count = 0 + self.in_progress_count = 0 + self.update_completed() + self.update_in_progress() + + def update_completed(self): + """ + Update the 'completed' widget. + """ + if self.completed_count == 0: + image = self.common.get_resource_path('images/share_completed_none.png') + else: + image = self.common.get_resource_path('images/share_completed.png') + self.completed_label.setText(' {1:d}'.format(image, self.completed_count)) + self.completed_label.setToolTip(strings._('history_completed_tooltip').format(self.completed_count)) + + def update_in_progress(self): + """ + Update the 'in progress' widget. + """ + if self.in_progress_count == 0: + image = self.common.get_resource_path('images/share_in_progress_none.png') + else: + image = self.common.get_resource_path('images/share_in_progress.png') + self.in_progress_label.setText(' {1:d}'.format(image, self.in_progress_count)) + self.in_progress_label.setToolTip(strings._('history_in_progress_tooltip', True).format(self.in_progress_count)) + class ToggleHistory(QtWidgets.QPushButton): """ diff --git a/onionshare_gui/mode/share_mode/__init__.py b/onionshare_gui/mode/share_mode/__init__.py index bae4bec8..0bf094c0 100644 --- a/onionshare_gui/mode/share_mode/__init__.py +++ b/onionshare_gui/mode/share_mode/__init__.py @@ -79,11 +79,6 @@ class ShareMode(Mode): strings._('gui_downloads') ) self.history.hide() - self.downloads_in_progress = 0 - self.downloads_completed = 0 - - # Information about share, and show downloads button - #self.info = ShareModeInfo(self.common, self) # Info label self.info_label = QtWidgets.QLabel() @@ -211,9 +206,9 @@ class ShareMode(Mode): self._zip_progress_bar = None self.filesize_warning.hide() - self.downloads_in_progress = 0 - self.downloads_completed = 0 - #self.info.update_downloads_in_progress() + self.history.in_progress_count = 0 + self.history.completed_count = 0 + self.history.update_in_progress() self.file_selection.file_list.adjustSize() def cancel_server_custom(self): @@ -249,8 +244,8 @@ class ShareMode(Mode): item = DownloadHistoryItem(self.common, event["data"]["id"], filesize) self.history.add(event["data"]["id"], item) self.toggle_history.update_indicator(True) - self.downloads_in_progress += 1 - #self.info.update_downloads_in_progress() + self.history.in_progress_count += 1 + self.history.update_in_progress() self.system_tray.showMessage(strings._('systray_download_started_title', True), strings._('systray_download_started_message', True)) @@ -264,12 +259,11 @@ class ShareMode(Mode): if event["data"]["bytes"] == self.web.share_mode.filesize: self.system_tray.showMessage(strings._('systray_download_completed_title', True), strings._('systray_download_completed_message', True)) - # Update the total 'completed downloads' info - self.downloads_completed += 1 - #self.info.update_downloads_completed() - # Update the 'in progress downloads' info - self.downloads_in_progress -= 1 - #self.info.update_downloads_in_progress() + # Update completed and in progress labels + self.history.completed_count += 1 + self.history.in_progress_count -= 1 + self.history.update_completed() + self.history.update_in_progress() # Close on finish? if self.common.settings.get('close_after_first_download'): @@ -279,8 +273,8 @@ class ShareMode(Mode): else: if self.server_status.status == self.server_status.STATUS_STOPPED: self.history.cancel(event["data"]["id"]) - self.downloads_in_progress = 0 - #self.info.update_downloads_in_progress() + self.history.in_progress_count = 0 + self.history.update_in_progress() def handle_request_canceled(self, event): """ @@ -288,9 +282,9 @@ class ShareMode(Mode): """ self.history.cancel(event["data"]["id"]) - # Update the 'in progress downloads' info - self.downloads_in_progress -= 1 - #self.info.update_downloads_in_progress() + # Update in progress count + self.history.in_progress_count -= 1 + self.history.update_in_progress() self.system_tray.showMessage(strings._('systray_download_canceled_title', True), strings._('systray_download_canceled_message', True)) def on_reload_settings(self): @@ -334,10 +328,6 @@ class ShareMode(Mode): """ Set the info counters back to zero. """ - self.downloads_completed = 0 - self.downloads_in_progress = 0 - #self.info.update_downloads_completed() - #self.info.update_downloads_in_progress() self.history.reset() def resize_window(self): diff --git a/onionshare_gui/mode/share_mode/info.py b/onionshare_gui/mode/share_mode/info.py deleted file mode 100644 index c692649c..00000000 --- a/onionshare_gui/mode/share_mode/info.py +++ /dev/null @@ -1,149 +0,0 @@ -# -*- coding: utf-8 -*- -""" -OnionShare | https://onionshare.org/ - -Copyright (C) 2014-2018 Micah Lee - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" -from PyQt5 import QtCore, QtWidgets, QtGui - -from onionshare import strings - - -class ShareModeInfo(QtWidgets.QWidget): - """ - Share mode information widget - """ - def __init__(self, common, share_mode): - super(ShareModeInfo, self).__init__() - self.common = common - self.share_mode = share_mode - - # Label - self.label_text = "" - self.label = QtWidgets.QLabel() - self.label.setStyleSheet(self.common.css['mode_info_label']) - - # In progress and completed labels - self.in_progress_downloads_count = QtWidgets.QLabel() - self.in_progress_downloads_count.setStyleSheet(self.common.css['mode_info_label']) - self.completed_downloads_count = QtWidgets.QLabel() - self.completed_downloads_count.setStyleSheet(self.common.css['mode_info_label']) - - # Toggle button - self.toggle_button = QtWidgets.QPushButton() - self.toggle_button.setDefault(False) - self.toggle_button.setFixedWidth(35) - self.toggle_button.setFixedHeight(30) - self.toggle_button.setFlat(True) - self.toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle.png')) ) - self.toggle_button.clicked.connect(self.toggle_downloads) - - # Keep track of indicator - self.indicator_count = 0 - self.indicator_label = QtWidgets.QLabel(parent=self.toggle_button) - self.indicator_label.setStyleSheet(self.common.css['download_uploads_indicator']) - self.update_indicator() - - # Layout - layout = QtWidgets.QHBoxLayout() - layout.addWidget(self.label) - layout.addStretch() - layout.addWidget(self.in_progress_downloads_count) - layout.addWidget(self.completed_downloads_count) - layout.addWidget(self.toggle_button) - self.setLayout(layout) - - self.update_downloads_completed() - self.update_downloads_in_progress() - - def update_label(self, s): - """ - Updates the text of the label. - """ - self.label_text = s - self.label.setText(self.label_text) - - def update_indicator(self, increment=False): - """ - Update the display of the indicator count. If increment is True, then - only increment the counter if Downloads is hidden. - """ - if increment and not self.share_mode.downloads.isVisible(): - self.indicator_count += 1 - - self.indicator_label.setText("{}".format(self.indicator_count)) - - if self.indicator_count == 0: - self.indicator_label.hide() - else: - size = self.indicator_label.sizeHint() - self.indicator_label.setGeometry(35-size.width(), 0, size.width(), size.height()) - self.indicator_label.show() - - def update_downloads_completed(self): - """ - Update the 'Downloads completed' info widget. - """ - if self.share_mode.downloads_completed == 0: - image = self.common.get_resource_path('images/share_completed_none.png') - else: - image = self.common.get_resource_path('images/share_completed.png') - self.completed_downloads_count.setText(' {1:d}'.format(image, self.share_mode.downloads_completed)) - self.completed_downloads_count.setToolTip(strings._('info_completed_downloads_tooltip', True).format(self.share_mode.downloads_completed)) - - def update_downloads_in_progress(self): - """ - Update the 'Downloads in progress' info widget. - """ - if self.share_mode.downloads_in_progress == 0: - image = self.common.get_resource_path('images/share_in_progress_none.png') - else: - image = self.common.get_resource_path('images/share_in_progress.png') - self.in_progress_downloads_count.setText(' {1:d}'.format(image, self.share_mode.downloads_in_progress)) - self.in_progress_downloads_count.setToolTip(strings._('info_in_progress_downloads_tooltip', True).format(self.share_mode.downloads_in_progress)) - - def toggle_downloads(self): - """ - Toggle showing and hiding the Downloads widget - """ - self.common.log('ShareModeInfo', 'toggle_downloads') - - if self.share_mode.downloads.isVisible(): - self.share_mode.downloads.hide() - self.toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle.png')) ) - self.toggle_button.setFlat(True) - else: - self.share_mode.downloads.show() - self.toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle_selected.png')) ) - self.toggle_button.setFlat(False) - - # Reset the indicator count - self.indicator_count = 0 - self.update_indicator() - - self.share_mode.resize_window() - - def show_less(self): - """ - Remove clutter widgets that aren't necessary. - """ - self.label.setText("") - - def show_more(self): - """ - Show all widgets. - """ - self.label.setText(self.label_text) diff --git a/share/locale/en.json b/share/locale/en.json index c7beb6ba..3537b0a2 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -151,8 +151,8 @@ "gui_status_indicator_receive_started": "Receiving", "gui_file_info": "{} files, {}", "gui_file_info_single": "{} file, {}", - "info_in_progress_downloads_tooltip": "{} download(s) in progress", - "info_completed_downloads_tooltip": "{} download(s) completed", + "history_in_progress_tooltip": "{} in progress", + "history_completed_tooltip": "{} completed", "info_in_progress_uploads_tooltip": "{} upload(s) in progress", "info_completed_uploads_tooltip": "{} upload(s) completed", "error_cannot_create_downloads_dir": "Could not create receive mode folder: {}",