[3250] | 1 | /*! |
---|
[4048] | 2 | \file gui_update.h |
---|
[3250] | 3 | \brief File that holds the class that creates the update-menu. |
---|
| 4 | */ |
---|
| 5 | |
---|
[4048] | 6 | #ifndef _GUI_UPDATE_H |
---|
| 7 | #define _GUI_UPDATE_H |
---|
[3250] | 8 | |
---|
[4047] | 9 | #include "gui.h" |
---|
| 10 | #include "gui_element.h" |
---|
[4049] | 11 | #include "gui_gtk.h" |
---|
[4024] | 12 | |
---|
[4083] | 13 | |
---|
| 14 | #define DATA_IDENTIFIER "data.oxd" |
---|
| 15 | |
---|
[3250] | 16 | #include <stdio.h> |
---|
[3270] | 17 | #ifdef HAVE_CURL |
---|
| 18 | #include <curl/curl.h> |
---|
| 19 | #include <curl/types.h> |
---|
| 20 | #include <curl/easy.h> |
---|
| 21 | #endif /* HAVE_CURL */ |
---|
[3273] | 22 | #ifdef HAVE_PTHREAD_H |
---|
[3275] | 23 | #define _MULTI_THREADED |
---|
[3272] | 24 | #include <pthread.h> |
---|
[3273] | 25 | #endif /* HAVE_PTHREAD_H */ |
---|
[3250] | 26 | using namespace std; |
---|
| 27 | |
---|
| 28 | //! Class that creates the execute-Options. |
---|
[4056] | 29 | class GuiUpdate : public GuiElement |
---|
[3250] | 30 | { |
---|
| 31 | private: |
---|
[3285] | 32 | // Defining Variables |
---|
| 33 | char* tmpDir; //!< The Temporary directory. |
---|
| 34 | char* homeDir; //!< The Home directory. |
---|
| 35 | char* installDataDir; //!< Where to install the Data to. |
---|
| 36 | char* installSourceDir; //!< Where to install the Source to. |
---|
| 37 | char* userName; //!< The user logged in. |
---|
| 38 | |
---|
[4746] | 39 | bool getSystemInfo(); |
---|
[4944] | 40 | |
---|
[3285] | 41 | // Window creation. |
---|
[3284] | 42 | Frame* updateFrame; //!< The Frame that holds the updateOptions. |
---|
| 43 | Box* updateBox; //!< The Box that holds the updateOptions. |
---|
| 44 | CheckButton* autoUpdate; //!< A Checkbutton to enable the automatic Updating. |
---|
[3261] | 45 | |
---|
[4944] | 46 | |
---|
[3284] | 47 | Button* updateDataWindowButton; //!< A Button to update the Data of orxonox. |
---|
| 48 | Window* updateDataWindow; //!< A Window for the data-update. |
---|
| 49 | Box* updateDataBox; //!< A Box for the Window for the Data-update. |
---|
| 50 | ProgressBar* updateDataBar; //!< A Bar to display the progress of the download. |
---|
| 51 | Button* updateDataBegin; //!< A Button to start the process. |
---|
[3257] | 52 | |
---|
[4836] | 53 | Button* updateSourceWindowButton; //!< A Button to update the Source of orxonox. @todo tricky |
---|
[3284] | 54 | Window* updateSourceWindow; //!< A Window for the Source-update. |
---|
| 55 | Box* updateSourceBox; //!< A Box for the Window for the Source-update. |
---|
| 56 | ProgressBar* updateSourceBar; //!< A Bar to display the progress of the download. |
---|
[3259] | 57 | |
---|
[3284] | 58 | Button* test; //!< will be deleted soon. |
---|
[3285] | 59 | |
---|
| 60 | #ifdef HAVE_GTK2 |
---|
[3315] | 61 | static gint updateDataFunc(GtkWidget* w, GdkEventKey* event, void* info); |
---|
| 62 | static gint updateSourceFunc(GtkWidget* w, GdkEventKey* event, void* info); |
---|
[3256] | 63 | #endif /* HAVE_GTK2 */ |
---|
[3254] | 64 | |
---|
[4083] | 65 | static bool checkDataDir(const char* fileName, void* object); |
---|
| 66 | |
---|
[3263] | 67 | #ifdef HAVE_CURL |
---|
[3267] | 68 | //! A Struct to hold information about one File to download. |
---|
[3263] | 69 | struct FileInfo |
---|
| 70 | { |
---|
[3284] | 71 | char* fileName; //!< The Name of the file we want to get. |
---|
| 72 | char* webRoot; //!< The Root of the File on The Web |
---|
| 73 | char* localRoot; //!< The Root directory to put the files on the local disk. |
---|
| 74 | FILE* fileHandle; //!< A fileHandler. |
---|
[3267] | 75 | |
---|
[3284] | 76 | Button* stateButton; //!< A button that shows either start or cancel; |
---|
| 77 | long int buttonSignal; //!< The Signal of the stateButton. |
---|
| 78 | ProgressBar* bar; //!< The ProgressBar, that sould be updated. |
---|
[3263] | 79 | }; |
---|
[3254] | 80 | |
---|
[3315] | 81 | static size_t curlWriteFunc(void* ptr, size_t size, size_t nmemb, FILE* stream); |
---|
| 82 | static size_t curlReadFunc(void* ptr, size_t size, size_t nmemb, FILE* stream); |
---|
| 83 | static int curlProgressFunc(ProgressBar* bar, double totalSize, double progress, double upTotal, double upProgress); |
---|
[3263] | 84 | |
---|
[3270] | 85 | static CURL* curlHandle; |
---|
[4944] | 86 | #ifdef HAVE_GTK2 |
---|
[3268] | 87 | static gint cancelDownload(GtkWidget* w, GdkEventKey* event, void* bar); |
---|
[4944] | 88 | #endif /* HAVE_GTK2 */ |
---|
[3272] | 89 | static bool isDownloading; |
---|
[4061] | 90 | static bool downloadCanceled; |
---|
[3272] | 91 | |
---|
[3315] | 92 | static bool download(void* fileInfo); |
---|
| 93 | static bool downloadWithStyle(void* fileInfo); |
---|
| 94 | static void* downloadThread(void* fileInfo); |
---|
[3274] | 95 | static void* downloadThreadFinished(void* fileInfo); |
---|
[3271] | 96 | |
---|
[4944] | 97 | |
---|
[3263] | 98 | #endif /* HAVE_CURL */ |
---|
| 99 | |
---|
[3250] | 100 | public: |
---|
[4746] | 101 | GuiUpdate(); |
---|
[6981] | 102 | virtual ~GuiUpdate(); |
---|
[4944] | 103 | |
---|
| 104 | #ifdef HAVE_CURL |
---|
[4746] | 105 | void updateDataWindowCreate(); |
---|
| 106 | Button* updateDataWindowGetButton(); |
---|
[3259] | 107 | |
---|
[4746] | 108 | void updateSourceWindowCreate(); |
---|
| 109 | Button* updateSourceWindowGetButton(); |
---|
[3298] | 110 | |
---|
[4746] | 111 | bool* checkForUpdates(); |
---|
[4944] | 112 | |
---|
[3285] | 113 | #endif /* HAVE_CURL */ |
---|
| 114 | |
---|
[3250] | 115 | }; |
---|
| 116 | |
---|
[4048] | 117 | #endif /* _GUI_UPDATE_H */ |
---|