Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/AppChooser/Dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class AppChooser.Dialog : PortalDialog {
public string filename { get; construct; }

private HashTable<string, AppButton> buttons;
private Gtk.Button open_button;
private Gtk.ListBox listbox;

public Dialog (
Expand Down Expand Up @@ -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) {
Expand All @@ -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")]
Expand Down
47 changes: 41 additions & 6 deletions src/PortalDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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 () {
Expand Down
12 changes: 2 additions & 10 deletions src/ScreenCast/Dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion src/ScreenCast/Session.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down