Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3270 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
Dec 24, 2004, 5:38:38 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/updater: minor changes

Location:
orxonox/branches/updater/src/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/updater/src/gui/orxonox_gui_update.cc

    r3268 r3270  
    3030#include "orxonox_gui.h"
    3131#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
    3733using namespace std;
    3834
     
    9490#ifdef HAVE_GTK2
    9591  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);
    9894#endif /* HAVE_GTK2 */
    9995
     
    194190}
    195191
     192CURL* OrxonoxGuiUpdate::curlHandle = NULL;
    196193
    197194void* OrxonoxGuiUpdate::download (void* fileInfo)
     
    200197  PRINTF(3)("Downloading.\n");
    201198  FileInfo* info = (FileInfo*)fileInfo;
    202   CURL* curl;
    203199  CURLcode res;
    204200  FILE* outfile;
    205   curl = curl_easy_init();
     201  curlHandle = curl_easy_init();
    206202  char* fileOnNet = new char [strlen(info->webRoot)+strlen(info->fileName)+1];
    207203  strcpy (fileOnNet, info->webRoot);
     
    211207  strcat (fileOnDisk, info->fileName);
    212208
    213   if(curl)
     209  if(curlHandle)
    214210    {
    215211      outfile = fopen(fileOnDisk, "w");
    216212     
    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);
    224220     
    225       res = curl_easy_perform(curl);
     221      res = curl_easy_perform(curlHandle);
    226222     
    227223      fclose(outfile);
    228       curl_easy_cleanup(curl);
     224      if (curlHandle)
     225        curl_easy_cleanup(curlHandle);
    229226    }
    230227  return NULL;
     
    234231gint OrxonoxGuiUpdate::cancelDownload(GtkWidget* w, GdkEventKey* event, void* bar)
    235232{
     233  //  curl_easy_cleanup(curlHandle);
     234  //  curlHandle = NULL;
    236235}
    237236#endif /* HAVE_GTK2 */
    238237
    239238#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 thread
    249    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, // dltotal
    290                       double d, // dlnow
    291                       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  
    99#include "orxonox_gui.h"
    1010#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 */
    1116using namespace std;
    1217
     
    5358  static int curlProgressFunc (ProgressBar* Bar, double totalSize, double progress, double upTotal, double upProgress);
    5459
     60  static CURL* curlHandle;
    5561  static void* download (void* fileInfo);
    5662#ifdef HAVE_GTK2
Note: See TracChangeset for help on using the changeset viewer.