author | nemo |
Fri, 08 May 2009 01:56:20 +0000 | |
changeset 2035 | 70734c4f52a7 |
parent 2034 | decdf48cffd7 |
child 2072 | 6e0fcbcc3f60 |
permissions | -rw-r--r-- |
579 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
579 | 3 |
* Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com> |
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 |
||
19 |
#include <QApplication> |
|
20 |
#include <QTranslator> |
|
21 |
#include <QLocale> |
|
22 |
#include <QMessageBox> |
|
1416
60b86d6fe9ae
Force plastique style, as others don't fully support stylesheets
unc0rr
parents:
1415
diff
changeset
|
23 |
#include <QPlastiqueStyle> |
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
24 |
#include <QRegExp> |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
25 |
#include <QMap> |
1146 | 26 |
|
579 | 27 |
#include "hwform.h" |
28 |
#include "hwconsts.h" |
|
29 |
||
30 |
bool checkForDir(const QString & dir) |
|
31 |
{ |
|
32 |
QDir tmpdir; |
|
33 |
if (!tmpdir.exists(dir)) |
|
34 |
if (!tmpdir.mkdir(dir)) |
|
35 |
{ |
|
36 |
QMessageBox::critical(0, |
|
37 |
QObject::tr("Error"), |
|
38 |
QObject::tr("Cannot create directory %1").arg(dir), |
|
39 |
QObject::tr("OK")); |
|
40 |
return false; |
|
41 |
} |
|
42 |
return true; |
|
43 |
} |
|
44 |
||
45 |
int main(int argc, char *argv[]) |
|
46 |
{ |
|
47 |
QApplication app(argc, argv); |
|
48 |
||
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
49 |
QStringList arguments = app.arguments(); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
50 |
QMap<QString, QString> parsedArgs; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
51 |
{ |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
52 |
QList<QString>::iterator i = arguments.begin(); |
2035 | 53 |
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
|
54 |
QString arg = *i; |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
55 |
|
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
56 |
QRegExp opt("--(\\S+)=(.+)"); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
57 |
if(opt.exactMatch(arg)) { |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
58 |
parsedArgs[opt.cap(1)] = opt.cap(2); |
2035 | 59 |
i = arguments.erase(i); |
60 |
} else { |
|
61 |
++i; |
|
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
62 |
} |
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 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
65 |
|
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
if(!f.exists()) { |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
69 |
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
|
70 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
71 |
*cDataDir = f.absoluteFilePath(); |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
72 |
} |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
73 |
|
1416
60b86d6fe9ae
Force plastique style, as others don't fully support stylesheets
unc0rr
parents:
1415
diff
changeset
|
74 |
app.setStyle(new QPlastiqueStyle); |
60b86d6fe9ae
Force plastique style, as others don't fully support stylesheets
unc0rr
parents:
1415
diff
changeset
|
75 |
|
579 | 76 |
QDateTime now = QDateTime::currentDateTime(); |
77 |
QDateTime zero; |
|
78 |
srand(now.secsTo(zero)); |
|
1215 | 79 |
rand(); |
579 | 80 |
|
81 |
Q_INIT_RESOURCE(hedgewars); |
|
82 |
||
1146 | 83 |
qApp->setStyleSheet |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
84 |
(QString( |
1219
89babaafe99d
Make dialogs and messageboxes be customized like main form
unc0rr
parents:
1217
diff
changeset
|
85 |
"HWForm,QDialog{" |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
86 |
"background-image: url(\":/res/Background.png\");" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
87 |
"background-position: bottom center;" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
88 |
"background-repeat: repeat-x;" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
89 |
"background-color: #870c8f;" |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
90 |
"}" |
1154 | 91 |
|
1897 | 92 |
"* {" |
1893 | 93 |
"color: #ffcc00;" |
94 |
"}" |
|
95 |
||
96 |
"QLineEdit, QListWidget, QTableView, QTextBrowser, QSpinBox, QComboBox, " |
|
97 |
"QComboBox QAbstractItemView, QMenu::item {" |
|
98 |
"background-color: #0d0544;" |
|
99 |
"}" |
|
100 |
||
101 |
"QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView, " |
|
102 |
"QTextBrowser, QSpinBox, QToolBox, QComboBox, " |
|
103 |
"QComboBox QAbstractItemView, IconedGroupBox, " |
|
1897 | 104 |
".QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget, " |
105 |
"QTabWidget::pane, QTabBar::tab {" |
|
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
106 |
"border: solid;" |
1214 | 107 |
"border-width: 3px;" |
1893 | 108 |
"border-color: #ffcc00;" |
109 |
"}" |
|
110 |
||
111 |
"QPushButton:hover, QLineEdit:hover, QListWidget:hover, " |
|
112 |
"QSpinBox:hover, QToolBox:hover, QComboBox:hover {" |
|
113 |
"border-color: yellow;" |
|
114 |
"}" |
|
115 |
||
116 |
"QLineEdit, QListWidget,QTableView, QTextBrowser, " |
|
117 |
"QSpinBox, QToolBox { " |
|
118 |
"border-radius: 12px;" |
|
119 |
"}" |
|
120 |
||
121 |
"QLineEdit, QLabel, QHeaderView, QListWidget, QTableView, " |
|
122 |
"QSpinBox, QToolBox::tab, QComboBox, QComboBox QAbstractItemView, " |
|
123 |
"IconedGroupBox, .QGroupBox, GameCFGWidget, TeamSelWidget, " |
|
124 |
"SelWeaponWidget, QCheckBox, QRadioButton {" |
|
125 |
"font: bold 14px;" |
|
126 |
"}" |
|
127 |
||
128 |
".QGroupBox,GameCFGWidget,TeamSelWidget,SelWeaponWidget {" |
|
129 |
"background-image: url(\":/res/panelbg.png\");" |
|
130 |
"background-position: bottom center;" |
|
131 |
"background-repeat: repeat-x;" |
|
132 |
"border-radius: 16px;" |
|
133 |
"background-color: #040200;" |
|
134 |
"padding: 6px;" |
|
135 |
"}" |
|
136 |
||
137 |
"IconedGroupBox, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" |
|
138 |
"background-color: #130f2c;" |
|
139 |
"}" |
|
140 |
||
141 |
||
142 |
"QPushButton {" |
|
1157 | 143 |
"border-radius: 10px;" |
1168 | 144 |
"background-origin: margin;" |
145 |
"background-position: top left;" |
|
1167 | 146 |
"background-color: #00351d;" |
1893 | 147 |
"}" |
148 |
||
149 |
"QPushButton:pressed{" |
|
150 |
"border-color: white;" |
|
151 |
"}" |
|
1154 | 152 |
|
1893 | 153 |
"QHeaderView {" |
154 |
"border-radius: 0;" |
|
155 |
"border-width: 0;" |
|
156 |
"border-bottom-width: 3px;" |
|
157 |
"background-color: #00351d;" |
|
158 |
"}" |
|
1894 | 159 |
"QTableView {" |
160 |
"alternate-background-color: #2f213a;" |
|
161 |
"}" |
|
1172 | 162 |
|
1893 | 163 |
"QTabBar::tab {" |
1897 | 164 |
"border-bottom-width: 0;" |
1893 | 165 |
"border-radius: 0;" |
166 |
"border-top-left-radius: 6px;" |
|
167 |
"border-top-right-radius: 6px;" |
|
168 |
"padding: 3px;" |
|
169 |
"}" |
|
170 |
"QTabBar::tab:!selected {" |
|
171 |
"color: #0d0544;" |
|
172 |
"background-color: #ffcc00;" |
|
173 |
"}" |
|
1289 | 174 |
"QSpinBox::up-button{" |
175 |
"background: transparent;" |
|
176 |
"width: 16px;" |
|
177 |
"height: 10px;" |
|
1893 | 178 |
"}" |
179 |
||
180 |
"QSpinBox::up-arrow {" |
|
1289 | 181 |
"image: url(\":/res/spin_up.png\");" |
1893 | 182 |
"}" |
183 |
||
184 |
"QSpinBox::down-arrow {" |
|
185 |
"image: url(\":/res/spin_down.png\");" |
|
186 |
"}" |
|
187 |
||
188 |
"QSpinBox::down-button {" |
|
1289 | 189 |
"background: transparent;" |
190 |
"width: 16px;" |
|
191 |
"height: 10px;" |
|
1172 | 192 |
"}" |
193 |
||
1893 | 194 |
"QComboBox {" |
1161 | 195 |
"border-radius: 15px;" |
1154 | 196 |
"padding: 3px;" |
1893 | 197 |
"}" |
1154 | 198 |
"QComboBox:pressed{" |
199 |
"border-color: white;" |
|
1893 | 200 |
"}" |
1154 | 201 |
"QComboBox::drop-down{" |
202 |
"border: transparent;" |
|
203 |
"width: 25px;" |
|
1893 | 204 |
"}" |
1154 | 205 |
"QComboBox::down-arrow {" |
1155 | 206 |
"image: url(\":/res/dropdown.png\");" |
1893 | 207 |
"}" |
1425 | 208 |
|
1893 | 209 |
"VertScrArea {" |
1425 | 210 |
"background-image: url(\":/res/panelbg.png\");" |
211 |
"background-position: bottom center;" |
|
212 |
"background-repeat: repeat-x;" |
|
1893 | 213 |
"}" |
1425 | 214 |
|
1893 | 215 |
"IconedGroupBox {" |
1198 | 216 |
"border-radius: 16px;" |
1228 | 217 |
"padding: 2px;" |
1893 | 218 |
"}" |
219 |
||
1201 | 220 |
".QGroupBox::title{" |
221 |
"subcontrol-origin: margin;" |
|
222 |
"subcontrol-position: top left;" |
|
223 |
//"padding-left: 82px;" |
|
224 |
//"padding-top: 26px;" |
|
225 |
"text-align: left;" |
|
1155 | 226 |
"}" |
227 |
||
228 |
"QCheckBox::indicator:checked{" |
|
229 |
"image: url(\":/res/checked.png\");" |
|
230 |
"}" |
|
231 |
"QCheckBox::indicator:unchecked{" |
|
232 |
"image: url(\":/res/unchecked.png\");" |
|
233 |
"}" |
|
1172 | 234 |
|
1252 | 235 |
".QWidget{" |
236 |
"background: transparent;" |
|
237 |
"}" |
|
1893 | 238 |
|
239 |
"QTabWidget::pane {" |
|
240 |
"border-top-width: 2px;" |
|
241 |
"}" |
|
1413 | 242 |
|
243 |
"QMenu{" |
|
244 |
"background-color: #ffcc00;" |
|
245 |
"margin: 3px;" |
|
1893 | 246 |
"}" |
247 |
"QMenu::item {" |
|
1413 | 248 |
"background-color: #0d0544;" |
249 |
"border: 1px solid transparent;" |
|
250 |
"font: bold;" |
|
251 |
"padding: 2px 25px 2px 20px;" |
|
1893 | 252 |
"}" |
253 |
"QMenu::item:selected {" |
|
1413 | 254 |
"background-color: #2d2564;" |
1893 | 255 |
"}" |
256 |
"QMenu::indicator {" |
|
1413 | 257 |
"width: 16px;" |
258 |
"height: 16px;" |
|
1893 | 259 |
"}" |
1413 | 260 |
"QMenu::indicator:non-exclusive:checked{" |
261 |
"image: url(\":/res/checked.png\");" |
|
1893 | 262 |
"}" |
1413 | 263 |
"QMenu::indicator:non-exclusive:unchecked{" |
264 |
"image: url(\":/res/unchecked.png\");" |
|
1893 | 265 |
"}" |
1450 | 266 |
|
267 |
"QToolTip{" |
|
268 |
"background-color: #0d0544;" |
|
1893 | 269 |
"}" |
1438 | 270 |
|
271 |
":disabled{" |
|
272 |
"color: #a0a0a0;" |
|
1893 | 273 |
"}" |
1152
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
274 |
) |
c72b939c00df
Make buttons border have different colors when mouse is over or it is pressed
unc0rr
parents:
1150
diff
changeset
|
275 |
); |
1150 | 276 |
|
579 | 277 |
bindir->cd("bin"); // workaround over NSIS installer |
278 |
||
279 |
cfgdir->setPath(cfgdir->homePath()); |
|
1965 | 280 |
#ifdef __APPLE__ |
281 |
if (checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars")) |
|
282 |
{ |
|
283 |
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Demos"); |
|
284 |
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Saves"); |
|
285 |
} |
|
1969 | 286 |
cfgdir->cd("Library/Application Support/Hedgewars"); |
1965 | 287 |
#else |
579 | 288 |
if (checkForDir(cfgdir->absolutePath() + "/.hedgewars")) |
289 |
{ |
|
290 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos"); |
|
291 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves"); |
|
292 |
} |
|
293 |
cfgdir->cd(".hedgewars"); |
|
1965 | 294 |
#endif |
579 | 295 |
|
296 |
datadir->cd(bindir->absolutePath()); |
|
297 |
datadir->cd(*cDataDir); |
|
298 |
if(!datadir->cd("hedgewars/Data")) { |
|
299 |
QMessageBox::critical(0, QMessageBox::tr("Error"), |
|
300 |
QMessageBox::tr("Failed to open data directory:\n%1\n" |
|
301 |
"Please check your installation"). |
|
302 |
arg(datadir->absolutePath()+"/hedgewars/Data")); |
|
303 |
return 1; |
|
304 |
} |
|
305 |
||
306 |
QTranslator Translator; |
|
307 |
Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name()); |
|
308 |
app.installTranslator(&Translator); |
|
309 |
||
310 |
Themes = new QStringList(); |
|
311 |
QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg"); |
|
312 |
if (themesfile.open(QIODevice::ReadOnly)) { |
|
313 |
QTextStream stream(&themesfile); |
|
314 |
QString str; |
|
315 |
while (!stream.atEnd()) |
|
316 |
{ |
|
317 |
Themes->append(stream.readLine()); |
|
318 |
} |
|
319 |
themesfile.close(); |
|
320 |
} else { |
|
321 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK"); |
|
322 |
} |
|
323 |
||
1210 | 324 |
QDir tmpdir; |
325 |
tmpdir.cd(datadir->absolutePath()); |
|
326 |
tmpdir.cd("Maps"); |
|
327 |
tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); |
|
328 |
mapList = new QStringList(tmpdir.entryList(QStringList("*"))); |
|
329 |
||
579 | 330 |
HWForm *Form = new HWForm(); |
331 |
Form->show(); |
|
332 |
return app.exec(); |
|
333 |
} |