author | unc0rr |
Wed, 05 Dec 2012 23:55:22 +0400 | |
branch | flibqtfrontend |
changeset 8233 | d3966a555e5e |
parent 8206 | 1633a6510834 |
child 8223 | 14d9a3c33650 |
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> |
1146 | 30 |
|
579 | 31 |
#include "hwform.h" |
32 |
#include "hwconsts.h" |
|
6721
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6700
diff
changeset
|
33 |
#include "newnetclient.h" |
579 | 34 |
|
6930 | 35 |
#include "DataManager.h" |
7768 | 36 |
#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
|
37 |
|
8078 | 38 |
#include "frontlib.h" |
39 |
||
3333 | 40 |
#ifdef _WIN32 |
41 |
#include <Shlobj.h> |
|
42 |
#endif |
|
5095
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
43 |
#ifdef __APPLE__ |
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
44 |
#include "CocoaInitializer.h" |
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
45 |
#endif |
3333 | 46 |
|
6579 | 47 |
|
48 |
//Determines the day of easter in year |
|
49 |
//from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++ |
|
50 |
QDate calculateEaster(long year) |
|
51 |
{ |
|
52 |
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
|
53 |
|
6579 | 54 |
c = year/100; |
55 |
n = year - 19*(year/19); |
|
56 |
k = (c - 17)/25; |
|
57 |
i = c - c/4 - (c - k)/3 + 19*n + 15; |
|
58 |
i = i - 30*(i/30); |
|
59 |
i = i - (i/28)*(1 - (i/28)*(29/(i + 1))*((21 - n)/11)); |
|
60 |
j = year + year/4 + i + 2 - c + c/4; |
|
61 |
j = j - 7*(j/7); |
|
62 |
l = i - j; |
|
63 |
m = 3 + (l + 40)/44; |
|
64 |
d = l + 28 - 31*(m / 4); |
|
65 |
||
66 |
return QDate(year, m, d); |
|
67 |
} |
|
68 |
||
69 |
//Checks season and assigns it to the variable season in "hwconsts.h" |
|
70 |
void checkSeason() |
|
71 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
72 |
QDate date = QDate::currentDate(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
73 |
|
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
74 |
//Christmas? |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
75 |
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
|
76 |
&& date.day() <= 26) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
77 |
season = SEASON_CHRISTMAS; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
78 |
//Hedgewars birthday? |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
79 |
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
|
80 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
81 |
season = SEASON_HWBDAY; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
82 |
years_since_foundation = date.year() - 2004; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
83 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
84 |
//Easter? |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
85 |
else if (calculateEaster(date.year()) == date) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
86 |
season = SEASON_EASTER; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
87 |
else |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
88 |
season = SEASON_NONE; |
6579 | 89 |
} |
90 |
||
579 | 91 |
bool checkForDir(const QString & dir) |
92 |
{ |
|
8206 | 93 |
QDir tmpdir(dir); |
94 |
if (!tmpdir.exists()) |
|
95 |
if (!tmpdir.mkpath(dir)) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
96 |
{ |
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
directoryMsg.exec(); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
103 |
return false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
104 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
105 |
return true; |
579 | 106 |
} |
107 |
||
8206 | 108 |
bool checkForFile(const QString & file) |
109 |
{ |
|
110 |
QFile tmpfile(file); |
|
111 |
if (!tmpfile.exists()) |
|
112 |
return tmpfile.open(QFile::WriteOnly); |
|
113 |
else |
|
114 |
return true; |
|
115 |
} |
|
116 |
||
8187
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
117 |
#ifdef __APPLE__ |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
118 |
static CocoaInitializer *cocoaInit = NULL; |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
119 |
// Function to be called at end of program's termination on OS X to release |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
120 |
// the NSAutoReleasePool contained within the CocoaInitializer. |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
121 |
void releaseCocoaPool(void) |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
122 |
{ |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
123 |
if (cocoaInit != NULL) |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
124 |
{ |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
125 |
delete cocoaInit; |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
126 |
cocoaInit = NULL; |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
127 |
} |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
128 |
} |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
129 |
#endif |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
130 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
131 |
int main(int argc, char *argv[]) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
132 |
{ |
8187
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
133 |
#ifdef __APPLE__ |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
134 |
// This creates the autoreleasepool that prevents leaking, and destroys it only on exit |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
135 |
cocoaInit = new CocoaInitializer(); |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
136 |
atexit(releaseCocoaPool); |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
137 |
#endif |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
138 |
|
5252 | 139 |
HWApplication app(argc, argv); |
7130 | 140 |
|
7772 | 141 |
FileEngineHandler engine(argv[0]); |
7768 | 142 |
|
8078 | 143 |
flib_init(); |
144 |
||
4888 | 145 |
app.setAttribute(Qt::AA_DontShowIconsInMenus,false); |
579 | 146 |
|
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
147 |
QStringList arguments = app.arguments(); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
148 |
QMap<QString, QString> parsedArgs; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
149 |
{ |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
150 |
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
|
151 |
while(i != arguments.end()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
152 |
{ |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
153 |
QString arg = *i; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
154 |
|
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
155 |
QRegExp opt("--(\\S+)=(.+)"); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
156 |
if(opt.exactMatch(arg)) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
157 |
{ |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
158 |
parsedArgs[opt.cap(1)] = opt.cap(2); |
2035 | 159 |
i = arguments.erase(i); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
160 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
161 |
else |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
162 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
163 |
++i; |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
164 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
165 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
166 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
167 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
168 |
if(parsedArgs.contains("data-dir")) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
169 |
{ |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
170 |
QFileInfo f(parsedArgs["data-dir"]); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
171 |
if(!f.exists()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
172 |
{ |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
173 |
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
|
174 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
175 |
*cDataDir = f.absoluteFilePath(); |
3932 | 176 |
custom_data = true; |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
177 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
178 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
179 |
if(parsedArgs.contains("config-dir")) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
180 |
{ |
2428 | 181 |
QFileInfo f(parsedArgs["config-dir"]); |
182 |
*cConfigDir = f.absoluteFilePath(); |
|
3932 | 183 |
custom_config = true; |
2428 | 184 |
} |
185 |
||
7772 | 186 |
app.setStyle(new QPlastiqueStyle()); |
2377 | 187 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
188 |
QDateTime now = QDateTime::currentDateTime(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
189 |
srand(now.toTime_t()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
190 |
rand(); |
579 | 191 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
192 |
Q_INIT_RESOURCE(hedgewars); |
579 | 193 |
|
6721
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6700
diff
changeset
|
194 |
qRegisterMetaType<HWTeam>("HWTeam"); |
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6700
diff
changeset
|
195 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
196 |
bindir->cd("bin"); // workaround over NSIS installer |
579 | 197 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
198 |
if(cConfigDir->length() == 0) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
199 |
cfgdir->setPath(cfgdir->homePath()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
200 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
201 |
cfgdir->setPath(*cConfigDir); |
2428 | 202 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
203 |
if(cConfigDir->length() == 0) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
204 |
{ |
1965 | 205 |
#ifdef __APPLE__ |
3758 | 206 |
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
207 |
cfgdir->cd("Library/Application Support/Hedgewars"); |
3333 | 208 |
#elif defined _WIN32 |
209 |
char path[1024]; |
|
210 |
if(!SHGetFolderPathA(0, CSIDL_PERSONAL, NULL, 0, path)) |
|
211 |
{ |
|
212 |
cfgdir->cd(path); |
|
3758 | 213 |
checkForDir(cfgdir->absolutePath() + "/Hedgewars"); |
3333 | 214 |
cfgdir->cd("Hedgewars"); |
215 |
} |
|
3758 | 216 |
else // couldn't retrieve documents folder? almost impossible, but in case fall back to classic path |
3333 | 217 |
{ |
3758 | 218 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars"); |
3333 | 219 |
cfgdir->cd(".hedgewars"); |
220 |
} |
|
2428 | 221 |
#else |
3758 | 222 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
223 |
cfgdir->cd(".hedgewars"); |
2428 | 224 |
#endif |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
225 |
} |
3758 | 226 |
|
227 |
if (checkForDir(cfgdir->absolutePath())) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
228 |
{ |
3758 | 229 |
// alternative loading/lookup paths |
230 |
checkForDir(cfgdir->absolutePath() + "/Data"); |
|
231 |
||
232 |
// config/save paths |
|
233 |
checkForDir(cfgdir->absolutePath() + "/Demos"); |
|
234 |
checkForDir(cfgdir->absolutePath() + "/Saves"); |
|
235 |
checkForDir(cfgdir->absolutePath() + "/Screenshots"); |
|
236 |
checkForDir(cfgdir->absolutePath() + "/Teams"); |
|
3914 | 237 |
checkForDir(cfgdir->absolutePath() + "/Logs"); |
7180 | 238 |
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
|
239 |
checkForDir(cfgdir->absolutePath() + "/VideoTemp"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
240 |
} |
579 | 241 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
242 |
datadir->cd(bindir->absolutePath()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
243 |
datadir->cd(*cDataDir); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
244 |
if(!datadir->cd("hedgewars/Data")) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
245 |
{ |
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
|
246 |
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
|
247 |
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
|
248 |
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
|
249 |
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
|
250 |
"Please check your installation!"). |
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
|
251 |
arg(datadir->absolutePath()+"/hedgewars/Data")); |
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
|
252 |
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
|
253 |
missingMsg.exec(); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
254 |
return 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
255 |
} |
579 | 256 |
|
7931 | 257 |
// setup PhysFS |
7772 | 258 |
engine.mount(datadir->absolutePath()); |
259 |
engine.mount(cfgdir->absolutePath() + "/Data"); |
|
8098 | 260 |
engine.mount(cfgdir->absolutePath()); |
7772 | 261 |
engine.setWriteDir(cfgdir->absolutePath()); |
8052 | 262 |
engine.mountPacks(); |
7772 | 263 |
|
8206 | 264 |
checkForFile("physfs://hedgewars.ini"); |
265 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
266 |
QTranslator Translator; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
267 |
{ |
8098 | 268 |
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
|
269 |
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
|
270 |
if(cc.isEmpty()) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
271 |
cc = QLocale::system().name(); |
6167 | 272 |
|
273 |
// load locale file into translator |
|
7931 | 274 |
if(!Translator.load(QString("physfs://Locale/hedgewars_%1").arg(cc))) |
275 |
qWarning("Failed to install translation"); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
276 |
app.installTranslator(&Translator); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
277 |
} |
2898 | 278 |
|
5756 | 279 |
#ifdef _WIN32 |
3679 | 280 |
// 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 | 281 |
if(!custom_config) |
3679 | 282 |
{ |
3932 | 283 |
QSettings registry_hklm("HKEY_LOCAL_MACHINE", QSettings::NativeFormat); |
284 |
registry_hklm.setValue("Software/Hedgewars/Frontend", bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe"); |
|
285 |
registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\")); |
|
3679 | 286 |
} |
287 |
#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
|
288 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
289 |
QString style = ""; |
6579 | 290 |
QString fname; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
291 |
|
6579 | 292 |
checkSeason(); |
293 |
//For each season, there is an extra stylesheet |
|
294 |
//Todo: change background for easter and birthday |
|
295 |
//(simply replace res/BackgroundBirthday.png and res/BackgroundEaster.png |
|
296 |
//with an appropriate background |
|
297 |
switch (season) |
|
298 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
299 |
case SEASON_CHRISTMAS : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
300 |
fname = "christmas.css"; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
301 |
break; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
302 |
case SEASON_EASTER : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
303 |
fname = "easter.css"; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
304 |
break; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
305 |
case SEASON_HWBDAY : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
306 |
fname = "birthday.css"; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
307 |
break; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
308 |
default : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
309 |
fname = "qt.css"; |
6579 | 310 |
} |
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
|
311 |
|
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
|
312 |
// load external stylesheet if there is any |
8049 | 313 |
QFile extFile("physfs://css/" + fname); |
2898 | 314 |
|
6579 | 315 |
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
|
316 |
|
7724 | 317 |
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
|
318 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
319 |
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
7724 | 320 |
style.append(file.readAll()); |
2377 | 321 |
|
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
|
322 |
app.form = new HWForm(NULL, style); |
5252 | 323 |
app.form->show(); |
8078 | 324 |
int r = app.exec(); |
325 |
||
326 |
flib_quit(); |
|
327 |
||
328 |
return r; |
|
2845 | 329 |
} |