[libchamplain] launcher-gtk: allow replacing exported map



commit e1f6e591ca752f20bb29cbe46b7f2e4e41468a56
Author: Jiří Techet <techet gmail com>
Date:   Tue Sep 27 00:34:36 2016 +0200

    launcher-gtk: allow replacing exported map
    
    It's too easy to miss there's already a png export in the current directory
    and expect the export happened alright even though it's still the original
    file.
    
    Also close the output stream correctly which was missing in the original
    code.

 demos/launcher-gtk.c |   17 +++--------------
 1 files changed, 3 insertions(+), 14 deletions(-)
---
diff --git a/demos/launcher-gtk.c b/demos/launcher-gtk.c
index 950b01f..70975b4 100644
--- a/demos/launcher-gtk.c
+++ b/demos/launcher-gtk.c
@@ -223,14 +223,6 @@ append_point (ChamplainPathLayer *layer, gdouble lon, gdouble lat)
 
 
 static void
-export_to_png_cb (GdkPixbuf    *pixbuf,
-    GAsyncResult *res)
-{
-  gdk_pixbuf_save_to_stream_finish (res, NULL);
-}
-
-
-static void
 export_png (GtkButton     *button,
     ChamplainView *view)
 {
@@ -254,18 +246,15 @@ export_png (GtkButton     *button,
     return;
 
   file = g_file_new_for_path ("champlain-map.png");
-  os = g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL);
+  os = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL);
   if (!os)
     {
       g_object_unref (pixbuf);
       return;
     }
 
-  gdk_pixbuf_save_to_stream_async (pixbuf,
-                                   G_OUTPUT_STREAM (os), "png",
-                                   NULL,
-                                   (GAsyncReadyCallback) export_to_png_cb,
-                                   NULL);
+  gdk_pixbuf_save_to_stream (pixbuf, G_OUTPUT_STREAM (os), "png", NULL, NULL);
+  g_output_stream_close (G_OUTPUT_STREAM (os), NULL, NULL);
 }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]