1 | /*! |
---|
2 | \file gui_update.h |
---|
3 | \brief File that holds the class that creates the update-menu. |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _GUI_UPDATE_H |
---|
7 | #define _GUI_UPDATE_H |
---|
8 | |
---|
9 | #include "gui.h" |
---|
10 | #include "gui_element.h" |
---|
11 | #include "gui_gtk.h" |
---|
12 | |
---|
13 | |
---|
14 | #define DATA_IDENTIFIER "data.oxd" |
---|
15 | |
---|
16 | #include <stdio.h> |
---|
17 | #ifdef HAVE_CURL |
---|
18 | #include <curl/curl.h> |
---|
19 | #include <curl/types.h> |
---|
20 | #include <curl/easy.h> |
---|
21 | #endif /* HAVE_CURL */ |
---|
22 | #ifdef HAVE_PTHREAD_H |
---|
23 | #define _MULTI_THREADED |
---|
24 | #include <pthread.h> |
---|
25 | #endif /* HAVE_PTHREAD_H */ |
---|
26 | using namespace std; |
---|
27 | |
---|
28 | //! Class that creates the execute-Options. |
---|
29 | class GuiUpdate : public GuiElement |
---|
30 | { |
---|
31 | private: |
---|
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 | |
---|
39 | bool getSystemInfo(); |
---|
40 | |
---|
41 | // Window creation. |
---|
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. |
---|
45 | |
---|
46 | |
---|
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. |
---|
52 | |
---|
53 | Button* updateSourceWindowButton; //!< A Button to update the Source of orxonox. @todo tricky |
---|
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. |
---|
57 | |
---|
58 | Button* test; //!< will be deleted soon. |
---|
59 | |
---|
60 | #ifdef HAVE_GTK2 |
---|
61 | static gint updateDataFunc(GtkWidget* w, GdkEventKey* event, void* info); |
---|
62 | static gint updateSourceFunc(GtkWidget* w, GdkEventKey* event, void* info); |
---|
63 | #endif /* HAVE_GTK2 */ |
---|
64 | |
---|
65 | static bool checkDataDir(const char* fileName, void* object); |
---|
66 | |
---|
67 | #ifdef HAVE_CURL |
---|
68 | //! A Struct to hold information about one File to download. |
---|
69 | struct FileInfo |
---|
70 | { |
---|
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. |
---|
75 | |
---|
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. |
---|
79 | }; |
---|
80 | |
---|
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); |
---|
84 | |
---|
85 | static CURL* curlHandle; |
---|
86 | #ifdef HAVE_GTK2 |
---|
87 | static gint cancelDownload(GtkWidget* w, GdkEventKey* event, void* bar); |
---|
88 | #endif /* HAVE_GTK2 */ |
---|
89 | static bool isDownloading; |
---|
90 | static bool downloadCanceled; |
---|
91 | |
---|
92 | static bool download(void* fileInfo); |
---|
93 | static bool downloadWithStyle(void* fileInfo); |
---|
94 | static void* downloadThread(void* fileInfo); |
---|
95 | static void* downloadThreadFinished(void* fileInfo); |
---|
96 | |
---|
97 | |
---|
98 | #endif /* HAVE_CURL */ |
---|
99 | |
---|
100 | public: |
---|
101 | GuiUpdate(); |
---|
102 | ~GuiUpdate(); |
---|
103 | |
---|
104 | #ifdef HAVE_CURL |
---|
105 | void updateDataWindowCreate(); |
---|
106 | Button* updateDataWindowGetButton(); |
---|
107 | |
---|
108 | void updateSourceWindowCreate(); |
---|
109 | Button* updateSourceWindowGetButton(); |
---|
110 | |
---|
111 | bool* checkForUpdates(); |
---|
112 | |
---|
113 | #endif /* HAVE_CURL */ |
---|
114 | |
---|
115 | }; |
---|
116 | |
---|
117 | #endif /* _GUI_UPDATE_H */ |
---|