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
96 changes: 8 additions & 88 deletions src/Access/Dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,7 @@
*/

[DBus (name = "org.freedesktop.impl.portal.Request")]
public class Access.Dialog : Granite.MessageDialog, PantheonWayland.ExtendedBehavior {
public enum ButtonAction {
SUGGESTED,
DESTRUCTIVE
}

public ButtonAction action { get; construct; }

public string parent_window { get; construct; }

public string app_id { get; construct; }

public string deny_label {
set {
deny_button.label = value;
}
}

public string grant_label {
set {
grant_button.label = value;
}
}

public class Access.Dialog : PortalDialog {
public string body {
set {
if (value != "") {
Expand All @@ -36,77 +13,20 @@ public class Access.Dialog : Granite.MessageDialog, PantheonWayland.ExtendedBeha
}
}

private unowned Gtk.Button grant_button;
private unowned Gtk.Button deny_button;
private List<Choice> choices;

public Dialog (ButtonAction action, string app_id, string parent_window, string icon) {
Object (
action: action,
app_id: app_id,
parent_window: parent_window,
image_icon: new ThemedIcon (icon),
buttons: Gtk.ButtonsType.NONE
);
}
private Granite.Box? custom_bin = null;

construct {
resizable = false;
modal = true;

choices = new List<Choice> ();

if (app_id != "") {
badge_icon = new DesktopAppInfo (app_id + ".desktop").get_icon ();
}

deny_button = add_button (_("Deny Access"), Gtk.ResponseType.CANCEL) as Gtk.Button;
grant_button = add_button (_("Grant Access"), Gtk.ResponseType.OK) as Gtk.Button;

if (action == ButtonAction.SUGGESTED) {
grant_button.add_css_class (Granite.CssClass.SUGGESTED);
default_widget = grant_button;
} else {
grant_button.add_css_class (Granite.CssClass.DESTRUCTIVE);
default_widget = deny_button;
}

custom_bin.orientation = Gtk.Orientation.VERTICAL;
custom_bin.spacing = 6;

if (parent_window == "") {
child.realize.connect (() => {
connect_to_shell ();
make_centered ();
set_keep_above ();
});
}
}

public override void show () {
((Gtk.Widget) base).realize ();

unowned var toplevel = (Gdk.Toplevel) get_surface ();

if (parent_window != "") {
try {
ExternalWindow.from_handle (parent_window).set_parent_of (toplevel);
} catch (Error e) {
warning ("Failed to associate portal window with parent '%s': %s", parent_window, e.message);
}
}

base.show ();
toplevel.focus (Gdk.CURRENT_TIME);
}

public override void close () {
response (Gtk.ResponseType.CANCEL);
base.close ();
}

[DBus (visible = false)]
public void add_choice (Choice choice) {
if (custom_bin == null) {
custom_bin = new Granite.Box (VERTICAL, HALF);
content = custom_bin;
}

choices.append (choice);
custom_bin.append (choice);
}
Expand All @@ -118,6 +38,6 @@ public class Access.Dialog : Granite.MessageDialog, PantheonWayland.ExtendedBeha

[DBus (name = "Close")]
public void on_close () throws DBusError, IOError {
response (Gtk.ResponseType.DELETE_EVENT);
response (DELETE_EVENT);
}
}
36 changes: 21 additions & 15 deletions src/Access/Portal.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,41 @@ public class Access.Portal : Object {
out uint32 response,
out HashTable<string, Variant> results
) throws DBusError, IOError {
Dialog.ButtonAction action = Dialog.ButtonAction.SUGGESTED;
string icon = "dialog-information";
uint register_id = 0;

var dialog = new Dialog () {
title = title,
secondary_text = sub_title,
body = body,
parent_handle = parent_window
};

if (app_id != "") {
dialog.primary_icon = new DesktopAppInfo (app_id + ".desktop").get_icon ();
} else {
// non-sandboxed access must be the system itself
dialog.primary_icon = new ThemedIcon ("io.elementary.settings");
}

if ("destructive" in options && options["destructive"].get_boolean ()) {
action = Dialog.ButtonAction.DESTRUCTIVE;
dialog.action_type = DESTRUCTIVE;
}

if ("icon" in options) {
// elementary HIG use non-symbolic icon, while portals ask for symbolic ones.
icon = options["icon"].get_string ().replace ("-symbolic", "");
dialog.secondary_icon = new ThemedIcon (options["icon"].get_string ().replace ("-symbolic", ""));
}

var dialog = new Dialog (action, app_id, parent_window, icon) {
primary_text = title,
secondary_text = sub_title,
body = body
};

if ("modal" in options) {
dialog.modal = options["modal"].get_boolean ();
}

if ("deny_label" in options) {
dialog.deny_label = options["deny_label"].get_string ();
dialog.cancel_label = options["deny_label"].get_string ();
}

if ("grant_label" in options) {
dialog.grant_label = options["grant_label"].get_string ();
dialog.allow_label = options["grant_label"].get_string ();
}

if ("choices" in options) {
Expand All @@ -67,7 +73,7 @@ public class Access.Portal : Object {

dialog.response.connect ((id) => {
switch (id) {
case Gtk.ResponseType.OK:
case ALLOW:
var choices_builder = new VariantBuilder (new VariantType ("a(ss)"));

dialog.get_choices ().foreach ((choice) => {
Expand All @@ -78,11 +84,11 @@ public class Access.Portal : Object {
_response = 0;
break;

case Gtk.ResponseType.CANCEL:
case CANCEL:
_response = 1;
break;

case Gtk.ResponseType.DELETE_EVENT:
case DELETE_EVENT:
_response = 2;
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/AppChooser/Dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public class AppChooser.Dialog : PortalDialog {
allow_label = _("Open");

content = frame;
default_height = 425;

listbox.row_activated.connect ((row) => {
choiced (((AppChooser.AppButton) row).app_id);
Expand Down
30 changes: 26 additions & 4 deletions src/PortalDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@ public class PortalDialog : Gtk.Window, PantheonWayland.ExtendedBehavior {
*/
public bool form_valid { get; set; default = true; }

public ActionType action_type { get; set; default = SUGGESTED; }

public enum ActionType {
SUGGESTED,
DESTRUCTIVE
}

public enum ResponseType {
ALLOW,
CANCEL
CANCEL,
DELETE_EVENT
}

/**
Expand Down Expand Up @@ -100,7 +108,6 @@ public class PortalDialog : Gtk.Window, PantheonWayland.ExtendedBehavior {

child = toolbarview;

default_height = 425;
Comment thread
ryonakano marked this conversation as resolved.
default_width = 325;
default_widget = allow_button;
modal = true;
Expand All @@ -121,10 +128,25 @@ public class PortalDialog : Gtk.Window, PantheonWayland.ExtendedBehavior {
bind_property ("allow-label", allow_button, "label");
bind_property ("cancel-label", cancel_button, "label");

notify["action-type"].connect (() => {
if (action_type == SUGGESTED) {
allow_button.add_css_class (Granite.CssClass.SUGGESTED);
cancel_button.receives_default = false;
allow_button.receives_default = true;
Comment thread
danirabbit marked this conversation as resolved.
default_widget = allow_button;
} else {
allow_button.add_css_class (Granite.CssClass.DESTRUCTIVE);
allow_button.receives_default = false;
cancel_button.receives_default = true;
Comment thread
danirabbit marked this conversation as resolved.
default_widget = cancel_button;
}
});

((Gtk.Widget) this).realize.connect (on_realize);

allow_button.clicked.connect (() => response (ResponseType.ALLOW));
cancel_button.clicked.connect (() => response (ResponseType.CANCEL));
allow_button.clicked.connect (() => response (ALLOW));
cancel_button.clicked.connect (() => response (CANCEL));
close_request.connect (() => { response (DELETE_EVENT); });
}

private void on_realize () {
Expand Down
1 change: 1 addition & 0 deletions src/ScreenCast/Dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class ScreenCast.Dialog : PortalDialog {
};

content = frame;
default_height = 425;

allow_label = _("Share");

Expand Down
Loading