[gnome-boxes/change-screenshot-target-folder] actions-popover: Save screenshots into ~/Pictures/Screenshots




commit 8004cad230b0153158a35fa4d80852ba49b1071a
Author: Felipe Borges <felipeborges gnome org>
Date:   Mon Mar 28 11:21:02 2022 +0200

    actions-popover: Save screenshots into ~/Pictures/Screenshots
    
    Ever since GNOME Shell 42, the screenshots are now saved under
    XDG_PICTURES_DIR/Screenshots.
    
    Boxes will attempt to create the directory if it doesn't exist.
    
    This directory name is translatable and both GNOME Boxes and GNOME
    Shell translations for the directory name should be the same for
    the same folder to be used.
    
    Fixes #776

 src/actions-popover.vala | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/src/actions-popover.vala b/src/actions-popover.vala
index 2700180f..9f2ea8de 100644
--- a/src/actions-popover.vala
+++ b/src/actions-popover.vala
@@ -104,22 +104,35 @@ private void open_in_new_win_activated () {
         App.app.open_in_new_window (window.current_item as Machine);
     }
 
-    private string get_screenshot_filename () {
+    private string get_screenshot_filename () throws GLib.Error {
+        // Translators: name of the folder under ~/Pictures for screenshots. This is the same folder where 
GNOME Shell saves screenshots.
+        string dir_name = _("Screenshots");
+        string path = Path.build_filename (GLib.Environment.get_user_special_dir 
(GLib.UserDirectory.PICTURES),
+                                           dir_name);
+        var dir = GLib.File.new_for_path (path);
+
+        // Lets ensure that the "Screenshots" directory really exists.
+        try {
+            dir.make_directory_with_parents (null);
+        } catch (GLib.Error error) {
+            if (!(error is GLib.IOError.EXISTS))
+                throw error;
+        }
+
         var now = new GLib.DateTime.now_local ();
         var timestamp = now.format ("%Y-%m-%d %H-%M-%S");
 
         // Translators: %s => the timestamp of when the screenshot was taken.
         var filename =_("Screenshot from %s").printf (timestamp);
 
-        return Path.build_filename (GLib.Environment.get_user_special_dir (GLib.UserDirectory.PICTURES),
-                                    filename);
+        return Path.build_filename (dir.get_path (), filename + ".png");
     }
 
     private void take_screenshot_activated () {
         var machine = window.current_item as Machine;
         try {
             Gdk.Pixbuf pixbuf = machine.display.get_pixbuf (0);
-            pixbuf.save (get_screenshot_filename () + ".png", "png");
+            pixbuf.save (get_screenshot_filename (), "png");
         } catch (GLib.Error error) {
             warning (error.message);
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]