diff options
author | Michael Fulbright <drmike@src.gnome.org> | 1999-11-09 23:51:35 +0000 |
---|---|---|
committer | Michael Fulbright <drmike@src.gnome.org> | 1999-11-09 23:51:35 +0000 |
commit | 78141c328fc16852f88d22e0ce3fb98ea5114a5d (patch) | |
tree | b9fce611e3c65d837de7dbcff8793bdde814c18f /demos/testpixbuf.c | |
parent | 39bb0d649caa4ef7329781cf4c4f2281a10f667a (diff) | |
download | gdk-pixbuf-78141c328fc16852f88d22e0ce3fb98ea5114a5d.tar.gz |
Fixed up testpixbuf.c to simulate downloading at certain speed, set
env var TBF_KBPS=n to get n kBytes/sec.
Dr Mike
Diffstat (limited to 'demos/testpixbuf.c')
-rw-r--r-- | demos/testpixbuf.c | 99 |
1 files changed, 62 insertions, 37 deletions
diff --git a/demos/testpixbuf.c b/demos/testpixbuf.c index 3035e2c97..c844f3f83 100644 --- a/demos/testpixbuf.c +++ b/demos/testpixbuf.c @@ -27,6 +27,16 @@ #include "gdk-pixbuf-io.h" #include "gdk-pixbuf-loader.h" +typedef struct { + FILE *imagefile; + GdkPixbufLoader *loader; + guchar *buf; + guint timeout; + guint readlen; + +} ProgressFileStatus; + + #define DEFAULT_WIDTH 24 #define DEFAULT_HEIGHT 24 @@ -417,18 +427,35 @@ new_testrgb_window (GdkPixbuf *pixbuf, gchar *title) return window; } + static gint update_timeout(gpointer data) { - GtkWidget** window_loc = data; + ProgressFileStatus *status = data; + gboolean done; + + done = TRUE; + if (!feof(status->imagefile)) { + gint nbytes; - if (*window_loc != NULL) { - gtk_widget_queue_draw(*window_loc); - } + nbytes = fread(status->buf, 1, status->readlen, + status->imagefile); - return TRUE; + done = !gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (status->loader), status->buf, nbytes); + + } + + if (done) { + gdk_pixbuf_loader_close (GDK_PIXBUF_LOADER (status->loader)); + gtk_object_destroy (GTK_OBJECT(status->loader)); + fclose (status->imagefile); + g_free (status->buf); + } + + return !done; } + static void progressive_prepared_callback(GdkPixbufLoader* loader, gpointer data) { @@ -449,7 +476,14 @@ progressive_prepared_callback(GdkPixbufLoader* loader, gpointer data) static void progressive_updated_callback(GdkPixbufLoader* loader, guint x, guint y, guint width, guint height, gpointer data) { - g_print ("progressive_updated_callback:\n\t%d\t%d\t%d\t%d\n", x, y, width, height); + GtkWidget** window_loc = data; + +/* g_print ("progressive_updated_callback:\n\t%d\t%d\t%d\t%d\n", x, y, width, height); */ + + if (*window_loc != NULL) + gtk_widget_queue_draw_area(*window_loc, + x, y, width, height); + return; } @@ -479,6 +513,16 @@ main (int argc, char **argv) if(tbf_readlen) readlen = atoi(tbf_readlen); } + { + char *tbf_bps = getenv("TBF_KBPS"); + guint bps; + + if (tbf_bps) { + bps = atoi(tbf_bps); + readlen = (bps*1024)/10; + } + } + i = 1; if (argc == 1) { const gchar*** xpmp; @@ -509,14 +553,15 @@ main (int argc, char **argv) found_valid = TRUE; } } - +#if 1 { GtkWidget* rgb_window = NULL; - guint timeout; - char *buf; + ProgressFileStatus status; pixbuf_loader = gdk_pixbuf_loader_new (); + status.loader = pixbuf_loader; + status.buf = g_malloc (readlen); gtk_signal_connect(GTK_OBJECT(pixbuf_loader), "area_prepared", GTK_SIGNAL_FUNC(progressive_prepared_callback), @@ -527,35 +572,15 @@ main (int argc, char **argv) GTK_SIGNAL_FUNC(progressive_updated_callback), &rgb_window); - timeout = gtk_timeout_add(1000, update_timeout, &rgb_window); - - file = fopen (argv[1], "r"); - g_assert (file != NULL); - buf = g_malloc(readlen); - - while (!feof(file)) { - int nbytes; - nbytes = fread(buf, 1, readlen, file); - - //printf("."); - fflush(stdout); - - if (gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (pixbuf_loader), buf, nbytes) == FALSE) - break; - - while (gtk_events_pending()) - gtk_main_iteration(); - } - printf("\n"); - gtk_timeout_remove (timeout); - gdk_pixbuf_loader_close (GDK_PIXBUF_LOADER (pixbuf_loader)); - gtk_object_destroy (GTK_OBJECT(pixbuf_loader)); - fclose (file); - - if (rgb_window != NULL) - gtk_widget_queue_draw(rgb_window); + + status.imagefile = fopen (argv[1], "r"); + g_assert (status.imagefile != NULL); + + status.readlen = readlen; + + status.timeout = gtk_timeout_add(100, update_timeout, &status); } - +#endif } if (found_valid) |