[virt-tools-list] [PATCH] remote-viewer: add a default extension to screenshot filenames

Victor Toso victortoso at redhat.com
Tue Jan 21 12:55:03 UTC 2020


Hi,

On Fri, Dec 13, 2019 at 11:16:23AM +0100, Julien Ropé wrote:
> From: Julien ROPE <jrope at redhat.com>
> 
> When doing a screenshot, if the user provides a filename without a file
> extension, an error occurs because the image format could not be determined.
> This patch adds a .png extension to such filenames, so that there is a default
> file format for screenshots.

Sure,

> 
> Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1752514
> 
> Signed-off-by: Julien Ropé <jrope at redhat.com>
> ---
>  src/virt-viewer-window.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
> index 4c08423..f58ebad 100644
> --- a/src/virt-viewer-window.c
> +++ b/src/virt-viewer-window.c
> @@ -1069,6 +1069,14 @@ virt_viewer_window_menu_file_screenshot(GtkWidget *menu G_GNUC_UNUSED,
>          GError *error = NULL;
>  
>          filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (dialog));
> +        if (g_strrstr(filename, ".") == NULL) {

Looks fine. In another way, I'd say the following diff might fix
some other corner cases too.

-        if (g_strrstr(filename, ".") == NULL) {
+        if (!g_str_has_suffix(filename, ".png")) {


> +            // no extension provided: add the .png default
> +            char *tmp_filename ;
> +            tmp_filename = g_strdup_printf("%s.png", filename) ;
> +            g_free(filename) ;
> +            filename = tmp_filename ;
> +        }
> +
>          if (!virt_viewer_window_save_screenshot(self, filename, &error)) {
>              virt_viewer_app_simple_message_dialog(self->priv->app,
>                                                    error->message);
> -- 
> 2.21.0
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20200121/f6633dd7/attachment.sig>


More information about the virt-tools-list mailing list