From 6976db47b89d79f064ccdadfb0dc1f505f5e7546 Mon Sep 17 00:00:00 2001 From: Arthur Jansen Date: Fri, 28 Dec 2018 17:04:35 +0100 Subject: [PATCH] Extended save function to also take files --- lib/screenshooter-actions.c | 46 ++++++++++++++++++++++--------------- lib/screenshooter-dialogs.c | 7 +----- lib/screenshooter-dialogs.h | 3 ++- lib/screenshooter-global.h | 1 + src/main.c | 18 +++++++++------ 5 files changed, 42 insertions(+), 33 deletions(-) diff --git a/lib/screenshooter-actions.c b/lib/screenshooter-actions.c index ebc2c9e..230f2e8 100644 --- a/lib/screenshooter-actions.c +++ b/lib/screenshooter-actions.c @@ -70,27 +70,35 @@ action_idle (ScreenshotData *sd) if (sd->action & SAVE) { - const gchar *save_location; - - if (sd->screenshot_dir == NULL) - sd->screenshot_dir = screenshooter_get_xdg_image_dir_uri (); - - save_location = screenshooter_save_screenshot (sd->screenshot, - sd->screenshot_dir, - sd->title, - sd->timestamp, - TRUE, - TRUE); - - if (save_location) + if (sd->path_is_file) { - const gchar *temp; - - g_free (sd->screenshot_dir); - temp = g_path_get_dirname (save_location); - sd->screenshot_dir = g_build_filename ("file://", temp, NULL); - TRACE ("New save directory: %s", sd->screenshot_dir); + save_screenshot_to (sd->screenshot, sd->screenshot_dir); } + else + { + const gchar *save_location; + + if (sd->screenshot_dir == NULL) + sd->screenshot_dir = screenshooter_get_xdg_image_dir_uri (); + + save_location = screenshooter_save_screenshot (sd->screenshot, + sd->screenshot_dir, + sd->title, + sd->timestamp, + TRUE, + TRUE); + + if (save_location) + { + const gchar *temp; + + g_free (sd->screenshot_dir); + temp = g_path_get_dirname (save_location); + sd->screenshot_dir = g_build_filename ("file://", temp, NULL); + TRACE ("New save directory: %s", sd->screenshot_dir); + } + } + } else { diff --git a/lib/screenshooter-dialogs.c b/lib/screenshooter-dialogs.c index af69b6a..d9b9b93 100644 --- a/lib/screenshooter-dialogs.c +++ b/lib/screenshooter-dialogs.c @@ -93,11 +93,6 @@ static gchar static void save_screenshot_to_remote_location (GdkPixbuf *screenshot, GFile *save_file); -static gchar -*save_screenshot_to (GdkPixbuf *screenshot, - const gchar *save_uri); - - /* Internals */ @@ -610,7 +605,7 @@ save_screenshot_to_remote_location (GdkPixbuf *screenshot, GFile *save_file) g_free (save_path); } -static gchar +gchar *save_screenshot_to (GdkPixbuf *screenshot, const gchar *save_uri) { GFile *save_file = g_file_new_for_uri (save_uri); diff --git a/lib/screenshooter-dialogs.h b/lib/screenshooter-dialogs.h index 33121a3..4bc5f4b 100644 --- a/lib/screenshooter-dialogs.h +++ b/lib/screenshooter-dialogs.h @@ -46,7 +46,8 @@ gchar *screenshooter_save_screenshot (GdkPixbuf *screenshot, gboolean save_dialog, gboolean show_preview); - +gchar *save_screenshot_to (GdkPixbuf *screenshot, + const gchar *save_uri); #endif diff --git a/lib/screenshooter-global.h b/lib/screenshooter-global.h index 1fc1c75..83b1290 100644 --- a/lib/screenshooter-global.h +++ b/lib/screenshooter-global.h @@ -51,6 +51,7 @@ typedef struct gboolean region_specified; gboolean timestamp; gchar *screenshot_dir; + gchar *path_is_file; gchar *title; gchar *app; GAppInfo *app_info; diff --git a/src/main.c b/src/main.c index 5e92cc3..b9f6976 100644 --- a/src/main.c +++ b/src/main.c @@ -306,16 +306,20 @@ int main (int argc, char **argv) { default_save_dir = g_file_new_for_commandline_arg (screenshot_dir); - if (G_LIKELY (g_file_query_exists (default_save_dir, NULL))) + sd->action_specified = TRUE; + g_free (sd->screenshot_dir); + sd->screenshot_dir = g_file_get_uri (default_save_dir); + + if (g_file_test (screenshot_dir, G_FILE_TEST_IS_DIR)) { - g_free (sd->screenshot_dir); - sd->screenshot_dir = g_file_get_uri (default_save_dir); - sd->action_specified = TRUE; + // Directory is given + sd->path_is_file = FALSE; } else - screenshooter_error (_("%s is not a valid directory, the default" - " directory will be used."), - screenshot_dir); + { + // File is given + sd->path_is_file = TRUE; + } g_object_unref (default_save_dir); g_free (screenshot_dir); -- 2.20.1