diff -ru xfce4-screenshooter-1.8.2/lib/screenshooter-actions.c xfce4-screenshooter-1.8.2.new/lib/screenshooter-actions.c --- xfce4-screenshooter-1.8.2/lib/screenshooter-actions.c 2014-12-16 23:58:09.000000000 +0100 +++ xfce4-screenshooter-1.8.2.new/lib/screenshooter-actions.c 2015-11-01 12:45:22.337911696 +0100 @@ -92,7 +92,8 @@ sd->title, sd->timestamp, TRUE, - sd->action_specified); + sd->action_specified, + sd->output_filetype); if (save_location) { @@ -118,7 +119,8 @@ sd->title, sd->timestamp, FALSE, - FALSE); + FALSE, + sd->output_filetype); if (screenshot_path != NULL) { diff -ru xfce4-screenshooter-1.8.2/lib/screenshooter-dialogs.c xfce4-screenshooter-1.8.2.new/lib/screenshooter-dialogs.c --- xfce4-screenshooter-1.8.2/lib/screenshooter-dialogs.c 2014-12-20 10:23:33.000000000 +0100 +++ xfce4-screenshooter-1.8.2.new/lib/screenshooter-dialogs.c 2015-11-01 13:50:11.480959176 +0100 @@ -64,7 +64,8 @@ static gchar *generate_filename_for_uri (const gchar *uri, const gchar *title, - gboolean timestamp); + gboolean timestamp, + gchar *output_filetype); static void cb_combo_active_item_changed (GtkWidget *box, ScreenshotData *sd); @@ -92,13 +93,16 @@ GCancellable *cancellable); static gchar *save_screenshot_to_local_path (GdkPixbuf *screenshot, - GFile *save_file); + GFile *save_file, + gchar *output_filetype); static void save_screenshot_to_remote_location (GdkPixbuf *screenshot, - GFile *save_file); + GFile *save_file, + gchar *output_filetype); static gchar *save_screenshot_to (GdkPixbuf *screenshot, - const gchar *save_uri); + const gchar *save_uri, + gchar *output_filetype); @@ -224,7 +228,8 @@ */ static gchar *generate_filename_for_uri (const gchar *uri, const gchar *title, - gboolean timestamp) + gboolean timestamp, + gchar *output_filetype) { gboolean exists = TRUE; GFile *directory; @@ -246,9 +251,9 @@ datetime = screenshooter_get_datetime (strftime_format); directory = g_file_new_for_uri (uri); if (!timestamp) - base_name = g_strconcat (title, ".png", NULL); + base_name = g_strconcat (title, ".", output_filetype, NULL); else - base_name = g_strconcat (title, "_", datetime, ".png", NULL); + base_name = g_strconcat (title, "_", datetime, ".", output_filetype, NULL); file = g_file_get_child (directory, base_name); @@ -266,7 +271,7 @@ for (i = 1; exists; ++i) { const gchar *extension = - g_strdup_printf ("-%d.png", i); + g_strdup_printf ("-%d.%s", i, output_filetype); if (!timestamp) base_name = g_strconcat (title, extension, NULL); @@ -516,12 +521,12 @@ static gchar -*save_screenshot_to_local_path (GdkPixbuf *screenshot, GFile *save_file) +*save_screenshot_to_local_path (GdkPixbuf *screenshot, GFile *save_file, gchar *output_filetype) { GError *error = NULL; gchar *save_path = g_file_get_path (save_file); - if (G_UNLIKELY (!gdk_pixbuf_save (screenshot, save_path, "png", &error, NULL))) + if (G_UNLIKELY (!gdk_pixbuf_save (screenshot, save_path, output_filetype, &error, NULL))) { if (error) { @@ -539,7 +544,7 @@ } static void -save_screenshot_to_remote_location (GdkPixbuf *screenshot, GFile *save_file) +save_screenshot_to_remote_location (GdkPixbuf *screenshot, GFile *save_file, gchar *output_filetype) { gchar *save_basename = g_file_get_basename (save_file); gchar *save_path = g_build_filename (g_get_tmp_dir (), save_basename, NULL); @@ -560,7 +565,7 @@ GtkWidget *label1= gtk_label_new (""); GtkWidget *label2 = gtk_label_new (parent_uri); - save_screenshot_to_local_path (screenshot, save_file_temp); + save_screenshot_to_local_path (screenshot, save_file_temp, output_filetype); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); @@ -618,7 +623,7 @@ } static gchar -*save_screenshot_to (GdkPixbuf *screenshot, const gchar *save_uri) +*save_screenshot_to (GdkPixbuf *screenshot, const gchar *save_uri, gchar *output_filetype) { GFile *save_file = g_file_new_for_uri (save_uri); gchar *result = NULL; @@ -632,9 +637,9 @@ /* If the URI is a local one, we save directly */ if (!screenshooter_is_remote_uri (save_uri)) - result = save_screenshot_to_local_path (screenshot, save_file); + result = save_screenshot_to_local_path (screenshot, save_file, output_filetype); else - save_screenshot_to_remote_location (screenshot, save_file); + save_screenshot_to_remote_location (screenshot, save_file, output_filetype); g_object_unref (save_file); @@ -1083,7 +1088,7 @@ /* Saves the @screenshot in the given @directory using - * @title and @timestamp to generate the file name. + * @title, @timestamp, and @output_filetype to generate the file name. * * @screenshot: a GdkPixbuf containing the screenshot. * @directory: the save location. @@ -1095,6 +1100,7 @@ * @show_preview: if @save_dialog is true, @show_preview will * decide whether the save dialog should display a preview of * @screenshot. + * @output_filetype: Image file type to save the screenshot to * * Returns: a string containing the path to the saved file. */ @@ -1104,9 +1110,10 @@ const gchar *title, gboolean timestamp, gboolean save_dialog, - gboolean show_preview) + gboolean show_preview, + gchar *output_filetype) { - const gchar *filename = generate_filename_for_uri (directory, title, timestamp); + const gchar *filename = generate_filename_for_uri (directory, title, timestamp, output_filetype); gchar *save_uri = g_build_filename (directory, filename, NULL); gchar *result; @@ -1169,7 +1176,14 @@ { g_free (save_uri); save_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser)); - result = save_screenshot_to (screenshot, save_uri); + + /* Check for file suffix, if givem use it, otherwiese use preset value */ + gchar *new_output_filetype = g_strrstr(save_uri, "."); + if (new_output_filetype) + ++new_output_filetype; + else + new_output_filetype = output_filetype; + result = save_screenshot_to (screenshot, save_uri, new_output_filetype); } else result = NULL; @@ -1177,7 +1191,7 @@ gtk_widget_destroy (chooser); } else - result = save_screenshot_to (screenshot, save_uri); + result = save_screenshot_to (screenshot, save_uri, output_filetype); g_free (save_uri); diff -ru xfce4-screenshooter-1.8.2/lib/screenshooter-dialogs.h xfce4-screenshooter-1.8.2.new/lib/screenshooter-dialogs.h --- xfce4-screenshooter-1.8.2/lib/screenshooter-dialogs.h 2014-12-16 23:02:42.000000000 +0100 +++ xfce4-screenshooter-1.8.2.new/lib/screenshooter-dialogs.h 2015-11-01 12:30:06.086900510 +0100 @@ -44,7 +44,8 @@ const gchar *title, gboolean timestamp, gboolean save_dialog, - gboolean show_preview); + gboolean show_preview, + gchar *output_filetype); diff -ru xfce4-screenshooter-1.8.2/lib/screenshooter-global.h xfce4-screenshooter-1.8.2.new/lib/screenshooter-global.h --- xfce4-screenshooter-1.8.2/lib/screenshooter-global.h 2014-12-12 22:20:23.000000000 +0100 +++ xfce4-screenshooter-1.8.2.new/lib/screenshooter-global.h 2015-11-01 12:29:35.342900135 +0100 @@ -55,6 +55,7 @@ gchar *app; gchar *last_user; GdkPixbuf *screenshot; + gchar *output_filetype; } ScreenshotData; diff -ru xfce4-screenshooter-1.8.2/src/main.c xfce4-screenshooter-1.8.2.new/src/main.c --- xfce4-screenshooter-1.8.2/src/main.c 2014-12-16 21:29:35.000000000 +0100 +++ xfce4-screenshooter-1.8.2.new/src/main.c 2015-11-01 13:34:22.538947591 +0100 @@ -25,7 +25,7 @@ #include #include - +#include /* Set default values for cli args */ gboolean version = FALSE; @@ -39,7 +39,7 @@ gchar *screenshot_dir; gchar *application; gint delay = 0; - +gchar *output_filetype = "png"; /* Set cli options. */ @@ -103,6 +103,11 @@ NULL }, { + "filetype", 't', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &output_filetype, + N_("Image file type to save screenshot to (default:png)"), + NULL + }, + { NULL, ' ', 0, 0, NULL, NULL, NULL @@ -132,6 +137,31 @@ } +static int check_filetype_supported(gchar *output_filetype) +{ + int supported = FALSE; + + GSList *supported_formats = gdk_pixbuf_get_formats (); + GSList *sf = supported_formats; + + while (sf != NULL && !supported) + { + GdkPixbufFormat *format = (GdkPixbufFormat *)sf->data; + gchar **ext = gdk_pixbuf_format_get_extensions(format); + int i = 0; + while (ext[i] != NULL && !supported) + { + supported |= (g_strcmp0(ext[i], output_filetype) == 0); + ++i; + } + g_strfreev(ext); + sf = sf->next; + } + + g_slist_free_1 (supported_formats); + return supported; +} + /* Main */ @@ -285,6 +315,14 @@ /* Default to no action specified */ sd->action_specified = FALSE; + if (!check_filetype_supported(output_filetype)) + { + g_printerr (_("Image output type '%s' not supported\n"), output_filetype); + return EXIT_FAILURE; + + } + + sd->output_filetype = output_filetype; /* Check if the directory read from the preferences is valid */ default_save_dir = g_file_new_for_uri (sd->screenshot_dir); diff -ru xfce4-screenshooter-1.8.2/xfce4-screenshooter.1 xfce4-screenshooter-1.8.2.new/xfce4-screenshooter.1 --- xfce4-screenshooter-1.8.2/xfce4-screenshooter.1 2014-12-12 22:14:58.000000000 +0100 +++ xfce4-screenshooter-1.8.2.new/xfce4-screenshooter.1 2015-11-01 13:26:39.049941933 +0100 @@ -33,6 +33,9 @@ \fB\-d\fR, \fB\-\-delay\fR Delay in seconds before taking the screenshot .TP +\fB\-t\fR, \fB\-\-filetype\fR +Output image file type to save the screenshot to. +.TP \fB\-m\fR, \fB\-\-mouse\fR Display the mouse on the screenshot .TP