author | dag10 |
Mon, 21 Jan 2013 14:07:39 -0500 | |
changeset 8419 | d99f46b676b5 |
parent 8406 | 8a834943609d |
child 8508 | f849b7b3af1d |
permissions | -rw-r--r-- |
579 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
6952 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
579 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
5252 | 19 |
#include "HWApplication.h" |
20 |
||
579 | 21 |
#include <QTranslator> |
22 |
#include <QLocale> |
|
23 |
#include <QMessageBox> |
|
1416
60b86d6fe9ae
Force plastique style, as others don't fully support stylesheets
unc0rr
parents:
1415
diff
changeset
|
24 |
#include <QPlastiqueStyle> |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
25 |
#include <QRegExp> |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
26 |
#include <QMap> |
2898 | 27 |
#include <QSettings> |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
28 |
#include <QStringListModel> |
6579 | 29 |
#include <QDate> |
8337
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
30 |
#include <QDesktopWidget> |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
31 |
#include <QLabel> |
1146 | 32 |
|
579 | 33 |
#include "hwform.h" |
34 |
#include "hwconsts.h" |
|
6721
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6700
diff
changeset
|
35 |
#include "newnetclient.h" |
579 | 36 |
|
6930 | 37 |
#include "DataManager.h" |
7768 | 38 |
#include "FileEngine.h" |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6129
diff
changeset
|
39 |
|
3333 | 40 |
#ifdef _WIN32 |
41 |
#include <Shlobj.h> |
|
8355 | 42 |
#elif defined __APPLE__ |
43 |
#include "CocoaInitializer.h" |
|
3333 | 44 |
#endif |
8355 | 45 |
#ifndef _WIN32 |
46 |
#include <signal.h> |
|
5095
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
47 |
#endif |
3333 | 48 |
|
8405
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
49 |
// Program resources |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
50 |
#ifdef __APPLE__ |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
51 |
static CocoaInitializer * cocoaInit = NULL; |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
52 |
#endif |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
53 |
static FileEngineHandler * engine = NULL; |
6579 | 54 |
|
55 |
//Determines the day of easter in year |
|
56 |
//from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++ |
|
57 |
QDate calculateEaster(long year) |
|
58 |
{ |
|
59 |
int c, n, k, i, j, l, m, d; |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
60 |
|
6579 | 61 |
c = year/100; |
62 |
n = year - 19*(year/19); |
|
63 |
k = (c - 17)/25; |
|
64 |
i = c - c/4 - (c - k)/3 + 19*n + 15; |
|
65 |
i = i - 30*(i/30); |
|
66 |
i = i - (i/28)*(1 - (i/28)*(29/(i + 1))*((21 - n)/11)); |
|
67 |
j = year + year/4 + i + 2 - c + c/4; |
|
68 |
j = j - 7*(j/7); |
|
69 |
l = i - j; |
|
70 |
m = 3 + (l + 40)/44; |
|
71 |
d = l + 28 - 31*(m / 4); |
|
72 |
||
73 |
return QDate(year, m, d); |
|
74 |
} |
|
75 |
||
76 |
//Checks season and assigns it to the variable season in "hwconsts.h" |
|
77 |
void checkSeason() |
|
78 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
79 |
QDate date = QDate::currentDate(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
80 |
|
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
81 |
//Christmas? |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
82 |
if (date.month() == 12 && date.day() >= 24 |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
83 |
&& date.day() <= 26) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
84 |
season = SEASON_CHRISTMAS; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
85 |
//Hedgewars birthday? |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
86 |
else if (date.month() == 10 && date.day() == 31) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
87 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
88 |
season = SEASON_HWBDAY; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
89 |
years_since_foundation = date.year() - 2004; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
90 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
91 |
//Easter? |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
92 |
else if (calculateEaster(date.year()) == date) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
93 |
season = SEASON_EASTER; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
94 |
else |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
95 |
season = SEASON_NONE; |
6579 | 96 |
} |
8355 | 97 |
#ifndef _WIN32 |
98 |
void terminateFrontend(int signal) |
|
99 |
{ |
|
8385
9e8924ff9813
Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents:
8355
diff
changeset
|
100 |
Q_UNUSED(signal); |
9e8924ff9813
Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents:
8355
diff
changeset
|
101 |
|
8355 | 102 |
QCoreApplication::exit(0); |
103 |
} |
|
104 |
#endif |
|
6579 | 105 |
|
579 | 106 |
bool checkForDir(const QString & dir) |
107 |
{ |
|
8206 | 108 |
QDir tmpdir(dir); |
109 |
if (!tmpdir.exists()) |
|
110 |
if (!tmpdir.mkpath(dir)) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
111 |
{ |
7794
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
112 |
QMessageBox directoryMsg(QApplication::activeWindow()); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
113 |
directoryMsg.setIcon(QMessageBox::Warning); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
114 |
directoryMsg.setWindowTitle(QMessageBox::tr("Main - Error")); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
115 |
directoryMsg.setText(QMessageBox::tr("Cannot create directory %1").arg(dir)); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
116 |
directoryMsg.setWindowModality(Qt::WindowModal); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
117 |
directoryMsg.exec(); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
118 |
return false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
119 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
120 |
return true; |
579 | 121 |
} |
122 |
||
8206 | 123 |
bool checkForFile(const QString & file) |
124 |
{ |
|
125 |
QFile tmpfile(file); |
|
126 |
if (!tmpfile.exists()) |
|
127 |
return tmpfile.open(QFile::WriteOnly); |
|
128 |
else |
|
129 |
return true; |
|
130 |
} |
|
131 |
||
8405
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
132 |
// Guaranteed to be the last thing ran in the application's life time. |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
133 |
// Closes resources that need to exist as long as possible. |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
134 |
void closeResources(void) |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
135 |
{ |
8187
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
136 |
#ifdef __APPLE__ |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
137 |
if (cocoaInit != NULL) |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
138 |
{ |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
139 |
delete cocoaInit; |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
140 |
cocoaInit = NULL; |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
141 |
} |
8405
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
142 |
#endif |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
143 |
if (engine != NULL) |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
144 |
{ |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
145 |
delete engine; |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
146 |
engine = NULL; |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
147 |
} |
8187
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
148 |
} |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
149 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
150 |
int main(int argc, char *argv[]) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
151 |
{ |
8406
8a834943609d
Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents:
8405
diff
changeset
|
152 |
// Since we're calling this first, closeResources() will be the last thing called after main() returns. |
8a834943609d
Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents:
8405
diff
changeset
|
153 |
atexit(closeResources); |
8a834943609d
Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents:
8405
diff
changeset
|
154 |
|
8187
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
155 |
#ifdef __APPLE__ |
8406
8a834943609d
Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents:
8405
diff
changeset
|
156 |
cocoaInit = new CocoaInitializer(); // Creates the autoreleasepool preventing cocoa object leaks on OS X. |
8187
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
157 |
#endif |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
158 |
|
8355 | 159 |
#ifndef _WIN32 |
160 |
signal(SIGINT, &terminateFrontend); |
|
161 |
#endif |
|
162 |
||
5252 | 163 |
HWApplication app(argc, argv); |
7130 | 164 |
|
8337
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
165 |
QLabel *splash = NULL; |
8344 | 166 |
#if defined Q_WS_WIN |
8337
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
167 |
QPixmap pixmap(":res/splash.png"); |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
168 |
splash = new QLabel(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint); |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
169 |
splash->setAttribute(Qt::WA_TranslucentBackground); |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
170 |
const QRect deskSize = QApplication::desktop()->screenGeometry(-1); |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
171 |
QPoint splashCenter = QPoint( (deskSize.width() - pixmap.width())/2, |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
172 |
(deskSize.height() - pixmap.height())/2 ); |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
173 |
splash->move(splashCenter); |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
174 |
splash->setPixmap(pixmap); |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
175 |
splash->show(); |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
176 |
#endif |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
177 |
|
8405
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
178 |
engine = new FileEngineHandler(argv[0]); |
7768 | 179 |
|
4888 | 180 |
app.setAttribute(Qt::AA_DontShowIconsInMenus,false); |
579 | 181 |
|
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
182 |
QStringList arguments = app.arguments(); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
183 |
QMap<QString, QString> parsedArgs; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
184 |
{ |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
185 |
QList<QString>::iterator i = arguments.begin(); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
186 |
while(i != arguments.end()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
187 |
{ |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
188 |
QString arg = *i; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
189 |
|
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
190 |
QRegExp opt("--(\\S+)=(.+)"); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
191 |
if(opt.exactMatch(arg)) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
192 |
{ |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
193 |
parsedArgs[opt.cap(1)] = opt.cap(2); |
2035 | 194 |
i = arguments.erase(i); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
195 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
196 |
else |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
197 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
198 |
++i; |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
199 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
200 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
201 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
202 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
203 |
if(parsedArgs.contains("data-dir")) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
204 |
{ |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
205 |
QFileInfo f(parsedArgs["data-dir"]); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
206 |
if(!f.exists()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
207 |
{ |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
208 |
qWarning() << "WARNING: Cannot open DATA_PATH=" << f.absoluteFilePath(); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
209 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
210 |
*cDataDir = f.absoluteFilePath(); |
3932 | 211 |
custom_data = true; |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
212 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
213 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
214 |
if(parsedArgs.contains("config-dir")) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
215 |
{ |
2428 | 216 |
QFileInfo f(parsedArgs["config-dir"]); |
8323
ab0b618bdf13
get executable directory at runtime rather than configure time
koda
parents:
8316
diff
changeset
|
217 |
cfgdir->setPath(f.absoluteFilePath()); |
3932 | 218 |
custom_config = true; |
2428 | 219 |
} |
8323
ab0b618bdf13
get executable directory at runtime rather than configure time
koda
parents:
8316
diff
changeset
|
220 |
else |
ab0b618bdf13
get executable directory at runtime rather than configure time
koda
parents:
8316
diff
changeset
|
221 |
{ |
ab0b618bdf13
get executable directory at runtime rather than configure time
koda
parents:
8316
diff
changeset
|
222 |
cfgdir->setPath(QDir::homePath()); |
ab0b618bdf13
get executable directory at runtime rather than configure time
koda
parents:
8316
diff
changeset
|
223 |
custom_config = false; |
ab0b618bdf13
get executable directory at runtime rather than configure time
koda
parents:
8316
diff
changeset
|
224 |
} |
2428 | 225 |
|
7772 | 226 |
app.setStyle(new QPlastiqueStyle()); |
2377 | 227 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
228 |
QDateTime now = QDateTime::currentDateTime(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
229 |
srand(now.toTime_t()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
230 |
rand(); |
579 | 231 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
232 |
Q_INIT_RESOURCE(hedgewars); |
579 | 233 |
|
6721
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6700
diff
changeset
|
234 |
qRegisterMetaType<HWTeam>("HWTeam"); |
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6700
diff
changeset
|
235 |
|
8323
ab0b618bdf13
get executable directory at runtime rather than configure time
koda
parents:
8316
diff
changeset
|
236 |
bindir->cd(QCoreApplication::applicationDirPath()); |
579 | 237 |
|
8323
ab0b618bdf13
get executable directory at runtime rather than configure time
koda
parents:
8316
diff
changeset
|
238 |
if(custom_config == false) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
239 |
{ |
1965 | 240 |
#ifdef __APPLE__ |
3758 | 241 |
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
242 |
cfgdir->cd("Library/Application Support/Hedgewars"); |
3333 | 243 |
#elif defined _WIN32 |
244 |
char path[1024]; |
|
245 |
if(!SHGetFolderPathA(0, CSIDL_PERSONAL, NULL, 0, path)) |
|
246 |
{ |
|
247 |
cfgdir->cd(path); |
|
3758 | 248 |
checkForDir(cfgdir->absolutePath() + "/Hedgewars"); |
3333 | 249 |
cfgdir->cd("Hedgewars"); |
250 |
} |
|
3758 | 251 |
else // couldn't retrieve documents folder? almost impossible, but in case fall back to classic path |
3333 | 252 |
{ |
3758 | 253 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars"); |
3333 | 254 |
cfgdir->cd(".hedgewars"); |
255 |
} |
|
2428 | 256 |
#else |
3758 | 257 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
258 |
cfgdir->cd(".hedgewars"); |
2428 | 259 |
#endif |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
260 |
} |
3758 | 261 |
|
262 |
if (checkForDir(cfgdir->absolutePath())) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
263 |
{ |
3758 | 264 |
// alternative loading/lookup paths |
265 |
checkForDir(cfgdir->absolutePath() + "/Data"); |
|
266 |
||
267 |
// config/save paths |
|
268 |
checkForDir(cfgdir->absolutePath() + "/Demos"); |
|
269 |
checkForDir(cfgdir->absolutePath() + "/Saves"); |
|
270 |
checkForDir(cfgdir->absolutePath() + "/Screenshots"); |
|
271 |
checkForDir(cfgdir->absolutePath() + "/Teams"); |
|
3914 | 272 |
checkForDir(cfgdir->absolutePath() + "/Logs"); |
7180 | 273 |
checkForDir(cfgdir->absolutePath() + "/Videos"); |
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
274 |
checkForDir(cfgdir->absolutePath() + "/VideoTemp"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
275 |
} |
579 | 276 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
277 |
datadir->cd(bindir->absolutePath()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
278 |
datadir->cd(*cDataDir); |
8316
89232b2fa1d6
cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents:
8223
diff
changeset
|
279 |
if(!datadir->cd("Data")) |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
280 |
{ |
7794
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
281 |
QMessageBox missingMsg(QApplication::activeWindow()); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
282 |
missingMsg.setIcon(QMessageBox::Critical); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
283 |
missingMsg.setWindowTitle(QMessageBox::tr("Main - Error")); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
284 |
missingMsg.setText(QMessageBox::tr("Failed to open data directory:\n%1\n\n" |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
285 |
"Please check your installation!"). |
8316
89232b2fa1d6
cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents:
8223
diff
changeset
|
286 |
arg(datadir->absolutePath()+"/Data")); |
7794
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
287 |
missingMsg.setWindowModality(Qt::WindowModal); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7724
diff
changeset
|
288 |
missingMsg.exec(); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
289 |
return 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
290 |
} |
579 | 291 |
|
7931 | 292 |
// setup PhysFS |
8405
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
293 |
engine->mount(datadir->absolutePath()); |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
294 |
engine->mount(cfgdir->absolutePath() + "/Data"); |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
295 |
engine->mount(cfgdir->absolutePath()); |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
296 |
engine->setWriteDir(cfgdir->absolutePath()); |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
297 |
engine->mountPacks(); |
7772 | 298 |
|
8206 | 299 |
checkForFile("physfs://hedgewars.ini"); |
300 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
301 |
QTranslator Translator; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
302 |
{ |
8098 | 303 |
QSettings settings("physfs://hedgewars.ini", QSettings::IniFormat); |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
304 |
QString cc = settings.value("misc/locale", QString()).toString(); |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
305 |
if(cc.isEmpty()) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
306 |
cc = QLocale::system().name(); |
6167 | 307 |
|
308 |
// load locale file into translator |
|
7931 | 309 |
if(!Translator.load(QString("physfs://Locale/hedgewars_%1").arg(cc))) |
310 |
qWarning("Failed to install translation"); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
311 |
app.installTranslator(&Translator); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
312 |
} |
2898 | 313 |
|
5756 | 314 |
#ifdef _WIN32 |
3679 | 315 |
// Win32 registry setup (used for xfire detection etc. - don't set it if we're running in "portable" mode with a custom config dir) |
3932 | 316 |
if(!custom_config) |
3679 | 317 |
{ |
3932 | 318 |
QSettings registry_hklm("HKEY_LOCAL_MACHINE", QSettings::NativeFormat); |
319 |
registry_hklm.setValue("Software/Hedgewars/Frontend", bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe"); |
|
320 |
registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\")); |
|
3679 | 321 |
} |
322 |
#endif |
|
6178
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
323 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
324 |
QString style = ""; |
6579 | 325 |
QString fname; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
326 |
|
6579 | 327 |
checkSeason(); |
328 |
//For each season, there is an extra stylesheet |
|
329 |
//Todo: change background for easter and birthday |
|
330 |
//(simply replace res/BackgroundBirthday.png and res/BackgroundEaster.png |
|
331 |
//with an appropriate background |
|
332 |
switch (season) |
|
333 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
334 |
case SEASON_CHRISTMAS : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
335 |
fname = "christmas.css"; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
336 |
break; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
337 |
case SEASON_EASTER : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
338 |
fname = "easter.css"; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
339 |
break; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
340 |
case SEASON_HWBDAY : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
341 |
fname = "birthday.css"; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
342 |
break; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
343 |
default : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
344 |
fname = "qt.css"; |
8337
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
345 |
break; |
6579 | 346 |
} |
6178
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
347 |
|
6176
19ef039a8474
frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents:
6174
diff
changeset
|
348 |
// load external stylesheet if there is any |
8049 | 349 |
QFile extFile("physfs://css/" + fname); |
2898 | 350 |
|
6579 | 351 |
QFile resFile(":/res/css/" + fname); |
6178
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
352 |
|
7724 | 353 |
QFile & file = (extFile.exists() ? extFile : resFile); |
6178
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
354 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
355 |
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
7724 | 356 |
style.append(file.readAll()); |
2377 | 357 |
|
6178
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
358 |
app.form = new HWForm(NULL, style); |
5252 | 359 |
app.form->show(); |
8337
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
360 |
if(splash) |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
361 |
splash->close(); |
8223
14d9a3c33650
backout rea7541f77944 since development of frontlib is on another branch
koda
parents:
8206
diff
changeset
|
362 |
return app.exec(); |
2845 | 363 |
} |