Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert the addition of tooltips to most SecureQLabel occurrences #1016

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions securedrop_client/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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))
Expand Down
23 changes: 23 additions & 0 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
Expand Down