- Timestamp:
- Dec 24, 2004, 5:38:38 PM (20 years ago)
- Location:
- orxonox/branches/updater/src/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/updater/src/gui/orxonox_gui_update.cc
r3268 r3270 30 30 #include "orxonox_gui.h" 31 31 #include <stdio.h> 32 #ifdef HAVE_CURL 33 #include <curl/curl.h> 34 #include <curl/types.h> 35 #include <curl/easy.h> 36 #endif /* HAVE_CURL */ 32 37 33 using namespace std; 38 34 … … 94 90 #ifdef HAVE_GTK2 95 91 updateDataWindowButton->connectSignal("button_press_event", updateDataWindow, Window::windowOpen); 96 updateDataWindow->connectSignal("destroy", updateDataWindow, Window::windowClose);97 updateDataWindow->connectSignal("delete_event", updateDataWindow, Window::windowClose);92 updateDataWindow->connectSignal("destroy", updateDataWindow, cancelDownload); 93 updateDataWindow->connectSignal("delete_event", updateDataWindow, cancelDownload); 98 94 #endif /* HAVE_GTK2 */ 99 95 … … 194 190 } 195 191 192 CURL* OrxonoxGuiUpdate::curlHandle = NULL; 196 193 197 194 void* OrxonoxGuiUpdate::download (void* fileInfo) … … 200 197 PRINTF(3)("Downloading.\n"); 201 198 FileInfo* info = (FileInfo*)fileInfo; 202 CURL* curl;203 199 CURLcode res; 204 200 FILE* outfile; 205 curl = curl_easy_init();201 curlHandle = curl_easy_init(); 206 202 char* fileOnNet = new char [strlen(info->webRoot)+strlen(info->fileName)+1]; 207 203 strcpy (fileOnNet, info->webRoot); … … 211 207 strcat (fileOnDisk, info->fileName); 212 208 213 if(curl )209 if(curlHandle) 214 210 { 215 211 outfile = fopen(fileOnDisk, "w"); 216 212 217 curl_easy_setopt(curl , CURLOPT_URL, fileOnNet);218 curl_easy_setopt(curl , CURLOPT_WRITEDATA, outfile);219 curl_easy_setopt(curl , CURLOPT_WRITEFUNCTION, curlWriteFunc);220 curl_easy_setopt(curl , CURLOPT_READFUNCTION, curlReadFunc);221 curl_easy_setopt(curl , CURLOPT_NOPROGRESS, FALSE);222 curl_easy_setopt(curl , CURLOPT_PROGRESSFUNCTION, curlProgressFunc);223 curl_easy_setopt(curl , CURLOPT_PROGRESSDATA, info->Bar);213 curl_easy_setopt(curlHandle, CURLOPT_URL, fileOnNet); 214 curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, outfile); 215 curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, curlWriteFunc); 216 curl_easy_setopt(curlHandle, CURLOPT_READFUNCTION, curlReadFunc); 217 curl_easy_setopt(curlHandle, CURLOPT_NOPROGRESS, FALSE); 218 curl_easy_setopt(curlHandle, CURLOPT_PROGRESSFUNCTION, curlProgressFunc); 219 curl_easy_setopt(curlHandle, CURLOPT_PROGRESSDATA, info->Bar); 224 220 225 res = curl_easy_perform(curl );221 res = curl_easy_perform(curlHandle); 226 222 227 223 fclose(outfile); 228 curl_easy_cleanup(curl); 224 if (curlHandle) 225 curl_easy_cleanup(curlHandle); 229 226 } 230 227 return NULL; … … 234 231 gint OrxonoxGuiUpdate::cancelDownload(GtkWidget* w, GdkEventKey* event, void* bar) 235 232 { 233 // curl_easy_cleanup(curlHandle); 234 // curlHandle = NULL; 236 235 } 237 236 #endif /* HAVE_GTK2 */ 238 237 239 238 #endif /* HAVE_CURL */ 240 241 242 /*243 int main(int argc, char **argv)244 {245 GtkWidget *Window, *Frame, *Frame2;246 GtkAdjustment *adj;247 248 // Init thread249 g_thread_init(NULL);250 gtk_init(&argc, &argv);251 Window = gtk_window_new(GTK_WINDOW_TOPLEVEL);252 Frame = gtk_frame_new(NULL);253 gtk_frame_set_shadow_type(GTK_FRAME(Frame), GTK_SHADOW_OUT);254 gtk_container_add(GTK_CONTAINER(Window), Frame);255 Frame2 = gtk_frame_new(NULL);256 gtk_frame_set_shadow_type(GTK_FRAME(Frame2), GTK_SHADOW_IN);257 gtk_container_add(GTK_CONTAINER(Frame), Frame2);258 gtk_container_set_border_width(GTK_CONTAINER(Frame2), 5);259 adj = (GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0);260 Bar = gtk_progress_bar_new_with_adjustment(adj);261 gtk_container_add(GTK_CONTAINER(Frame2), Bar);262 gtk_widget_show_all(Window);263 264 if (!g_thread_create(&my_thread, argv[1], FALSE, NULL) != 0)265 g_warning("can't create the thread");266 267 268 gdk_threads_enter();269 gtk_main();270 gdk_threads_leave();271 return 0;272 }273 274 275 276 277 278 size_t writeFunc(void *ptr, size_t size, size_t nmemb, FILE *stream)279 {280 return fwrite(ptr, size, nmemb, stream);281 }282 283 size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream)284 {285 return fread(ptr, size, nmemb, stream);286 }287 288 int my_progress_func(GtkWidget *Bar,289 double t, // dltotal290 double d, // dlnow291 double ultotal,292 double ulnow)293 {294 gdk_threads_enter();295 gtk_progress_set_value(GTK_PROGRESS(Bar), d*100.0/t);296 gdk_threads_leave();297 return 0;298 }299 300 void *my_thread(void *ptr)301 {302 CURL *curl;303 CURLcode res;304 FILE *outfile;305 gchar *url = ptr;306 307 curl = curl_easy_init();308 if(curl)309 {310 outfile = fopen("test.curl", "w");311 312 curl_easy_setopt(curl, CURLOPT_URL, url);313 curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);314 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);315 curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func);316 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);317 curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);318 curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, Bar);319 320 res = curl_easy_perform(curl);321 322 fclose(outfile);323 curl_easy_cleanup(curl);324 }325 326 return NULL;327 }328 329 */330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 -
orxonox/branches/updater/src/gui/orxonox_gui_update.h
r3268 r3270 9 9 #include "orxonox_gui.h" 10 10 #include <stdio.h> 11 #ifdef HAVE_CURL 12 #include <curl/curl.h> 13 #include <curl/types.h> 14 #include <curl/easy.h> 15 #endif /* HAVE_CURL */ 11 16 using namespace std; 12 17 … … 53 58 static int curlProgressFunc (ProgressBar* Bar, double totalSize, double progress, double upTotal, double upProgress); 54 59 60 static CURL* curlHandle; 55 61 static void* download (void* fileInfo); 56 62 #ifdef HAVE_GTK2
Note: See TracChangeset
for help on using the changeset viewer.