Skip to content

Commit

Permalink
Access: add modifications for use in gala's CloseDialog (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marukesu authored Jan 24, 2022
1 parent 350b832 commit a888641
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/Access/Dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@

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

public uint register_id { get; set; default = 0; }

public ButtonAction action { get; construct; }

public string parent_window { get; construct; }

public string app_id { get; construct; }
Expand Down Expand Up @@ -36,8 +43,9 @@ public class Access.Dialog : Granite.MessageDialog {
private List<Choice> choices;
private Gtk.Box box;

public Dialog (string app_id, string parent_window, string icon) {
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),
Expand All @@ -51,6 +59,7 @@ public class Access.Dialog : Granite.MessageDialog {
modal = true;

choices = new List<Choice> ();
set_role ("AccessDialog"); // used in Gala.CloseDialog
set_keep_above (true);

if (app_id != "") {
Expand All @@ -59,9 +68,15 @@ public class Access.Dialog : Granite.MessageDialog {

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

set_default (deny_button);
unowned var grant_context = grant_button.get_style_context ();

if (action == ButtonAction.SUGGESTED) {
grant_context.add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
set_default (grant_button);
} else {
grant_context.add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
set_default (deny_button);
}

box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
custom_bin.child = box;
Expand Down
7 changes: 6 additions & 1 deletion src/Access/Portal.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ 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";

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

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

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

0 comments on commit a888641

Please sign in to comment.