00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _UPDATERWINDOW_H
00023 #define _UPDATERWINDOW_H
00024
00025 #include "gui/widgets/window.h"
00026
00027 #include "utils/mutex.h"
00028
00029 #include <guichan/actionlistener.hpp>
00030
00031 #include <string>
00032 #include <vector>
00033
00034 class BrowserBox;
00035 class Button;
00036 class ProgressBar;
00037 class ScrollArea;
00038
00039 struct SDL_Thread;
00040
00046 class UpdaterWindow : public Window, public gcn::ActionListener
00047 {
00048 public:
00056 UpdaterWindow(const std::string &updateHost,
00057 const std::string &updatesDir);
00058
00062 ~UpdaterWindow();
00063
00067 void setProgress(float p);
00068
00072 void setLabel(const std::string &);
00073
00077 void enable();
00078
00083 void loadNews();
00084
00085 void action(const gcn::ActionEvent &event);
00086
00087 void logic();
00088
00089 int updateState;
00090
00091 private:
00092 void download();
00093
00097 static int downloadThread(void *ptr);
00098
00102 static int updateProgress(void *ptr,
00103 double dt, double dn, double ut, double un);
00104
00108 static size_t memoryWrite(void *ptr, size_t size, size_t nmemb,
00109 FILE *stream);
00110
00111 enum DownloadStatus
00112 {
00113 UPDATE_ERROR,
00114 UPDATE_IDLE,
00115 UPDATE_LIST,
00116 UPDATE_COMPLETE,
00117 UPDATE_NEWS,
00118 UPDATE_RESOURCES
00119 };
00120
00122 SDL_Thread *mThread;
00123
00125 DownloadStatus mDownloadStatus;
00126
00128 std::string mUpdateHost;
00129
00131 std::string mUpdatesDir;
00132
00134 std::string mCurrentFile;
00135
00137 std::string mNewLabelCaption;
00138
00140 Mutex mLabelMutex;
00141
00143 unsigned long mCurrentChecksum;
00144
00146 bool mStoreInMemory;
00147
00149 bool mDownloadComplete;
00150
00152 bool mUserCancel;
00153
00155 int mDownloadedBytes;
00156
00158 char *mMemoryBuffer;
00159
00161 char *mCurlError;
00162
00164 std::vector<std::string> mLines;
00165
00167 unsigned int mLineIndex;
00168
00169 gcn::Label *mLabel;
00170 Button *mCancelButton;
00171 Button *mPlayButton;
00172 ProgressBar *mProgressBar;
00173 BrowserBox *mBrowserBox;
00174 ScrollArea *mScrollArea;
00175 };
00176
00177 #endif