equal
deleted
inserted
replaced
25 #include <QRegExp> |
25 #include <QRegExp> |
26 #include <QMap> |
26 #include <QMap> |
27 #include <QSettings> |
27 #include <QSettings> |
28 #include <QStringListModel> |
28 #include <QStringListModel> |
29 #include <QDate> |
29 #include <QDate> |
|
30 #include <QDesktopWidget> |
|
31 #include <QLabel> |
30 |
32 |
31 #include "hwform.h" |
33 #include "hwform.h" |
32 #include "hwconsts.h" |
34 #include "hwconsts.h" |
33 #include "newnetclient.h" |
35 #include "newnetclient.h" |
34 |
36 |
37 |
39 |
38 #include "frontlib.h" |
40 #include "frontlib.h" |
39 |
41 |
40 #ifdef _WIN32 |
42 #ifdef _WIN32 |
41 #include <Shlobj.h> |
43 #include <Shlobj.h> |
42 #endif |
44 #elif defined __APPLE__ |
43 #ifdef __APPLE__ |
|
44 #include "CocoaInitializer.h" |
45 #include "CocoaInitializer.h" |
|
46 #endif |
|
47 #ifndef _WIN32 |
|
48 #include <signal.h> |
45 #endif |
49 #endif |
46 |
50 |
47 |
51 |
48 //Determines the day of easter in year |
52 //Determines the day of easter in year |
49 //from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++ |
53 //from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++ |
85 else if (calculateEaster(date.year()) == date) |
89 else if (calculateEaster(date.year()) == date) |
86 season = SEASON_EASTER; |
90 season = SEASON_EASTER; |
87 else |
91 else |
88 season = SEASON_NONE; |
92 season = SEASON_NONE; |
89 } |
93 } |
|
94 #ifndef _WIN32 |
|
95 void terminateFrontend(int signal) |
|
96 { |
|
97 QCoreApplication::exit(0); |
|
98 } |
|
99 #endif |
90 |
100 |
91 bool checkForDir(const QString & dir) |
101 bool checkForDir(const QString & dir) |
92 { |
102 { |
93 QDir tmpdir(dir); |
103 QDir tmpdir(dir); |
94 if (!tmpdir.exists()) |
104 if (!tmpdir.exists()) |
134 // This creates the autoreleasepool that prevents leaking, and destroys it only on exit |
144 // This creates the autoreleasepool that prevents leaking, and destroys it only on exit |
135 cocoaInit = new CocoaInitializer(); |
145 cocoaInit = new CocoaInitializer(); |
136 atexit(releaseCocoaPool); |
146 atexit(releaseCocoaPool); |
137 #endif |
147 #endif |
138 |
148 |
|
149 #ifndef _WIN32 |
|
150 signal(SIGINT, &terminateFrontend); |
|
151 #endif |
|
152 |
139 HWApplication app(argc, argv); |
153 HWApplication app(argc, argv); |
|
154 |
|
155 QLabel *splash = NULL; |
|
156 #if defined Q_WS_WIN |
|
157 QPixmap pixmap(":res/splash.png"); |
|
158 splash = new QLabel(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint); |
|
159 splash->setAttribute(Qt::WA_TranslucentBackground); |
|
160 const QRect deskSize = QApplication::desktop()->screenGeometry(-1); |
|
161 QPoint splashCenter = QPoint( (deskSize.width() - pixmap.width())/2, |
|
162 (deskSize.height() - pixmap.height())/2 ); |
|
163 splash->move(splashCenter); |
|
164 splash->setPixmap(pixmap); |
|
165 splash->show(); |
|
166 #endif |
140 |
167 |
141 FileEngineHandler engine(argv[0]); |
168 FileEngineHandler engine(argv[0]); |
142 |
169 |
143 flib_init(); |
170 flib_init(); |
144 |
171 |
177 } |
204 } |
178 |
205 |
179 if(parsedArgs.contains("config-dir")) |
206 if(parsedArgs.contains("config-dir")) |
180 { |
207 { |
181 QFileInfo f(parsedArgs["config-dir"]); |
208 QFileInfo f(parsedArgs["config-dir"]); |
182 *cConfigDir = f.absoluteFilePath(); |
209 cfgdir->setPath(f.absoluteFilePath()); |
183 custom_config = true; |
210 custom_config = true; |
|
211 } |
|
212 else |
|
213 { |
|
214 cfgdir->setPath(QDir::homePath()); |
|
215 custom_config = false; |
184 } |
216 } |
185 |
217 |
186 app.setStyle(new QPlastiqueStyle()); |
218 app.setStyle(new QPlastiqueStyle()); |
187 |
219 |
188 QDateTime now = QDateTime::currentDateTime(); |
220 QDateTime now = QDateTime::currentDateTime(); |
191 |
223 |
192 Q_INIT_RESOURCE(hedgewars); |
224 Q_INIT_RESOURCE(hedgewars); |
193 |
225 |
194 qRegisterMetaType<HWTeam>("HWTeam"); |
226 qRegisterMetaType<HWTeam>("HWTeam"); |
195 |
227 |
196 bindir->cd("bin"); // workaround over NSIS installer |
228 bindir->cd(QCoreApplication::applicationDirPath()); |
197 |
229 |
198 if(cConfigDir->length() == 0) |
230 if(custom_config == false) |
199 cfgdir->setPath(cfgdir->homePath()); |
|
200 else |
|
201 cfgdir->setPath(*cConfigDir); |
|
202 |
|
203 if(cConfigDir->length() == 0) |
|
204 { |
231 { |
205 #ifdef __APPLE__ |
232 #ifdef __APPLE__ |
206 checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"); |
233 checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"); |
207 cfgdir->cd("Library/Application Support/Hedgewars"); |
234 cfgdir->cd("Library/Application Support/Hedgewars"); |
208 #elif defined _WIN32 |
235 #elif defined _WIN32 |
239 checkForDir(cfgdir->absolutePath() + "/VideoTemp"); |
266 checkForDir(cfgdir->absolutePath() + "/VideoTemp"); |
240 } |
267 } |
241 |
268 |
242 datadir->cd(bindir->absolutePath()); |
269 datadir->cd(bindir->absolutePath()); |
243 datadir->cd(*cDataDir); |
270 datadir->cd(*cDataDir); |
244 if(!datadir->cd("hedgewars/Data")) |
271 if(!datadir->cd("Data")) |
245 { |
272 { |
246 QMessageBox missingMsg(QApplication::activeWindow()); |
273 QMessageBox missingMsg(QApplication::activeWindow()); |
247 missingMsg.setIcon(QMessageBox::Critical); |
274 missingMsg.setIcon(QMessageBox::Critical); |
248 missingMsg.setWindowTitle(QMessageBox::tr("Main - Error")); |
275 missingMsg.setWindowTitle(QMessageBox::tr("Main - Error")); |
249 missingMsg.setText(QMessageBox::tr("Failed to open data directory:\n%1\n\n" |
276 missingMsg.setText(QMessageBox::tr("Failed to open data directory:\n%1\n\n" |
250 "Please check your installation!"). |
277 "Please check your installation!"). |
251 arg(datadir->absolutePath()+"/hedgewars/Data")); |
278 arg(datadir->absolutePath()+"/Data")); |
252 missingMsg.setWindowModality(Qt::WindowModal); |
279 missingMsg.setWindowModality(Qt::WindowModal); |
253 missingMsg.exec(); |
280 missingMsg.exec(); |
254 return 1; |
281 return 1; |
255 } |
282 } |
256 |
283 |
305 case SEASON_HWBDAY : |
332 case SEASON_HWBDAY : |
306 fname = "birthday.css"; |
333 fname = "birthday.css"; |
307 break; |
334 break; |
308 default : |
335 default : |
309 fname = "qt.css"; |
336 fname = "qt.css"; |
|
337 break; |
310 } |
338 } |
311 |
339 |
312 // load external stylesheet if there is any |
340 // load external stylesheet if there is any |
313 QFile extFile("physfs://css/" + fname); |
341 QFile extFile("physfs://css/" + fname); |
314 |
342 |
319 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
347 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
320 style.append(file.readAll()); |
348 style.append(file.readAll()); |
321 |
349 |
322 app.form = new HWForm(NULL, style); |
350 app.form = new HWForm(NULL, style); |
323 app.form->show(); |
351 app.form->show(); |
|
352 |
|
353 if(splash) |
|
354 splash->close(); |
|
355 |
324 int r = app.exec(); |
356 int r = app.exec(); |
325 |
357 |
326 flib_quit(); |
358 flib_quit(); |
327 |
359 |
328 return r; |
360 return r; |