diff --git a/onionshare/web/send_base_mode.py b/onionshare/web/send_base_mode.py index 402bc32f..eb6525d1 100644 --- a/onionshare/web/send_base_mode.py +++ b/onionshare/web/send_base_mode.py @@ -79,6 +79,15 @@ class SendBaseModeWeb: self.set_file_info_custom(filenames, processed_size_callback) def directory_listing(self, filenames, path='', filesystem_path=None): + # Tell the GUI about the directory listing + download_id = self.download_count + self.download_count += 1 + self.web.add_request(self.web.REQUEST_INDIVIDUAL_FILE_STARTED, '/{}'.format(path), { + 'id': download_id, + 'method': request.method, + 'directory_listing': True + }) + # If filesystem_path is None, this is the root directory listing files, dirs = self.build_directory_listing(filenames, filesystem_path) r = self.directory_listing_template(path, files, dirs) @@ -132,13 +141,11 @@ class SendBaseModeWeb: file_to_download = filesystem_path filesize = os.path.getsize(filesystem_path) - # Each download has a unique id - download_id = self.download_count - self.download_count += 1 - path = request.path # Tell GUI the individual file started + download_id = self.download_count + self.download_count += 1 self.web.add_request(self.web.REQUEST_INDIVIDUAL_FILE_STARTED, path, { 'id': download_id, 'filesize': filesize, diff --git a/onionshare_gui/mode/history.py b/onionshare_gui/mode/history.py index a9fbbb36..ce783d46 100644 --- a/onionshare_gui/mode/history.py +++ b/onionshare_gui/mode/history.py @@ -352,34 +352,34 @@ class IndividualFileHistoryItem(HistoryItem): self.id = id self.path = path - self.method = data['method'] - self.total_bytes = data['filesize'] + self.total_bytes = 0 self.downloaded_bytes = 0 + self.method = data['method'] self.started = time.time() self.started_dt = datetime.fromtimestamp(self.started) self.status = HistoryItem.STATUS_STARTED + self.directory_listing = 'directory_listing' in data + # Labels self.timestamp_label = QtWidgets.QLabel(self.started_dt.strftime("%b %d, %I:%M%p")) self.method_label = QtWidgets.QLabel("{} {}".format(self.method, self.path)) - self.status_label = QtWidgets.QLabel() + self.status_code_label = QtWidgets.QLabel() # Progress bar self.progress_bar = QtWidgets.QProgressBar() self.progress_bar.setTextVisible(True) self.progress_bar.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.progress_bar.setAlignment(QtCore.Qt.AlignHCenter) - self.progress_bar.setMinimum(0) - self.progress_bar.setMaximum(data['filesize']) self.progress_bar.setValue(0) self.progress_bar.setStyleSheet(self.common.css['downloads_uploads_progress_bar']) - self.progress_bar.total_bytes = data['filesize'] # Text layout labels_layout = QtWidgets.QHBoxLayout() labels_layout.addWidget(self.timestamp_label) labels_layout.addWidget(self.method_label) - labels_layout.addWidget(self.status_label) + labels_layout.addWidget(self.status_code_label) + labels_layout.addStretch() # Layout layout = QtWidgets.QVBoxLayout() @@ -389,11 +389,26 @@ class IndividualFileHistoryItem(HistoryItem): # All non-GET requests are error 405 Method Not Allowed if self.method.lower() != 'get': - self.status_label.setText("405") + self.status_code_label.setText("405") + self.status = HistoryItem.STATUS_FINISHED self.progress_bar.hide() + return + + # Is this a directory listing? + if self.directory_listing: + self.status_code_label.setText("200") + self.status = HistoryItem.STATUS_FINISHED + self.progress_bar.hide() + return + else: - # Start at 0 - self.update(0) + self.total_bytes = data['filesize'] + self.progress_bar.setMinimum(0) + self.progress_bar.setMaximum(data['filesize']) + self.progress_bar.total_bytes = data['filesize'] + + # Start at 0 + self.update(0) def update(self, downloaded_bytes): self.downloaded_bytes = downloaded_bytes