| 1 | /*! |
|---|
| 2 | \file orxonox_gui_update.h |
|---|
| 3 | \brief File that holds the class that creates the update-menu. |
|---|
| 4 | */ |
|---|
| 5 | |
|---|
| 6 | #ifndef _ORXONOX_GUI_UPDATE_H |
|---|
| 7 | #define _ORXONOX_GUI_UPDATE_H |
|---|
| 8 | |
|---|
| 9 | #include "orxonox_gui.h" |
|---|
| 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 */ |
|---|
| 16 | #ifdef HAVE_PTHREAD_H |
|---|
| 17 | #define _MULTI_THREADED |
|---|
| 18 | #include <pthread.h> |
|---|
| 19 | #endif /* HAVE_PTHREAD_H */ |
|---|
| 20 | using namespace std; |
|---|
| 21 | |
|---|
| 22 | //! Class that creates the execute-Options. |
|---|
| 23 | class OrxonoxGuiUpdate |
|---|
| 24 | { |
|---|
| 25 | private: |
|---|
| 26 | // Defining Variables |
|---|
| 27 | char* tmpDir; //!< The Temporary directory. |
|---|
| 28 | char* homeDir; //!< The Home directory. |
|---|
| 29 | char* installDataDir; //!< Where to install the Data to. |
|---|
| 30 | char* installSourceDir; //!< Where to install the Source to. |
|---|
| 31 | char* userName; //!< The user logged in. |
|---|
| 32 | |
|---|
| 33 | bool getSystemInfo(void); |
|---|
| 34 | |
|---|
| 35 | // Window creation. |
|---|
| 36 | Frame* updateFrame; //!< The Frame that holds the updateOptions. |
|---|
| 37 | Box* updateBox; //!< The Box that holds the updateOptions. |
|---|
| 38 | CheckButton* autoUpdate; //!< A Checkbutton to enable the automatic Updating. |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | Button* updateDataWindowButton; //!< A Button to update the Data of orxonox. |
|---|
| 42 | Window* updateDataWindow; //!< A Window for the data-update. |
|---|
| 43 | Box* updateDataBox; //!< A Box for the Window for the Data-update. |
|---|
| 44 | ProgressBar* updateDataBar; //!< A Bar to display the progress of the download. |
|---|
| 45 | Button* updateDataBegin; //!< A Button to start the process. |
|---|
| 46 | |
|---|
| 47 | Button* updateSourceWindowButton; //!< A Button to update the Source of orxonox. \todo tricky |
|---|
| 48 | Window* updateSourceWindow; //!< A Window for the Source-update. |
|---|
| 49 | Box* updateSourceBox; //!< A Box for the Window for the Source-update. |
|---|
| 50 | ProgressBar* updateSourceBar; //!< A Bar to display the progress of the download. |
|---|
| 51 | |
|---|
| 52 | Button* test; //!< will be deleted soon. |
|---|
| 53 | |
|---|
| 54 | #ifdef HAVE_GTK2 |
|---|
| 55 | static gint updateDataFunc(GtkWidget* w, GdkEventKey* event, void* info); |
|---|
| 56 | static gint updateSourceFunc(GtkWidget* w, GdkEventKey* event, void* info); |
|---|
| 57 | #endif /* HAVE_GTK2 */ |
|---|
| 58 | |
|---|
| 59 | #ifdef HAVE_CURL |
|---|
| 60 | //! A Struct to hold information about one File to download. |
|---|
| 61 | struct FileInfo |
|---|
| 62 | { |
|---|
| 63 | char* fileName; //!< The Name of the file we want to get. |
|---|
| 64 | char* webRoot; //!< The Root of the File on The Web |
|---|
| 65 | char* localRoot; //!< The Root directory to put the files on the local disk. |
|---|
| 66 | FILE* fileHandle; //!< A fileHandler. |
|---|
| 67 | |
|---|
| 68 | Button* stateButton; //!< A button that shows either start or cancel; |
|---|
| 69 | long int buttonSignal; //!< The Signal of the stateButton. |
|---|
| 70 | ProgressBar* bar; //!< The ProgressBar, that sould be updated. |
|---|
| 71 | }; |
|---|
| 72 | |
|---|
| 73 | static size_t curlWriteFunc(void* ptr, size_t size, size_t nmemb, FILE* stream); |
|---|
| 74 | static size_t curlReadFunc(void* ptr, size_t size, size_t nmemb, FILE* stream); |
|---|
| 75 | static int curlProgressFunc(ProgressBar* bar, double totalSize, double progress, double upTotal, double upProgress); |
|---|
| 76 | |
|---|
| 77 | static CURL* curlHandle; |
|---|
| 78 | #ifdef HAVE_GTK2 |
|---|
| 79 | static gint cancelDownload(GtkWidget* w, GdkEventKey* event, void* bar); |
|---|
| 80 | #endif /* HAVE_GTK2 */ |
|---|
| 81 | #ifdef HAVE_PTHREAD_H |
|---|
| 82 | static pthread_t* downloadThreadID; |
|---|
| 83 | static pthread_t* downloadThreadFinishID; |
|---|
| 84 | #endif /* HAVE_PTHREAD_H */ |
|---|
| 85 | static bool isDownloading; |
|---|
| 86 | |
|---|
| 87 | static bool download(void* fileInfo); |
|---|
| 88 | static bool downloadWithStyle(void* fileInfo); |
|---|
| 89 | static void* downloadThread(void* fileInfo); |
|---|
| 90 | static void* downloadThreadFinished(void* fileInfo); |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | #endif /* HAVE_CURL */ |
|---|
| 94 | |
|---|
| 95 | public: |
|---|
| 96 | OrxonoxGuiUpdate(void); |
|---|
| 97 | ~OrxonoxGuiUpdate(void); |
|---|
| 98 | |
|---|
| 99 | Widget* getWidget(void); |
|---|
| 100 | #ifdef HAVE_CURL |
|---|
| 101 | void updateDataWindowCreate(void); |
|---|
| 102 | Button* updateDataWindowGetButton(void); |
|---|
| 103 | |
|---|
| 104 | void updateSourceWindowCreate(void); |
|---|
| 105 | Button* updateSourceWindowGetButton(void); |
|---|
| 106 | |
|---|
| 107 | bool* checkForUpdates(void); |
|---|
| 108 | |
|---|
| 109 | #endif /* HAVE_CURL */ |
|---|
| 110 | |
|---|
| 111 | }; |
|---|
| 112 | |
|---|
| 113 | #endif /* _ORXONOX_GUI_UPDATE_H */ |
|---|