mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-14 16:57:16 -05:00
Show IndividualFileHistoryItem widgets for directory listings
This commit is contained in:
parent
644b47082a
commit
655bb5bad1
@ -79,6 +79,15 @@ class SendBaseModeWeb:
|
|||||||
self.set_file_info_custom(filenames, processed_size_callback)
|
self.set_file_info_custom(filenames, processed_size_callback)
|
||||||
|
|
||||||
def directory_listing(self, filenames, path='', filesystem_path=None):
|
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
|
# If filesystem_path is None, this is the root directory listing
|
||||||
files, dirs = self.build_directory_listing(filenames, filesystem_path)
|
files, dirs = self.build_directory_listing(filenames, filesystem_path)
|
||||||
r = self.directory_listing_template(path, files, dirs)
|
r = self.directory_listing_template(path, files, dirs)
|
||||||
@ -132,13 +141,11 @@ class SendBaseModeWeb:
|
|||||||
file_to_download = filesystem_path
|
file_to_download = filesystem_path
|
||||||
filesize = os.path.getsize(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
|
path = request.path
|
||||||
|
|
||||||
# Tell GUI the individual file started
|
# 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, {
|
self.web.add_request(self.web.REQUEST_INDIVIDUAL_FILE_STARTED, path, {
|
||||||
'id': download_id,
|
'id': download_id,
|
||||||
'filesize': filesize,
|
'filesize': filesize,
|
||||||
|
@ -352,34 +352,34 @@ class IndividualFileHistoryItem(HistoryItem):
|
|||||||
|
|
||||||
self.id = id
|
self.id = id
|
||||||
self.path = path
|
self.path = path
|
||||||
self.method = data['method']
|
self.total_bytes = 0
|
||||||
self.total_bytes = data['filesize']
|
|
||||||
self.downloaded_bytes = 0
|
self.downloaded_bytes = 0
|
||||||
|
self.method = data['method']
|
||||||
self.started = time.time()
|
self.started = time.time()
|
||||||
self.started_dt = datetime.fromtimestamp(self.started)
|
self.started_dt = datetime.fromtimestamp(self.started)
|
||||||
self.status = HistoryItem.STATUS_STARTED
|
self.status = HistoryItem.STATUS_STARTED
|
||||||
|
|
||||||
|
self.directory_listing = 'directory_listing' in data
|
||||||
|
|
||||||
# Labels
|
# Labels
|
||||||
self.timestamp_label = QtWidgets.QLabel(self.started_dt.strftime("%b %d, %I:%M%p"))
|
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.method_label = QtWidgets.QLabel("{} {}".format(self.method, self.path))
|
||||||
self.status_label = QtWidgets.QLabel()
|
self.status_code_label = QtWidgets.QLabel()
|
||||||
|
|
||||||
# Progress bar
|
# Progress bar
|
||||||
self.progress_bar = QtWidgets.QProgressBar()
|
self.progress_bar = QtWidgets.QProgressBar()
|
||||||
self.progress_bar.setTextVisible(True)
|
self.progress_bar.setTextVisible(True)
|
||||||
self.progress_bar.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
self.progress_bar.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
||||||
self.progress_bar.setAlignment(QtCore.Qt.AlignHCenter)
|
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.setValue(0)
|
||||||
self.progress_bar.setStyleSheet(self.common.css['downloads_uploads_progress_bar'])
|
self.progress_bar.setStyleSheet(self.common.css['downloads_uploads_progress_bar'])
|
||||||
self.progress_bar.total_bytes = data['filesize']
|
|
||||||
|
|
||||||
# Text layout
|
# Text layout
|
||||||
labels_layout = QtWidgets.QHBoxLayout()
|
labels_layout = QtWidgets.QHBoxLayout()
|
||||||
labels_layout.addWidget(self.timestamp_label)
|
labels_layout.addWidget(self.timestamp_label)
|
||||||
labels_layout.addWidget(self.method_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
|
||||||
layout = QtWidgets.QVBoxLayout()
|
layout = QtWidgets.QVBoxLayout()
|
||||||
@ -389,11 +389,26 @@ class IndividualFileHistoryItem(HistoryItem):
|
|||||||
|
|
||||||
# All non-GET requests are error 405 Method Not Allowed
|
# All non-GET requests are error 405 Method Not Allowed
|
||||||
if self.method.lower() != 'get':
|
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()
|
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:
|
else:
|
||||||
# Start at 0
|
self.total_bytes = data['filesize']
|
||||||
self.update(0)
|
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):
|
def update(self, downloaded_bytes):
|
||||||
self.downloaded_bytes = downloaded_bytes
|
self.downloaded_bytes = downloaded_bytes
|
||||||
|
Loading…
Reference in New Issue
Block a user