summaryrefslogtreecommitdiff
path: root/src/authorize-dialog.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2024-06-30 20:45:42 +0200
committerJörg Frings-Fürst <debian@jff.email>2024-06-30 20:45:42 +0200
commit26d8dd51f3ecc4bd6861ed5155acb3090a1983d4 (patch)
tree08d9369065e32f20a80f9cf916a5b1a468b39527 /src/authorize-dialog.vala
parent1676db749dc23da9fcd9c767de2f1e9a0c61b2b2 (diff)
New upstream version 46.0upstream/46.0upstream
Diffstat (limited to 'src/authorize-dialog.vala')
-rw-r--r--src/authorize-dialog.vala71
1 files changed, 65 insertions, 6 deletions
diff --git a/src/authorize-dialog.vala b/src/authorize-dialog.vala
index 7cb2a66..ab0237a 100644
--- a/src/authorize-dialog.vala
+++ b/src/authorize-dialog.vala
@@ -11,18 +11,21 @@
*/
[GtkTemplate (ui = "/org/gnome/SimpleScan/ui/authorize-dialog.ui")]
-private class AuthorizeDialog : Gtk.Dialog
+private class AuthorizeDialog : Gtk.Window
{
[GtkChild]
- private unowned Gtk.Label authorize_label;
+ private unowned Adw.PreferencesGroup preferences_group;
[GtkChild]
- private unowned Gtk.Entry username_entry;
+ private unowned Adw.EntryRow username_entry;
[GtkChild]
- private unowned Gtk.Entry password_entry;
+ private unowned Adw.PasswordEntryRow password_entry;
- public AuthorizeDialog (string title)
+ public signal void authorized (AuthorizeDialogResponse res);
+
+ public AuthorizeDialog (Gtk.Window parent, string title)
{
- authorize_label.set_text (title);
+ preferences_group.set_title (title);
+ set_transient_for (parent);
}
public string get_username ()
@@ -34,4 +37,60 @@ private class AuthorizeDialog : Gtk.Dialog
{
return password_entry.text;
}
+
+ [GtkCallback]
+ private void authorize_button_cb ()
+ {
+ authorized (AuthorizeDialogResponse.new_authorized (get_username (), get_password ()));
+ }
+
+ [GtkCallback]
+ private void cancel_button_cb ()
+ {
+ authorized (AuthorizeDialogResponse.new_canceled ());
+ }
+
+ public async AuthorizeDialogResponse open()
+ {
+ SourceFunc callback = open.callback;
+
+ AuthorizeDialogResponse response = {};
+
+ authorized.connect ((res) =>
+ {
+ response = res;
+ callback ();
+ });
+
+ present ();
+ yield;
+ close ();
+
+ return response;
+ }
+}
+
+public struct AuthorizeDialogResponse
+{
+ public string username;
+ public string password;
+ public bool success;
+
+ public static AuthorizeDialogResponse new_canceled ()
+ {
+ return AuthorizeDialogResponse ()
+ {
+ success = false,
+ };
+ }
+
+ public static AuthorizeDialogResponse new_authorized (string username, string password)
+ {
+ return AuthorizeDialogResponse ()
+ {
+ username = username,
+ password = password,
+ success = true,
+ };
+ }
}