From 06a407d47745a4d03eff34ea5237e36e79785085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=AF=E6=96=87=E5=AE=9E?= Date: Wed, 10 Jan 2018 17:21:50 +0800 Subject: [PATCH] add --filename cmdline option support --- lib/screenshooter-actions.c | 9 ++++++++- lib/screenshooter-global.h | 1 + src/main.c | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/screenshooter-actions.c b/lib/screenshooter-actions.c index ad288fb..69b291d 100644 --- a/lib/screenshooter-actions.c +++ b/lib/screenshooter-actions.c @@ -83,6 +83,7 @@ gboolean screenshooter_action_idle (ScreenshotData *sd) if (sd->action == SAVE) { const gchar *save_location; + gboolean save_dialog = sd->screenshot_filename ? FALSE : TRUE; if (sd->screenshot_dir == NULL) sd->screenshot_dir = screenshooter_get_xdg_image_dir_uri (); @@ -91,16 +92,22 @@ gboolean screenshooter_action_idle (ScreenshotData *sd) sd->screenshot_dir, sd->title, sd->timestamp, - TRUE, + save_dialog, sd->action_specified); if (save_location) { const gchar *temp; + gchar *t_filename; g_free (sd->screenshot_dir); temp = g_path_get_dirname (save_location); + t_filename = g_path_get_basename (save_location); sd->screenshot_dir = g_build_filename ("file://", temp, NULL); + if (sd->screenshot_filename) { + g_chdir(temp); + g_rename(t_filename, sd->screenshot_filename); + } TRACE ("New save directory: %s", sd->screenshot_dir); } } diff --git a/lib/screenshooter-global.h b/lib/screenshooter-global.h index 3ffcf2c..acaa3ab 100644 --- a/lib/screenshooter-global.h +++ b/lib/screenshooter-global.h @@ -50,6 +50,7 @@ typedef struct gboolean plugin; gboolean action_specified; gboolean timestamp; + gchar *screenshot_filename; gchar *screenshot_dir; gchar *title; gchar *app; diff --git a/src/main.c b/src/main.c index f7a0568..dc68fc1 100644 --- a/src/main.c +++ b/src/main.c @@ -38,6 +38,7 @@ gboolean clipboard = FALSE; gboolean upload_imgur = FALSE; gchar *screenshot_dir = NULL; gchar *application = NULL; +gchar *filename = NULL; gint delay = 0; @@ -56,6 +57,11 @@ static GOptionEntry entries[] = NULL }, { + "filename", 'F', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &filename, + N_("filename the screenshot"), + NULL + }, + { "fullscreen", 'f', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &fullscreen, N_("Take a screenshot of the entire screen"), NULL @@ -345,6 +351,9 @@ int main (int argc, char **argv) if (!sd->action) sd->action = SAVE; + if (filename) + sd->screenshot_filename = filename; + /* If the user gave a directory name, check that it is valid */ if (screenshot_dir != NULL) { -- 2.13.6