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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
# SPDX-License-Identifier: GPL-3.0-only
from __future__ import annotations
from gettext import gettext as _
from gi.repository import Adw, GLib, GObject, Gtk
from gsecrets.safe_element import SafeEntry
from gsecrets.utils import format_time
@Gtk.Template(resource_path="/org/gnome/World/Secrets/gtk/expiration_date_row.ui")
class ExpirationDateRow(Adw.Bin):
"""Expiration date widget.
All the dates are stored and gathered in UTC and showed in the local
timezone.
"""
__gtype_name__ = "ExpirationDateRow"
action_row = Gtk.Template.Child()
calendar = Gtk.Template.Child()
popover = Gtk.Template.Child()
remove_button = Gtk.Template.Child()
popover_edit_button = Gtk.Template.Child()
list_box = Gtk.Template.Child()
_safe_entry = None
def do_mnemonic_activate(self, group_cycling: bool) -> bool:
# pylint: disable=arguments-differ
return self.action_row.mnemonic_activate(group_cycling)
@GObject.Property(type=SafeEntry)
def safe_entry(self) -> SafeEntry:
return self._safe_entry
@safe_entry.setter # type: ignore
def safe_entry(self, entry: SafeEntry) -> None:
self._safe_entry = entry
entry.bind_property(
"expires",
self.remove_button,
"sensitive",
GObject.BindingFlags.SYNC_CREATE,
)
entry.connect("notify::expired", self.on_safe_entry_notify_expired)
expiry_date = entry.expiry_time # UTC
if entry.props.expires and expiry_date:
self.calendar.select_day(expiry_date.to_local())
self.action_row.props.title = format_time(expiry_date, hours=False).lstrip()
if entry.props.expired:
self.action_row.props.subtitle = _("Entry expired")
def on_safe_entry_notify_expired(
self,
safe_entry: SafeEntry,
_gparam: GObject.ParamSpecBoolean,
) -> None:
if safe_entry.props.expired:
self.action_row.props.subtitle = _("Entry expired")
else:
self.action_row.props.subtitle = None
@Gtk.Template.Callback()
def on_edit_button_clicked(self, _button: Gtk.Button) -> None:
safe_entry = self.props.safe_entry
date = self.calendar.get_date().to_utc()
safe_entry.expiry_time = date
self.action_row.props.title = format_time(date, hours=False).lstrip()
safe_entry.props.expires = True
self.popover.popdown()
@Gtk.Template.Callback()
def on_remove_button_clicked(self, _button: Gtk.Button) -> None:
safe_entry = self.props.safe_entry
self.action_row.props.title = _("Expiration Date not Set")
self.action_row.props.subtitle = None
now = GLib.DateTime.new_now_utc()
self.calendar.select_day(now)
safe_entry.props.expires = False
|