Commit f28878b6 authored by Michael Natterer's avatar Michael Natterer 😴

plug-ins: start the progress before opening files for loading/saving

so the user gets feedback as early as possible.
parent 208c3ecd
......@@ -335,6 +335,8 @@ load_image (const gchar *file,
gint i, j, k; /* Counters */
size_t n_read; /* Number of items read from file */
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (file));
/* Open the file for reading */
fp = g_fopen (file, "r");
......@@ -347,9 +349,6 @@ load_image (const gchar *file,
return -1;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (file));
/* Get the image dimensions and create the image... */
n_read = fread (header, 4, 1, fp);
......@@ -769,6 +768,9 @@ save_image (const gchar *file,
width = gegl_buffer_get_width (buffer);
height = gegl_buffer_get_height (buffer);
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (file));
/* Open the file for writing */
fp = g_fopen (file, "w");
......@@ -780,9 +782,6 @@ save_image (const gchar *file,
return FALSE;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (file));
/* Headers */
memset (header, 0, 32);
strcpy ((gchar *) header, "KiSS");
......
......@@ -331,7 +331,9 @@ load_image (const gchar *filename,
gboolean is_signed = FALSE;
guint8 in_sequence = 0;
/* open the file */
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
DICOM = g_fopen (filename, "rb");
if (! DICOM)
......@@ -342,9 +344,6 @@ load_image (const gchar *filename,
return -1;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
/* allocate the necessary structures */
dicominfo = g_new0 (DicomInfo, 1);
......
......@@ -345,13 +345,13 @@ load_image (GFile *file,
gsize size;
gint i;
gimp_progress_init_printf (_("Opening '%s'"),
g_file_get_parse_name (file));
input = G_INPUT_STREAM (g_file_read (file, NULL, error));
if (! input)
return -1;
gimp_progress_init_printf (_("Opening '%s'"),
g_file_get_parse_name (file));
size = G_STRUCT_OFFSET (BrushHeader, magic_number);
if (! g_input_stream_read_all (input, &bh, size,
......@@ -671,13 +671,13 @@ save_image (GFile *file,
bpp = babl_format_get_bytes_per_pixel (format);
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
if (! output)
return FALSE;
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
buffer = gimp_drawable_get_buffer (drawable_ID);
width = gimp_drawable_width (drawable_ID);
......
......@@ -348,6 +348,9 @@ load_image (const gchar *filename,
gchar version[4];
gint32 image_ID = -1;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
fd = g_fopen (filename, "rb");
if (! fd)
......@@ -358,9 +361,6 @@ load_image (const gchar *filename,
return -1;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
if (! ReadOK (fd, buf, 6))
{
g_message ("Error reading magic number");
......
......@@ -791,6 +791,11 @@ save_image (const gchar *filename,
}
/* init the progress meter */
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/* open the destination file for writing */
outfile = g_fopen (filename, "wb");
if (!outfile)
......@@ -802,11 +807,6 @@ save_image (const gchar *filename,
}
/* init the progress meter */
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/* write the GIFheader */
if (colors < 256)
......
......@@ -662,13 +662,13 @@ gih_load_image (GFile *file,
GimpParasite *pipe_parasite;
gsize bytes_read;
gimp_progress_init_printf (_("Opening '%s'"),
g_file_get_parse_name (file));
input = G_INPUT_STREAM (g_file_read (file, NULL, error));
if (! input)
return -1;
gimp_progress_init_printf (_("Opening '%s'"),
g_file_get_parse_name (file));
/* The file format starts with a painfully simple text header */
/* get the name */
......@@ -1294,13 +1294,13 @@ gih_save_image (GFile *file,
imagew = gimp_image_width (image_ID);
imageh = gimp_image_height (image_ID);
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
if (! output)
return FALSE;
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
parstring = gimp_pixpipe_params_build (&gihparams);
header = g_strdup_printf ("%s\n%d %s\n",
......
......@@ -233,6 +233,9 @@ save_image (const gchar *filename,
cols = gegl_buffer_get_width (buffer);
rows = gegl_buffer_get_height (buffer);
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
fp = g_fopen (filename, "w");
if (! fp)
......@@ -260,9 +263,6 @@ save_image (const gchar *filename,
fprintf (fp, "<CAPTION>%s</CAPTION>\n",
gtmvals.captiontxt);
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
buf = g_newa (guchar, babl_format_get_bytes_per_pixel (format));
buf2 = g_newa (guchar, babl_format_get_bytes_per_pixel (format));
......
......@@ -317,13 +317,13 @@ load_image (GFile *file,
GimpImageType image_type;
gsize bytes_read;
gimp_progress_init_printf (_("Opening '%s'"),
g_file_get_parse_name (file));
input = G_INPUT_STREAM (g_file_read (file, NULL, error));
if (! input)
return -1;
gimp_progress_init_printf (_("Opening '%s'"),
g_file_get_parse_name (file));
if (! g_input_stream_read_all (input, &ph, sizeof (PatternHeader),
&bytes_read, NULL, error) ||
bytes_read != sizeof (PatternHeader))
......@@ -515,13 +515,13 @@ save_image (GFile *file,
return FALSE;
}
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
if (! output)
return FALSE;
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
buffer = gimp_drawable_get_buffer (drawable_ID);
width = gegl_buffer_get_width (buffer);
......
......@@ -356,6 +356,9 @@ load_image (const gchar *filename,
guchar *dest, cmap[768];
guint8 header_buf[128];
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
fd = g_fopen (filename, "rb");
if (! fd)
......@@ -366,9 +369,6 @@ load_image (const gchar *filename,
return -1;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
if (fread (header_buf, 128, 1, fd) == 0)
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
......
......@@ -357,13 +357,13 @@ load_image (GFile *file,
PIX_DEBUG_PRINT ("Opening file: %s\n", filename);
gimp_progress_init_printf (_("Opening '%s'"),
g_file_get_parse_name (file));
input = G_INPUT_STREAM (g_file_read (file, NULL, error));
if (! input)
return -1;
gimp_progress_init_printf (_("Opening '%s'"),
g_file_get_parse_name (file));
/* Read header information */
if (! get_short (input, &width, error) ||
! get_short (input, &height, error) ||
......@@ -536,13 +536,13 @@ save_image (GFile *file,
guchar *src;
guchar *src_base;
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
if (! output)
return FALSE;
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
/* Get info about image */
buffer = gimp_drawable_get_buffer (drawable_ID);
......
......@@ -855,6 +855,9 @@ load_image (const gchar *filename,
* Open the file and initialize the PNG read "engine"...
*/
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
fp = g_fopen (filename, "rb");
if (fp == NULL)
......@@ -867,9 +870,6 @@ load_image (const gchar *filename,
png_init_io (pp, fp);
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
/*
* Get the image dimensions and create the image...
*/
......@@ -1480,6 +1480,9 @@ save_image (const gchar *filename,
* Open the file and initialize the PNG write "engine"...
*/
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
fp = g_fopen (filename, "wb");
if (fp == NULL)
{
......@@ -1491,9 +1494,6 @@ save_image (const gchar *filename,
png_init_io (pp, fp);
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/*
* Get the buffer for the current image...
*/
......
......@@ -494,14 +494,13 @@ load_image (GFile *file,
PNMScanner *volatile scan;
int ctr;
/* open the file */
gimp_progress_init_printf (_("Opening '%s'"),
g_file_get_parse_name (file));
input = G_INPUT_STREAM (g_file_read (file, NULL, error));
if (! input)
return -1;
gimp_progress_init_printf (_("Opening '%s'"),
g_file_get_parse_name (file));
/* allocate the necessary structures */
pnminfo = g_new (PNMInfo, 1);
......@@ -1052,14 +1051,14 @@ save_image (GFile *file,
return FALSE;
}
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
/* open the file */
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
if (! output)
return FALSE;
gimp_progress_init_printf (_("Saving '%s'"),
g_file_get_parse_name (file));
buffer = gimp_drawable_get_buffer (drawable_ID);
xres = gegl_buffer_get_width (buffer);
......
......@@ -1011,6 +1011,9 @@ load_image (const gchar *filename,
g_print (" GraphicsAlphaBits: %d\n", plvals.graphicsalpha);
#endif
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
/* Try to see if PostScript file is available */
ifp = g_fopen (filename, "r");
if (ifp == NULL)
......@@ -1022,9 +1025,6 @@ load_image (const gchar *filename,
}
fclose (ifp);
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
ifp = ps_open (filename, &plvals, &llx, &lly, &urx, &ury, &is_epsf);
if (!ifp)
{
......@@ -1187,6 +1187,9 @@ save_image (const gchar *filename,
break;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/* Open the output file. */
ofp = g_fopen (filename, "wb");
if (!ofp)
......@@ -1197,9 +1200,6 @@ save_image (const gchar *filename,
return FALSE;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
save_ps_header (ofp, filename);
switch (drawable_type)
......
......@@ -899,6 +899,9 @@ load_image (const gchar *filename,
data = g_new0 (RawGimpData, 1);
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
data->fp = g_fopen (filename, "rb");
if (! data->fp)
{
......@@ -908,9 +911,6 @@ load_image (const gchar *filename,
return -1;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
size = get_file_info (filename);
switch (runtime->image_type)
......
......@@ -426,6 +426,9 @@ load_image (const gchar *filename,
L_SUNFILEHEADER sunhdr;
guchar *suncolmap = NULL;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
ifp = g_fopen (filename, "rb");
if (!ifp)
{
......@@ -526,9 +529,6 @@ load_image (const gchar *filename,
return -1;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
switch (sunhdr.l_ras_depth)
{
case 1: /* bitmap */
......@@ -599,6 +599,9 @@ save_image (const gchar *filename,
break;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/* Open the output file. */
ofp = g_fopen (filename, "wb");
if (! ofp)
......@@ -609,9 +612,6 @@ save_image (const gchar *filename,
return FALSE;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
if (drawable_type == GIMP_INDEXED_IMAGE)
retval = save_index (ofp,image_ID, drawable_ID, FALSE, psvals.rle);
else if (drawable_type == GIMP_GRAY_IMAGE)
......
......@@ -435,6 +435,9 @@ load_image (const gchar *filename,
long offset;
gint32 image_ID = -1;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
fp = g_fopen (filename, "rb");
if (! fp)
......@@ -445,9 +448,6 @@ load_image (const gchar *filename,
return -1;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
/* Is file big enough for a footer? */
if (!fseek (fp, -26L, SEEK_END))
{
......@@ -1173,6 +1173,9 @@ save_image (const gchar *filename,
width = gegl_buffer_get_width (buffer);
height = gegl_buffer_get_height (buffer);
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
if ((fp = g_fopen (filename, "wb")) == NULL)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
......@@ -1181,9 +1184,6 @@ save_image (const gchar *filename,
return FALSE;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
header[0] = 0; /* No image identifier / description */
if (dtype == GIMP_INDEXED_IMAGE)
......
......@@ -982,14 +982,14 @@ load_image (const gchar *filename,
guchar *pixels;
guint width, height;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
pixels = wmf_load_file (filename, &width, &height, error);
if (! pixels)
return -1;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
image = gimp_image_new (width, height, GIMP_RGB);
gimp_image_set_filename (image, filename);
gimp_image_set_resolution (image,
......
......@@ -731,6 +731,9 @@ load_image (const gchar *filename,
0xff, 0xff, 0xff /* white */
};
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
fp = g_fopen (filename, "rb");
if (! fp)
{
......@@ -740,9 +743,6 @@ load_image (const gchar *filename,
return -1;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
comment = fgetcomment (fp);
/* Loosely parse the header */
......@@ -1023,6 +1023,9 @@ save_image (const gchar *filename,
dark = 1;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/* Now actually save the data. */
fp = g_fopen (filename, "w");
if (! fp)
......@@ -1033,9 +1036,6 @@ save_image (const gchar *filename,
return FALSE;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/* Maybe write the image comment. */
#if 0
/* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
......
......@@ -646,6 +646,9 @@ load_image (const gchar *filename,
gint img_height;
gint i, j;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
/* Open the file and check it is a valid X cursor */
fp = g_fopen (filename, "rb");
......@@ -665,9 +668,6 @@ load_image (const gchar *filename,
return -1;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
/* check dimension is valid. */
for (i = 0; i < imagesp->nimage; i++)
......@@ -1451,6 +1451,9 @@ save_image (const gchar *filename,
0,
NULL);
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/*
* Open the file pointer.
*/
......@@ -1464,9 +1467,6 @@ save_image (const gchar *filename,
return FALSE;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/* get layers */
orig_layers = gimp_image_get_layers (orig_image_ID, &nlayers);
layers = gimp_image_get_layers (image_ID, &nlayers);
......
......@@ -435,6 +435,9 @@ load_image (const gchar *filename,
L_XWDFILEHEADER xwdhdr;
L_XWDCOLOR *xwdcolmap = NULL;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
ifp = g_fopen (filename, "rb");
if (!ifp)
{
......@@ -536,9 +539,6 @@ load_image (const gchar *filename,
goto out;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
depth = xwdhdr.l_pixmap_depth;
bpp = xwdhdr.l_bits_per_pixel;
......@@ -638,6 +638,9 @@ save_image (const gchar *filename,
break;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/* Open the output file. */
ofp = g_fopen (filename, "wb");
if (! ofp)
......@@ -648,9 +651,6 @@ save_image (const gchar *filename,
return FALSE;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
switch (drawable_type)
{
case GIMP_INDEXED_IMAGE:
......
......@@ -197,6 +197,9 @@ ReadBMP (const gchar *name,
gchar magick[2];
Bitmap_Channel masks[4];
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (name));
filename = name;
fd = g_fopen (filename, "rb");
......@@ -208,9 +211,6 @@ ReadBMP (const gchar *name,
goto out;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (name));
/* It is a File. Now is it a Bitmap? Read the shortest possible header */
if (!ReadOK (fd, magick, 2) || !(!strncmp (magick, "BA", 2) ||
......
......@@ -312,6 +312,10 @@ WriteBMP (const gchar *filename,
gimp_set_data (SAVE_PROC, &BMPSaveData, sizeof (BMPSaveData));
/* Let's begin the progress */
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/* Let's take some file */
outfile = g_fopen (filename, "wb");
if (!outfile)
......@@ -332,10 +336,6 @@ WriteBMP (const gchar *filename,
g_object_unref (buffer);
/* And let's begin the progress */
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
cur_progress = 0;
max_progress = drawable_height;
......
......@@ -171,6 +171,9 @@ load_image (const gchar *filename,
int end;
int num;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
loader = exr_loader_new (filename);
if (!loader)
{
......@@ -227,9 +230,6 @@ load_image (const gchar *filename,
goto out;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
image = gimp_image_new_with_precision (width, height,
image_type, image_precision);
if (image == -1)
......
......@@ -470,6 +470,9 @@ save_image (const gchar *filename,
break;
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
/* Open the output file. */
ofp = fits_open (filename, "w");
if (!ofp)
......@@ -480,9 +483,6 @@ save_image (const gchar *filename,
return (FALSE);
}
gimp_progress_init_printf (_("Saving '%s'"),
gimp_filename_to_utf8 (filename));
retval = save_fits (ofp,image_ID, drawable_ID);
fits_close (ofp);
......
......@@ -491,6 +491,9 @@ load_image (const gchar *filename,
s_fli_header fli_header;
gint cnt;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
file = g_fopen (filename ,"rb");
if (!file)
{
......@@ -500,9 +503,6 @@ load_image (const gchar *filename,
return -1;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
fli_read_header (file, &fli_header);
if (fli_header.magic == NO_HEADER)
return -1;
......
......@@ -86,6 +86,9 @@ load_image (const gchar *filename,
if (!preview)
{
jerr.pub.output_message = my_output_message;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
}
if ((infile = g_fopen (filename, "rb")) == NULL)
......@@ -96,10 +99,6 @@ load_image (const gchar *filename,
return -1;
}
if (!