screenshotmanager: Only create non-existing "Screenshots" subfolder in PICTURES (#462)

This commit is contained in:
Rico Tzschichholz 2019-02-06 13:47:17 +01:00 committed by GitHub
parent 74e7541c2b
commit 9493139c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -143,33 +143,22 @@ namespace Gala
selection_area.get_selection_rectangle (out x, out y, out width, out height); selection_area.get_selection_rectangle (out x, out y, out width, out height);
} }
public static void create_dir_if_missing (string path) throws Error {
File file = File.new_for_path (path);
if (!file.query_exists ()) {
try {
file.make_directory_with_parents ();
} catch (Error e) {
throw e;
}
}
}
static string find_target_path () static string find_target_path ()
{ {
var pictures_path = Environment.get_user_special_dir (UserDirectory.PICTURES); // Try to create dedicated "Screenshots" subfolder in PICTURES xdg-dir
var screenshot_folder = _("Screenshots"); unowned string? base_path = Environment.get_user_special_dir (UserDirectory.PICTURES);
var path = Path.build_path ( if (base_path != null && FileUtils.test (base_path, FileTest.EXISTS)) {
Path.DIR_SEPARATOR_S, var path = Path.build_path (Path.DIR_SEPARATOR_S, base_path, _("Screenshots"));
pictures_path, if (FileUtils.test (path, FileTest.EXISTS)) {
screenshot_folder return path;
); } else if (DirUtils.create (path, 0755) == 0) {
try { return path;
create_dir_if_missing (path); } else {
return path; return base_path;
} catch (Error e) { }
warning (e.message);
return pictures_path;
} }
return Environment.get_home_dir ();
} }
static bool save_image (Cairo.ImageSurface image, string filename, out string used_filename) static bool save_image (Cairo.ImageSurface image, string filename, out string used_filename)