From 634b8ecebd72c1108ad99bcbe3c096cf6cd14a94 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 20 Jan 2019 15:49:08 -0800 Subject: [PATCH] When canceling a receive mode transfer, display date range in the UI --- onionshare_gui/mode/history.py | 21 +++++++++++++++++---- share/locale/en.json | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/onionshare_gui/mode/history.py b/onionshare_gui/mode/history.py index 02c34ec4..0ebd8b93 100644 --- a/onionshare_gui/mode/history.py +++ b/onionshare_gui/mode/history.py @@ -45,19 +45,32 @@ class HistoryItem(QtWidgets.QWidget): When an item finishes, returns a string displaying the start/end datetime range. started is a datetime object. """ + return self._get_label_text('gui_all_modes_transfer_finished', 'gui_all_modes_transfer_finished_range', started) + + def get_canceled_label_text(self, started): + """ + When an item is canceled, returns a string displaying the start/end datetime range. + started is a datetime object. + """ + return self._get_label_text('gui_all_modes_transfer_canceled', 'gui_all_modes_transfer_canceled_range', started) + + def _get_label_text(self, string_name, string_range_name, started): + """ + Return a string that contains a date, or date range. + """ ended = datetime.now() if started.year == ended.year and started.month == ended.month and started.day == ended.day: if started.hour == ended.hour and started.minute == ended.minute: - text = strings._('gui_all_modes_transfer_finished').format( + text = strings._(string_name).format( started.strftime("%b %d, %I:%M%p") ) else: - text = strings._('gui_all_modes_transfer_finished_range').format( + text = strings._(string_range_name).format( started.strftime("%b %d, %I:%M%p"), ended.strftime("%I:%M%p") ) else: - text = strings._('gui_all_modes_transfer_finished_range').format( + text = strings._(string_range_name).format( started.strftime("%b %d, %I:%M%p"), ended.strftime("%b %d, %I:%M%p") ) @@ -311,7 +324,7 @@ class ReceiveHistoryItem(HistoryItem): self.progress_bar.hide() # Change the label - self.label.setText(strings._('gui_canceled')) + self.label.setText(self.get_canceled_label_text(self.started)) class HistoryItemList(QtWidgets.QScrollArea): diff --git a/share/locale/en.json b/share/locale/en.json index a3307e49..3ad2efda 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -171,6 +171,8 @@ "gui_all_modes_transfer_started": "Started {}", "gui_all_modes_transfer_finished_range": "Transferred {} - {}", "gui_all_modes_transfer_finished": "Transferred {}", + "gui_all_modes_transfer_canceled_range": "Canceled {} - {}", + "gui_all_modes_transfer_canceled": "Canceled {}", "gui_all_modes_progress_complete": "%p%, {0:s} elapsed.", "gui_all_modes_progress_starting": "{0:s}, %p% (calculating)", "gui_all_modes_progress_eta": "{0:s}, ETA: {1:s}, %p%",