Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Aug 8, 2024
1 parent a049b60 commit 0e15d27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
27 changes: 17 additions & 10 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
public class Screenshot.Application : Gtk.Application {
public const string SAVE_FOLDER = _("Screenshots");

private Settings settings = new Settings ("io.elementary.screenshot");
private Gdk.Pixbuf? pixbuf = null;

public Application () {
Object (
application_id: "io.elementary.screenshot",
Expand Down Expand Up @@ -66,7 +69,6 @@ public class Screenshot.Application : Gtk.Application {
private async void take_screenshot () {
var portal = new Xdp.Portal ();

Gdk.Pixbuf pixbuf;
try {
var file_uri = yield portal.take_screenshot (null, INTERACTIVE, null);

Expand All @@ -77,10 +79,10 @@ public class Screenshot.Application : Gtk.Application {
return;
}

var save_dialog = new SaveDialog (pixbuf, new Settings ("io.elementary.screenshot"), null);
var save_dialog = new SaveDialog (pixbuf, settings);

save_dialog.save_response.connect ((response, folder_dir, output_name, format) => {
save_dialog.destroy ();
save_dialog.save_response.connect ((dialog, response, folder_dir, output_name, format) => {
dialog.destroy ();

if (response) {
string[] formats = {".png", ".jpg", ".jpeg", ".bmp", ".tiff"};
Expand All @@ -91,19 +93,24 @@ public class Screenshot.Application : Gtk.Application {
}

try {
save_file (output, format, folder_dir, pixbuf);
save_file (output, format, folder_dir);
} catch (GLib.Error e) {
show_error_dialog (e.message);
}

release ();
}

release ();
});

save_dialog.present ();
}

private void save_file (string file_name, string format, owned string folder_dir, Gdk.Pixbuf screenshot) throws GLib.Error {
private void save_file (string file_name, string format, owned string folder_dir) throws GLib.Error {
if (pixbuf == null) {
critical ("Pixbuf is null");
return;
}

string full_file_name = "";
string folder_from_settings = "";

Expand All @@ -130,7 +137,7 @@ public class Screenshot.Application : Gtk.Application {
attempt++;
} while (File.new_for_path (full_file_name).query_exists ());

screenshot.save (full_file_name, format);
pixbuf.save (full_file_name, format);
}

private void show_error_dialog (string error_message) {
Expand All @@ -141,7 +148,7 @@ public class Screenshot.Application : Gtk.Application {
Gtk.ButtonsType.CLOSE
);
dialog.show_error_details (error_message);
dialog.response.connect ((dialog, response) => dialog.destroy ());
dialog.response.connect (dialog.destroy);
dialog.present ();
}

Expand Down
5 changes: 2 additions & 3 deletions src/SaveDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ public class Screenshot.SaveDialog : Granite.Dialog {
private Gtk.Label folder_name;
private Gtk.Image folder_image;

public SaveDialog (Gdk.Pixbuf pixbuf, Settings settings, Gtk.Window? parent) {
public SaveDialog (Gdk.Pixbuf pixbuf, Settings settings) {
Object (
deletable: false,
modal: true,
pixbuf: pixbuf,
settings: settings,
title: _("Screenshot"),
transient_for: parent
title: _("Screenshot")
);
}

Expand Down

0 comments on commit 0e15d27

Please sign in to comment.