mirror of https://github.com/GNOME/gimp.git
app/core/gimpdrawable-blend.c some progress cleanup.
2004-08-11 Michael Natterer <mitch@gimp.org> * app/core/gimpdrawable-blend.c * app/core/gimpprogress.c: some progress cleanup. * app/display/gimpstatusbar.c (gimp_statusbar_progress_start): no need to warn if there is already a progress active, just silently return NULL as all other GimpProgressInterface implementors. * app/plug-in/plug-in-progress.c: several progress fixes. It's still a mess. * plug-ins/common/url.c: don't show progress depending on run_mode. Run the actual file plug-in with the same run_mode we were invoked with.
This commit is contained in:
parent
846bacd905
commit
502f9b71f3
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
2004-08-11 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/core/gimpdrawable-blend.c
|
||||
* app/core/gimpprogress.c: some progress cleanup.
|
||||
|
||||
* app/display/gimpstatusbar.c (gimp_statusbar_progress_start): no
|
||||
need to warn if there is already a progress active, just silently
|
||||
return NULL as all other GimpProgressInterface implementors.
|
||||
|
||||
* app/plug-in/plug-in-progress.c: several progress fixes.
|
||||
It's still a mess.
|
||||
|
||||
* plug-ins/common/url.c: don't show progress depending on
|
||||
run_mode. Run the actual file plug-in with the same run_mode we
|
||||
were invoked with.
|
||||
|
||||
2004-08-11 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/gui/file-open-location-dialog.c
|
||||
|
|
|
@ -1023,7 +1023,8 @@ gradient_fill_region (GimpImage *gimage,
|
|||
max_depth, threshold,
|
||||
gradient_render_pixel, &rbd,
|
||||
gradient_put_pixel, &ppd,
|
||||
gimp_progress_update_and_flush,
|
||||
progress ?
|
||||
gimp_progress_update_and_flush : NULL,
|
||||
progress);
|
||||
|
||||
g_free (ppd.row_data);
|
||||
|
@ -1133,8 +1134,9 @@ gradient_fill_region (GimpImage *gimage,
|
|||
{
|
||||
curr_progress += PR->w * PR->h;
|
||||
|
||||
gimp_progress_update_and_flush (0, max_progress, curr_progress,
|
||||
progress);
|
||||
gimp_progress_set_value (progress,
|
||||
(gdouble) curr_progress /
|
||||
(gdouble) max_progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ gimp_progress_update_and_flush (gint min,
|
|||
gpointer data)
|
||||
{
|
||||
gimp_progress_set_value (GIMP_PROGRESS (data),
|
||||
(gfloat) (current - min) / (gfloat) (max - min));
|
||||
(gdouble) (current - min) / (gdouble) (max - min));
|
||||
|
||||
while (g_main_context_pending (NULL))
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
|
|
|
@ -292,12 +292,12 @@ gimp_statusbar_progress_start (GimpProgress *progress,
|
|||
|
||||
statusbar->progress_active = TRUE;
|
||||
|
||||
if (GTK_WIDGET_DRAWABLE (bar))
|
||||
gdk_window_process_updates (bar->window, TRUE);
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
g_warning ("%s: progress bar already active for statusbar %p",
|
||||
G_STRFUNC, statusbar);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -326,7 +326,12 @@ gimp_statusbar_progress_set_text (GimpProgress *progress,
|
|||
|
||||
if (statusbar->progress_active)
|
||||
{
|
||||
GtkWidget *bar = statusbar->progressbar;
|
||||
|
||||
gimp_statusbar_replace (statusbar, "progress", message);
|
||||
|
||||
if (GTK_WIDGET_DRAWABLE (bar))
|
||||
gdk_window_process_updates (bar->window, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,16 +60,24 @@ plug_in_progress_start (PlugIn *plug_in,
|
|||
if (plug_in->progress)
|
||||
{
|
||||
if (plug_in->progress_active)
|
||||
plug_in_progress_end (plug_in);
|
||||
|
||||
if (gimp_progress_start (plug_in->progress, message, TRUE))
|
||||
{
|
||||
g_signal_connect (plug_in->progress, "cancel",
|
||||
G_CALLBACK (plug_in_progress_cancel),
|
||||
plug_in);
|
||||
gimp_progress_set_text (plug_in->progress, message);
|
||||
gimp_progress_set_value (plug_in->progress, 0.0);
|
||||
|
||||
plug_in->progress_active = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (! gimp_progress_start (plug_in->progress, message, TRUE))
|
||||
{
|
||||
gimp_progress_set_text (plug_in->progress, message);
|
||||
gimp_progress_set_value (plug_in->progress, 0.0);
|
||||
}
|
||||
|
||||
g_signal_connect (plug_in->progress, "cancel",
|
||||
G_CALLBACK (plug_in_progress_cancel),
|
||||
plug_in);
|
||||
|
||||
plug_in->progress_active = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +87,7 @@ plug_in_progress_update (PlugIn *plug_in,
|
|||
{
|
||||
g_return_if_fail (plug_in != NULL);
|
||||
|
||||
if (! plug_in->progress && plug_in->progress_active)
|
||||
if (! (plug_in->progress && plug_in->progress_active))
|
||||
plug_in_progress_start (plug_in, NULL, -1);
|
||||
|
||||
if (plug_in->progress && plug_in->progress_active)
|
||||
|
|
|
@ -60,16 +60,24 @@ plug_in_progress_start (PlugIn *plug_in,
|
|||
if (plug_in->progress)
|
||||
{
|
||||
if (plug_in->progress_active)
|
||||
plug_in_progress_end (plug_in);
|
||||
|
||||
if (gimp_progress_start (plug_in->progress, message, TRUE))
|
||||
{
|
||||
g_signal_connect (plug_in->progress, "cancel",
|
||||
G_CALLBACK (plug_in_progress_cancel),
|
||||
plug_in);
|
||||
gimp_progress_set_text (plug_in->progress, message);
|
||||
gimp_progress_set_value (plug_in->progress, 0.0);
|
||||
|
||||
plug_in->progress_active = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (! gimp_progress_start (plug_in->progress, message, TRUE))
|
||||
{
|
||||
gimp_progress_set_text (plug_in->progress, message);
|
||||
gimp_progress_set_value (plug_in->progress, 0.0);
|
||||
}
|
||||
|
||||
g_signal_connect (plug_in->progress, "cancel",
|
||||
G_CALLBACK (plug_in_progress_cancel),
|
||||
plug_in);
|
||||
|
||||
plug_in->progress_active = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +87,7 @@ plug_in_progress_update (PlugIn *plug_in,
|
|||
{
|
||||
g_return_if_fail (plug_in != NULL);
|
||||
|
||||
if (! plug_in->progress && plug_in->progress_active)
|
||||
if (! (plug_in->progress && plug_in->progress_active))
|
||||
plug_in_progress_start (plug_in, NULL, -1);
|
||||
|
||||
if (plug_in->progress && plug_in->progress_active)
|
||||
|
|
|
@ -63,8 +63,8 @@ query (void)
|
|||
{
|
||||
static GimpParamDef load_args[] =
|
||||
{
|
||||
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
||||
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
||||
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
||||
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
||||
{ GIMP_PDB_STRING, "raw_filename", "The name entered" }
|
||||
};
|
||||
|
||||
|
@ -115,9 +115,7 @@ run (const gchar *name,
|
|||
|
||||
if (strcmp (name, "file_url_load") == 0)
|
||||
{
|
||||
image_ID = load_image (param[2].data.d_string,
|
||||
run_mode,
|
||||
&status);
|
||||
image_ID = load_image (param[2].data.d_string, run_mode, &status);
|
||||
|
||||
if (image_ID != -1 &&
|
||||
status == GIMP_PDB_SUCCESS)
|
||||
|
@ -140,18 +138,16 @@ load_image (const gchar *filename,
|
|||
GimpRunMode run_mode,
|
||||
GimpPDBStatusType *status)
|
||||
{
|
||||
gint32 image_ID;
|
||||
gchar *ext = strrchr (filename, '.');
|
||||
gchar *tmpname;
|
||||
gint pid;
|
||||
gint wpid;
|
||||
gint process_status;
|
||||
gint p[2];
|
||||
gboolean name_image = FALSE;
|
||||
gint32 image_ID;
|
||||
gchar *ext = strrchr (filename, '.');
|
||||
gchar *tmpname;
|
||||
gint pid;
|
||||
gint p[2];
|
||||
gboolean name_image = FALSE;
|
||||
|
||||
fprintf (stderr, "Loading URL: %s\n", filename);
|
||||
|
||||
if (!ext || ext[1] == 0 || strchr(ext, '/'))
|
||||
if (!ext || ext[1] == 0 || strchr (ext, '/'))
|
||||
tmpname = gimp_temp_name ("xxx");
|
||||
else
|
||||
{
|
||||
|
@ -195,220 +191,203 @@ load_image (const gchar *filename,
|
|||
}
|
||||
else
|
||||
{
|
||||
if (run_mode == GIMP_RUN_NONINTERACTIVE)
|
||||
{
|
||||
wpid = waitpid (pid, &process_status, 0);
|
||||
FILE *input;
|
||||
gchar buf[BUFSIZE];
|
||||
gboolean seen_resolve = FALSE;
|
||||
gboolean connected = FALSE;
|
||||
gboolean file_found = FALSE;
|
||||
gchar sizestr[32];
|
||||
gint size = 0;
|
||||
gchar *message;
|
||||
gint i, j;
|
||||
gchar dot;
|
||||
gint kilobytes = 0;
|
||||
gboolean finished = FALSE;
|
||||
|
||||
if ((wpid < 0)
|
||||
|| !WIFEXITED (process_status)
|
||||
|| (WEXITSTATUS (process_status) != 0))
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE *input;
|
||||
gchar buf[BUFSIZE];
|
||||
gboolean seen_resolve = FALSE;
|
||||
gboolean connected = FALSE;
|
||||
gboolean file_found = FALSE;
|
||||
gchar sizestr[32];
|
||||
gint size = 0;
|
||||
gchar *message;
|
||||
gint i, j;
|
||||
gchar dot;
|
||||
gint kilobytes = 0;
|
||||
gboolean finished = FALSE;
|
||||
|
||||
gboolean debug = FALSE;
|
||||
gboolean debug = FALSE;
|
||||
|
||||
#define DEBUG(x) if (debug) fprintf (stderr, (x))
|
||||
|
||||
close (p[1]);
|
||||
close (p[1]);
|
||||
|
||||
input = fdopen (p[0], "r");
|
||||
input = fdopen (p[0], "r");
|
||||
|
||||
/* hardcoded and not-really-foolproof scanning of wget putput */
|
||||
/* hardcoded and not-really-foolproof scanning of wget putput */
|
||||
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
/* no message here because failing on the first line means
|
||||
* that wget was not found
|
||||
*/
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
/* no message here because failing on the first line means
|
||||
* that wget was not found
|
||||
*/
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The second line is the local copy of the file */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
/* The second line is the local copy of the file */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The third line is "Connecting to..." */
|
||||
gimp_progress_init ("Connecting to server... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
/* The third line is "Connecting to..." */
|
||||
gimp_progress_init ("Connecting to server... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
|
||||
read_connect:
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "connected"))
|
||||
{
|
||||
connected = TRUE;
|
||||
}
|
||||
/* newer wgets have a "Resolving foo" line, so eat it */
|
||||
else if (!seen_resolve && strstr (buf, "Resolving"))
|
||||
{
|
||||
seen_resolve = TRUE;
|
||||
goto read_connect;
|
||||
}
|
||||
read_connect:
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "connected"))
|
||||
{
|
||||
connected = TRUE;
|
||||
}
|
||||
/* newer wgets have a "Resolving foo" line, so eat it */
|
||||
else if (!seen_resolve && strstr (buf, "Resolving"))
|
||||
{
|
||||
seen_resolve = TRUE;
|
||||
goto read_connect;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The fourth line is either the network request or an error */
|
||||
gimp_progress_init ("Opening URL... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
/* The fourth line is either the network request or an error */
|
||||
gimp_progress_init ("Opening URL... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (! connected)
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (! connected)
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The fifth line is either the length of the file or an error */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "Length"))
|
||||
{
|
||||
file_found = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
/* The fifth line is either the length of the file or an error */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "Length"))
|
||||
{
|
||||
file_found = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
if (sscanf (buf, "Length: %31s", sizestr) != 1)
|
||||
{
|
||||
g_message ("Could not parse wget's file length message");
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
if (sscanf (buf, "Length: %31s", sizestr) != 1)
|
||||
{
|
||||
g_message ("Could not parse wget's file length message");
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* strip away commas */
|
||||
for (i = 0, j = 0; i < sizeof (sizestr); i++, j++)
|
||||
{
|
||||
if (sizestr[i] == ',')
|
||||
i++;
|
||||
/* strip away commas */
|
||||
for (i = 0, j = 0; i < sizeof (sizestr); i++, j++)
|
||||
{
|
||||
if (sizestr[i] == ',')
|
||||
i++;
|
||||
|
||||
sizestr[j] = sizestr[i];
|
||||
sizestr[j] = sizestr[i];
|
||||
|
||||
if (sizestr[j] == '\0')
|
||||
break;
|
||||
}
|
||||
if (sizestr[j] == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
size = atoi (sizestr);
|
||||
size = atoi (sizestr);
|
||||
|
||||
/* Start the actual download... */
|
||||
message = g_strdup_printf ("Downloading %d bytes of image data... "
|
||||
"(timeout is "TIMEOUT" seconds)", size);
|
||||
gimp_progress_init (message);
|
||||
g_free (message);
|
||||
/* Start the actual download... */
|
||||
message = g_strdup_printf ("Downloading %d bytes of image data... "
|
||||
"(timeout is "TIMEOUT" seconds)", size);
|
||||
gimp_progress_init (message);
|
||||
g_free (message);
|
||||
|
||||
/* Switch to byte parsing wget's output... */
|
||||
/* Switch to byte parsing wget's output... */
|
||||
|
||||
while (1)
|
||||
{
|
||||
dot = fgetc (input);
|
||||
while (1)
|
||||
{
|
||||
dot = fgetc (input);
|
||||
|
||||
if (feof (input))
|
||||
break;
|
||||
if (feof (input))
|
||||
break;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fputc (dot, stderr);
|
||||
fflush (stderr);
|
||||
}
|
||||
if (debug)
|
||||
{
|
||||
fputc (dot, stderr);
|
||||
fflush (stderr);
|
||||
}
|
||||
|
||||
if (dot == '.') /* one kilobyte */
|
||||
{
|
||||
kilobytes++;
|
||||
gimp_progress_update ((gdouble) (kilobytes * 1024) /
|
||||
(gdouble) size);
|
||||
}
|
||||
else if (dot == ':') /* the time string contains a ':' */
|
||||
{
|
||||
fgets (buf, BUFSIZE, input);
|
||||
if (dot == '.') /* one kilobyte */
|
||||
{
|
||||
kilobytes++;
|
||||
gimp_progress_update ((gdouble) (kilobytes * 1024) /
|
||||
(gdouble) size);
|
||||
}
|
||||
else if (dot == ':') /* the time string contains a ':' */
|
||||
{
|
||||
fgets (buf, BUFSIZE, input);
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
if (! strstr (buf, "error"))
|
||||
{
|
||||
finished = TRUE;
|
||||
gimp_progress_update (1.0);
|
||||
}
|
||||
if (! strstr (buf, "error"))
|
||||
{
|
||||
finished = TRUE;
|
||||
gimp_progress_update (1.0);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! finished)
|
||||
{
|
||||
g_message ("wget exited before finishing downloading URL\n'%s'",
|
||||
filename);
|
||||
unlink (tmpname);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (! finished)
|
||||
{
|
||||
g_message ("wget exited before finishing downloading URL\n'%s'",
|
||||
filename);
|
||||
unlink (tmpname);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
image_ID = gimp_file_load (GIMP_RUN_INTERACTIVE, tmpname, tmpname);
|
||||
image_ID = gimp_file_load (run_mode, tmpname, tmpname);
|
||||
|
||||
unlink (tmpname);
|
||||
g_free (tmpname);
|
||||
|
|
|
@ -63,8 +63,8 @@ query (void)
|
|||
{
|
||||
static GimpParamDef load_args[] =
|
||||
{
|
||||
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
||||
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
||||
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
||||
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
||||
{ GIMP_PDB_STRING, "raw_filename", "The name entered" }
|
||||
};
|
||||
|
||||
|
@ -115,9 +115,7 @@ run (const gchar *name,
|
|||
|
||||
if (strcmp (name, "file_url_load") == 0)
|
||||
{
|
||||
image_ID = load_image (param[2].data.d_string,
|
||||
run_mode,
|
||||
&status);
|
||||
image_ID = load_image (param[2].data.d_string, run_mode, &status);
|
||||
|
||||
if (image_ID != -1 &&
|
||||
status == GIMP_PDB_SUCCESS)
|
||||
|
@ -140,18 +138,16 @@ load_image (const gchar *filename,
|
|||
GimpRunMode run_mode,
|
||||
GimpPDBStatusType *status)
|
||||
{
|
||||
gint32 image_ID;
|
||||
gchar *ext = strrchr (filename, '.');
|
||||
gchar *tmpname;
|
||||
gint pid;
|
||||
gint wpid;
|
||||
gint process_status;
|
||||
gint p[2];
|
||||
gboolean name_image = FALSE;
|
||||
gint32 image_ID;
|
||||
gchar *ext = strrchr (filename, '.');
|
||||
gchar *tmpname;
|
||||
gint pid;
|
||||
gint p[2];
|
||||
gboolean name_image = FALSE;
|
||||
|
||||
fprintf (stderr, "Loading URL: %s\n", filename);
|
||||
|
||||
if (!ext || ext[1] == 0 || strchr(ext, '/'))
|
||||
if (!ext || ext[1] == 0 || strchr (ext, '/'))
|
||||
tmpname = gimp_temp_name ("xxx");
|
||||
else
|
||||
{
|
||||
|
@ -195,220 +191,203 @@ load_image (const gchar *filename,
|
|||
}
|
||||
else
|
||||
{
|
||||
if (run_mode == GIMP_RUN_NONINTERACTIVE)
|
||||
{
|
||||
wpid = waitpid (pid, &process_status, 0);
|
||||
FILE *input;
|
||||
gchar buf[BUFSIZE];
|
||||
gboolean seen_resolve = FALSE;
|
||||
gboolean connected = FALSE;
|
||||
gboolean file_found = FALSE;
|
||||
gchar sizestr[32];
|
||||
gint size = 0;
|
||||
gchar *message;
|
||||
gint i, j;
|
||||
gchar dot;
|
||||
gint kilobytes = 0;
|
||||
gboolean finished = FALSE;
|
||||
|
||||
if ((wpid < 0)
|
||||
|| !WIFEXITED (process_status)
|
||||
|| (WEXITSTATUS (process_status) != 0))
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE *input;
|
||||
gchar buf[BUFSIZE];
|
||||
gboolean seen_resolve = FALSE;
|
||||
gboolean connected = FALSE;
|
||||
gboolean file_found = FALSE;
|
||||
gchar sizestr[32];
|
||||
gint size = 0;
|
||||
gchar *message;
|
||||
gint i, j;
|
||||
gchar dot;
|
||||
gint kilobytes = 0;
|
||||
gboolean finished = FALSE;
|
||||
|
||||
gboolean debug = FALSE;
|
||||
gboolean debug = FALSE;
|
||||
|
||||
#define DEBUG(x) if (debug) fprintf (stderr, (x))
|
||||
|
||||
close (p[1]);
|
||||
close (p[1]);
|
||||
|
||||
input = fdopen (p[0], "r");
|
||||
input = fdopen (p[0], "r");
|
||||
|
||||
/* hardcoded and not-really-foolproof scanning of wget putput */
|
||||
/* hardcoded and not-really-foolproof scanning of wget putput */
|
||||
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
/* no message here because failing on the first line means
|
||||
* that wget was not found
|
||||
*/
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
/* no message here because failing on the first line means
|
||||
* that wget was not found
|
||||
*/
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The second line is the local copy of the file */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
/* The second line is the local copy of the file */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The third line is "Connecting to..." */
|
||||
gimp_progress_init ("Connecting to server... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
/* The third line is "Connecting to..." */
|
||||
gimp_progress_init ("Connecting to server... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
|
||||
read_connect:
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "connected"))
|
||||
{
|
||||
connected = TRUE;
|
||||
}
|
||||
/* newer wgets have a "Resolving foo" line, so eat it */
|
||||
else if (!seen_resolve && strstr (buf, "Resolving"))
|
||||
{
|
||||
seen_resolve = TRUE;
|
||||
goto read_connect;
|
||||
}
|
||||
read_connect:
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "connected"))
|
||||
{
|
||||
connected = TRUE;
|
||||
}
|
||||
/* newer wgets have a "Resolving foo" line, so eat it */
|
||||
else if (!seen_resolve && strstr (buf, "Resolving"))
|
||||
{
|
||||
seen_resolve = TRUE;
|
||||
goto read_connect;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The fourth line is either the network request or an error */
|
||||
gimp_progress_init ("Opening URL... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
/* The fourth line is either the network request or an error */
|
||||
gimp_progress_init ("Opening URL... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (! connected)
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (! connected)
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The fifth line is either the length of the file or an error */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "Length"))
|
||||
{
|
||||
file_found = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
/* The fifth line is either the length of the file or an error */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "Length"))
|
||||
{
|
||||
file_found = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
if (sscanf (buf, "Length: %31s", sizestr) != 1)
|
||||
{
|
||||
g_message ("Could not parse wget's file length message");
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
if (sscanf (buf, "Length: %31s", sizestr) != 1)
|
||||
{
|
||||
g_message ("Could not parse wget's file length message");
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* strip away commas */
|
||||
for (i = 0, j = 0; i < sizeof (sizestr); i++, j++)
|
||||
{
|
||||
if (sizestr[i] == ',')
|
||||
i++;
|
||||
/* strip away commas */
|
||||
for (i = 0, j = 0; i < sizeof (sizestr); i++, j++)
|
||||
{
|
||||
if (sizestr[i] == ',')
|
||||
i++;
|
||||
|
||||
sizestr[j] = sizestr[i];
|
||||
sizestr[j] = sizestr[i];
|
||||
|
||||
if (sizestr[j] == '\0')
|
||||
break;
|
||||
}
|
||||
if (sizestr[j] == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
size = atoi (sizestr);
|
||||
size = atoi (sizestr);
|
||||
|
||||
/* Start the actual download... */
|
||||
message = g_strdup_printf ("Downloading %d bytes of image data... "
|
||||
"(timeout is "TIMEOUT" seconds)", size);
|
||||
gimp_progress_init (message);
|
||||
g_free (message);
|
||||
/* Start the actual download... */
|
||||
message = g_strdup_printf ("Downloading %d bytes of image data... "
|
||||
"(timeout is "TIMEOUT" seconds)", size);
|
||||
gimp_progress_init (message);
|
||||
g_free (message);
|
||||
|
||||
/* Switch to byte parsing wget's output... */
|
||||
/* Switch to byte parsing wget's output... */
|
||||
|
||||
while (1)
|
||||
{
|
||||
dot = fgetc (input);
|
||||
while (1)
|
||||
{
|
||||
dot = fgetc (input);
|
||||
|
||||
if (feof (input))
|
||||
break;
|
||||
if (feof (input))
|
||||
break;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fputc (dot, stderr);
|
||||
fflush (stderr);
|
||||
}
|
||||
if (debug)
|
||||
{
|
||||
fputc (dot, stderr);
|
||||
fflush (stderr);
|
||||
}
|
||||
|
||||
if (dot == '.') /* one kilobyte */
|
||||
{
|
||||
kilobytes++;
|
||||
gimp_progress_update ((gdouble) (kilobytes * 1024) /
|
||||
(gdouble) size);
|
||||
}
|
||||
else if (dot == ':') /* the time string contains a ':' */
|
||||
{
|
||||
fgets (buf, BUFSIZE, input);
|
||||
if (dot == '.') /* one kilobyte */
|
||||
{
|
||||
kilobytes++;
|
||||
gimp_progress_update ((gdouble) (kilobytes * 1024) /
|
||||
(gdouble) size);
|
||||
}
|
||||
else if (dot == ':') /* the time string contains a ':' */
|
||||
{
|
||||
fgets (buf, BUFSIZE, input);
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
if (! strstr (buf, "error"))
|
||||
{
|
||||
finished = TRUE;
|
||||
gimp_progress_update (1.0);
|
||||
}
|
||||
if (! strstr (buf, "error"))
|
||||
{
|
||||
finished = TRUE;
|
||||
gimp_progress_update (1.0);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! finished)
|
||||
{
|
||||
g_message ("wget exited before finishing downloading URL\n'%s'",
|
||||
filename);
|
||||
unlink (tmpname);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (! finished)
|
||||
{
|
||||
g_message ("wget exited before finishing downloading URL\n'%s'",
|
||||
filename);
|
||||
unlink (tmpname);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
image_ID = gimp_file_load (GIMP_RUN_INTERACTIVE, tmpname, tmpname);
|
||||
image_ID = gimp_file_load (run_mode, tmpname, tmpname);
|
||||
|
||||
unlink (tmpname);
|
||||
g_free (tmpname);
|
||||
|
|
|
@ -63,8 +63,8 @@ query (void)
|
|||
{
|
||||
static GimpParamDef load_args[] =
|
||||
{
|
||||
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
||||
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
||||
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
||||
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
||||
{ GIMP_PDB_STRING, "raw_filename", "The name entered" }
|
||||
};
|
||||
|
||||
|
@ -115,9 +115,7 @@ run (const gchar *name,
|
|||
|
||||
if (strcmp (name, "file_url_load") == 0)
|
||||
{
|
||||
image_ID = load_image (param[2].data.d_string,
|
||||
run_mode,
|
||||
&status);
|
||||
image_ID = load_image (param[2].data.d_string, run_mode, &status);
|
||||
|
||||
if (image_ID != -1 &&
|
||||
status == GIMP_PDB_SUCCESS)
|
||||
|
@ -140,18 +138,16 @@ load_image (const gchar *filename,
|
|||
GimpRunMode run_mode,
|
||||
GimpPDBStatusType *status)
|
||||
{
|
||||
gint32 image_ID;
|
||||
gchar *ext = strrchr (filename, '.');
|
||||
gchar *tmpname;
|
||||
gint pid;
|
||||
gint wpid;
|
||||
gint process_status;
|
||||
gint p[2];
|
||||
gboolean name_image = FALSE;
|
||||
gint32 image_ID;
|
||||
gchar *ext = strrchr (filename, '.');
|
||||
gchar *tmpname;
|
||||
gint pid;
|
||||
gint p[2];
|
||||
gboolean name_image = FALSE;
|
||||
|
||||
fprintf (stderr, "Loading URL: %s\n", filename);
|
||||
|
||||
if (!ext || ext[1] == 0 || strchr(ext, '/'))
|
||||
if (!ext || ext[1] == 0 || strchr (ext, '/'))
|
||||
tmpname = gimp_temp_name ("xxx");
|
||||
else
|
||||
{
|
||||
|
@ -195,220 +191,203 @@ load_image (const gchar *filename,
|
|||
}
|
||||
else
|
||||
{
|
||||
if (run_mode == GIMP_RUN_NONINTERACTIVE)
|
||||
{
|
||||
wpid = waitpid (pid, &process_status, 0);
|
||||
FILE *input;
|
||||
gchar buf[BUFSIZE];
|
||||
gboolean seen_resolve = FALSE;
|
||||
gboolean connected = FALSE;
|
||||
gboolean file_found = FALSE;
|
||||
gchar sizestr[32];
|
||||
gint size = 0;
|
||||
gchar *message;
|
||||
gint i, j;
|
||||
gchar dot;
|
||||
gint kilobytes = 0;
|
||||
gboolean finished = FALSE;
|
||||
|
||||
if ((wpid < 0)
|
||||
|| !WIFEXITED (process_status)
|
||||
|| (WEXITSTATUS (process_status) != 0))
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE *input;
|
||||
gchar buf[BUFSIZE];
|
||||
gboolean seen_resolve = FALSE;
|
||||
gboolean connected = FALSE;
|
||||
gboolean file_found = FALSE;
|
||||
gchar sizestr[32];
|
||||
gint size = 0;
|
||||
gchar *message;
|
||||
gint i, j;
|
||||
gchar dot;
|
||||
gint kilobytes = 0;
|
||||
gboolean finished = FALSE;
|
||||
|
||||
gboolean debug = FALSE;
|
||||
gboolean debug = FALSE;
|
||||
|
||||
#define DEBUG(x) if (debug) fprintf (stderr, (x))
|
||||
|
||||
close (p[1]);
|
||||
close (p[1]);
|
||||
|
||||
input = fdopen (p[0], "r");
|
||||
input = fdopen (p[0], "r");
|
||||
|
||||
/* hardcoded and not-really-foolproof scanning of wget putput */
|
||||
/* hardcoded and not-really-foolproof scanning of wget putput */
|
||||
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
/* no message here because failing on the first line means
|
||||
* that wget was not found
|
||||
*/
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
/* no message here because failing on the first line means
|
||||
* that wget was not found
|
||||
*/
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The second line is the local copy of the file */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
/* The second line is the local copy of the file */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The third line is "Connecting to..." */
|
||||
gimp_progress_init ("Connecting to server... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
/* The third line is "Connecting to..." */
|
||||
gimp_progress_init ("Connecting to server... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
|
||||
read_connect:
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "connected"))
|
||||
{
|
||||
connected = TRUE;
|
||||
}
|
||||
/* newer wgets have a "Resolving foo" line, so eat it */
|
||||
else if (!seen_resolve && strstr (buf, "Resolving"))
|
||||
{
|
||||
seen_resolve = TRUE;
|
||||
goto read_connect;
|
||||
}
|
||||
read_connect:
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "connected"))
|
||||
{
|
||||
connected = TRUE;
|
||||
}
|
||||
/* newer wgets have a "Resolving foo" line, so eat it */
|
||||
else if (!seen_resolve && strstr (buf, "Resolving"))
|
||||
{
|
||||
seen_resolve = TRUE;
|
||||
goto read_connect;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The fourth line is either the network request or an error */
|
||||
gimp_progress_init ("Opening URL... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
/* The fourth line is either the network request or an error */
|
||||
gimp_progress_init ("Opening URL... "
|
||||
"(timeout is "TIMEOUT" seconds)");
|
||||
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (! connected)
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (! connected)
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
/* The fifth line is either the length of the file or an error */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "Length"))
|
||||
{
|
||||
file_found = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
/* The fifth line is either the length of the file or an error */
|
||||
if (fgets (buf, BUFSIZE, input) == NULL)
|
||||
{
|
||||
g_message ("wget exited abnormally on URL '%s'", filename);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
else if (strstr (buf, "Length"))
|
||||
{
|
||||
file_found = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_message ("A network error occured: %s", buf);
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
if (sscanf (buf, "Length: %31s", sizestr) != 1)
|
||||
{
|
||||
g_message ("Could not parse wget's file length message");
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
if (sscanf (buf, "Length: %31s", sizestr) != 1)
|
||||
{
|
||||
g_message ("Could not parse wget's file length message");
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* strip away commas */
|
||||
for (i = 0, j = 0; i < sizeof (sizestr); i++, j++)
|
||||
{
|
||||
if (sizestr[i] == ',')
|
||||
i++;
|
||||
/* strip away commas */
|
||||
for (i = 0, j = 0; i < sizeof (sizestr); i++, j++)
|
||||
{
|
||||
if (sizestr[i] == ',')
|
||||
i++;
|
||||
|
||||
sizestr[j] = sizestr[i];
|
||||
sizestr[j] = sizestr[i];
|
||||
|
||||
if (sizestr[j] == '\0')
|
||||
break;
|
||||
}
|
||||
if (sizestr[j] == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
size = atoi (sizestr);
|
||||
size = atoi (sizestr);
|
||||
|
||||
/* Start the actual download... */
|
||||
message = g_strdup_printf ("Downloading %d bytes of image data... "
|
||||
"(timeout is "TIMEOUT" seconds)", size);
|
||||
gimp_progress_init (message);
|
||||
g_free (message);
|
||||
/* Start the actual download... */
|
||||
message = g_strdup_printf ("Downloading %d bytes of image data... "
|
||||
"(timeout is "TIMEOUT" seconds)", size);
|
||||
gimp_progress_init (message);
|
||||
g_free (message);
|
||||
|
||||
/* Switch to byte parsing wget's output... */
|
||||
/* Switch to byte parsing wget's output... */
|
||||
|
||||
while (1)
|
||||
{
|
||||
dot = fgetc (input);
|
||||
while (1)
|
||||
{
|
||||
dot = fgetc (input);
|
||||
|
||||
if (feof (input))
|
||||
break;
|
||||
if (feof (input))
|
||||
break;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fputc (dot, stderr);
|
||||
fflush (stderr);
|
||||
}
|
||||
if (debug)
|
||||
{
|
||||
fputc (dot, stderr);
|
||||
fflush (stderr);
|
||||
}
|
||||
|
||||
if (dot == '.') /* one kilobyte */
|
||||
{
|
||||
kilobytes++;
|
||||
gimp_progress_update ((gdouble) (kilobytes * 1024) /
|
||||
(gdouble) size);
|
||||
}
|
||||
else if (dot == ':') /* the time string contains a ':' */
|
||||
{
|
||||
fgets (buf, BUFSIZE, input);
|
||||
if (dot == '.') /* one kilobyte */
|
||||
{
|
||||
kilobytes++;
|
||||
gimp_progress_update ((gdouble) (kilobytes * 1024) /
|
||||
(gdouble) size);
|
||||
}
|
||||
else if (dot == ':') /* the time string contains a ':' */
|
||||
{
|
||||
fgets (buf, BUFSIZE, input);
|
||||
|
||||
DEBUG (buf);
|
||||
DEBUG (buf);
|
||||
|
||||
if (! strstr (buf, "error"))
|
||||
{
|
||||
finished = TRUE;
|
||||
gimp_progress_update (1.0);
|
||||
}
|
||||
if (! strstr (buf, "error"))
|
||||
{
|
||||
finished = TRUE;
|
||||
gimp_progress_update (1.0);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! finished)
|
||||
{
|
||||
g_message ("wget exited before finishing downloading URL\n'%s'",
|
||||
filename);
|
||||
unlink (tmpname);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (! finished)
|
||||
{
|
||||
g_message ("wget exited before finishing downloading URL\n'%s'",
|
||||
filename);
|
||||
unlink (tmpname);
|
||||
g_free (tmpname);
|
||||
*status = GIMP_PDB_EXECUTION_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
image_ID = gimp_file_load (GIMP_RUN_INTERACTIVE, tmpname, tmpname);
|
||||
image_ID = gimp_file_load (run_mode, tmpname, tmpname);
|
||||
|
||||
unlink (tmpname);
|
||||
g_free (tmpname);
|
||||
|
|
Loading…
Reference in New Issue