1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: curlgtk.c,v 1.1 2005-06-24 13:02:16 andy Exp $
10 /* Copyright (c) 2000 David Odin (aka DindinX) for MandrakeSoft */
11 /* an attempt to use the curl library in concert with a gtk-threaded application */
16 #include <curl/curl.h>
17 #include <curl/types.h> /* new for v7 */
18 #include <curl/easy.h> /* new for v7 */
24 size_t my_read_func(void *ptr
, size_t size
, size_t nmemb
, FILE *stream
)
26 return fread(ptr
, size
, nmemb
, stream
);
29 int my_progress_func(GtkWidget
*Bar
, int t
, int d
)
31 /* printf("%d / %d (%g %%)\n", d, t, d*100.0/t);*/
33 gtk_progress_set_value(GTK_PROGRESS(Bar
), d
*100.0/t
);
38 void *curl_thread(void *ptr
)
45 curl
= curl_easy_init();
48 outfile
= fopen("/tmp/test.curl", "w");
50 curl_easy_setopt(curl
, CURLOPT_URL
, url
);
51 curl_easy_setopt(curl
, CURLOPT_FILE
, outfile
);
52 curl_easy_setopt(curl
, CURLOPT_READFUNCTION
, my_read_func
);
53 curl_easy_setopt(curl
, CURLOPT_PROGRESSFUNCTION
, my_progress_func
);
54 curl_easy_setopt(curl
, CURLOPT_PROGRESSDATA
, Bar
);
56 res
= curl_easy_perform(curl
);
60 curl_easy_cleanup(curl
);
65 int main(int argc
, char **argv
)
67 GtkWidget
*Window
, *Frame
, *Frame2
;
74 gtk_init(&argc
, &argv
);
75 Window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
76 Frame
= gtk_frame_new(NULL
);
77 gtk_frame_set_shadow_type(GTK_FRAME(Frame
), GTK_SHADOW_OUT
);
78 gtk_container_add(GTK_CONTAINER(Window
), Frame
);
79 Frame2
= gtk_frame_new(NULL
);
80 gtk_frame_set_shadow_type(GTK_FRAME(Frame2
), GTK_SHADOW_IN
);
81 gtk_container_add(GTK_CONTAINER(Frame
), Frame2
);
82 gtk_container_set_border_width(GTK_CONTAINER(Frame2
), 5);
83 adj
= (GtkAdjustment
*)gtk_adjustment_new(0, 0, 100, 0, 0, 0);
84 Bar
= gtk_progress_bar_new_with_adjustment(adj
);
85 gtk_container_add(GTK_CONTAINER(Frame2
), Bar
);
86 gtk_widget_show_all(Window
);
88 pthread_create(&curl_tid
, NULL
, curl_thread
, argv
[1]);