From def8289a8ba232a93da7e35e8a9810f3f54cbc57 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 10 Feb 2018 11:48:14 -0800 Subject: [PATCH] Added an info label to file selection, to show the total count and size --- onionshare_gui/file_selection.py | 37 ++++++++++++++++++++++++++------ onionshare_gui/onionshare_gui.py | 1 - share/locale/en.json | 3 ++- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/onionshare_gui/file_selection.py b/onionshare_gui/file_selection.py index d52fd017..317edc1a 100644 --- a/onionshare_gui/file_selection.py +++ b/onionshare_gui/file_selection.py @@ -207,15 +207,18 @@ class FileList(QtWidgets.QListWidget): icon = ip.icon(fileinfo) if os.path.isfile(filename): - size = common.human_readable_filesize(fileinfo.size()) + size_bytes = fileinfo.size() + size_readable = common.human_readable_filesize(size_bytes) else: - size = common.human_readable_filesize(common.dir_size(filename)) - item_name = '{0:s} ({1:s})'.format(basename, size) + size_bytes = common.dir_size(filename) + size_readable = common.human_readable_filesize(size_bytes) + item_name = '{0:s} ({1:s})'.format(basename, size_readable) # Create a new item item = QtWidgets.QListWidgetItem(item_name) - item.setToolTip(size) + item.setToolTip(size_readable) item.setIcon(icon) + item.size_bytes = size_bytes # Item's delete button def delete_item(): @@ -252,12 +255,17 @@ class FileSelection(QtWidgets.QVBoxLayout): super(FileSelection, self).__init__() self.server_on = False - # file list + # Info label + self.info_label = QtWidgets.QLabel() + self.info_label.setStyleSheet('QLabel { font-size: 12px; color: #666666; }') + + # File list self.file_list = FileList() self.file_list.currentItemChanged.connect(self.update) self.file_list.files_dropped.connect(self.update) + self.file_list.files_updated.connect(self.update) - # buttons + # Buttons self.add_button = QtWidgets.QPushButton(strings._('gui_add', True)) self.add_button.clicked.connect(self.add) self.delete_button = QtWidgets.QPushButton(strings._('gui_delete', True)) @@ -267,7 +275,8 @@ class FileSelection(QtWidgets.QVBoxLayout): button_layout.addWidget(self.add_button) button_layout.addWidget(self.delete_button) - # add the widgets + # Add the widgets + self.addWidget(self.info_label) self.addWidget(self.file_list) self.addLayout(button_layout) @@ -277,6 +286,20 @@ class FileSelection(QtWidgets.QVBoxLayout): """ Update the GUI elements based on the current state. """ + # Update the info label + file_count = self.file_list.count() + if file_count == 0: + self.info_label.hide() + else: + total_size_bytes = 0 + for index in range(self.file_list.count()): + item = self.file_list.item(index) + total_size_bytes += item.size_bytes + total_size_readable = common.human_readable_filesize(total_size_bytes) + + self.info_label.setText(strings._('gui_file_info', True).format(file_count, total_size_readable)) + self.info_label.show() + # All buttons should be hidden if the server is on if self.server_on: self.add_button.hide() diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 05e01530..5d0999b2 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -182,7 +182,6 @@ class OnionShareGui(QtWidgets.QMainWindow): self.check_for_updates() def update_primary_action(self): - common.log('OnionShareGui', 'update_primary_action') # Resize window self.adjustSize() diff --git a/share/locale/en.json b/share/locale/en.json index 4644d21e..2daff998 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -140,5 +140,6 @@ "gui_url_persistence_warning": "Every share will have the same URL.

If you want to go back to using one-time URLs, turn off persistence in the Settings.", "gui_status_indicator_stopped": "Ready to Share", "gui_status_indicator_working": "Starting...", - "gui_status_indicator_started": "Sharing" + "gui_status_indicator_started": "Sharing", + "gui_file_info": "{} Files, {}" }