File: history_row.py

package info (click to toggle)
secrets 11.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,744 kB
  • sloc: python: 6,509; xml: 7; makefile: 4
file content (64 lines) | stat: -rw-r--r-- 2,055 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# SPDX-License-Identifier: GPL-3.0-only
from __future__ import annotations

from gettext import gettext as _

from gi.repository import Adw, GObject, Gtk

from gsecrets.utils import format_time


@Gtk.Template(resource_path="/org/gnome/World/Secrets/gtk/history_row.ui")
class HistoryRow(Adw.ActionRow):
    __gtype_name__ = "HistoryRow"

    visibility_button = Gtk.Template.Child()

    _reveal: bool = False

    def __init__(self, history_entry, window):
        super().__init__()

        self.history_entry = history_entry
        self.list_model = window.list_model
        self.password = history_entry.password
        self.safe_entry = window.safe_entry
        self.unlocked_database = window.unlocked_database
        self.window = window

        self.props.subtitle = format_time(history_entry.mtime)
        self.props.title = "•" * len(self.password)

        self.install_property_action("historyrow.reveal", "reveal")

    @GObject.Property(type=bool, default=False)
    def reveal(self) -> bool:
        return self._reveal

    @reveal.setter  # type: ignore
    def reveal(self, reveal) -> bool:
        button = self.visibility_button
        if reveal:
            button.props.icon_name = "eye-not-looking-symbolic"
            button.props.tooltip_text = _("Hide Text")
            self.props.title = self.password
        else:
            button.props.icon_name = "eye-open-negative-filled-symbolic"
            button.props.tooltip_text = _("Show Text")
            self.props.title = "•" * len(self.password)

        self._reveal = reveal

    @Gtk.Template.Callback()
    def _on_copy_button_clicked(self, _button):
        self.unlocked_database.send_to_clipboard(self.password)

    @Gtk.Template.Callback()
    def _on_delete_button_clicked(self, _button):
        self.safe_entry.delete_history(self.history_entry)
        found, pos = self.list_model.find(self.history_entry)
        if found:
            self.list_model.remove(pos)

        if self.list_model.get_n_items() == 0:
            self.window.close()