mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Added an info label to file selection, to show the total count and size
This commit is contained in:
parent
532d5d5cf0
commit
fe24c543cc
@ -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()
|
||||
|
@ -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()
|
||||
|
||||
|
@ -140,5 +140,6 @@
|
||||
"gui_url_persistence_warning": "Every share will have the same URL.<br><br>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, {}"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user