mirror of
https://gitlab.gnome.org/World/Authenticator.git
synced 2025-03-04 08:44:40 +01:00
AccountRow: add delete action
moves the edit action to popover along with delete button
This commit is contained in:
parent
61eff04ffc
commit
87d1bf3787
4 changed files with 90 additions and 27 deletions
|
@ -7,10 +7,47 @@
|
|||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">edit-copy-symbolic</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="edit_img">
|
||||
<property name="visible">True</property>
|
||||
<object class="GtkPopoverMenu" id="more_actions_popover">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">document-edit-symbolic</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkModelButton" id="edit_btn">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="text" translatable="yes">Edit</property>
|
||||
<signal name="clicked" handler="edit_btn_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkModelButton" id="delete_btn">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="text" translatable="yes">Delete</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="submenu">main</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<template class="AccountRow" parent="GtkListBoxRow">
|
||||
<property name="visible">True</property>
|
||||
|
@ -22,19 +59,27 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="edit_btn">
|
||||
<object class="GtkMenuButton" id="more_actions_btn">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Edit the account name and provider</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="image">edit_img</property>
|
||||
<signal name="clicked" handler="edit_btn_clicked" swapped="no"/>
|
||||
<property name="popover">more_actions_popover</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="more_actions_img">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">view-more-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="image-button"/>
|
||||
<class name="flat"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">3</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
|
@ -47,12 +92,14 @@
|
|||
<property name="tooltip_text" translatable="yes">Copy PIN to clipboard</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="image">copy_img</property>
|
||||
<signal name="activate" handler="copy_btn_clicked" swapped="no"/>
|
||||
<signal name="clicked" handler="copy_btn_clicked" swapped="no"/>
|
||||
<style>
|
||||
<class name="flat"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">3</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
|
|
|
@ -27,6 +27,11 @@ from Authenticator.utils import load_pixbuf_from_provider
|
|||
class AccountsWidget(Gtk.Box, GObject.GObject):
|
||||
instance = None
|
||||
|
||||
__gsignals__ = {
|
||||
'account-removed': (GObject.SignalFlags.RUN_LAST, None, ()),
|
||||
'account-added': (GObject.SignalFlags.RUN_LAST, None, ()),
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
|
||||
GObject.GObject.__init__(self)
|
||||
|
@ -41,8 +46,8 @@ class AccountsWidget(Gtk.Box, GObject.GObject):
|
|||
self.otp_progress_bar = Gtk.ProgressBar()
|
||||
self.otp_progress_bar.get_style_context().add_class("progress-bar")
|
||||
self.add(self.otp_progress_bar)
|
||||
AccountsManager.get_default().connect(
|
||||
"counter_updated", self._on_counter_updated)
|
||||
AccountsManager.get_default().connect("counter_updated",
|
||||
self._on_counter_updated)
|
||||
|
||||
self.accounts_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
|
||||
|
@ -71,6 +76,7 @@ class AccountsWidget(Gtk.Box, GObject.GObject):
|
|||
self.accounts_container.pack_start(provider_widget, False, False, 0)
|
||||
accounts_list.add_row(account)
|
||||
self._reorder()
|
||||
self.emit("account-added")
|
||||
|
||||
@property
|
||||
def accounts_lists(self):
|
||||
|
@ -81,10 +87,6 @@ class AccountsWidget(Gtk.Box, GObject.GObject):
|
|||
self.accounts_container.remove(account_list.get_parent())
|
||||
self._providers = {}
|
||||
|
||||
def set_state(self, state):
|
||||
for account_list in self._providers.values():
|
||||
account_list.set_state(state)
|
||||
|
||||
def update_provider(self, account, new_provider):
|
||||
current_account_list = None
|
||||
account_row = None
|
||||
|
@ -113,7 +115,10 @@ class AccountsWidget(Gtk.Box, GObject.GObject):
|
|||
def _on_account_deleted(self, account_list):
|
||||
if len(account_list.get_children()) == 0:
|
||||
self._to_delete.append(account_list)
|
||||
|
||||
self._reorder()
|
||||
self._clean_unneeded_providers_widgets()
|
||||
self.emit("account-removed")
|
||||
|
||||
def _clean_unneeded_providers_widgets(self):
|
||||
for account_list in self._to_delete:
|
||||
provider_widget = account_list.get_parent()
|
||||
|
@ -188,11 +193,13 @@ class AccountsList(Gtk.ListBox, GObject.GObject):
|
|||
account = Account(_id, name, provider, secret_id)
|
||||
self.add_row(account)
|
||||
|
||||
def delete(self, _):
|
||||
# Remove an account from the list
|
||||
self.emit("changed", False)
|
||||
|
||||
def add_row(self, account):
|
||||
row = AccountRow(account)
|
||||
row.delete_btn.connect("clicked", self.__on_delete_child, row)
|
||||
self.add(row)
|
||||
|
||||
def __on_delete_child(self, model_btn, account_row):
|
||||
self.remove(account_row)
|
||||
account_row.account.remove()
|
||||
self.emit("account-deleted")
|
||||
|
||||
|
|
|
@ -37,6 +37,9 @@ class AccountRow(Gtk.ListBoxRow, GObject.GObject):
|
|||
account_name_label = Gtk.Template.Child()
|
||||
pin_label = Gtk.Template.Child()
|
||||
|
||||
more_actions_btn = Gtk.Template.Child()
|
||||
delete_btn = Gtk.Template.Child()
|
||||
|
||||
def __init__(self, account):
|
||||
"""
|
||||
:param account: Account
|
||||
|
@ -77,6 +80,7 @@ class AccountRow(Gtk.ListBoxRow, GObject.GObject):
|
|||
Copy button clicked signal handler.
|
||||
Copies the OTP pin to the clipboard
|
||||
"""
|
||||
print(self._account.otp.pin)
|
||||
self._account.copy_pin()
|
||||
|
||||
@Gtk.Template.Callback('edit_btn_clicked')
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
"""
|
||||
from gi.repository import Gtk, GObject, Gio, GLib
|
||||
|
||||
from Authenticator.models import Logger, Settings, AccountsManager
|
||||
from Authenticator.models import Database, Logger, Settings, AccountsManager
|
||||
from Authenticator.widgets.accounts import AccountsWidget, AddAccountWindow
|
||||
|
||||
|
||||
|
@ -109,7 +109,7 @@ class Window(Gtk.ApplicationWindow, GObject.GObject):
|
|||
"""
|
||||
if self.props.state == WindowState.NORMAL:
|
||||
toggled = not self.search_btn.props.active
|
||||
self.search_btn.set_property("toggled", toggled)
|
||||
self.search_btn.set_property("active", toggled)
|
||||
|
||||
def save_state(self):
|
||||
"""
|
||||
|
@ -145,13 +145,18 @@ class Window(Gtk.ApplicationWindow, GObject.GObject):
|
|||
|
||||
# Set up accounts Widget
|
||||
accounts_widget = AccountsWidget.get_default()
|
||||
accounts_widget.connect("account-removed", self.__on_accounts_changed)
|
||||
accounts_widget.connect("account-added", self.__on_accounts_changed)
|
||||
self.accounts_viewport.add(accounts_widget)
|
||||
|
||||
self.search_bar.bind_property("search-mode-enabled", self.search_btn,
|
||||
"active", GObject.BindingFlags.BIDIRECTIONAL)
|
||||
|
||||
def _on_account_delete(self, *_):
|
||||
self.notify("state")
|
||||
def __on_accounts_changed(self, *_):
|
||||
if Database.get_default().count == 0:
|
||||
self.props.state = WindowState.EMPTY
|
||||
else:
|
||||
self.props.state = WindowState.NORMAL
|
||||
|
||||
@Gtk.Template.Callback('unlock_btn_clicked')
|
||||
def __unlock_btn_clicked(self, *_):
|
||||
|
|
Loading…
Add table
Reference in a new issue