[3250] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | This program is distributed in the hope that it will be useful, |
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | GNU General Public License for more details. |
---|
| 15 | |
---|
| 16 | You should have received a copy of the GNU General Public License |
---|
| 17 | along with this program; if not, write to the Free Software Foundation, |
---|
| 18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | ### File Specific: |
---|
| 22 | main-programmer: Benjamin Grauer |
---|
| 23 | |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "orxonox_gui_update.h" |
---|
| 27 | #include <iostream> |
---|
| 28 | #include <string> |
---|
| 29 | |
---|
| 30 | #include "orxonox_gui.h" |
---|
| 31 | #include <stdio.h> |
---|
[3285] | 32 | #include <stdlib.h> |
---|
[3270] | 33 | |
---|
[3250] | 34 | using namespace std; |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | \brief Creates an Audio-Frame |
---|
| 38 | */ |
---|
| 39 | OrxonoxGuiUpdate::OrxonoxGuiUpdate () |
---|
| 40 | { |
---|
[3285] | 41 | this->getSystemInfo(); |
---|
| 42 | |
---|
[3253] | 43 | this->updateFrame = new Frame ("Update-Options:"); |
---|
[3261] | 44 | this->updateFrame->setGroupName ("update"); |
---|
[3253] | 45 | this->updateBox = new Box ('v'); |
---|
[3281] | 46 | #ifdef HAVE_CURL |
---|
[3250] | 47 | |
---|
[3261] | 48 | // the Button for autoUpdating |
---|
| 49 | this->autoUpdate = new CheckButton ("auto update"); |
---|
| 50 | this->updateBox->fill(this->autoUpdate); |
---|
| 51 | this->autoUpdate->setFlagName ("update", "u", 0); |
---|
[3288] | 52 | this->autoUpdate->saveability(); |
---|
[3253] | 53 | |
---|
[3261] | 54 | this->updateSourceWindowCreate (); |
---|
| 55 | this->updateBox->fill(this->updateSourceWindowGetButton()); |
---|
| 56 | |
---|
| 57 | this->updateDataWindowCreate (); |
---|
| 58 | this->updateBox->fill(this->updateDataWindowGetButton()); |
---|
| 59 | |
---|
[3281] | 60 | #else /* HAVE_CURL */ |
---|
| 61 | Label* noCurlLabel = new Label("since you do not have cURL,\nthis option is not availible"); |
---|
| 62 | this->updateBox->fill(noCurlLabel); |
---|
| 63 | #endif /* HAVE_CURL */ |
---|
[3253] | 64 | this->updateFrame->fill(this->updateBox); |
---|
[3281] | 65 | |
---|
[3250] | 66 | } |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | \brief Return the Frame |
---|
| 70 | \return Returns the Audio-frame |
---|
| 71 | */ |
---|
| 72 | Widget* OrxonoxGuiUpdate::getWidget () |
---|
| 73 | { |
---|
| 74 | return updateFrame; |
---|
| 75 | } |
---|
[3253] | 76 | |
---|
[3285] | 77 | /** |
---|
| 78 | \brief Look what info we can get from this system |
---|
| 79 | */ |
---|
| 80 | bool OrxonoxGuiUpdate::getSystemInfo(void) |
---|
| 81 | { |
---|
| 82 | PRINTF(3)("Grabbing system information\n"); |
---|
| 83 | tmpDir = getenv("TMPDIR"); |
---|
| 84 | if (!tmpDir) |
---|
| 85 | tmpDir = "/tmp"; |
---|
| 86 | PRINTF(4)("Temporary directory is: %s\n", tmpDir); |
---|
| 87 | |
---|
| 88 | #ifdef __WIN32__ |
---|
| 89 | homeDir = getenv ("USERPROFILE"); |
---|
| 90 | #else |
---|
| 91 | homeDir = getenv("HOME"); |
---|
| 92 | #endif |
---|
| 93 | PRINTF(4)("Home directory is %s\n", homeDir); |
---|
| 94 | |
---|
| 95 | installDataDir = "/usr/share/games/orxonox"; |
---|
[3286] | 96 | PRINTF(4)("Installation of orxonox-data will go to this directory: %s\n", installDataDir); |
---|
[3285] | 97 | |
---|
| 98 | installSourceDir = "/usr/games/bin"; |
---|
[3286] | 99 | PRINTF(4)("Installation of orxonox-source will go to this directory: %s\n", installSourceDir); |
---|
[3285] | 100 | |
---|
| 101 | userName = getenv("USER"); |
---|
| 102 | PRINTF(4)("Logged in username is: %s\n", userName); |
---|
| 103 | } |
---|
| 104 | |
---|
[3281] | 105 | #ifdef HAVE_CURL |
---|
[3286] | 106 | bool* OrxonoxGuiUpdate::checkForUpdates(void) |
---|
| 107 | { |
---|
| 108 | PRINTF(3)("checking for new version of orxonox\n"); |
---|
| 109 | FileInfo updateFileInfo; |
---|
| 110 | updateFileInfo.fileName = "update_info"; |
---|
| 111 | updateFileInfo.webRoot = "http://www.orxonox.ethz.ch/files/data"; |
---|
[3298] | 112 | updateFileInfo.localRoot = this->tmpDir; |
---|
[3286] | 113 | |
---|
| 114 | download(&updateFileInfo); |
---|
| 115 | } |
---|
| 116 | #endif /* HAVE_CURL */ |
---|
| 117 | #ifdef HAVE_CURL |
---|
[3275] | 118 | /** |
---|
| 119 | \brief Creates a window, and all it contains for the Data-update. |
---|
| 120 | */ |
---|
[3261] | 121 | void OrxonoxGuiUpdate::updateDataWindowCreate (void) |
---|
[3253] | 122 | { |
---|
[3261] | 123 | updateDataWindow = new Window ("update orxonox::Data"); |
---|
| 124 | updateDataBox = new Box ('v'); |
---|
[3253] | 125 | |
---|
[3257] | 126 | // the close-Button of the Update Window. |
---|
[3261] | 127 | // updateWindowClose = new Button ("close"); |
---|
[3257] | 128 | #ifdef HAVE_GTK2 |
---|
[3261] | 129 | // updateWindowClose->connectSignal("button_press_event", updateWindow, Window::windowClose); |
---|
[3257] | 130 | #endif /* HAVE_GTK2 */ |
---|
[3261] | 131 | // updateWindowBox->fill(updateWindowClose); |
---|
[3253] | 132 | |
---|
[3261] | 133 | updateDataBar = new ProgressBar (); |
---|
| 134 | updateDataBox->fill(updateDataBar); |
---|
[3263] | 135 | |
---|
[3274] | 136 | FileInfo* dataInfo = new FileInfo; |
---|
| 137 | dataInfo->bar = updateDataBar; |
---|
| 138 | |
---|
| 139 | updateDataBegin = new Button ("begin."); |
---|
| 140 | dataInfo->stateButton = updateDataBegin; |
---|
[3291] | 141 | #ifdef HAVE_GTK2 |
---|
[3274] | 142 | dataInfo->buttonSignal = updateDataBegin->connectSignal ("button_press_event", dataInfo, updateDataFunc); |
---|
[3291] | 143 | #endif /* HAVE_GTK2 */ |
---|
[3263] | 144 | updateDataBox->fill(updateDataBegin); |
---|
| 145 | |
---|
[3261] | 146 | updateDataWindow->fill (updateDataBox); |
---|
[3253] | 147 | |
---|
[3261] | 148 | updateDataWindowButton = new Button ("update orxonox::Data"); |
---|
[3254] | 149 | #ifdef HAVE_GTK2 |
---|
[3261] | 150 | updateDataWindowButton->connectSignal("button_press_event", updateDataWindow, Window::windowOpen); |
---|
[3271] | 151 | updateDataWindow->connectSignal("destroy", updateDataWindow, Window::windowClose); |
---|
| 152 | updateDataWindow->connectSignal("delete_event", updateDataWindow, Window::windowClose); |
---|
[3253] | 153 | #endif /* HAVE_GTK2 */ |
---|
| 154 | |
---|
| 155 | } |
---|
| 156 | |
---|
[3258] | 157 | /** |
---|
[3275] | 158 | \returns A Pointer to the Button of the UpdaterDataWindow |
---|
[3258] | 159 | */ |
---|
[3259] | 160 | Button* OrxonoxGuiUpdate::updateDataWindowGetButton(void) |
---|
| 161 | { |
---|
[3261] | 162 | return updateDataWindowButton; |
---|
[3259] | 163 | } |
---|
| 164 | |
---|
[3275] | 165 | /** |
---|
| 166 | \brief Creates a window, and all it contains for the Source-update. |
---|
| 167 | */ |
---|
[3259] | 168 | void OrxonoxGuiUpdate::updateSourceWindowCreate (void) |
---|
| 169 | { |
---|
| 170 | // the button, that opens this Window. |
---|
[3261] | 171 | updateSourceWindowButton = new Button ("update orxonox::Source"); |
---|
[3259] | 172 | |
---|
| 173 | // the Window itself |
---|
| 174 | updateSourceWindow = new Window ("update orxonox::Source"); |
---|
| 175 | |
---|
[3261] | 176 | updateSourceBox = new Box (); |
---|
[3259] | 177 | |
---|
| 178 | updateSourceBar = new ProgressBar (); |
---|
[3261] | 179 | updateSourceBox->fill(updateSourceBar); |
---|
[3259] | 180 | test = new Button ("increment"); |
---|
[3261] | 181 | |
---|
| 182 | #ifdef HAVE_GTK2 |
---|
[3259] | 183 | test->connectSignal("button_press_event", updateSourceBar, updateSourceFunc); |
---|
[3261] | 184 | #endif /* HAVE_GTK2 */ |
---|
| 185 | |
---|
| 186 | updateSourceBox->fill(test); |
---|
| 187 | updateSourceWindow->fill(updateSourceBox); |
---|
[3259] | 188 | #ifdef HAVE_GTK2 |
---|
[3261] | 189 | updateSourceWindowButton->connectSignal("button_press_event", updateSourceWindow, Window::windowOpen); |
---|
| 190 | updateSourceWindow->connectSignal("destroy", updateSourceWindow, Window::windowClose); |
---|
| 191 | updateSourceWindow->connectSignal("delete_event", updateSourceWindow, Window::windowClose); |
---|
[3259] | 192 | #endif /* HAVE_GTK2 */ |
---|
| 193 | |
---|
| 194 | } |
---|
| 195 | |
---|
[3275] | 196 | /** |
---|
| 197 | \returns A Pointer to the Button of the UpdaterSourceWindow |
---|
| 198 | */ |
---|
[3259] | 199 | Button* OrxonoxGuiUpdate::updateSourceWindowGetButton(void) |
---|
| 200 | { |
---|
[3261] | 201 | return updateSourceWindowButton; |
---|
[3259] | 202 | } |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | #ifdef HAVE_GTK2 |
---|
[3258] | 206 | /** |
---|
| 207 | \brief updates the Data of orxonox. |
---|
| 208 | \param w The widget, that executed this Function. |
---|
| 209 | \param event The event that trigered this Function. |
---|
| 210 | \param button The Button, that triggered this event. |
---|
| 211 | */ |
---|
[3274] | 212 | gint OrxonoxGuiUpdate::updateDataFunc(GtkWidget* w, GdkEventKey* event, void* info) |
---|
[3254] | 213 | { |
---|
[3274] | 214 | FileInfo* dataInfo = (FileInfo*)info; |
---|
[3254] | 215 | |
---|
[3274] | 216 | dataInfo->fileName = "02%20orxonox%203.mp3"; |
---|
| 217 | dataInfo->webRoot = "http://www.orxonox.ethz.ch/files/"; |
---|
| 218 | dataInfo->localRoot = "./"; |
---|
| 219 | PRINTF(3)("Preparing to download file %s.\n", dataInfo->fileName); |
---|
[3286] | 220 | downloadWithStyle(dataInfo); |
---|
[3254] | 221 | } |
---|
| 222 | |
---|
[3258] | 223 | /** |
---|
| 224 | \brief updates the source of orxonox. |
---|
| 225 | \param w The widget, that executed this Function. |
---|
| 226 | \param event The event that trigered this Function. |
---|
| 227 | \param button The Button, that triggered this event. |
---|
| 228 | */ |
---|
[3259] | 229 | gint OrxonoxGuiUpdate::updateSourceFunc(GtkWidget* w, GdkEventKey* event, void* bar) |
---|
[3254] | 230 | { |
---|
[3259] | 231 | ProgressBar* tmpBar = static_cast<ProgressBar*>(bar); |
---|
| 232 | tmpBar->setTotalSize(20); |
---|
| 233 | tmpBar->setProgress(tmpBar->getProgress()+1); |
---|
[3254] | 234 | } |
---|
[3263] | 235 | #endif /* HAVE_GTK2 */ |
---|
[3254] | 236 | |
---|
[3275] | 237 | /** |
---|
| 238 | \brief The Function Curl calls to write out the File. |
---|
| 239 | \param ptr A Pointer to the date to write. |
---|
| 240 | \param size The size in bytes of one nmemb to write. |
---|
| 241 | \param nmemb The Count of size to write. |
---|
| 242 | \param stream Filehandler to write to. |
---|
| 243 | */ |
---|
[3263] | 244 | size_t OrxonoxGuiUpdate::curlWriteFunc (void* ptr, size_t size, size_t nmemb, FILE* stream) |
---|
| 245 | { |
---|
| 246 | return fwrite(ptr, size, nmemb, stream); |
---|
| 247 | } |
---|
| 248 | |
---|
[3275] | 249 | /** |
---|
| 250 | \brief The Function Curl calls to write out the File. |
---|
| 251 | \param ptr A Pointer to the date to write to. |
---|
| 252 | \param size The size in bytes of one nmemb to write. |
---|
| 253 | \param nmemb The Count of size to write. |
---|
| 254 | \param stream Filehandler to get data from. |
---|
| 255 | */ |
---|
[3263] | 256 | size_t OrxonoxGuiUpdate::curlReadFunc (void* ptr, size_t size, size_t nmemb, FILE* stream) |
---|
| 257 | { |
---|
| 258 | return fread(ptr, size, nmemb, stream); |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | |
---|
[3275] | 262 | /** |
---|
| 263 | \brief An update Function for the GUI, to show the progress. |
---|
| 264 | \param Bar th ProgressBar to update |
---|
| 265 | \param totalSize The total size of the download in bytes. |
---|
| 266 | \param progress The current Progress of the download in bytes. |
---|
| 267 | \param upTotal not needed |
---|
| 268 | \param upProgress not needed |
---|
| 269 | */ |
---|
[3263] | 270 | int OrxonoxGuiUpdate::curlProgressFunc (ProgressBar* Bar, double totalSize, double progress, double upTotal, double upProgress) |
---|
| 271 | { |
---|
| 272 | Bar->setProgress(progress); |
---|
| 273 | Bar->setTotalSize(totalSize); |
---|
[3274] | 274 | #ifdef HAVE_GTK2 |
---|
| 275 | #ifndef HAVE_PTHREAD_H |
---|
| 276 | while(gtk_events_pending()) gtk_main_iteration(); |
---|
| 277 | #endif |
---|
| 278 | #endif |
---|
[3263] | 279 | return 0; |
---|
| 280 | } |
---|
| 281 | |
---|
[3275] | 282 | /** |
---|
[3281] | 283 | \brief The Curl handle for only one CURL (static). |
---|
[3275] | 284 | */ |
---|
[3270] | 285 | CURL* OrxonoxGuiUpdate::curlHandle = NULL; |
---|
[3273] | 286 | |
---|
| 287 | #ifdef HAVE_PTHREAD_H |
---|
[3275] | 288 | /** \brief The download Thread ID */ |
---|
[3272] | 289 | pthread_t* OrxonoxGuiUpdate::downloadThreadID = new pthread_t; |
---|
[3275] | 290 | /** \brief The download Thread ID*/ |
---|
| 291 | pthread_t* OrxonoxGuiUpdate::downloadThreadFinishID = new pthread_t; |
---|
[3273] | 292 | #endif /* HAVE_PTHREAD_H */ |
---|
[3275] | 293 | /** |
---|
| 294 | \brief A bool parameter that shows if we are downloading. |
---|
| 295 | */ |
---|
[3272] | 296 | bool OrxonoxGuiUpdate::isDownloading = false; |
---|
[3266] | 297 | |
---|
[3286] | 298 | |
---|
[3275] | 299 | /** |
---|
[3286] | 300 | \brief Initializes a Download without displaying it. |
---|
[3275] | 301 | \param fileInfo the FileInfo. |
---|
[3286] | 302 | |
---|
| 303 | !! BE AWARE THIS WILL NOT BE THREADED. !! |
---|
[3275] | 304 | */ |
---|
[3286] | 305 | bool OrxonoxGuiUpdate::download(void* fileInfo) |
---|
[3263] | 306 | { |
---|
[3274] | 307 | if (isDownloading) |
---|
| 308 | { |
---|
| 309 | PRINTF(2)("unable to Download. already getting some file\n"); |
---|
| 310 | return false; |
---|
| 311 | } |
---|
[3263] | 312 | PRINTF(3)("Downloading.\n"); |
---|
| 313 | FileInfo* info = (FileInfo*)fileInfo; |
---|
| 314 | CURLcode res; |
---|
[3286] | 315 | CURL* localCurl; |
---|
| 316 | localCurl = curl_easy_init(); |
---|
| 317 | char* fileOnNet = new char [strlen(info->webRoot)+strlen(info->fileName)+2]; |
---|
| 318 | strcpy (fileOnNet, info->webRoot); |
---|
| 319 | if (fileOnNet[strlen(fileOnNet)] != '/') //!< \todo windows-shit |
---|
| 320 | strcat (fileOnNet, "/"); |
---|
| 321 | strcat (fileOnNet, info->fileName); |
---|
| 322 | char* fileOnDisk = new char [strlen(info->localRoot)+strlen(info->fileName)+2]; |
---|
| 323 | strcpy (fileOnDisk, info->localRoot); |
---|
| 324 | if (fileOnDisk[strlen(fileOnDisk)] != '/') //!< \todo windows-shit |
---|
| 325 | strcat (fileOnDisk, "/"); |
---|
| 326 | strcat (fileOnDisk, info->fileName); |
---|
| 327 | |
---|
| 328 | if(localCurl) |
---|
| 329 | { |
---|
| 330 | |
---|
| 331 | info->fileHandle = fopen(fileOnDisk, "w"); |
---|
| 332 | |
---|
| 333 | curl_easy_setopt(localCurl, CURLOPT_URL, fileOnNet); |
---|
| 334 | curl_easy_setopt(localCurl, CURLOPT_WRITEDATA, info->fileHandle); |
---|
| 335 | curl_easy_setopt(localCurl, CURLOPT_WRITEFUNCTION, curlWriteFunc); |
---|
| 336 | curl_easy_setopt(localCurl, CURLOPT_READFUNCTION, curlReadFunc); |
---|
[3291] | 337 | curl_easy_setopt(localCurl, CURLOPT_NOPROGRESS, true); |
---|
[3286] | 338 | |
---|
| 339 | curl_easy_perform(localCurl); |
---|
| 340 | |
---|
| 341 | curl_easy_cleanup(localCurl); |
---|
| 342 | fclose (info->fileHandle); |
---|
| 343 | } |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | /** |
---|
| 347 | \brief Initializes a Download with some style. |
---|
| 348 | \param fileInfo the FileInfo. |
---|
| 349 | \todo release thread-lock. |
---|
| 350 | |
---|
| 351 | Downloading with a Button that gets a different Name while downloading, and a Bar, that gets to be updated. More to be followed |
---|
| 352 | */ |
---|
| 353 | bool OrxonoxGuiUpdate::downloadWithStyle(void* fileInfo) |
---|
| 354 | { |
---|
| 355 | if (isDownloading) |
---|
| 356 | { |
---|
| 357 | PRINTF(2)("unable to Download. already getting some file\n"); |
---|
| 358 | return false; |
---|
| 359 | } |
---|
| 360 | PRINTF(3)("Downloading.\n"); |
---|
| 361 | FileInfo* info = (FileInfo*)fileInfo; |
---|
| 362 | CURLcode res; |
---|
[3270] | 363 | curlHandle = curl_easy_init(); |
---|
[3267] | 364 | char* fileOnNet = new char [strlen(info->webRoot)+strlen(info->fileName)+1]; |
---|
| 365 | strcpy (fileOnNet, info->webRoot); |
---|
| 366 | strcat (fileOnNet, info->fileName); |
---|
| 367 | char* fileOnDisk = new char [strlen(info->localRoot)+strlen(info->fileName)+1]; |
---|
| 368 | strcpy (fileOnDisk, info->localRoot); |
---|
| 369 | strcat (fileOnDisk, info->fileName); |
---|
[3273] | 370 | |
---|
[3270] | 371 | if(curlHandle) |
---|
[3263] | 372 | { |
---|
[3271] | 373 | |
---|
[3272] | 374 | info->fileHandle = fopen(fileOnDisk, "w"); |
---|
[3274] | 375 | |
---|
[3270] | 376 | curl_easy_setopt(curlHandle, CURLOPT_URL, fileOnNet); |
---|
[3272] | 377 | curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, info->fileHandle); |
---|
[3270] | 378 | curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, curlWriteFunc); |
---|
| 379 | curl_easy_setopt(curlHandle, CURLOPT_READFUNCTION, curlReadFunc); |
---|
[3291] | 380 | curl_easy_setopt(curlHandle, CURLOPT_NOPROGRESS, false); |
---|
[3270] | 381 | curl_easy_setopt(curlHandle, CURLOPT_PROGRESSFUNCTION, curlProgressFunc); |
---|
[3274] | 382 | curl_easy_setopt(curlHandle, CURLOPT_PROGRESSDATA, info->bar); |
---|
[3271] | 383 | |
---|
[3272] | 384 | if (!isDownloading) |
---|
[3271] | 385 | { |
---|
[3303] | 386 | #ifdef HAVE_PTHREAD_H |
---|
[3284] | 387 | pthread_join(*downloadThreadFinishID, NULL); |
---|
[3303] | 388 | #endif /* HAVE_PTHREAD_H */ |
---|
[3291] | 389 | #ifdef HAVE_GTK2 |
---|
[3284] | 390 | info->stateButton->disconnectSignal(info->buttonSignal); |
---|
| 391 | info->buttonSignal = info->stateButton->connectSignal("button_press_event", info, cancelDownload); |
---|
[3291] | 392 | #endif /* HAVE_GTK2 */ |
---|
[3284] | 393 | #ifdef HAVE_PTHREAD_H |
---|
| 394 | info->stateButton->setTitle("cancel"); |
---|
| 395 | #else /* HAVE_PTHREAD_H */ |
---|
| 396 | info->stateButton->setTitle("please wait"); |
---|
| 397 | #endif /* HAVE_PTHREAD_H */ |
---|
| 398 | |
---|
[3271] | 399 | //! \todo check if threads really were created. |
---|
[3273] | 400 | #ifdef HAVE_PTHREAD_H |
---|
[3272] | 401 | pthread_create(downloadThreadID, NULL, downloadThread, info); |
---|
[3275] | 402 | pthread_create(downloadThreadFinishID, NULL, downloadThreadFinished, info); |
---|
[3273] | 403 | #else |
---|
| 404 | downloadThread(info); |
---|
[3274] | 405 | downloadThreadFinished(info); |
---|
[3273] | 406 | #endif /* HAVE_PTHREAD_H */ |
---|
| 407 | |
---|
[3272] | 408 | // res = curl_easy_perform(curlHandle); |
---|
| 409 | |
---|
| 410 | // fclose(outfile); |
---|
[3271] | 411 | } |
---|
[3274] | 412 | else |
---|
| 413 | PRINTF(1)("thread already in use\n"); |
---|
| 414 | |
---|
[3263] | 415 | } |
---|
[3274] | 416 | return true; |
---|
[3263] | 417 | } |
---|
[3275] | 418 | |
---|
| 419 | /** |
---|
| 420 | \brief The downloading process (either threaded or not). |
---|
| 421 | \param fileInfo the FileInfo. |
---|
[3282] | 422 | |
---|
| 423 | \todo Threads get locked, if the cancel button is pressed in to small intervals. |
---|
[3275] | 424 | */ |
---|
[3271] | 425 | void* OrxonoxGuiUpdate::downloadThread(void* fileInfo) |
---|
| 426 | { |
---|
[3284] | 427 | isDownloading = true; |
---|
[3274] | 428 | curl_easy_perform(curlHandle); |
---|
| 429 | } |
---|
| 430 | |
---|
[3275] | 431 | /** |
---|
| 432 | \brief Finishes a downloading process. |
---|
| 433 | \param fileInfo the FileInfo. |
---|
| 434 | */ |
---|
[3274] | 435 | void* OrxonoxGuiUpdate::downloadThreadFinished(void* fileInfo) |
---|
| 436 | { |
---|
[3272] | 437 | FileInfo* info = (FileInfo*)fileInfo; |
---|
[3274] | 438 | #ifdef HAVE_PTHREAD_H |
---|
| 439 | pthread_join (*downloadThreadID, NULL); |
---|
[3291] | 440 | #ifdef HAVE_GTK2 |
---|
[3283] | 441 | gdk_threads_enter(); |
---|
[3291] | 442 | #endif /* HAVE_GTK2 */ |
---|
[3274] | 443 | #endif /* HAVE_PTHREAD_H */ |
---|
[3271] | 444 | if (curlHandle) |
---|
| 445 | curl_easy_cleanup(curlHandle); |
---|
[3274] | 446 | |
---|
[3271] | 447 | PRINTF(3)("Closing the downloaded file.\n"); |
---|
[3272] | 448 | fclose(info->fileHandle); |
---|
| 449 | |
---|
[3274] | 450 | if (isDownloading) |
---|
| 451 | info->stateButton->setTitle("go on"); |
---|
| 452 | // else |
---|
| 453 | // info->stateButton->setTitle("done"); |
---|
[3291] | 454 | #ifdef HAVE_GTK2 |
---|
[3274] | 455 | info->stateButton->disconnectSignal(info->buttonSignal); |
---|
| 456 | info->buttonSignal = info->stateButton->connectSignal("button_press_event", info, updateDataFunc); |
---|
[3291] | 457 | #endif /* HAVE_GTK2 */ |
---|
[3272] | 458 | isDownloading = false; |
---|
[3283] | 459 | #ifdef HAVE_PTHREAD_H |
---|
[3291] | 460 | #ifdef HAVE_GTK2 |
---|
[3274] | 461 | gdk_threads_leave(); |
---|
[3291] | 462 | #endif /* HAVE_GTK2 */ |
---|
[3283] | 463 | #endif /* HAVE_PTHREAD_H */ |
---|
[3274] | 464 | |
---|
[3271] | 465 | } |
---|
| 466 | |
---|
[3268] | 467 | #ifdef HAVE_GTK2 |
---|
[3275] | 468 | /** |
---|
| 469 | \brief canceles a downloading session. |
---|
| 470 | \param w The widget, that executed this Function. |
---|
| 471 | \param event The event that trigered this Function. |
---|
| 472 | \param bar The Bar, that triggered this event. |
---|
| 473 | |
---|
| 474 | \todo canceling a session in non-threaded mode. |
---|
| 475 | */ |
---|
[3268] | 476 | gint OrxonoxGuiUpdate::cancelDownload(GtkWidget* w, GdkEventKey* event, void* bar) |
---|
| 477 | { |
---|
[3274] | 478 | #ifdef HAVE_PTHREAD_H |
---|
| 479 | pthread_cancel(*downloadThreadID); |
---|
| 480 | #else |
---|
| 481 | PRINTF(2)("Cannot cancle the Downloading process until after this File, because no threading was enabled"); |
---|
| 482 | #endif /* HAVE_PTHREAD_H*/ |
---|
[3268] | 483 | } |
---|
| 484 | #endif /* HAVE_GTK2 */ |
---|
| 485 | |
---|
[3263] | 486 | #endif /* HAVE_CURL */ |
---|