mirror of
https://gitlab.gnome.org/World/Authenticator.git
synced 2025-03-06 09:40:59 +01:00
ui: update add account to use Gtk.Template
This commit is contained in:
parent
74eef3925f
commit
2ef6f9ebe3
3 changed files with 89 additions and 49 deletions
|
@ -12,6 +12,7 @@
|
|||
<file compressed="true" preprocess="xml-stripblanks" alias="shortcuts.ui">ui/shortcuts.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks" alias="about_dialog.ui">about_dialog.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks" alias="account_config.ui">ui/account_config.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks" alias="account_add.ui">ui/account_add.ui</file>
|
||||
|
||||
<!-- Default pre-shipped icons -->
|
||||
<file alias="amazon.svg">icons/hicolor/48x48/apps/amazon.svg</file>
|
||||
|
|
67
data/ui/account_add.ui
Normal file
67
data/ui/account_add.ui
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.0 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.22"/>
|
||||
<object class="GtkImage" id="scan_img">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">qrscanner-symbolic</property>
|
||||
</object>
|
||||
<template class="AddAccountWindow" parent="GtkWindow">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="type">popup</property>
|
||||
<property name="window_position">center-on-parent</property>
|
||||
<property name="default_width">350</property>
|
||||
<property name="default_height">500</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">Add a new account</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="close_btn">
|
||||
<property name="label" translatable="yes">Close</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<signal name="clicked" handler="close_btn_clicked" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="add_btn">
|
||||
<property name="label" translatable="yes">Add</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<signal name="clicked" handler="add_btn_clicked" swapped="no"/>
|
||||
<style>
|
||||
<class name="suggested-action"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="scan_btn">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Scan QR Code</property>
|
||||
<property name="image">scan_img</property>
|
||||
<signal name="clicked" handler="scan_btn_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
|
@ -24,57 +24,33 @@ from gi import require_version
|
|||
require_version("Gtk", "3.0")
|
||||
require_version('Gd', '1.0')
|
||||
|
||||
from gi.repository import Gd, Gio, Gtk, GObject, Gdk
|
||||
from gi.repository import Gd, Gio, Gtk, GObject, Gdk, GLib
|
||||
|
||||
from ..headerbar import HeaderBarButton
|
||||
from ...models import OTP
|
||||
from ...utils import load_pixbuf_from_provider
|
||||
|
||||
|
||||
@Gtk.Template(resource_path='/com/github/bilelmoussaoui/Authenticator/account_add.ui')
|
||||
class AddAccountWindow(Gtk.Window):
|
||||
"""Add Account Window."""
|
||||
|
||||
__gtype_name__ = "AddAccountWindow"
|
||||
|
||||
add_btn = Gtk.Template.Child()
|
||||
|
||||
def __init__(self):
|
||||
Gtk.Window.__init__(self)
|
||||
self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
|
||||
self.set_size_request(400, 600)
|
||||
self.resize(400, 600)
|
||||
self._build_widgets()
|
||||
self.connect('key_press_event', self._on_key_press)
|
||||
super(AddAccountWindow, self).__init__()
|
||||
self.init_template('AddAccountWindow')
|
||||
self.__init_widgets()
|
||||
|
||||
def _build_widgets(self):
|
||||
def __init_widgets(self):
|
||||
"""Create the Add Account widgets."""
|
||||
# Header Bar
|
||||
header_bar = Gtk.HeaderBar()
|
||||
header_bar.set_show_close_button(False)
|
||||
header_bar.set_title(_("Add a new account"))
|
||||
self.set_titlebar(header_bar)
|
||||
# Next btn
|
||||
self.add_btn = Gtk.Button()
|
||||
self.add_btn.set_label(_("Add"))
|
||||
self.add_btn.connect("clicked", self._on_add)
|
||||
self.add_btn.get_style_context().add_class("suggested-action")
|
||||
self.add_btn.set_sensitive(False)
|
||||
header_bar.pack_end(self.add_btn)
|
||||
|
||||
# QR code scan btn
|
||||
self.scan_btn = HeaderBarButton("qrscanner-symbolic",
|
||||
_("Scan QR code"))
|
||||
self.scan_btn.connect("clicked", self._on_scan)
|
||||
header_bar.pack_end(self.scan_btn)
|
||||
|
||||
# Back btn
|
||||
self.close_btn = Gtk.Button()
|
||||
self.close_btn.set_label(_("Close"))
|
||||
self.close_btn.connect("clicked", self._on_quit)
|
||||
|
||||
header_bar.pack_start(self.close_btn)
|
||||
|
||||
self.account_config = AccountConfig()
|
||||
self.account_config.connect("changed", self._on_account_config_changed)
|
||||
|
||||
self.add(self.account_config)
|
||||
|
||||
@Gtk.Template.Callback('scan_btn_clicked')
|
||||
def _on_scan(self, *_):
|
||||
"""
|
||||
QR Scan button clicked signal handler.
|
||||
|
@ -84,32 +60,27 @@ class AddAccountWindow(Gtk.Window):
|
|||
|
||||
def _on_account_config_changed(self, _, state):
|
||||
"""Set the sensitivity of the AddButton depends on the AccountConfig."""
|
||||
print(state)
|
||||
self.add_btn.set_sensitive(state)
|
||||
|
||||
@Gtk.Template.Callback('close_btn_clicked')
|
||||
def _on_quit(self, *_):
|
||||
self.destroy()
|
||||
|
||||
@Gtk.Template.Callback('add_btn_clicked')
|
||||
def _on_add(self, *_):
|
||||
from .list import AccountsWidget
|
||||
from ...models import AccountsManager, Account
|
||||
account_obj = self.account_config.account
|
||||
account = Account.create(account_obj["username"], account_obj["provider"], account_obj["token"])
|
||||
# Create a new account
|
||||
account = Account.create(account_obj["username"],
|
||||
account_obj["provider"],
|
||||
account_obj["token"])
|
||||
# Add it to the AccountsManager
|
||||
AccountsManager.get_default().add(account)
|
||||
AccountsWidget.get_default().append(account)
|
||||
self._on_quit()
|
||||
|
||||
def _on_key_press(self, _, event):
|
||||
_, key_val = event.get_keyval()
|
||||
modifiers = event.get_state()
|
||||
|
||||
if key_val == Gdk.KEY_Escape:
|
||||
self._on_quit()
|
||||
|
||||
# CTRL + Q
|
||||
if modifiers == Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD2_MASK:
|
||||
if key_val == Gdk.KEY_q:
|
||||
self._on_scan()
|
||||
|
||||
@Gtk.Template(resource_path='/com/github/bilelmoussaoui/Authenticator/account_config.ui')
|
||||
class AccountConfig(Gtk.Box, GObject.GObject):
|
||||
__gsignals__ = {
|
||||
|
@ -253,4 +224,5 @@ class AccountConfig(Gtk.Box, GObject.GObject):
|
|||
"""
|
||||
self.notification_label.set_text(message)
|
||||
self.notification.set_reveal_child(True)
|
||||
|
||||
GLib.timeout_add_seconds(5,
|
||||
lambda _: self.notification.set_reveal_child(False), None)
|
||||
|
|
Loading…
Add table
Reference in a new issue