~ubuntu-branches/ubuntu/warty/curl/warty

« back to all changes in this revision

Viewing changes to docs/examples/curlgtk.c

  • Committer: Bazaar Package Importer
  • Author(s): Domenico Andreoli
  • Date: 2004-06-04 19:09:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040604190925-wy048bp31320r2z6
Tags: 7.12.0.is.7.11.2-1
* Reverted to version 7.11.2 (closes: #252348).
* Disabled support for libidn (closes: #252367). This is to leave
  curl in unstable as much similar as possible to the one in testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
 
 *                                  _   _ ____  _     
3
 
 *  Project                     ___| | | |  _ \| |    
4
 
 *                             / __| | | | |_) | |    
5
 
 *                            | (__| |_| |  _ <| |___ 
 
2
 *                                  _   _ ____  _
 
3
 *  Project                     ___| | | |  _ \| |
 
4
 *                             / __| | | | |_) | |
 
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * $Id: curlgtk.c,v 1.2 2001/02/20 13:56:39 bagder Exp $
 
8
 * $Id: curlgtk.c,v 1.4 2004/02/09 07:12:33 bagder Exp $
9
9
 */
10
10
/* Copyright (c) 2000 David Odin (aka DindinX) for MandrakeSoft */
11
11
/* an attempt to use the curl library in concert with a gtk-threaded application */
17
17
#include <curl/types.h> /* new for v7 */
18
18
#include <curl/easy.h> /* new for v7 */
19
19
 
20
 
#include <pthread.h>
21
 
 
22
20
GtkWidget *Bar;
23
21
 
 
22
size_t my_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
 
23
{
 
24
  return fwrite(ptr, size, nmemb, stream);
 
25
}
 
26
 
24
27
size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
25
28
{
26
29
  return fread(ptr, size, nmemb, stream);
27
30
}
28
31
 
29
 
int my_progress_func(GtkWidget *Bar, int t, int d)
 
32
int my_progress_func(GtkWidget *Bar,
 
33
                     double t, /* dltotal */
 
34
                     double d, /* dlnow */
 
35
                     double ultotal,
 
36
                     double ulnow)
30
37
{
31
38
/*  printf("%d / %d (%g %%)\n", d, t, d*100.0/t);*/
32
39
  gdk_threads_enter();
41
48
  CURLcode res;
42
49
  FILE *outfile;
43
50
  gchar *url = ptr;
44
 
  
 
51
 
45
52
  curl = curl_easy_init();
46
53
  if(curl)
47
54
  {
48
 
    outfile = fopen("/tmp/test.curl", "w");
 
55
    outfile = fopen("test.curl", "w");
49
56
 
50
57
    curl_easy_setopt(curl, CURLOPT_URL, url);
51
 
    curl_easy_setopt(curl, CURLOPT_FILE, outfile);
 
58
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
 
59
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);
52
60
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func);
 
61
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
53
62
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);
54
63
    curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, Bar);
55
 
    
 
64
 
56
65
    res = curl_easy_perform(curl);
57
66
 
58
67
    fclose(outfile);
59
68
    /* always cleanup */
60
69
    curl_easy_cleanup(curl);
61
70
  }
 
71
 
62
72
  return NULL;
63
73
}
64
74
 
66
76
{
67
77
  GtkWidget *Window, *Frame, *Frame2;
68
78
  GtkAdjustment *adj;
69
 
  pthread_t curl_tid;
70
79
 
71
80
  /* Init thread */
72
81
  g_thread_init(NULL);
73
 
  
 
82
 
74
83
  gtk_init(&argc, &argv);
75
84
  Window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
76
85
  Frame = gtk_frame_new(NULL);
85
94
  gtk_container_add(GTK_CONTAINER(Frame2), Bar);
86
95
  gtk_widget_show_all(Window);
87
96
 
88
 
  pthread_create(&curl_tid, NULL, curl_thread, argv[1]);
89
 
    
 
97
  if (!g_thread_create(&curl_thread, argv[1], FALSE, NULL) != 0)
 
98
    g_warning("can't create the thread");
 
99
 
 
100
 
90
101
  gdk_threads_enter();
91
102
  gtk_main();
92
103
  gdk_threads_leave();