diff options
author | Miguel Jacq <mig@mig5.net> | 2018-02-21 15:19:18 +1100 |
---|---|---|
committer | Miguel Jacq <mig@mig5.net> | 2018-02-21 15:19:18 +1100 |
commit | 21b08252d3569848eab4178597585b686b0a332c (patch) | |
tree | 182790b90dc8eec1a3bc99c0b586fbf32c8532ef /onionshare_gui | |
parent | 4002bb554787d420223b8ea8176327a555aae728 (diff) | |
download | onionshare-21b08252d3569848eab4178597585b686b0a332c.tar.gz onionshare-21b08252d3569848eab4178597585b686b0a332c.zip |
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
Diffstat (limited to 'onionshare_gui')
-rw-r--r-- | onionshare_gui/file_selection.py | 20 | ||||
-rw-r--r-- | onionshare_gui/onionshare_gui.py | 9 |
2 files changed, 18 insertions, 11 deletions
diff --git a/onionshare_gui/file_selection.py b/onionshare_gui/file_selection.py index f08073db..4f4c43f2 100644 --- a/onionshare_gui/file_selection.py +++ b/onionshare_gui/file_selection.py @@ -94,7 +94,7 @@ class FileList(QtWidgets.QListWidget): Update the GUI elements based on the current state. """ # 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_text.show() else: @@ -193,15 +193,14 @@ class FileList(QtWidgets.QListWidget): """ 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 not os.access(filename, os.R_OK): Alert(strings._("not_a_readable_file", True).format(filename)) return - self.filenames.append(filename) - # Re-sort the list internally - self.filenames.sort() - fileinfo = QtCore.QFileInfo(filename) basename = os.path.basename(filename.rstrip('/')) ip = QtWidgets.QFileIconProvider() @@ -221,16 +220,22 @@ class FileList(QtWidgets.QListWidget): # Item's name and size labels item_name = QtWidgets.QLabel(basename) + item.filename = filename item_name.setWordWrap(False) item_name.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed) item_name.setStyleSheet('QLabel { color: #000000; font-size: 13px; }') item_size = QtWidgets.QLabel(size_readable) 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 def delete_item(): itemrow = self.row(item) - self.filenames.pop(itemrow) self.takeItem(itemrow) self.files_updated.emit() @@ -330,7 +335,6 @@ class FileSelection(QtWidgets.QVBoxLayout): selected = self.file_list.selectedItems() for item in selected: itemrow = self.file_list.row(item) - self.file_list.filenames.pop(itemrow) self.file_list.takeItem(itemrow) 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. """ - return len(self.file_list.filenames) + return len(range(self.count())) def setFocus(self): """ diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 323adabc..61c2abc0 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -410,8 +410,11 @@ class OnionShareGui(QtWidgets.QMainWindow): # add progress bar to the status bar, indicating the crunching of files. self._zip_progress_bar = ZipProgressBar(0) - self._zip_progress_bar.total_files_size = OnionShareGui._compute_total_size( - self.file_selection.file_list.filenames) + self.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) # prepare the files for sending in a new thread @@ -421,7 +424,7 @@ class OnionShareGui(QtWidgets.QMainWindow): if self._zip_progress_bar != None: self._zip_progress_bar.update_processed_size_signal.emit(x) 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.starting_server_step3.emit() |