[gimp/gimp-2-8] Bug 766886: the save bar keeps saving even whit a full bar



commit 3efa22b65093b52e0d7901746d66b8adc82e1160
Author: Massimo Valentini <mvalentini src gnome org>
Date:   Sun Jun 5 19:02:12 2016 +0200

    Bug 766886: the save bar keeps saving even whit a full bar
    
    
    
    based on ffd97c0eb8dab934e2b73d71051980ec28892483

 plug-ins/file-compressor/file-compressor.c |   38 ++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/plug-ins/file-compressor/file-compressor.c b/plug-ins/file-compressor/file-compressor.c
index 8b37264..58812d8 100644
--- a/plug-ins/file-compressor/file-compressor.c
+++ b/plug-ins/file-compressor/file-compressor.c
@@ -159,6 +159,7 @@ bzip2_load                                (const char         *infile,
 static gboolean
 bzip2_save                                (const char         *infile,
                                            const char         *outfile);
+static goffset             get_file_info  (const gchar        *filename);
 
 static const Compressor compressors[] =
 {
@@ -412,6 +413,9 @@ save_image (const Compressor  *compressor,
       return GIMP_PDB_EXECUTION_ERROR;
     }
 
+  gimp_progress_init_printf (_("Compressing '%s'"),
+                             gimp_filename_to_utf8 (filename));
+
   if (!compressor->save_fn (tmpname, filename))
     {
       g_unlink (tmpname);
@@ -421,6 +425,7 @@ save_image (const Compressor  *compressor,
     }
 
   g_unlink (tmpname);
+  gimp_progress_update (1.0);
   g_free (tmpname);
 
   /* ask the core to save a thumbnail for compressed XCF files */
@@ -597,6 +602,7 @@ gzip_save (const char *infile,
   gzFile out;
   char buf[16384];
   int len;
+  goffset tot = 0, file_size;
 
   ret = FALSE;
   in = NULL;
@@ -617,6 +623,7 @@ gzip_save (const char *infile,
       goto out;
     }
 
+  file_size = get_file_info (infile);
   while (TRUE)
     {
       len = fread (buf, 1, sizeof buf, in);
@@ -633,6 +640,8 @@ gzip_save (const char *infile,
 
       if (gzwrite (out, buf, len) != len)
         break;
+
+      gimp_progress_update ((tot += len) * 1.0 / file_size);
     }
 
  out:
@@ -715,6 +724,7 @@ bzip2_save (const char *infile,
   BZFILE *out;
   char buf[16384];
   int len;
+  goffset tot = 0, file_size;
 
   ret = FALSE;
   in = NULL;
@@ -735,6 +745,7 @@ bzip2_save (const char *infile,
       goto out;
     }
 
+  file_size = get_file_info (infile);
   while (TRUE)
     {
       len = fread (buf, 1, sizeof buf, in);
@@ -751,6 +762,8 @@ bzip2_save (const char *infile,
 
       if (BZ2_bzwrite (out, buf, len) != len)
         break;
+
+      gimp_progress_update ((tot += len) * 1.0 / file_size);
     }
 
  out:
@@ -764,3 +777,28 @@ bzip2_save (const char *infile,
 
   return ret;
 }
+
+/* get file size from a filename */
+static goffset
+get_file_info (const gchar *filename)
+{
+  GFile     *file = g_file_new_for_path (filename);
+  GFileInfo *info;
+  goffset    size = 1;
+
+  info = g_file_query_info (file,
+                            G_FILE_ATTRIBUTE_STANDARD_SIZE,
+                            G_FILE_QUERY_INFO_NONE,
+                            NULL, NULL);
+
+  if (info)
+    {
+      size = g_file_info_get_size (info);
+
+      g_object_unref (info);
+    }
+
+  g_object_unref (file);
+
+  return size;
+}


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