author | sheepluva |
Sat, 22 Oct 2011 19:37:39 +0200 | |
changeset 6186 | 255aff92216d |
parent 6178 | affa860f2983 |
child 6196 | c16e84558f71 |
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> |
1146 | 29 |
|
579 | 30 |
#include "hwform.h" |
31 |
#include "hwconsts.h" |
|
32 |
||
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
|
33 |
#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
|
34 |
|
3333 | 35 |
#ifdef _WIN32 |
36 |
#include <Shlobj.h> |
|
37 |
#endif |
|
5095
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
38 |
#ifdef __APPLE__ |
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
39 |
#include "CocoaInitializer.h" |
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
40 |
#endif |
3333 | 41 |
|
579 | 42 |
bool checkForDir(const QString & dir) |
43 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
44 |
QDir tmpdir; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
45 |
if (!tmpdir.exists(dir)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
46 |
if (!tmpdir.mkdir(dir)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
47 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
48 |
QMessageBox::critical(0, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
49 |
QObject::tr("Error"), |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
50 |
QObject::tr("Cannot create directory %1").arg(dir), |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
51 |
QObject::tr("OK")); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
52 |
return false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
53 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
54 |
return true; |
579 | 55 |
} |
56 |
||
3697 | 57 |
int main(int argc, char *argv[]) { |
5252 | 58 |
HWApplication app(argc, argv); |
4888 | 59 |
app.setAttribute(Qt::AA_DontShowIconsInMenus,false); |
579 | 60 |
|
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
61 |
QStringList arguments = app.arguments(); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
62 |
QMap<QString, QString> parsedArgs; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
63 |
{ |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
64 |
QList<QString>::iterator i = arguments.begin(); |
2035 | 65 |
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
|
66 |
QString arg = *i; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
67 |
|
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
68 |
QRegExp opt("--(\\S+)=(.+)"); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
69 |
if(opt.exactMatch(arg)) { |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
70 |
parsedArgs[opt.cap(1)] = opt.cap(2); |
2035 | 71 |
i = arguments.erase(i); |
72 |
} else { |
|
73 |
++i; |
|
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
74 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
75 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
76 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
77 |
|
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
78 |
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
|
79 |
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
|
80 |
if(!f.exists()) { |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
81 |
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
|
82 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
83 |
*cDataDir = f.absoluteFilePath(); |
3932 | 84 |
custom_data = true; |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
85 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
86 |
|
2428 | 87 |
if(parsedArgs.contains("config-dir")) { |
88 |
QFileInfo f(parsedArgs["config-dir"]); |
|
89 |
*cConfigDir = f.absoluteFilePath(); |
|
3932 | 90 |
custom_config = true; |
2428 | 91 |
} |
92 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
93 |
app.setStyle(new QPlastiqueStyle); |
2377 | 94 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
95 |
QDateTime now = QDateTime::currentDateTime(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
96 |
srand(now.toTime_t()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
97 |
rand(); |
579 | 98 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
99 |
Q_INIT_RESOURCE(hedgewars); |
579 | 100 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
101 |
bindir->cd("bin"); // workaround over NSIS installer |
579 | 102 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
103 |
if(cConfigDir->length() == 0) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
104 |
cfgdir->setPath(cfgdir->homePath()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
105 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
106 |
cfgdir->setPath(*cConfigDir); |
2428 | 107 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
108 |
if(cConfigDir->length() == 0) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
109 |
{ |
1965 | 110 |
#ifdef __APPLE__ |
3758 | 111 |
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
112 |
cfgdir->cd("Library/Application Support/Hedgewars"); |
3333 | 113 |
#elif defined _WIN32 |
114 |
char path[1024]; |
|
115 |
if(!SHGetFolderPathA(0, CSIDL_PERSONAL, NULL, 0, path)) |
|
116 |
{ |
|
117 |
cfgdir->cd(path); |
|
3758 | 118 |
checkForDir(cfgdir->absolutePath() + "/Hedgewars"); |
3333 | 119 |
cfgdir->cd("Hedgewars"); |
120 |
} |
|
3758 | 121 |
else // couldn't retrieve documents folder? almost impossible, but in case fall back to classic path |
3333 | 122 |
{ |
3758 | 123 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars"); |
3333 | 124 |
cfgdir->cd(".hedgewars"); |
125 |
} |
|
2428 | 126 |
#else |
3758 | 127 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
128 |
cfgdir->cd(".hedgewars"); |
2428 | 129 |
#endif |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
130 |
} |
3758 | 131 |
|
132 |
if (checkForDir(cfgdir->absolutePath())) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
133 |
{ |
3758 | 134 |
// alternative loading/lookup paths |
135 |
// TODO: Uncomment paths as they're implemented |
|
136 |
checkForDir(cfgdir->absolutePath() + "/Data"); |
|
137 |
//checkForDir(cfgdir->absolutePath() + "/Data/Forts"); |
|
138 |
//checkForDir(cfgdir->absolutePath() + "/Data/Graphics"); |
|
139 |
//checkForDir(cfgdir->absolutePath() + "/Data/Graphics/Flags"); |
|
140 |
//checkForDir(cfgdir->absolutePath() + "/Data/Graphics/Graves"); |
|
141 |
//checkForDir(cfgdir->absolutePath() + "/Data/Graphics/Hats"); |
|
142 |
//checkForDir(cfgdir->absolutePath() + "/Data/Maps"); |
|
143 |
//checkForDir(cfgdir->absolutePath() + "/Data/Missions"); |
|
144 |
//checkForDir(cfgdir->absolutePath() + "/Data/Missions/Campaign"); |
|
145 |
//checkForDir(cfgdir->absolutePath() + "/Data/Missions/Training"); |
|
146 |
//checkForDir(cfgdir->absolutePath() + "/Data/Sounds"); |
|
147 |
//checkForDir(cfgdir->absolutePath() + "/Data/Sounds/voices"); |
|
148 |
//checkForDir(cfgdir->absolutePath() + "/Data/Themes"); |
|
149 |
||
150 |
// config/save paths |
|
151 |
checkForDir(cfgdir->absolutePath() + "/Demos"); |
|
152 |
checkForDir(cfgdir->absolutePath() + "/Saves"); |
|
153 |
checkForDir(cfgdir->absolutePath() + "/Screenshots"); |
|
154 |
checkForDir(cfgdir->absolutePath() + "/Teams"); |
|
3914 | 155 |
checkForDir(cfgdir->absolutePath() + "/Logs"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
156 |
} |
579 | 157 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
158 |
datadir->cd(bindir->absolutePath()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
159 |
datadir->cd(*cDataDir); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
160 |
if(!datadir->cd("hedgewars/Data")) { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
161 |
QMessageBox::critical(0, QMessageBox::tr("Error"), |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
162 |
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
|
163 |
"Please check your installation"). |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
164 |
arg(datadir->absolutePath()+"/hedgewars/Data")); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
165 |
return 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
166 |
} |
579 | 167 |
|
6186
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
168 |
// copy data/default css files to cfgdir as templates |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
169 |
QString userCssDir = cfgdir->absolutePath() + "/Data/css"; |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
170 |
if (checkForDir(userCssDir)) |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
171 |
{ |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
172 |
QString defaultCssDir = ":res/css"; |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
173 |
QStringList cssFiles = QDir(defaultCssDir).entryList(QDir::Files); |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
174 |
foreach (const QString & cssFile, cssFiles) |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
175 |
{ |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
176 |
QString srcName = datadir->absolutePath()+"/css/"+cssFile; |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
177 |
|
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
178 |
if (!QFile::exists(srcName)) |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
179 |
srcName = defaultCssDir+"/"+cssFile; |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
180 |
|
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
181 |
QString tmpName = userCssDir + "/template_" + cssFile; |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
182 |
if (QFile::exists(tmpName)) |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
183 |
QFile::remove(tmpName); |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
184 |
|
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
185 |
QFile(srcName).copy(tmpName); |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
186 |
} |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
187 |
} |
255aff92216d
let's create some templates so that the user knows how to start off
sheepluva
parents:
6178
diff
changeset
|
188 |
|
5276
562070d3f978
Derive themes list from list of dirs in Themes folder which have icon.png inside
unc0rr
parents:
5257
diff
changeset
|
189 |
{ |
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
|
190 |
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
|
191 |
|
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
|
192 |
themes.append(HWDataManager::instance().entryList( |
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
|
193 |
"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
|
194 |
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
|
195 |
); |
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
|
196 |
|
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
197 |
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
|
198 |
|
5307 | 199 |
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
|
200 |
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
|
201 |
{ |
6167 | 202 |
QString file = HWDataManager::instance().findFileForRead( |
203 |
QString("Themes/%1/icon.png").arg(themes.at(i)) |
|
204 |
); |
|
5307 | 205 |
|
6167 | 206 |
if(QFile::exists(file)) |
5307 | 207 |
{ // load icon |
208 |
QPair<QIcon, QIcon> ic; |
|
6167 | 209 |
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
|
210 |
|
6167 | 211 |
// load preview icon |
212 |
ic.second = QIcon( |
|
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
|
213 |
HWDataManager::instance().findFileForRead( |
6167 | 214 |
QString("Themes/%1/icon@2x.png").arg(themes.at(i)) |
215 |
) |
|
216 |
); |
|
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
|
217 |
|
5307 | 218 |
icons.prepend(ic); |
219 |
} |
|
220 |
else |
|
221 |
{ |
|
222 |
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
|
223 |
} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
224 |
} |
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
|
225 |
|
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
5276
diff
changeset
|
226 |
themesModel = new ThemesModel(themes); |
5307 | 227 |
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
|
228 |
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
|
229 |
{ |
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 |
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
|
231 |
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
|
232 |
} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
233 |
} |
579 | 234 |
|
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
|
235 |
mapList = new QStringList(HWDataManager::instance().entryList( |
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
|
236 |
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
|
237 |
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
|
238 |
) |
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
|
239 |
); |
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
|
240 |
|
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
|
241 |
scriptList = new QStringList(HWDataManager::instance().entryList( |
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
|
242 |
QString("Scripts/Multiplayer"), |
6174 | 243 |
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
|
244 |
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
|
245 |
) |
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
|
246 |
); |
2898 | 247 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
248 |
QTranslator Translator; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
249 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
250 |
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
|
251 |
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
|
252 |
if(cc.isEmpty()) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
253 |
cc = QLocale::system().name(); |
6167 | 254 |
|
255 |
// load locale file into translator |
|
256 |
Translator.load( |
|
257 |
HWDataManager::instance().findFileForRead( |
|
258 |
QString("Locale/hedgewars_" + cc) |
|
259 |
) |
|
260 |
); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
261 |
app.installTranslator(&Translator); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
262 |
} |
2898 | 263 |
|
5756 | 264 |
#ifdef _WIN32 |
3679 | 265 |
// 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 | 266 |
if(!custom_config) |
3679 | 267 |
{ |
3932 | 268 |
QSettings registry_hklm("HKEY_LOCAL_MACHINE", QSettings::NativeFormat); |
269 |
registry_hklm.setValue("Software/Hedgewars/Frontend", bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe"); |
|
270 |
registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\")); |
|
3679 | 271 |
} |
272 |
#endif |
|
5095
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
273 |
#ifdef __APPLE__ |
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
274 |
// 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
|
275 |
CocoaInitializer initializer; |
15dd764b728c
fix autorelease pools not being set (issue 209) and format code a little
koda
parents:
4976
diff
changeset
|
276 |
#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
|
277 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
278 |
QString style = ""; |
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
279 |
|
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
|
280 |
// load external stylesheet if there is any |
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
|
281 |
QFile extFile(HWDataManager::instance().findFileForRead("css/qt.css")); |
2898 | 282 |
|
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
|
283 |
QFile resFile(":/res/css/qt.css"); |
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
284 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
285 |
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
|
286 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
287 |
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
|
288 |
{ |
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
|
289 |
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
|
290 |
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
|
291 |
{ |
19ef039a8474
frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents:
6174
diff
changeset
|
292 |
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
|
293 |
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
|
294 |
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
|
295 |
} |
19ef039a8474
frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents:
6174
diff
changeset
|
296 |
} |
2377 | 297 |
|
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
|
298 |
app.form = new HWForm(NULL, style); |
5252 | 299 |
app.form->show(); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
300 |
return app.exec(); |
2845 | 301 |
} |