mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-06 22:09:15 -04:00
Use the QListWidgetItems for building lists of filenames. Set, but avoid displaying, the QString from Qt.DisplayRole which is necessary for correct sorting in the list
This commit is contained in:
parent
4002bb5547
commit
21b08252d3
2 changed files with 18 additions and 11 deletions
|
@ -94,7 +94,7 @@ class FileList(QtWidgets.QListWidget):
|
||||||
Update the GUI elements based on the current state.
|
Update the GUI elements based on the current state.
|
||||||
"""
|
"""
|
||||||
# file list should have a background image if empty
|
# file list should have a background image if empty
|
||||||
if len(self.filenames) == 0:
|
if self.count() == 0:
|
||||||
self.drop_here_image.show()
|
self.drop_here_image.show()
|
||||||
self.drop_here_text.show()
|
self.drop_here_text.show()
|
||||||
else:
|
else:
|
||||||
|
@ -193,15 +193,14 @@ class FileList(QtWidgets.QListWidget):
|
||||||
"""
|
"""
|
||||||
Add a file or directory to this widget.
|
Add a file or directory to this widget.
|
||||||
"""
|
"""
|
||||||
|
for index in range(self.count()):
|
||||||
|
self.filenames.append(self.item(index))
|
||||||
|
|
||||||
if filename not in self.filenames:
|
if filename not in self.filenames:
|
||||||
if not os.access(filename, os.R_OK):
|
if not os.access(filename, os.R_OK):
|
||||||
Alert(strings._("not_a_readable_file", True).format(filename))
|
Alert(strings._("not_a_readable_file", True).format(filename))
|
||||||
return
|
return
|
||||||
|
|
||||||
self.filenames.append(filename)
|
|
||||||
# Re-sort the list internally
|
|
||||||
self.filenames.sort()
|
|
||||||
|
|
||||||
fileinfo = QtCore.QFileInfo(filename)
|
fileinfo = QtCore.QFileInfo(filename)
|
||||||
basename = os.path.basename(filename.rstrip('/'))
|
basename = os.path.basename(filename.rstrip('/'))
|
||||||
ip = QtWidgets.QFileIconProvider()
|
ip = QtWidgets.QFileIconProvider()
|
||||||
|
@ -221,16 +220,22 @@ class FileList(QtWidgets.QListWidget):
|
||||||
|
|
||||||
# Item's name and size labels
|
# Item's name and size labels
|
||||||
item_name = QtWidgets.QLabel(basename)
|
item_name = QtWidgets.QLabel(basename)
|
||||||
|
item.filename = filename
|
||||||
item_name.setWordWrap(False)
|
item_name.setWordWrap(False)
|
||||||
item_name.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed)
|
item_name.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed)
|
||||||
item_name.setStyleSheet('QLabel { color: #000000; font-size: 13px; }')
|
item_name.setStyleSheet('QLabel { color: #000000; font-size: 13px; }')
|
||||||
item_size = QtWidgets.QLabel(size_readable)
|
item_size = QtWidgets.QLabel(size_readable)
|
||||||
item_size.setStyleSheet('QLabel { color: #666666; font-size: 11px; }')
|
item_size.setStyleSheet('QLabel { color: #666666; font-size: 11px; }')
|
||||||
|
|
||||||
|
# Use the basename as the method with which to sort the list
|
||||||
|
item.setData(QtCore.Qt.DisplayRole, basename)
|
||||||
|
# But we don't want to *display* the QString (we have our own QLabel), so paint over it.
|
||||||
|
item.brush = QtGui.QBrush(QtGui.QColor('white'))
|
||||||
|
item.setForeground(item.brush)
|
||||||
|
|
||||||
# Item's delete button
|
# Item's delete button
|
||||||
def delete_item():
|
def delete_item():
|
||||||
itemrow = self.row(item)
|
itemrow = self.row(item)
|
||||||
self.filenames.pop(itemrow)
|
|
||||||
self.takeItem(itemrow)
|
self.takeItem(itemrow)
|
||||||
self.files_updated.emit()
|
self.files_updated.emit()
|
||||||
|
|
||||||
|
@ -330,7 +335,6 @@ class FileSelection(QtWidgets.QVBoxLayout):
|
||||||
selected = self.file_list.selectedItems()
|
selected = self.file_list.selectedItems()
|
||||||
for item in selected:
|
for item in selected:
|
||||||
itemrow = self.file_list.row(item)
|
itemrow = self.file_list.row(item)
|
||||||
self.file_list.filenames.pop(itemrow)
|
|
||||||
self.file_list.takeItem(itemrow)
|
self.file_list.takeItem(itemrow)
|
||||||
self.file_list.files_updated.emit()
|
self.file_list.files_updated.emit()
|
||||||
|
|
||||||
|
@ -357,7 +361,7 @@ class FileSelection(QtWidgets.QVBoxLayout):
|
||||||
"""
|
"""
|
||||||
Returns the total number of files and folders in the list.
|
Returns the total number of files and folders in the list.
|
||||||
"""
|
"""
|
||||||
return len(self.file_list.filenames)
|
return len(range(self.count()))
|
||||||
|
|
||||||
def setFocus(self):
|
def setFocus(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -410,8 +410,11 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
|
|
||||||
# add progress bar to the status bar, indicating the crunching of files.
|
# add progress bar to the status bar, indicating the crunching of files.
|
||||||
self._zip_progress_bar = ZipProgressBar(0)
|
self._zip_progress_bar = ZipProgressBar(0)
|
||||||
self._zip_progress_bar.total_files_size = OnionShareGui._compute_total_size(
|
self.filenames = []
|
||||||
self.file_selection.file_list.filenames)
|
for index in range(self.file_selection.file_list.count()):
|
||||||
|
self.filenames.append(self.file_selection.file_list.item(index).filename)
|
||||||
|
|
||||||
|
self._zip_progress_bar.total_files_size = OnionShareGui._compute_total_size(self.filenames)
|
||||||
self.status_bar.insertWidget(0, self._zip_progress_bar)
|
self.status_bar.insertWidget(0, self._zip_progress_bar)
|
||||||
|
|
||||||
# prepare the files for sending in a new thread
|
# prepare the files for sending in a new thread
|
||||||
|
@ -421,7 +424,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
if self._zip_progress_bar != None:
|
if self._zip_progress_bar != None:
|
||||||
self._zip_progress_bar.update_processed_size_signal.emit(x)
|
self._zip_progress_bar.update_processed_size_signal.emit(x)
|
||||||
try:
|
try:
|
||||||
web.set_file_info(self.file_selection.file_list.filenames, processed_size_callback=_set_processed_size)
|
web.set_file_info(self.filenames, processed_size_callback=_set_processed_size)
|
||||||
self.app.cleanup_filenames.append(web.zip_filename)
|
self.app.cleanup_filenames.append(web.zip_filename)
|
||||||
self.starting_server_step3.emit()
|
self.starting_server_step3.emit()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue