summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2019-09-03 21:59:49 -0700
committerMicah Lee <micah@micahflee.com>2019-09-03 21:59:49 -0700
commit655bb5bad1ccadd3aaa0f4bd20119de350429be5 (patch)
tree5352c32a1651897ee236606c5567bc94df93369c
parent644b47082a716de9a7e2311b9f3c2a75c4d96fbe (diff)
downloadonionshare-655bb5bad1ccadd3aaa0f4bd20119de350429be5.tar.gz
onionshare-655bb5bad1ccadd3aaa0f4bd20119de350429be5.zip
Show IndividualFileHistoryItem widgets for directory listings
-rw-r--r--onionshare/web/send_base_mode.py15
-rw-r--r--onionshare_gui/mode/history.py35
2 files changed, 36 insertions, 14 deletions
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