mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Use constants for history item status, to be consistent with other parts of the project
This commit is contained in:
parent
759a0dc2a3
commit
8cf8aa201d
@ -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,7 +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 = '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")))
|
||||||
@ -125,7 +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 = 'finished'
|
self.status = HistoryItem.STATUS_FINISHED
|
||||||
|
|
||||||
else:
|
else:
|
||||||
elapsed = time.time() - self.started
|
elapsed = time.time() - self.started
|
||||||
@ -144,7 +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 = 'canceled'
|
self.status = HistoryItem.STATUS_CANCELED
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def estimated_time_remaining(self):
|
def estimated_time_remaining(self):
|
||||||
@ -240,7 +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 = 'started'
|
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")))
|
||||||
@ -318,7 +322,7 @@ class ReceiveHistoryItem(HistoryItem):
|
|||||||
|
|
||||||
elif data['action'] == 'finished':
|
elif data['action'] == 'finished':
|
||||||
# Change the status
|
# Change the status
|
||||||
self.status = 'finished'
|
self.status = HistoryItem.STATUS_FINISHED
|
||||||
|
|
||||||
# Hide the progress bar
|
# Hide the progress bar
|
||||||
self.progress_bar.hide()
|
self.progress_bar.hide()
|
||||||
@ -328,7 +332,7 @@ class ReceiveHistoryItem(HistoryItem):
|
|||||||
|
|
||||||
elif data['action'] == 'canceled':
|
elif data['action'] == 'canceled':
|
||||||
# Change the status
|
# Change the status
|
||||||
self.status = 'canceled'
|
self.status = HistoryItem.STATUS_CANCELED
|
||||||
|
|
||||||
# Hide the progress bar
|
# Hide the progress bar
|
||||||
self.progress_bar.hide()
|
self.progress_bar.hide()
|
||||||
@ -400,7 +404,7 @@ class HistoryItemList(QtWidgets.QScrollArea):
|
|||||||
Reset all items, emptying the list. Override this method.
|
Reset all items, emptying the list. Override this method.
|
||||||
"""
|
"""
|
||||||
for key, item in self.items.copy().items():
|
for key, item in self.items.copy().items():
|
||||||
if item.status != 'started':
|
if item.status != HistoryItem.STATUS_STARTED:
|
||||||
self.items_layout.removeWidget(item)
|
self.items_layout.removeWidget(item)
|
||||||
item.close()
|
item.close()
|
||||||
del self.items[key]
|
del self.items[key]
|
||||||
|
Loading…
Reference in New Issue
Block a user