From 5069dcabb89bbf7745bc14cf39c54161b92d8b20 Mon Sep 17 00:00:00 2001 From: John Hensley Date: Thu, 26 Mar 2020 18:44:19 -0400 Subject: [PATCH] Revert the addition of tooltips to most SecureQLabel occurrences Tooltips are only needed in the conversation view for long filenames that get truncated. --- securedrop_client/gui/__init__.py | 8 ++++---- securedrop_client/gui/widgets.py | 6 ++++-- tests/gui/test_widgets.py | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/securedrop_client/gui/__init__.py b/securedrop_client/gui/__init__.py index f796e3b81..54b1aac2d 100644 --- a/securedrop_client/gui/__init__.py +++ b/securedrop_client/gui/__init__.py @@ -154,7 +154,7 @@ def __init__( flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags(), wordwrap: bool = True, max_length: int = 0, - with_tooltip: bool = True, + with_tooltip: bool = False, ): super().__init__(parent, flags) self.wordwrap = wordwrap @@ -166,11 +166,11 @@ def __init__( def setText(self, text: str) -> None: self.setTextFormat(Qt.PlainText) - if self.with_tooltip: - tooltip_label = SecureQLabel(text, with_tooltip=False) - self.setToolTip(tooltip_label.text()) elided_text = self.get_elided_text(text) self.elided = True if elided_text != text else False + if self.elided and self.with_tooltip: + tooltip_label = SecureQLabel(text) + self.setToolTip(tooltip_label.text()) super().setText(elided_text) def get_elided_text(self, full_text: str) -> str: diff --git a/securedrop_client/gui/widgets.py b/securedrop_client/gui/widgets.py index 513c732ea..86d35df51 100644 --- a/securedrop_client/gui/widgets.py +++ b/securedrop_client/gui/widgets.py @@ -1175,7 +1175,7 @@ def __init__(self, controller: Controller, source: Source): summary_layout.setSpacing(0) self.name = QLabel() self.name.setObjectName('source_name') - self.preview = SecureQLabel(max_length=self.PREVIEW_WIDTH, with_tooltip=False) + self.preview = SecureQLabel(max_length=self.PREVIEW_WIDTH) self.preview.setObjectName('preview') self.preview.setFixedSize(QSize(self.PREVIEW_WIDTH, self.PREVIEW_HEIGHT)) self.waiting_delete_confirmation = QLabel('Deletion in progress') @@ -2248,7 +2248,9 @@ def __init__( self.export_button.clicked.connect(self._on_export_clicked) self.print_button.clicked.connect(self._on_print_clicked) - self.file_name = SecureQLabel(wordwrap=False, max_length=self.FILENAME_WIDTH_PX) + self.file_name = SecureQLabel( + wordwrap=False, max_length=self.FILENAME_WIDTH_PX, with_tooltip=True + ) self.file_name.setObjectName('file_name') self.file_name.installEventFilter(self) self.file_name.setCursor(QCursor(Qt.PointingHandCursor)) diff --git a/tests/gui/test_widgets.py b/tests/gui/test_widgets.py index 99a13d79a..8929ad5bc 100644 --- a/tests/gui/test_widgets.py +++ b/tests/gui/test_widgets.py @@ -2373,6 +2373,29 @@ def test_FileWidget_on_file_download_updates_items_when_uuid_matches(mocker, sou assert not fw.file_name.isHidden() +def test_FileWidget_filename_truncation(mocker, source, session): + """ + FileWidget should truncate long filenames. + + The full filename should be available in the tooltip. + """ + filename = "1-{}".format("x" * 1000) + file = factory.File(source=source['source'], filename=filename) + session.add(file) + session.commit() + + get_file = mocker.MagicMock(return_value=file) + controller = mocker.MagicMock(get_file=get_file) + + fw = FileWidget(file.uuid, controller, mocker.MagicMock(), mocker.MagicMock(), 0) + fw.update = mocker.MagicMock() + + fw._on_file_downloaded(file.source.uuid, file.uuid, str(file)) + + assert fw.file_name.text().endswith("...") + assert fw.file_name.toolTip() == filename + + def test_FileWidget_on_file_download_updates_items_when_uuid_does_not_match( mocker, homedir, session, source, ):