Skip to content

Commit

Permalink
Add a preview to the approval dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmhewitt committed Dec 11, 2023
1 parent 7861d2e commit 8c9c4b7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
35 changes: 33 additions & 2 deletions src/Screenshot/ApprovalDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
public signal void response (Gtk.ResponseType response_type);

public string parent_window { get; construct; }
public string app_id { get; construct; }
public string screenshot_uri { get; construct; }

public ApprovalDialog (string parent_window, bool modal, string screenshot_uri) {
public ApprovalDialog (string parent_window, bool modal, string app_id, string screenshot_uri) {
Object (
resizable: false,
parent_window: parent_window,
modal: modal,
app_id: app_id,
screenshot_uri: screenshot_uri
);
}
Expand All @@ -29,7 +31,32 @@
});
}

// TODO: Add a screenshot preview and wording
var title = new Gtk.Label (_("Share Screenshot")) {
max_width_chars = 0, // Wrap, but secondary label sets the width
selectable = true,
wrap = true,
xalign = 0
};
title.add_css_class (Granite.STYLE_CLASS_TITLE_LABEL);

var subtitle = new Gtk.Label (_("Share this screenshot with the requesting app?")) {
max_width_chars = 50,
width_chars = 50, // Prevents a bug where extra height is preserved
selectable = true,
wrap = true,
xalign = 0
};

if (app_id != null) {
var app_info = new GLib.DesktopAppInfo (app_id + ".desktop");
if (app_info != null) {
subtitle.label = _("Share this screenshot with %s?").printf (app_info.get_display_name ());
}
}

var screenshot_filename = GLib.Filename.from_uri (screenshot_uri);
var screenshot_image = new Gtk.Picture.for_pixbuf (new Gdk.Pixbuf.from_file_at_scale (screenshot_filename, 384, 384, true)) {
};

var allow_button = new Gtk.Button.with_label (_("Share Screenshot")) {
receives_default = true
Expand All @@ -55,6 +82,10 @@
margin_bottom = 12,
margin_start = 12
};
box.add_css_class ("dialog-vbox");
box.append (title);
box.append (subtitle);
box.append (screenshot_image);
box.append (actions);

var window_handle = new Gtk.WindowHandle () {
Expand Down
4 changes: 2 additions & 2 deletions src/Screenshot/Portal.vala
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public class Screenshot.Portal : Object {
}

// This app has not been pre-approved to take screenshots, so we prompt the user
var dialog = new ApprovalDialog (parent_window, modal, uri);
var dialog = new ApprovalDialog (parent_window, modal, app_id, uri);

bool cancelled = true;
dialog.response.connect ((response_id) => {
Expand Down Expand Up @@ -230,7 +230,7 @@ public class Screenshot.Portal : Object {
return;
} else {
// This app has not been pre-approved to take screenshots, so we prompt the user
var approval_dialog = new ApprovalDialog (parent_window, modal, uri);
var approval_dialog = new ApprovalDialog (parent_window, modal, app_id, uri);

bool approval_cancelled = true;
approval_dialog.response.connect ((response_id) => {
Expand Down

0 comments on commit 8c9c4b7

Please sign in to comment.