diff --git a/src/AppChooser/Dialog.vala b/src/AppChooser/Dialog.vala index eed619d3..70309027 100644 --- a/src/AppChooser/Dialog.vala +++ b/src/AppChooser/Dialog.vala @@ -23,7 +23,6 @@ public class AppChooser.Dialog : PortalDialog { public string filename { get; construct; } private HashTable buttons; - private Gtk.Button open_button; private Gtk.ListBox listbox; public Dialog ( @@ -92,22 +91,21 @@ public class AppChooser.Dialog : PortalDialog { margin_start = 12 }; - var cancel_button = add_button (_("Cancel")); - - open_button = add_button (_("Open")); - open_button.receives_default = true; - open_button.add_css_class (Granite.CssClass.SUGGESTED); + allow_label = _("Open"); content = frame; - default_widget = open_button; - listbox.row_activated.connect ((row) => { choiced (((AppChooser.AppButton) row).app_id); }); - open_button.clicked.connect (() => choiced (((AppChooser.AppButton) listbox.get_selected_row ()).app_id)); - cancel_button.clicked.connect (() => choiced ("")); + response.connect ((response) => { + if (response == CANCEL) { + choiced (""); + } else { + choiced (((AppChooser.AppButton) listbox.get_selected_row ()).app_id); + } + }); } private void add_choice (string choice) { @@ -128,7 +126,7 @@ public class AppChooser.Dialog : PortalDialog { buttons[last_choice].grab_focus (); } - open_button.sensitive = listbox.get_row_at_index (0) != null; + form_valid = listbox.get_row_at_index (0) != null; } [DBus (name = "Close")] diff --git a/src/PortalDialog.vala b/src/PortalDialog.vala index 239c7cbb..e63bca71 100644 --- a/src/PortalDialog.vala +++ b/src/PortalDialog.vala @@ -4,6 +4,11 @@ */ public class PortalDialog : Gtk.Window, PantheonWayland.ExtendedBehavior { + /** + * The {@link PortalDialog.ResponseType} that has been selected by the user + */ + public signal void response (ResponseType response); + /** * The {@link GLib.Icon} that is used to display the primary_icon representing the app making the request */ @@ -24,6 +29,26 @@ public class PortalDialog : Gtk.Window, PantheonWayland.ExtendedBehavior { */ public Gtk.Widget content { get; set; } + /** + * The label of the button which denies access + */ + public string cancel_label { get; set; } + + /** + * The label of the button which allows access + */ + public string allow_label { get; set; } + + /** + * Whether the allow button should be disabled + */ + public bool form_valid { get; set; default = true; } + + public enum ResponseType { + ALLOW, + CANCEL + } + /** * The parent window identifier as described by https://flatpak.github.io/xdg-desktop-portal/docs/window-identifiers.html */ @@ -56,9 +81,18 @@ public class PortalDialog : Gtk.Window, PantheonWayland.ExtendedBehavior { header.append (overlay); header.append (header_label); + var cancel_button = new Gtk.Button.with_label (_("Don't Allow")); + + var allow_button = new Gtk.Button.with_label (_("Allow")) { + receives_default = true + }; + allow_button.add_css_class (Granite.CssClass.SUGGESTED); + button_box = new Granite.Box (HORIZONTAL, HALF) { homogeneous = true }; + button_box.append (cancel_button); + button_box.append (allow_button); var toolbarview = new Granite.ToolBox (); toolbarview.add_bottom_bar (button_box); @@ -68,6 +102,7 @@ public class PortalDialog : Gtk.Window, PantheonWayland.ExtendedBehavior { default_height = 425; default_width = 325; + default_widget = allow_button; modal = true; // We need to hide the title area @@ -82,14 +117,14 @@ public class PortalDialog : Gtk.Window, PantheonWayland.ExtendedBehavior { bind_property ("content", toolbarview, "content"); bind_property ("title", header_label, "label"); bind_property ("secondary-text", header_label, "secondary-text"); - ((Gtk.Widget) this).realize.connect (on_realize); - } + bind_property ("form-valid", allow_button, "sensitive"); + bind_property ("allow-label", allow_button, "label"); + bind_property ("cancel-label", cancel_button, "label"); - public Gtk.Button add_button (string button_text) { - var button = new Gtk.Button.with_label (button_text); - button_box.append (button); + ((Gtk.Widget) this).realize.connect (on_realize); - return button; + allow_button.clicked.connect (() => response (ResponseType.ALLOW)); + cancel_button.clicked.connect (() => response (ResponseType.CANCEL)); } private void on_realize () { diff --git a/src/ScreenCast/Dialog.vala b/src/ScreenCast/Dialog.vala index 33199a56..de96a0c4 100644 --- a/src/ScreenCast/Dialog.vala +++ b/src/ScreenCast/Dialog.vala @@ -6,8 +6,6 @@ */ public class ScreenCast.Dialog : PortalDialog { - public signal void response (string response); - public SourceType source_types { get; construct; } public bool allow_multiple { get; construct; } @@ -72,18 +70,12 @@ public class ScreenCast.Dialog : PortalDialog { content = frame; - var cancel_button = add_button (_("Cancel")); - - var accept_button = add_button (_("Share")); - accept_button.add_css_class (Granite.CssClass.SUGGESTED); + allow_label = _("Share"); - bind_property ("n-selected", accept_button, "sensitive", SYNC_CREATE, (binding, from_val, ref to_val) => { + bind_property ("n-selected", this, "form-valid", SYNC_CREATE, (binding, from_val, ref to_val) => { to_val.set_boolean (n_selected > 0); return true; }); - - accept_button.clicked.connect (() => response ("accept")); - cancel_button.clicked.connect (() => response ("cancel")); } private async void populate_windows () { diff --git a/src/ScreenCast/Session.vala b/src/ScreenCast/Session.vala index 8f09bdc3..4fdc556f 100644 --- a/src/ScreenCast/Session.vala +++ b/src/ScreenCast/Session.vala @@ -104,7 +104,7 @@ public class ScreenCast.Session : Object { dialog.response.connect ((response) => { dialog.close (); - if (response == "cancel") { + if (response == CANCEL) { started (1, streams); } else { setup_recording.begin (dialog);