diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2024-06-30 20:46:13 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2024-06-30 20:46:13 +0200 |
commit | 9b3a82a302bd88c64bb714b009d223f8683f7178 (patch) | |
tree | 9c387fef03143f2f5f809672bf51e6495f874050 /src/authorize-dialog.vala | |
parent | a675d0fb9f307b714d0b9cf19690d2b08b666d7c (diff) | |
parent | bca1cc8681bbaf662dabc961f84b06adc1255e08 (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'src/authorize-dialog.vala')
-rw-r--r-- | src/authorize-dialog.vala | 71 |
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, + }; + } } |