Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TLMSP curl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CYBER - Cyber Security
TS 103 523 MSP
TLMSP
TLMSP curl
Commits
e7736324
Commit
e7736324
authored
24 years ago
by
Daniel Stenberg
Browse files
Options
Downloads
Patches
Plain Diff
David Odin (aka DindinX) for MandrakeSoft, tiny example with GTK
parent
e0e01e5a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/examples/curlgtk.c
+87
-0
87 additions, 0 deletions
docs/examples/curlgtk.c
with
87 additions
and
0 deletions
docs/examples/curlgtk.c
0 → 100644
+
87
−
0
View file @
e7736324
/* curlgtk.c */
/* Copyright (c) 2000 David Odin (aka DindinX) for MandrakeSoft */
/* an attempt to use the curl library in concert with a gtk-threaded application */
#include
<stdio.h>
#include
<gtk/gtk.h>
#include
<curl/curl.h>
#include
<curl/types.h>
/* new for v7 */
#include
<curl/easy.h>
/* new for v7 */
#include
<pthread.h>
GtkWidget
*
Bar
;
size_t
my_read_func
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
FILE
*
stream
)
{
return
fread
(
ptr
,
size
,
nmemb
,
stream
);
}
int
my_progress_func
(
GtkWidget
*
Bar
,
int
t
,
int
d
)
{
/* printf("%d / %d (%g %%)\n", d, t, d*100.0/t);*/
gdk_threads_enter
();
gtk_progress_set_value
(
GTK_PROGRESS
(
Bar
),
d
*
100
.
0
/
t
);
gdk_threads_leave
();
return
0
;
}
void
*
curl_thread
(
void
*
ptr
)
{
CURL
*
curl
;
CURLcode
res
;
FILE
*
outfile
;
gchar
*
url
=
ptr
;
curl
=
curl_easy_init
();
if
(
curl
)
{
outfile
=
fopen
(
"/tmp/test.curl"
,
"w"
);
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
url
);
curl_easy_setopt
(
curl
,
CURLOPT_FILE
,
outfile
);
curl_easy_setopt
(
curl
,
CURLOPT_READFUNCTION
,
my_read_func
);
curl_easy_setopt
(
curl
,
CURLOPT_PROGRESSFUNCTION
,
my_progress_func
);
curl_easy_setopt
(
curl
,
CURLOPT_PROGRESSDATA
,
Bar
);
res
=
curl_easy_perform
(
curl
);
fclose
(
outfile
);
/* always cleanup */
curl_easy_cleanup
(
curl
);
}
return
NULL
;
}
int
main
(
int
argc
,
char
**
argv
)
{
GtkWidget
*
Window
,
*
Frame
,
*
Frame2
;
GtkAdjustment
*
adj
;
pthread_t
curl_tid
;
/* Init thread */
g_thread_init
(
NULL
);
gtk_init
(
&
argc
,
&
argv
);
Window
=
gtk_window_new
(
GTK_WINDOW_TOPLEVEL
);
Frame
=
gtk_frame_new
(
NULL
);
gtk_frame_set_shadow_type
(
GTK_FRAME
(
Frame
),
GTK_SHADOW_OUT
);
gtk_container_add
(
GTK_CONTAINER
(
Window
),
Frame
);
Frame2
=
gtk_frame_new
(
NULL
);
gtk_frame_set_shadow_type
(
GTK_FRAME
(
Frame2
),
GTK_SHADOW_IN
);
gtk_container_add
(
GTK_CONTAINER
(
Frame
),
Frame2
);
gtk_container_set_border_width
(
GTK_CONTAINER
(
Frame2
),
5
);
adj
=
(
GtkAdjustment
*
)
gtk_adjustment_new
(
0
,
0
,
100
,
0
,
0
,
0
);
Bar
=
gtk_progress_bar_new_with_adjustment
(
adj
);
gtk_container_add
(
GTK_CONTAINER
(
Frame2
),
Bar
);
gtk_widget_show_all
(
Window
);
pthread_create
(
&
curl_tid
,
NULL
,
curl_thread
,
argv
[
1
]);
gdk_threads_enter
();
gtk_main
();
gdk_threads_leave
();
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment