diff options
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, + }; + } } |