- Timestamp:
- Dec 24, 2004, 1:15:38 PM (20 years ago)
- Location:
- orxonox/branches/updater/src/gui
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/updater/src/gui/orxonox_gui.cc
r3252 r3263 41 41 OrxonoxGuiKeys* keys; 42 42 OrxonoxGuiUpdate* update; 43 int verbose = 4; 43 44 44 45 int main( int argc, char *argv[] ) … … 58 59 initGTK(argc, argv); 59 60 #endif /* HAVE_GTK2 */ 61 60 62 orxonoxGUI = new Window( "Grafical OrxOnoX loader, "PACKAGE_VERSION); 61 63 #ifdef HAVE_GTK2 -
orxonox/branches/updater/src/gui/orxonox_gui_gtk.cc
r3259 r3263 47 47 bool initGTK(int argc, char *argv[]) 48 48 { 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 */ 49 54 gtk_init (&argc, &argv); 50 55 gtk_rc_parse( "rc" ); … … 56 61 bool mainloopGTK(void) 57 62 { 63 gdk_threads_enter(); 64 PRINTF(1)("test\n"); 58 65 gtk_main(); 66 gdk_threads_leave(); 59 67 } 60 68 #endif /* HAVE_GTK2 */ … … 529 537 this->init(); 530 538 } 539 531 540 /** 532 541 \brief Creates a new EventBox with name title … … 1204 1213 gtk_progress_set_value(GTK_PROGRESS(widget), this->progress*100.0/this->totalSize); 1205 1214 #endif /* HAVE_GTK2 */ 1215 PRINTF(3)("Progress: %f\n", progress*100.0/totalSize); 1216 1206 1217 } 1207 1218 -
orxonox/branches/updater/src/gui/orxonox_gui_gtk.h
r3254 r3263 10 10 #include <config.h> 11 11 #endif 12 13 extern int verbose; // soon obsolete here 12 14 13 15 #include "../debug.h" … … 36 38 #endif /* HAVE_GTK2 */ 37 39 38 39 40 //! This is the topmost object that can be displayed all others are derived from it. 40 41 class Widget -
orxonox/branches/updater/src/gui/orxonox_gui_update.cc
r3261 r3263 30 30 #include "orxonox_gui.h" 31 31 #include <stdio.h> 32 #include <curl/curl.h> 33 #include <curl/types.h> 34 #include <curl/easy.h> /* new for v7 */ 32 35 using namespace std; 33 36 … … 79 82 updateDataBar = new ProgressBar (); 80 83 updateDataBox->fill(updateDataBar); 84 85 updateDataBegin = new Button ("begin Download"); 86 updateDataBegin->connectSignal ("button_press_event", updateDataBar, updateDataFunc); 87 updateDataBox->fill(updateDataBegin); 88 81 89 updateDataWindow->fill (updateDataBox); 82 90 … … 139 147 \param button The Button, that triggered this event. 140 148 */ 141 gint OrxonoxGuiUpdate::updateDataFunc(GtkWidget* w, GdkEventKey* event, void* button) 142 { 143 149 gint 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"); 144 163 } 145 164 … … 156 175 tmpBar->setProgress(tmpBar->getProgress()+1); 157 176 } 158 159 #endif /* HAVE_GTK2 */ 177 #endif /* HAVE_GTK2 */ 178 179 #ifdef HAVE_CURL 180 size_t OrxonoxGuiUpdate::curlWriteFunc (void* ptr, size_t size, size_t nmemb, FILE* stream) 181 { 182 return fwrite(ptr, size, nmemb, stream); 183 } 184 185 size_t OrxonoxGuiUpdate::curlReadFunc (void* ptr, size_t size, size_t nmemb, FILE* stream) 186 { 187 return fread(ptr, size, nmemb, stream); 188 } 189 190 191 int 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 201 void* 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 269 size_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 24 24 Box* updateDataBox; //!< A Box for the Window for the Data-update. 25 25 ProgressBar* updateDataBar; //!< A Bar to display the progress of the download. 26 26 Button* updateDataBegin; //!< A Button to start the process. 27 27 28 28 Button* updateSourceWindowButton;//!< A Button to update the Source of orxonox. \todo tricky … … 38 38 #endif /* HAVE_GTK2 */ 39 39 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 */ 40 55 41 56 public:
Note: See TracChangeset
for help on using the changeset viewer.