author | Xeli |
Tue, 24 Jan 2012 18:11:56 +0100 | |
changeset 6597 | 814683bbd230 |
parent 6579 | fc52f7c22c9b |
child 6600 | 5810e42d8375 |
permissions | -rw-r--r-- |
579 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
4976 | 3 |
* Copyright (c) 2005-2011 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" |
|
33 |
||
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
|
34 |
#include "HWDataManager.h" |
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
|
35 |
|
3333 | 36 |
#ifdef _WIN32 |
37 |
#include <Shlobj.h> |
|
38 |
#endif |
|
5095
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
39 |
#ifdef __APPLE__ |
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
40 |
#include "CocoaInitializer.h" |
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
41 |
#endif |
3333 | 42 |
|
6579 | 43 |
|
44 |
//Determines the day of easter in year |
|
45 |
//from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++ |
|
46 |
QDate calculateEaster(long year) |
|
47 |
{ |
|
48 |
int c, n, k, i, j, l, m, d; |
|
49 |
||
50 |
c = year/100; |
|
51 |
n = year - 19*(year/19); |
|
52 |
k = (c - 17)/25; |
|
53 |
i = c - c/4 - (c - k)/3 + 19*n + 15; |
|
54 |
i = i - 30*(i/30); |
|
55 |
i = i - (i/28)*(1 - (i/28)*(29/(i + 1))*((21 - n)/11)); |
|
56 |
j = year + year/4 + i + 2 - c + c/4; |
|
57 |
j = j - 7*(j/7); |
|
58 |
l = i - j; |
|
59 |
m = 3 + (l + 40)/44; |
|
60 |
d = l + 28 - 31*(m / 4); |
|
61 |
||
62 |
return QDate(year, m, d); |
|
63 |
} |
|
64 |
||
65 |
//Checks season and assigns it to the variable season in "hwconsts.h" |
|
66 |
void checkSeason() |
|
67 |
{ |
|
68 |
QDate date = QDate::currentDate(); |
|
69 |
||
70 |
//Christmas? |
|
71 |
if (date.month() == 12 && date.daysInMonth() >= 24 |
|
72 |
&& date.daysInMonth() <= 26) |
|
73 |
season = SEASON_CHRISTMAS; |
|
74 |
//Hedgewars birthday? |
|
75 |
else if (date.month() == 10 && date.daysInMonth() == 31) |
|
76 |
{ |
|
77 |
season = SEASON_HWBDAY; |
|
78 |
years_since_foundation = date.year() - 2004; |
|
79 |
} |
|
80 |
//Easter? |
|
81 |
else if (calculateEaster(date.year()) == date) |
|
82 |
season = SEASON_EASTER; |
|
83 |
else |
|
84 |
season = SEASON_NONE; |
|
85 |
} |
|
86 |
||
579 | 87 |
bool checkForDir(const QString & dir) |
88 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
89 |
QDir tmpdir; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
90 |
if (!tmpdir.exists(dir)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
91 |
if (!tmpdir.mkdir(dir)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
92 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
93 |
QMessageBox::critical(0, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
94 |
QObject::tr("Error"), |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
95 |
QObject::tr("Cannot create directory %1").arg(dir), |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
96 |
QObject::tr("OK")); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
97 |
return false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
98 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
99 |
return true; |
579 | 100 |
} |
101 |
||
3697 | 102 |
int main(int argc, char *argv[]) { |
5252 | 103 |
HWApplication app(argc, argv); |
4888 | 104 |
app.setAttribute(Qt::AA_DontShowIconsInMenus,false); |
579 | 105 |
|
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
106 |
QStringList arguments = app.arguments(); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
107 |
QMap<QString, QString> parsedArgs; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
108 |
{ |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
109 |
QList<QString>::iterator i = arguments.begin(); |
2035 | 110 |
while(i != arguments.end()) { |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
111 |
QString arg = *i; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
112 |
|
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
113 |
QRegExp opt("--(\\S+)=(.+)"); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
114 |
if(opt.exactMatch(arg)) { |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
115 |
parsedArgs[opt.cap(1)] = opt.cap(2); |
2035 | 116 |
i = arguments.erase(i); |
117 |
} else { |
|
118 |
++i; |
|
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
119 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
120 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
121 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
122 |
|
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
123 |
if(parsedArgs.contains("data-dir")) { |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
124 |
QFileInfo f(parsedArgs["data-dir"]); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
125 |
if(!f.exists()) { |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
126 |
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
|
127 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
128 |
*cDataDir = f.absoluteFilePath(); |
3932 | 129 |
custom_data = true; |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
130 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
131 |
|
2428 | 132 |
if(parsedArgs.contains("config-dir")) { |
133 |
QFileInfo f(parsedArgs["config-dir"]); |
|
134 |
*cConfigDir = f.absoluteFilePath(); |
|
3932 | 135 |
custom_config = true; |
2428 | 136 |
} |
137 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
138 |
app.setStyle(new QPlastiqueStyle); |
2377 | 139 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
140 |
QDateTime now = QDateTime::currentDateTime(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
141 |
srand(now.toTime_t()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
142 |
rand(); |
579 | 143 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
144 |
Q_INIT_RESOURCE(hedgewars); |
579 | 145 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
146 |
bindir->cd("bin"); // workaround over NSIS installer |
579 | 147 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
148 |
if(cConfigDir->length() == 0) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
149 |
cfgdir->setPath(cfgdir->homePath()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
150 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
151 |
cfgdir->setPath(*cConfigDir); |
2428 | 152 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
153 |
if(cConfigDir->length() == 0) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
154 |
{ |
1965 | 155 |
#ifdef __APPLE__ |
3758 | 156 |
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
157 |
cfgdir->cd("Library/Application Support/Hedgewars"); |
3333 | 158 |
#elif defined _WIN32 |
159 |
char path[1024]; |
|
160 |
if(!SHGetFolderPathA(0, CSIDL_PERSONAL, NULL, 0, path)) |
|
161 |
{ |
|
162 |
cfgdir->cd(path); |
|
3758 | 163 |
checkForDir(cfgdir->absolutePath() + "/Hedgewars"); |
3333 | 164 |
cfgdir->cd("Hedgewars"); |
165 |
} |
|
3758 | 166 |
else // couldn't retrieve documents folder? almost impossible, but in case fall back to classic path |
3333 | 167 |
{ |
3758 | 168 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars"); |
3333 | 169 |
cfgdir->cd(".hedgewars"); |
170 |
} |
|
2428 | 171 |
#else |
3758 | 172 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
173 |
cfgdir->cd(".hedgewars"); |
2428 | 174 |
#endif |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
175 |
} |
3758 | 176 |
|
177 |
if (checkForDir(cfgdir->absolutePath())) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
178 |
{ |
3758 | 179 |
// alternative loading/lookup paths |
180 |
checkForDir(cfgdir->absolutePath() + "/Data"); |
|
181 |
||
182 |
// config/save paths |
|
183 |
checkForDir(cfgdir->absolutePath() + "/Demos"); |
|
184 |
checkForDir(cfgdir->absolutePath() + "/Saves"); |
|
185 |
checkForDir(cfgdir->absolutePath() + "/Screenshots"); |
|
186 |
checkForDir(cfgdir->absolutePath() + "/Teams"); |
|
3914 | 187 |
checkForDir(cfgdir->absolutePath() + "/Logs"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
188 |
} |
579 | 189 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
190 |
datadir->cd(bindir->absolutePath()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
191 |
datadir->cd(*cDataDir); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
192 |
if(!datadir->cd("hedgewars/Data")) { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
193 |
QMessageBox::critical(0, QMessageBox::tr("Error"), |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
194 |
QMessageBox::tr("Failed to open data directory:\n%1\n" |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
195 |
"Please check your installation"). |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
196 |
arg(datadir->absolutePath()+"/hedgewars/Data")); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
197 |
return 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
198 |
} |
579 | 199 |
|
6196 | 200 |
HWDataManager & dataMgr = HWDataManager::instance(); |
201 |
||
5276
562070d3f978
Derive themes list from list of dirs in Themes folder which have icon.png inside
unc0rr
parents:
5257
diff
changeset
|
202 |
{ |
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
|
203 |
QStringList themes; |
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
|
204 |
|
6196 | 205 |
themes.append(dataMgr.entryList( |
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
|
206 |
"Themes", |
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
|
207 |
QDir::AllDirs | QDir::NoDotAndDotDot) |
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
|
208 |
); |
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
|
209 |
|
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
210 |
QList<QPair<QIcon, QIcon> > icons; |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
211 |
|
5307 | 212 |
themes.sort(); |
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
|
213 |
for(int i = themes.size() - 1; i >= 0; --i) |
5276
562070d3f978
Derive themes list from list of dirs in Themes folder which have icon.png inside
unc0rr
parents:
5257
diff
changeset
|
214 |
{ |
6196 | 215 |
QString file = dataMgr.findFileForRead( |
6167 | 216 |
QString("Themes/%1/icon.png").arg(themes.at(i)) |
217 |
); |
|
5307 | 218 |
|
6167 | 219 |
if(QFile::exists(file)) |
5307 | 220 |
{ // load icon |
221 |
QPair<QIcon, QIcon> ic; |
|
6167 | 222 |
ic.first = QIcon(file); |
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
|
223 |
|
6167 | 224 |
// load preview icon |
225 |
ic.second = QIcon( |
|
6196 | 226 |
dataMgr.findFileForRead( |
6167 | 227 |
QString("Themes/%1/icon@2x.png").arg(themes.at(i)) |
228 |
) |
|
229 |
); |
|
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
|
230 |
|
5307 | 231 |
icons.prepend(ic); |
232 |
} |
|
233 |
else |
|
234 |
{ |
|
235 |
themes.removeAt(i); |
|
5276
562070d3f978
Derive themes list from list of dirs in Themes folder which have icon.png inside
unc0rr
parents:
5257
diff
changeset
|
236 |
} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
237 |
} |
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
|
238 |
|
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
239 |
themesModel = new ThemesModel(themes); |
5307 | 240 |
Q_ASSERT(themes.size() == icons.size()); |
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
|
241 |
for(int i = 0; i < icons.size(); ++i) |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
242 |
{ |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
243 |
themesModel->setData(themesModel->index(i), icons[i].first, Qt::DecorationRole); |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
244 |
themesModel->setData(themesModel->index(i), icons[i].second, Qt::UserRole); |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
245 |
} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
246 |
} |
579 | 247 |
|
6196 | 248 |
mapList = new QStringList(dataMgr.entryList( |
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
|
249 |
QString("Maps"), |
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
|
250 |
QDir::Dirs | QDir::NoDotAndDotDot |
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
|
251 |
) |
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
|
252 |
); |
5238
46ddaf14509d
Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents:
5095
diff
changeset
|
253 |
|
6196 | 254 |
scriptList = new QStringList(dataMgr.entryList( |
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
|
255 |
QString("Scripts/Multiplayer"), |
6174 | 256 |
QDir::Files, |
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
|
257 |
QStringList("*.lua") |
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
|
258 |
) |
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
|
259 |
); |
2898 | 260 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
261 |
QTranslator Translator; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
262 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
263 |
QSettings settings(cfgdir->absolutePath() + "/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
|
264 |
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
|
265 |
if(cc.isEmpty()) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
266 |
cc = QLocale::system().name(); |
6167 | 267 |
|
268 |
// load locale file into translator |
|
269 |
Translator.load( |
|
6196 | 270 |
dataMgr.findFileForRead( |
6167 | 271 |
QString("Locale/hedgewars_" + cc) |
272 |
) |
|
273 |
); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
274 |
app.installTranslator(&Translator); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
275 |
} |
2898 | 276 |
|
5756 | 277 |
#ifdef _WIN32 |
3679 | 278 |
// 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 | 279 |
if(!custom_config) |
3679 | 280 |
{ |
3932 | 281 |
QSettings registry_hklm("HKEY_LOCAL_MACHINE", QSettings::NativeFormat); |
282 |
registry_hklm.setValue("Software/Hedgewars/Frontend", bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe"); |
|
283 |
registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\")); |
|
3679 | 284 |
} |
285 |
#endif |
|
5095
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
286 |
#ifdef __APPLE__ |
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
287 |
// this creates the autoreleasepool that prevents leaking |
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
288 |
CocoaInitializer initializer; |
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
289 |
#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
|
290 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
291 |
QString style = ""; |
6579 | 292 |
QString fname; |
293 |
||
294 |
checkSeason(); |
|
295 |
//For each season, there is an extra stylesheet |
|
296 |
//Todo: change background for easter and birthday |
|
297 |
//(simply replace res/BackgroundBirthday.png and res/BackgroundEaster.png |
|
298 |
//with an appropriate background |
|
299 |
switch (season) |
|
300 |
{ |
|
301 |
case SEASON_CHRISTMAS : fname = "christmas.css"; |
|
302 |
break; |
|
303 |
case SEASON_EASTER : fname = "easter.css"; |
|
304 |
break; |
|
305 |
case SEASON_HWBDAY : fname = "birthday.css"; |
|
306 |
break; |
|
307 |
default : fname = "qt.css"; |
|
308 |
} |
|
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
|
309 |
|
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
|
310 |
// load external stylesheet if there is any |
6579 | 311 |
QFile extFile(dataMgr.findFileForRead("css/" + fname)); |
2898 | 312 |
|
6579 | 313 |
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
|
314 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
315 |
QFile & file = (extFile.exists()?extFile:resFile); |
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 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
317 |
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
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
|
318 |
{ |
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
|
319 |
QTextStream in(&file); |
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
|
320 |
while (!in.atEnd()) |
19ef039a8474
frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents:
6174
diff
changeset
|
321 |
{ |
19ef039a8474
frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents:
6174
diff
changeset
|
322 |
QString line = in.readLine(); |
19ef039a8474
frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents:
6174
diff
changeset
|
323 |
if(!line.isEmpty()) |
19ef039a8474
frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents:
6174
diff
changeset
|
324 |
style.append(line); |
19ef039a8474
frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents:
6174
diff
changeset
|
325 |
} |
19ef039a8474
frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents:
6174
diff
changeset
|
326 |
} |
2377 | 327 |
|
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
|
328 |
app.form = new HWForm(NULL, style); |
5252 | 329 |
app.form->show(); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
330 |
return app.exec(); |
2845 | 331 |
} |