-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmainwindow.h
264 lines (202 loc) · 5.49 KB
/
mainwindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui>
#include <QtCore>
#include <QtNetwork>
namespace Ui
{
class MainWindow;
}
typedef QMap<QString,QVariant> ArgMap;
class UpdateWidget;
class GameInfo {
public:
GameInfo() {
}
GameInfo( const GameInfo &info ) {
m_name = info.m_name;
m_title = info.m_title;
m_version = info.m_version;
m_lang = info.m_lang;
m_size = info.m_size;
}
virtual ~GameInfo() {
}
void setName( const QString &name ) {
m_name = name;
}
void setTitle( const QString &title ) {
m_title = title;
}
void setVersion( const QString &version ) {
m_version = version;
}
void setLang( const QString &lang ) {
m_lang = lang;
}
void setSize( const QString &size ) {
m_size = size;
}
QString name() const {
return m_name;
}
QString title() const {
return m_title;
}
QString version() const {
return m_version;
}
QString lang() const {
return m_lang;
}
QString size() const {
QString size = QObject::tr( "unknown" ); //результат
bool convert_ok;
double res = m_size.toInt(&convert_ok) / 1024.0 / 1024.0; //размер в МБ
//Если размер задан
if(convert_ok) {
res = ceil(res*10)/10; //округление до десятых
QString unt = QObject::tr( "MB" ); //единица измерения
//Если значение получилось низким, то делаем в КБ
if(res < 0.2) {
res = m_size.toInt() / 1024.0;
res = ceil(res*10)/10;
unt = QObject::tr( "KB" );
}
size = QString::number(res) + unt; //преобразуем результат в строку
}
return size;
}
virtual GameInfo operator=( const GameInfo &info ) {
m_name = info.m_name;
m_title = info.m_title;
m_version = info.m_version;
m_lang = info.m_lang;
m_size = info.m_size;
return *this;
}
bool operator==( const GameInfo &info ) {
return ( m_name == info.m_name ) && ( m_version == info.m_version ); // && ( m_lang == info.m_lang );
}
private:
QString m_name;
QString m_title;
QString m_version;
QString m_lang;
QString m_size;
};
class NetGameInfo : public GameInfo {
public:
NetGameInfo() {
}
NetGameInfo( const NetGameInfo &info ) : GameInfo( info ) {
m_url = info.m_url;
m_md5 = info.m_md5;
m_instead = info.m_instead;
m_descUrl = info.m_descUrl;
m_depends = info.m_depends;
}
virtual NetGameInfo operator=( const NetGameInfo &info ) {
GameInfo::operator=( info );
m_url = info.m_url;
m_md5 = info.m_md5;
m_instead = info.m_instead;
m_descUrl = info.m_descUrl;
m_depends = info.m_depends;
return *this;
}
virtual ~NetGameInfo() {
}
void setUrl( const QString &url ) {
m_url = url;
}
void setMD5( const QString &md5 ) {
m_md5 = md5;
}
void setInstead( const QString &instead ) {
m_instead = instead;
}
void setDescUrl( const QString &descUrl ) {
m_descUrl = descUrl;
}
void setDepends( const QStringList &depends ) {
m_depends = depends;
}
QString url() {
return m_url;
}
QString MD5() {
return m_md5;
}
QString instead() {
return m_instead;
}
QString descUrl() {
return m_descUrl;
}
QStringList depends() {
return m_depends;
}
private:
QString m_url;
QString m_md5;
QString m_instead;
QString m_descUrl;
QStringList m_depends;
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(const ArgMap &argMap, QWidget *parent = 0);
~MainWindow();
private:
ArgMap args;
QList<QTreeWidgetItem *> findEssentialGames( QTreeWidgetItem * );
bool getLocalGameInfo( const QDir gameDir, const QString gameID, GameInfo &info );
bool hasLocalGame( const GameInfo & );
void parseGameList( QXmlStreamReader *xml );
void parseGameInfo( QXmlStreamReader *xml );
bool downloadGame(QTreeWidgetItem *game);
// QString getGameDirPath() const;
// QString getDefaultInterpreterPath() const;
// QString getConfigPath() const;
// bool checkOrCreateGameDir(QString gameDir);
void resetConfig();
void loadConfig();
void saveConfig();
QNetworkProxy *m_networkProxy;
UpdateWidget *m_swUpdateWidget;
QTemporaryFile *m_gameFile;
QHttp *m_listServer, *m_gameServer;
QProgressDialog *m_listLoadProgress, *m_gameLoadProgress;
QString m_downloadingFileName;
QProcess *m_process;
Ui::MainWindow *m_ui;
bool listIsDirty;
private slots:
void refreshLocalGameList();
void refreshNetGameList(bool next=false);
void installSelectedGame();
void resetPushButtonClicked();
void detailsLinkClicked( const QString & );
void playSelectedGame();
void browseInsteadPath();
void browseGamesPath();
void removeSelectedGame();
void abortGameDownloading();
void abortGameListDownloading();
void listServerDone( bool );
void gameServerResponseHeaderReceived( const QHttpResponseHeader & );
void gameServerDone( bool error );
void processFinished( int exitCode, QProcess::ExitStatus exitStatus );
void processStarted();
void processError( QProcess::ProcessError );
void addSourcePushButtonClicked();
void deleteSourcePushButtonClicked();
void gamesDirChanged();
void tabChanged(int pos);
void updateProxy();
void checkUpdates();
};
#endif // MAINWINDOW_H