Skip to content

Commit 893bd08

Browse files
committed
PolkitDialog: don't subclass Granite.MessageDialog
1 parent bedaaf4 commit 893bd08

File tree

1 file changed

+78
-14
lines changed

1 file changed

+78
-14
lines changed

src/PolkitDialog.vala

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* https://github.com/solus-project/budgie-desktop
2424
*/
2525

26-
public class Ag.PolkitDialog : Granite.MessageDialog {
26+
public class Ag.PolkitDialog : Gtk.Window {
2727
public signal void done ();
2828
public bool was_canceled = false;
2929

@@ -57,8 +57,41 @@ public class Ag.PolkitDialog : Granite.MessageDialog {
5757
cancellable = _cancellable;
5858
cancellable.cancelled.connect (cancel);
5959

60-
primary_text = _("Authentication Required");
61-
secondary_text = message;
60+
var image = new Gtk.Image.from_icon_name ("dialog-password") {
61+
pixel_size = 48
62+
};
63+
64+
var overlay = new Gtk.Overlay () {
65+
child = image,
66+
valign = START
67+
};
68+
69+
if (icon_name != "" && Gtk.IconTheme.get_for_display (Gdk.Display.get_default ()).has_icon (icon_name)) {
70+
var badge = new Gtk.Image.from_icon_name (icon_name) {
71+
pixel_size = 24,
72+
halign = END,
73+
valign = END
74+
};
75+
76+
overlay.add_overlay (badge);
77+
}
78+
79+
var primary_label = new Gtk.Label (_("Authentication Required")) {
80+
max_width_chars = 0, // Wrap, but secondary label sets the width
81+
selectable = true,
82+
wrap = true,
83+
xalign = 0
84+
};
85+
primary_label.add_css_class (Granite.STYLE_CLASS_TITLE_LABEL);
86+
87+
var secondary_label = new Gtk.Label (message) {
88+
max_width_chars = 50,
89+
width_chars = 50, // Prevents a bug where extra height is preserved
90+
selectable = true,
91+
use_markup = true,
92+
wrap = true,
93+
xalign = 0
94+
};
6295

6396
password_entry = new Gtk.Entry () {
6497
activates_default = true,
@@ -100,26 +133,57 @@ public class Ag.PolkitDialog : Granite.MessageDialog {
100133
credentials_box.append (password_entry);
101134
credentials_box.append (feedback_revealer);
102135

103-
image_icon = new ThemedIcon ("dialog-password");
104-
105-
if (icon_name != "" && Gtk.IconTheme.get_for_display (Gdk.Display.get_default ()).has_icon (icon_name)) {
106-
badge_icon = new ThemedIcon (icon_name);
107-
}
108-
109-
custom_bin.append (credentials_box);
136+
var content_area = new Gtk.Grid () {
137+
column_spacing = 12,
138+
row_spacing = 6,
139+
vexpand = true
140+
};
141+
content_area.attach (overlay, 0, 0, 1, 2);
142+
content_area.attach (primary_label, 1, 0);
143+
content_area.attach (secondary_label, 1, 1);
144+
content_area.attach (credentials_box, 1, 3);
145+
content_area.add_css_class (Granite.STYLE_CLASS_DIALOG_CONTENT_AREA);
110146

111-
var cancel_button = (Gtk.Button)add_button (_("Cancel"), Gtk.ResponseType.CANCEL);
147+
var cancel_button = new Gtk.Button.with_label (_("Cancel"));
112148
cancel_button.clicked.connect (() => cancel ());
113149

114-
var authenticate_button = (Gtk.Button)add_button (_("Authenticate"), Gtk.ResponseType.APPLY);
115-
authenticate_button.receives_default = true;
150+
var authenticate_button = new Gtk.Button.with_label (_("Authenticate")) {
151+
receives_default = true
152+
};
116153
authenticate_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
117154
authenticate_button.clicked.connect (authenticate);
118155

156+
var button_box = new Gtk.Box (HORIZONTAL, 0) {
157+
halign = END
158+
};
159+
button_box.append (cancel_button);
160+
button_box.append (authenticate_button);
161+
button_box.add_css_class ("dialog-action-area");
162+
119163
default_widget = authenticate_button;
120164
focus_widget = password_entry;
121165

122-
close.connect (cancel);
166+
var vbox = new Gtk.Box (VERTICAL, 0);
167+
vbox.append (content_area);
168+
vbox.append (button_box);
169+
vbox.add_css_class ("dialog-vbox");
170+
171+
add_css_class ("dialog");
172+
add_css_class (Granite.STYLE_CLASS_MESSAGE_DIALOG);
173+
child = vbox;
174+
deletable = false;
175+
resizable = false;
176+
modal = true;
177+
178+
// We need to hide the title area
179+
titlebar = new Gtk.Grid () {
180+
visible = false
181+
};
182+
183+
close_request.connect (() => {
184+
cancel ();
185+
return Gdk.EVENT_PROPAGATE;
186+
});
123187

124188
update_idents ();
125189
select_session ();

0 commit comments

Comments
 (0)