Skip to content

Commit

Permalink
Revert the addition of tooltips to most SecureQLabel occurrences
Browse files Browse the repository at this point in the history
Tooltips are only needed in the conversation view for long filenames
that get truncated.
  • Loading branch information
rmol authored and sssoleileraaa committed Mar 27, 2020
1 parent 97ce5bb commit 5ec5c7c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
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

0 comments on commit 5ec5c7c

Please sign in to comment.