Merge branch 'develop' into 899_send_files_ajax

This commit is contained in:
Micah Lee 2019-02-17 10:08:01 -08:00
commit 430396a433
3 changed files with 31 additions and 18 deletions

View file

@ -361,14 +361,14 @@ class ReceiveModeRequest(Request):
self.told_gui_about_request = True self.told_gui_about_request = True
filename = secure_filename(filename) self.filename = secure_filename(filename)
self.progress[filename] = { self.progress[self.filename] = {
'uploaded_bytes': 0, 'uploaded_bytes': 0,
'complete': False 'complete': False
} }
f = ReceiveModeFile(self, filename, self.file_write_func, self.file_close_func) f = ReceiveModeFile(self, self.filename, self.file_write_func, self.file_close_func)
if f.upload_error: if f.upload_error:
self.web.common.log('ReceiveModeRequest', '_get_file_stream', 'Error creating file') self.web.common.log('ReceiveModeRequest', '_get_file_stream', 'Error creating file')
self.upload_error = True self.upload_error = True
@ -391,7 +391,7 @@ class ReceiveModeRequest(Request):
if self.told_gui_about_request: if self.told_gui_about_request:
upload_id = self.upload_id upload_id = self.upload_id
if not self.web.stop_q.empty(): if not self.web.stop_q.empty() or not self.progress[self.filename]['complete']:
# Inform the GUI that the upload has canceled # Inform the GUI that the upload has canceled
self.web.add_request(self.web.REQUEST_UPLOAD_CANCELED, self.path, { self.web.add_request(self.web.REQUEST_UPLOAD_CANCELED, self.path, {
'id': upload_id 'id': upload_id

View file

@ -31,6 +31,10 @@ class HistoryItem(QtWidgets.QWidget):
""" """
The base history item The base history item
""" """
STATUS_STARTED = 0
STATUS_FINISHED = 1
STATUS_CANCELED = 2
def __init__(self): def __init__(self):
super(HistoryItem, self).__init__() super(HistoryItem, self).__init__()
@ -90,6 +94,7 @@ class ShareHistoryItem(HistoryItem):
self.downloaded_bytes = 0 self.downloaded_bytes = 0
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
# Label # Label
self.label = QtWidgets.QLabel(strings._('gui_all_modes_transfer_started').format(self.started_dt.strftime("%b %d, %I:%M%p"))) self.label = QtWidgets.QLabel(strings._('gui_all_modes_transfer_started').format(self.started_dt.strftime("%b %d, %I:%M%p")))
@ -124,6 +129,7 @@ class ShareHistoryItem(HistoryItem):
# Change the label # Change the label
self.label.setText(self.get_finished_label_text(self.started_dt)) self.label.setText(self.get_finished_label_text(self.started_dt))
self.status = HistoryItem.STATUS_FINISHED
else: else:
elapsed = time.time() - self.started elapsed = time.time() - self.started
@ -142,6 +148,7 @@ class ShareHistoryItem(HistoryItem):
def cancel(self): def cancel(self):
self.progress_bar.setFormat(strings._('gui_canceled')) self.progress_bar.setFormat(strings._('gui_canceled'))
self.status = HistoryItem.STATUS_CANCELED
@property @property
def estimated_time_remaining(self): def estimated_time_remaining(self):
@ -237,6 +244,7 @@ class ReceiveHistoryItem(HistoryItem):
self.id = id self.id = id
self.content_length = content_length self.content_length = content_length
self.started = datetime.now() self.started = datetime.now()
self.status = HistoryItem.STATUS_STARTED
# Label # Label
self.label = QtWidgets.QLabel(strings._('gui_all_modes_transfer_started').format(self.started.strftime("%b %d, %I:%M%p"))) self.label = QtWidgets.QLabel(strings._('gui_all_modes_transfer_started').format(self.started.strftime("%b %d, %I:%M%p")))
@ -313,6 +321,9 @@ class ReceiveHistoryItem(HistoryItem):
self.files[data['filename']].set_dir(data['dir']) self.files[data['filename']].set_dir(data['dir'])
elif data['action'] == 'finished': elif data['action'] == 'finished':
# Change the status
self.status = HistoryItem.STATUS_FINISHED
# Hide the progress bar # Hide the progress bar
self.progress_bar.hide() self.progress_bar.hide()
@ -320,6 +331,9 @@ class ReceiveHistoryItem(HistoryItem):
self.label.setText(self.get_finished_label_text(self.started)) self.label.setText(self.get_finished_label_text(self.started))
elif data['action'] == 'canceled': elif data['action'] == 'canceled':
# Change the status
self.status = HistoryItem.STATUS_CANCELED
# Hide the progress bar # Hide the progress bar
self.progress_bar.hide() self.progress_bar.hide()
@ -389,11 +403,11 @@ class HistoryItemList(QtWidgets.QScrollArea):
""" """
Reset all items, emptying the list. Override this method. Reset all items, emptying the list. Override this method.
""" """
for item in self.items.values(): for key, item in self.items.copy().items():
self.items_layout.removeWidget(item) if item.status != HistoryItem.STATUS_STARTED:
item.close() self.items_layout.removeWidget(item)
self.items = {} item.close()
del self.items[key]
class History(QtWidgets.QWidget): class History(QtWidgets.QWidget):
""" """
@ -494,16 +508,17 @@ class History(QtWidgets.QWidget):
Reset all items. Reset all items.
""" """
self.item_list.reset() self.item_list.reset()
if len(self.item_list.items) == 0:
# Hide not empty, show empty
self.not_empty.hide()
self.empty.show()
# Reset in-progress counter
self.in_progress_count = 0
self.update_in_progress()
# Hide not empty, show empty # Reset completed counter
self.not_empty.hide()
self.empty.show()
# Reset counters
self.completed_count = 0 self.completed_count = 0
self.in_progress_count = 0
self.update_completed() self.update_completed()
self.update_in_progress()
def update_completed(self): def update_completed(self):
""" """

View file

@ -198,9 +198,7 @@ class ReceiveMode(Mode):
self.history.update(event["data"]["id"], { self.history.update(event["data"]["id"], {
'action': 'canceled' 'action': 'canceled'
}) })
self.history.completed_count += 1
self.history.in_progress_count -= 1 self.history.in_progress_count -= 1
self.history.update_completed()
self.history.update_in_progress() self.history.update_in_progress()
def on_reload_settings(self): def on_reload_settings(self):