-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDialog.vala
123 lines (99 loc) · 3.28 KB
/
Dialog.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* SPDX-FileCopyrightText: 2021-2023 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
[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 string body {
set {
if (value != "") {
secondary_text += "\n\n" + value;
}
}
}
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
);
}
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.STYLE_CLASS_SUGGESTED_ACTION);
default_widget = grant_button;
} else {
grant_button.add_css_class (Granite.STYLE_CLASS_DESTRUCTIVE_ACTION);
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) {
choices.append (choice);
custom_bin.append (choice);
}
[DBus (visible = false)]
public unowned List<Choice> get_choices () {
return choices;
}
[DBus (name = "Close")]
public void on_close () throws DBusError, IOError {
response (Gtk.ResponseType.DELETE_EVENT);
}
}