Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3263 in orxonox.OLD for orxonox/branches/updater


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

orxonox/branches/updater: now the Data-bar downloads something, and the Progress is displayed. (not very nice, but it works).

NOT THREAD SAVE <<

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

Legend:

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

    r3252 r3263  
    4141  OrxonoxGuiKeys* keys;
    4242  OrxonoxGuiUpdate* update;
     43int verbose = 4;
    4344
    4445int main( int argc, char *argv[] )
     
    5859  initGTK(argc, argv);
    5960#endif /* HAVE_GTK2 */
     61
    6062  orxonoxGUI = new Window( "Grafical OrxOnoX loader, "PACKAGE_VERSION);
    6163#ifdef HAVE_GTK2
  • orxonox/branches/updater/src/gui/orxonox_gui_gtk.cc

    r3259 r3263  
    4747bool initGTK(int argc, char *argv[])
    4848{
     49#ifdef HAVE_GTHREAD
     50  PRINTF(3)("Initializing the ThreadSystem of the GUI\n");
     51  g_thread_init(NULL);
     52  gdk_threads_init();
     53#endif /* HAVE_GTHREAD */
    4954  gtk_init (&argc, &argv);
    5055  gtk_rc_parse( "rc" );
     
    5661bool mainloopGTK(void)
    5762{
     63  gdk_threads_enter();
     64  PRINTF(1)("test\n");
    5865  gtk_main();
     66  gdk_threads_leave();
    5967}
    6068#endif /* HAVE_GTK2 */
     
    529537  this->init();
    530538}
     539
    531540/**
    532541   \brief Creates a new EventBox with name title
     
    12041213  gtk_progress_set_value(GTK_PROGRESS(widget), this->progress*100.0/this->totalSize);
    12051214#endif /* HAVE_GTK2 */
     1215  PRINTF(3)("Progress: %f\n", progress*100.0/totalSize);
     1216
    12061217}
    12071218
  • orxonox/branches/updater/src/gui/orxonox_gui_gtk.h

    r3254 r3263  
    1010#include <config.h>
    1111#endif
     12
     13extern int verbose; // soon obsolete here
    1214
    1315#include "../debug.h"
     
    3638#endif /* HAVE_GTK2 */
    3739
    38 
    3940//! This is the topmost object that can be displayed all others are derived from it.
    4041class Widget
  • orxonox/branches/updater/src/gui/orxonox_gui_update.cc

    r3261 r3263  
    3030#include "orxonox_gui.h"
    3131#include <stdio.h>
     32#include <curl/curl.h>
     33#include <curl/types.h>
     34#include <curl/easy.h> /* new for v7 */
    3235using namespace std;
    3336
     
    7982  updateDataBar = new ProgressBar ();
    8083  updateDataBox->fill(updateDataBar);
     84
     85  updateDataBegin = new Button ("begin Download");
     86  updateDataBegin->connectSignal ("button_press_event", updateDataBar, updateDataFunc);
     87  updateDataBox->fill(updateDataBegin);
     88
    8189  updateDataWindow->fill (updateDataBox);
    8290
     
    139147   \param button The Button, that triggered this event.
    140148*/
    141 gint OrxonoxGuiUpdate::updateDataFunc(GtkWidget* w, GdkEventKey* event, void* button)
    142 {
    143 
     149gint OrxonoxGuiUpdate::updateDataFunc(GtkWidget* w, GdkEventKey* event, void* bar)
     150{
     151  FileInfo* info = new FileInfo;
     152
     153  info->fileOnDisk = new char [5];
     154  strcpy (info->fileOnDisk, "test");
     155  info->fileOnNet = new char [100];
     156  strcpy(info->fileOnNet, "http://www.orxonox.ethz.ch/files/taskHorizon.at.bermuda-funk.ogg");
     157  info->Bar = (ProgressBar*)bar;
     158  PRINTF(3)("Preparing to download file %s.\n", info->fileOnNet);
     159  //downloadThread (info);
     160
     161  if (!g_thread_create(&downloadThread, info, FALSE, NULL) != 0)
     162    PRINTF(1)("can't create the thread");
    144163}
    145164
     
    156175  tmpBar->setProgress(tmpBar->getProgress()+1);
    157176}
    158 
    159 #endif /* HAVE_GTK2 */
     177#endif /* HAVE_GTK2 */
     178
     179#ifdef HAVE_CURL
     180size_t OrxonoxGuiUpdate::curlWriteFunc (void* ptr, size_t size, size_t nmemb, FILE* stream)
     181{
     182  return fwrite(ptr, size, nmemb, stream);
     183}
     184
     185size_t OrxonoxGuiUpdate::curlReadFunc (void* ptr, size_t size, size_t nmemb, FILE* stream)
     186{
     187  return fread(ptr, size, nmemb, stream);
     188}
     189
     190
     191int OrxonoxGuiUpdate::curlProgressFunc (ProgressBar* Bar, double totalSize, double progress, double upTotal, double upProgress)
     192{
     193  //  gdk_threads_enter();
     194  Bar->setProgress(progress);
     195  Bar->setTotalSize(totalSize);
     196  //  gdk_threads_leave();
     197  return 0;
     198
     199}
     200
     201void* OrxonoxGuiUpdate::downloadThread (void* fileInfo)
     202{
     203  PRINTF(3)("Downloading.\n");
     204  FileInfo* info = (FileInfo*)fileInfo;
     205  CURL* curl;
     206  CURLcode res;
     207  FILE* outfile;
     208  curl = curl_easy_init();
     209
     210  if(curl)
     211    {
     212      outfile = fopen(info->fileOnDisk, "w");
     213     
     214      curl_easy_setopt(curl, CURLOPT_URL, info->fileOnNet);
     215      curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
     216      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWriteFunc);
     217      curl_easy_setopt(curl, CURLOPT_READFUNCTION, curlReadFunc);
     218      curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
     219      curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curlProgressFunc);
     220      curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, info->Bar);
     221     
     222      res = curl_easy_perform(curl);
     223     
     224      fclose(outfile);
     225      curl_easy_cleanup(curl);
     226    }
     227  return NULL;
     228}
     229
     230#endif /* HAVE_CURL */
     231
     232
     233/*
     234 int main(int argc, char **argv)
     235 {
     236   GtkWidget *Window, *Frame, *Frame2;
     237   GtkAdjustment *adj;
     238   
     239   // Init thread
     240   g_thread_init(NULL);
     241   gtk_init(&argc, &argv);
     242   Window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
     243   Frame = gtk_frame_new(NULL);
     244   gtk_frame_set_shadow_type(GTK_FRAME(Frame), GTK_SHADOW_OUT);
     245   gtk_container_add(GTK_CONTAINER(Window), Frame);
     246   Frame2 = gtk_frame_new(NULL);
     247   gtk_frame_set_shadow_type(GTK_FRAME(Frame2), GTK_SHADOW_IN);
     248   gtk_container_add(GTK_CONTAINER(Frame), Frame2);
     249   gtk_container_set_border_width(GTK_CONTAINER(Frame2), 5);
     250   adj = (GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0);
     251   Bar = gtk_progress_bar_new_with_adjustment(adj);
     252   gtk_container_add(GTK_CONTAINER(Frame2), Bar);
     253   gtk_widget_show_all(Window);
     254 
     255   if (!g_thread_create(&my_thread, argv[1], FALSE, NULL) != 0)
     256     g_warning("can't create the thread");
     257 
     258 
     259   gdk_threads_enter();
     260   gtk_main();
     261  gdk_threads_leave();
     262   return 0;
     263 }
     264
     265
     266
     267
     268
     269size_t writeFunc(void *ptr, size_t size, size_t nmemb, FILE *stream)
     270 {
     271   return fwrite(ptr, size, nmemb, stream);
     272 }
     273 
     274 size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
     275 {
     276   return fread(ptr, size, nmemb, stream);
     277 }
     278 
     279 int my_progress_func(GtkWidget *Bar,
     280                      double t, // dltotal
     281                      double d, // dlnow
     282                      double ultotal,
     283                      double ulnow)
     284 {
     285   gdk_threads_enter();
     286   gtk_progress_set_value(GTK_PROGRESS(Bar), d*100.0/t);
     287   gdk_threads_leave();
     288   return 0;
     289 }
     290
     291 void *my_thread(void *ptr)
     292 {
     293   CURL *curl;
     294   CURLcode res;
     295   FILE *outfile;
     296   gchar *url = ptr;
     297 
     298   curl = curl_easy_init();
     299   if(curl)
     300   {
     301     outfile = fopen("test.curl", "w");
     302 
     303     curl_easy_setopt(curl, CURLOPT_URL, url);
     304     curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
     305     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);
     306     curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func);
     307     curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
     308     curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);
     309     curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, Bar);
     310 
     311     res = curl_easy_perform(curl);
     312 
     313     fclose(outfile);
     314     curl_easy_cleanup(curl);
     315   }
     316 
     317   return NULL;
     318 }
     319 
     320*/
     321
     322
     323
     324
     325
     326
     327
     328
     329
     330
     331
     332
     333
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
  • orxonox/branches/updater/src/gui/orxonox_gui_update.h

    r3261 r3263  
    2424  Box* updateDataBox;          //!< A Box for the Window for the Data-update.
    2525  ProgressBar* updateDataBar;  //!< A Bar to display the progress of the download.
    26 
     26  Button* updateDataBegin;     //!< A Button to start the process.
    2727
    2828  Button* updateSourceWindowButton;//!< A Button to update the Source of orxonox. \todo tricky
     
    3838#endif /* HAVE_GTK2 */
    3939
     40#ifdef HAVE_CURL
     41  struct FileInfo
     42  {
     43    char* fileOnNet;
     44    char* fileOnDisk;
     45    ProgressBar* Bar;
     46  };
     47
     48  static size_t curlWriteFunc (void* ptr, size_t size, size_t nmemb, FILE* stream);
     49  static size_t curlReadFunc (void* ptr, size_t size, size_t nmemb, FILE* stream);
     50  static int curlProgressFunc (ProgressBar* Bar, double totalSize, double progress, double upTotal, double upProgress);
     51
     52  static void* downloadThread (void* fileInfo);
     53 
     54#endif /* HAVE_CURL */
    4055
    4156 public:
Note: See TracChangeset for help on using the changeset viewer.