author | nemo |
Tue, 13 Mar 2018 10:02:01 -0400 | |
branch | qt5transition |
changeset 13178 | b4f48e7a4953 |
parent 12897 | fc47fc4af6bd |
child 13179 | ddfb4a73524b |
permissions | -rw-r--r-- |
579 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
579 | 17 |
*/ |
18 |
||
5252 | 19 |
#include "HWApplication.h" |
20 |
||
579 | 21 |
#include <QTranslator> |
22 |
#include <QLocale> |
|
2034
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
23 |
#include <QRegExp> |
decdf48cffd7
david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents:
1969
diff
changeset
|
24 |
#include <QMap> |
2898 | 25 |
#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
|
26 |
#include <QStringListModel> |
6579 | 27 |
#include <QDate> |
8337
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
28 |
#include <QDesktopWidget> |
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
29 |
#include <QLabel> |
11488 | 30 |
#include <QLibraryInfo> |
13178
b4f48e7a4953
seems to help styling some - some CSS tweaks may still be needed - lobby for example
nemo
parents:
12897
diff
changeset
|
31 |
#include <QStyle> |
b4f48e7a4953
seems to help styling some - some CSS tweaks may still be needed - lobby for example
nemo
parents:
12897
diff
changeset
|
32 |
#include <QStyleFactory> |
1146 | 33 |
|
579 | 34 |
#include "hwform.h" |
35 |
#include "hwconsts.h" |
|
6721
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6700
diff
changeset
|
36 |
#include "newnetclient.h" |
579 | 37 |
|
6930 | 38 |
#include "DataManager.h" |
7768 | 39 |
#include "FileEngine.h" |
8799
44e520374cfc
drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents:
8722
diff
changeset
|
40 |
#include "MessageDialog.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
|
41 |
|
9711
7d0329f37181
To prevent that weird crash, you need to initialize SDL before Qt
unc0rr
parents:
9163
diff
changeset
|
42 |
#include "SDLInteraction.h" |
7d0329f37181
To prevent that weird crash, you need to initialize SDL before Qt
unc0rr
parents:
9163
diff
changeset
|
43 |
|
3333 | 44 |
#ifdef _WIN32 |
45 |
#include <Shlobj.h> |
|
8355 | 46 |
#elif defined __APPLE__ |
47 |
#include "CocoaInitializer.h" |
|
12661 | 48 |
|
49 |
#endif |
|
50 |
||
51 |
#ifdef Q_OS_WIN |
|
52 |
#include <QSplashScreen> |
|
3333 | 53 |
#endif |
54 |
||
8405
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
55 |
// Program resources |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
56 |
#ifdef __APPLE__ |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
57 |
static CocoaInitializer * cocoaInit = NULL; |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
58 |
#endif |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
59 |
static FileEngineHandler * engine = NULL; |
6579 | 60 |
|
61 |
//Determines the day of easter in year |
|
62 |
//from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++ |
|
63 |
QDate calculateEaster(long year) |
|
64 |
{ |
|
65 |
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
|
66 |
|
6579 | 67 |
c = year/100; |
68 |
n = year - 19*(year/19); |
|
69 |
k = (c - 17)/25; |
|
70 |
i = c - c/4 - (c - k)/3 + 19*n + 15; |
|
71 |
i = i - 30*(i/30); |
|
72 |
i = i - (i/28)*(1 - (i/28)*(29/(i + 1))*((21 - n)/11)); |
|
73 |
j = year + year/4 + i + 2 - c + c/4; |
|
74 |
j = j - 7*(j/7); |
|
75 |
l = i - j; |
|
76 |
m = 3 + (l + 40)/44; |
|
77 |
d = l + 28 - 31*(m / 4); |
|
78 |
||
79 |
return QDate(year, m, d); |
|
80 |
} |
|
81 |
||
82 |
//Checks season and assigns it to the variable season in "hwconsts.h" |
|
83 |
void checkSeason() |
|
84 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
85 |
QDate date = QDate::currentDate(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
86 |
|
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
87 |
//Christmas? |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
88 |
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
|
89 |
&& date.day() <= 26) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
90 |
season = SEASON_CHRISTMAS; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
91 |
//Hedgewars birthday? |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
92 |
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
|
93 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
94 |
season = SEASON_HWBDAY; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
95 |
years_since_foundation = date.year() - 2004; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
96 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
97 |
//Easter? |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
98 |
else if (calculateEaster(date.year()) == date) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
99 |
season = SEASON_EASTER; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
100 |
else |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
101 |
season = SEASON_NONE; |
6579 | 102 |
} |
8385
9e8924ff9813
Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents:
8355
diff
changeset
|
103 |
|
6579 | 104 |
|
579 | 105 |
bool checkForDir(const QString & dir) |
106 |
{ |
|
8206 | 107 |
QDir tmpdir(dir); |
108 |
if (!tmpdir.exists()) |
|
109 |
if (!tmpdir.mkpath(dir)) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
110 |
{ |
8799
44e520374cfc
drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents:
8722
diff
changeset
|
111 |
MessageDialog::ShowErrorMessage(HWApplication::tr("Cannot create directory %1").arg(dir)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
112 |
return false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
113 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
114 |
return true; |
579 | 115 |
} |
116 |
||
8405
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
117 |
// Guaranteed to be the last thing ran in the application's life time. |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
118 |
// Closes resources that need to exist as long as possible. |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
119 |
void closeResources(void) |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
120 |
{ |
8187
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
121 |
#ifdef __APPLE__ |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
122 |
if (cocoaInit != NULL) |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
123 |
{ |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
124 |
delete cocoaInit; |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
125 |
cocoaInit = NULL; |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
126 |
} |
8405
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
127 |
#endif |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
128 |
if (engine != NULL) |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
129 |
{ |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
130 |
delete engine; |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
131 |
engine = NULL; |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
132 |
} |
8187
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
133 |
} |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
134 |
|
10405
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
135 |
QString getUsage() |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
136 |
{ |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
137 |
return QString( |
10407 | 138 |
"%1: hedgewars [%2...] [%3]\n" |
10405
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
139 |
"\n" |
10407 | 140 |
"%4:\n" |
141 |
" --help %5\n" |
|
142 |
" --config-dir=PATH %6\n" |
|
143 |
" --data-dir=PATH %7\n" |
|
144 |
"\n" |
|
145 |
"%8" |
|
10405
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
146 |
"\n" |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
147 |
).arg(HWApplication::tr("Usage", "command-line")) |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
148 |
.arg(HWApplication::tr("OPTION", "command-line")) |
10407 | 149 |
.arg(HWApplication::tr("CONNECTSTRING", "command-line")) |
10405
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
150 |
.arg(HWApplication::tr("Options", "command-line")) |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
151 |
.arg(HWApplication::tr("Display this help", "command-line")) |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
152 |
.arg(HWApplication::tr("Custom path for configuration data and user data", "command-line")) |
10407 | 153 |
.arg(HWApplication::tr("Custom path to the game data folder", "command-line")) |
10486 | 154 |
.arg(HWApplication::tr("Hedgewars can use a %1 (e.g. \"%2\") to connect on start.", "command-line").arg(HWApplication::tr("CONNECTSTRING", "command-line")).arg(QString("hwplay://") + NETGAME_DEFAULT_SERVER)); |
10405
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
155 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
156 |
|
13178
b4f48e7a4953
seems to help styling some - some CSS tweaks may still be needed - lobby for example
nemo
parents:
12897
diff
changeset
|
157 |
int main(int argc, char *argv[]) { |
b4f48e7a4953
seems to help styling some - some CSS tweaks may still be needed - lobby for example
nemo
parents:
12897
diff
changeset
|
158 |
/* Qt5 removed motif, plastique. These are now in qt5-style-plugins which was NOT backported by debian/ubuntu to stable/LTS - windows appears to render best of the remaining options */ |
b4f48e7a4953
seems to help styling some - some CSS tweaks may still be needed - lobby for example
nemo
parents:
12897
diff
changeset
|
159 |
QApplication::setStyle(QStyleFactory::create("windows")); |
8406
8a834943609d
Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents:
8405
diff
changeset
|
160 |
// Since we're calling this first, closeResources() will be the last thing called after main() returns. |
8a834943609d
Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents:
8405
diff
changeset
|
161 |
atexit(closeResources); |
8a834943609d
Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents:
8405
diff
changeset
|
162 |
|
8187
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
163 |
#ifdef __APPLE__ |
8406
8a834943609d
Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents:
8405
diff
changeset
|
164 |
cocoaInit = new CocoaInitializer(); // Creates the autoreleasepool preventing cocoa object leaks on OS X. |
8187
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
165 |
#endif |
fa725fe25708
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents:
8117
diff
changeset
|
166 |
|
9711
7d0329f37181
To prevent that weird crash, you need to initialize SDL before Qt
unc0rr
parents:
9163
diff
changeset
|
167 |
SDLInteraction::instance(); |
7d0329f37181
To prevent that weird crash, you need to initialize SDL before Qt
unc0rr
parents:
9163
diff
changeset
|
168 |
|
5252 | 169 |
HWApplication app(argc, argv); |
13178
b4f48e7a4953
seems to help styling some - some CSS tweaks may still be needed - lobby for example
nemo
parents:
12897
diff
changeset
|
170 |
//qDebug() << app.style(); |
10405
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
171 |
app.setAttribute(Qt::AA_DontShowIconsInMenus,false); |
7130 | 172 |
|
12661 | 173 |
// file engine, to be initialized later |
10405
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
174 |
engine = NULL; |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
175 |
|
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
176 |
// parse arguments |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
177 |
|
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
178 |
QStringList arguments = app.arguments(); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
179 |
QMap<QString, QString> parsedArgs; |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
180 |
{ |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
181 |
QList<QString>::iterator i = arguments.begin(); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
182 |
while(i != arguments.end()) |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
183 |
{ |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
184 |
QString arg = *i; |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
185 |
|
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
186 |
|
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
187 |
QRegExp opt("--(\\S+)=(.+)"); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
188 |
if(opt.exactMatch(arg)) |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
189 |
{ |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
190 |
parsedArgs[opt.cap(1)] = opt.cap(2); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
191 |
i = arguments.erase(i); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
192 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
193 |
else |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
194 |
{ |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
195 |
if(arg.startsWith("--")) { |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
196 |
if(arg == "--help") |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
197 |
{ |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
198 |
printf("%s", getUsage().toUtf8().constData()); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
199 |
return 0; |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
200 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
201 |
// argument is something wrong |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
202 |
fprintf(stderr, "%s\n\n%s", |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
203 |
HWApplication::tr("Malformed option argument: %1", "command-line").arg(arg).toUtf8().constData(), |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
204 |
getUsage().toUtf8().constData()); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
205 |
return 1; |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
206 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
207 |
|
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
208 |
// if not starting with --, then always skip |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
209 |
// (because we can't determine if executable path/call or not - on windows) |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
210 |
++i; |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
211 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
212 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
213 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
214 |
|
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
215 |
if(parsedArgs.contains("data-dir")) |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
216 |
{ |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
217 |
QFileInfo f(parsedArgs["data-dir"]); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
218 |
parsedArgs.remove("data-dir"); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
219 |
if(!f.exists()) |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
220 |
{ |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
221 |
qWarning() << "WARNING: Cannot open DATA_PATH=" << f.absoluteFilePath(); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
222 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
223 |
*cDataDir = f.absoluteFilePath(); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
224 |
custom_data = true; |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
225 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
226 |
|
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
227 |
if(parsedArgs.contains("config-dir")) |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
228 |
{ |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
229 |
QFileInfo f(parsedArgs["config-dir"]); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
230 |
parsedArgs.remove("config-dir"); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
231 |
cfgdir->setPath(f.absoluteFilePath()); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
232 |
custom_config = true; |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
233 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
234 |
else |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
235 |
{ |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
236 |
cfgdir->setPath(QDir::homePath()); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
237 |
custom_config = false; |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
238 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
239 |
|
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
240 |
if (!parsedArgs.isEmpty()) { |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
241 |
foreach (const QString & key, parsedArgs.keys()) |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
242 |
{ |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
243 |
fprintf(stderr, "%s\n", HWApplication::tr("Unknown option argument: %1", "command-line").arg(QString("--") + key).toUtf8().constData()); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
244 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
245 |
fprintf(stderr, "\n%s", getUsage().toUtf8().constData()); |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
246 |
return 1; |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
247 |
} |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
248 |
|
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
249 |
// end of parameter parsing |
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
250 |
|
12661 | 251 |
|
252 |
#ifdef Q_OS_WIN |
|
253 |
QPixmap pixmap(":/res/splash.png"); |
|
254 |
QSplashScreen splash(pixmap); |
|
255 |
splash.show(); |
|
8337
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
256 |
#endif |
12661 | 257 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
258 |
QDateTime now = QDateTime::currentDateTime(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
259 |
srand(now.toTime_t()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
260 |
rand(); |
579 | 261 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
262 |
Q_INIT_RESOURCE(hedgewars); |
579 | 263 |
|
6721
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6700
diff
changeset
|
264 |
qRegisterMetaType<HWTeam>("HWTeam"); |
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6700
diff
changeset
|
265 |
|
8323
ab0b618bdf13
get executable directory at runtime rather than configure time
koda
parents:
8316
diff
changeset
|
266 |
bindir->cd(QCoreApplication::applicationDirPath()); |
579 | 267 |
|
8323
ab0b618bdf13
get executable directory at runtime rather than configure time
koda
parents:
8316
diff
changeset
|
268 |
if(custom_config == false) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
269 |
{ |
1965 | 270 |
#ifdef __APPLE__ |
3758 | 271 |
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
272 |
cfgdir->cd("Library/Application Support/Hedgewars"); |
3333 | 273 |
#elif defined _WIN32 |
274 |
char path[1024]; |
|
275 |
if(!SHGetFolderPathA(0, CSIDL_PERSONAL, NULL, 0, path)) |
|
276 |
{ |
|
277 |
cfgdir->cd(path); |
|
3758 | 278 |
checkForDir(cfgdir->absolutePath() + "/Hedgewars"); |
3333 | 279 |
cfgdir->cd("Hedgewars"); |
280 |
} |
|
3758 | 281 |
else // couldn't retrieve documents folder? almost impossible, but in case fall back to classic path |
3333 | 282 |
{ |
9094 | 283 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars"); |
284 |
cfgdir->cd(".hedgewars"); |
|
3333 | 285 |
} |
2428 | 286 |
#else |
9094 | 287 |
checkForDir(cfgdir->absolutePath() + "/.hedgewars"); |
288 |
cfgdir->cd(".hedgewars"); |
|
2428 | 289 |
#endif |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
290 |
} |
3758 | 291 |
|
292 |
if (checkForDir(cfgdir->absolutePath())) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
293 |
{ |
3758 | 294 |
// alternative loading/lookup paths |
295 |
checkForDir(cfgdir->absolutePath() + "/Data"); |
|
296 |
||
297 |
// config/save paths |
|
298 |
checkForDir(cfgdir->absolutePath() + "/Demos"); |
|
299 |
checkForDir(cfgdir->absolutePath() + "/Saves"); |
|
300 |
checkForDir(cfgdir->absolutePath() + "/Screenshots"); |
|
301 |
checkForDir(cfgdir->absolutePath() + "/Teams"); |
|
3914 | 302 |
checkForDir(cfgdir->absolutePath() + "/Logs"); |
7180 | 303 |
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
|
304 |
checkForDir(cfgdir->absolutePath() + "/VideoTemp"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
305 |
} |
579 | 306 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
307 |
datadir->cd(bindir->absolutePath()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
308 |
datadir->cd(*cDataDir); |
8799
44e520374cfc
drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents:
8722
diff
changeset
|
309 |
if (!datadir->cd("Data")) |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
310 |
{ |
8799
44e520374cfc
drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents:
8722
diff
changeset
|
311 |
MessageDialog::ShowFatalMessage(HWApplication::tr("Failed to open data directory:\n%1\n\nPlease check your installation!").arg(datadir->absolutePath()+"/Data")); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
312 |
return 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
313 |
} |
579 | 314 |
|
7931 | 315 |
// setup PhysFS |
10405
469ce70ba163
fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents:
10108
diff
changeset
|
316 |
engine = new FileEngineHandler(argv[0]); |
8405
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
317 |
engine->mount(datadir->absolutePath()); |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
318 |
engine->mount(cfgdir->absolutePath() + "/Data"); |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
319 |
engine->mount(cfgdir->absolutePath()); |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
320 |
engine->setWriteDir(cfgdir->absolutePath()); |
becac012d502
Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents:
8385
diff
changeset
|
321 |
engine->mountPacks(); |
7772 | 322 |
|
11488 | 323 |
QTranslator TranslatorHedgewars; |
324 |
QTranslator TranslatorQt; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
325 |
{ |
8918
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8882
diff
changeset
|
326 |
QSettings settings(DataManager::instance().settingsFileName(), QSettings::IniFormat); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8882
diff
changeset
|
327 |
settings.setIniCodec("UTF-8"); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8882
diff
changeset
|
328 |
|
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
|
329 |
QString cc = settings.value("misc/locale", QString()).toString(); |
8882
73d6d7f27945
fix 'failed to install translation' message when misc/locale in hedgewars.ini is empty (which is *always* when 'system default' is selected)
koda
parents:
8799
diff
changeset
|
330 |
if (cc.isEmpty()) |
9027
4b8e326251b3
Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents:
8918
diff
changeset
|
331 |
{ |
4b8e326251b3
Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents:
8918
diff
changeset
|
332 |
cc = QLocale::system().name(); |
4b8e326251b3
Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents:
8918
diff
changeset
|
333 |
|
4b8e326251b3
Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents:
8918
diff
changeset
|
334 |
// Fallback to current input locale if "C" locale is returned |
4b8e326251b3
Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents:
8918
diff
changeset
|
335 |
if(cc == "C") |
12897
fc47fc4af6bd
Finish porting. Seems to work, but no thorough testing has been performed
unc0rr
parents:
12661
diff
changeset
|
336 |
cc = HWApplication::inputMethod()->locale().name(); |
9027
4b8e326251b3
Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents:
8918
diff
changeset
|
337 |
} |
6167 | 338 |
|
11488 | 339 |
// Load locale files into translators |
340 |
if (!TranslatorHedgewars.load(QString("physfs://Locale/hedgewars_%1").arg(cc))) |
|
341 |
qWarning("Failed to install Hedgewars translation (%s)", qPrintable(cc)); |
|
342 |
if (!TranslatorQt.load(QString("%1/qt_%2").arg(QLibraryInfo::location(QLibraryInfo::TranslationsPath), cc))) |
|
343 |
qWarning("Failed to install Qt translation (%s)", qPrintable(cc)); |
|
344 |
app.installTranslator(&TranslatorHedgewars); |
|
345 |
app.installTranslator(&TranslatorQt); |
|
10488 | 346 |
app.setLayoutDirection(QLocale(cc).textDirection()); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2913
diff
changeset
|
347 |
} |
2898 | 348 |
|
5756 | 349 |
#ifdef _WIN32 |
11851 | 350 |
// Win32 registry setup (used for external software detection etc. |
351 |
// don't set it if running in "portable" mode with a custom config dir) |
|
3932 | 352 |
if(!custom_config) |
3679 | 353 |
{ |
3932 | 354 |
QSettings registry_hklm("HKEY_LOCAL_MACHINE", QSettings::NativeFormat); |
355 |
registry_hklm.setValue("Software/Hedgewars/Frontend", bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe"); |
|
356 |
registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\")); |
|
3679 | 357 |
} |
358 |
#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
|
359 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
360 |
QString style = ""; |
6579 | 361 |
QString fname; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
362 |
|
6579 | 363 |
checkSeason(); |
364 |
//For each season, there is an extra stylesheet |
|
365 |
//Todo: change background for easter and birthday |
|
366 |
//(simply replace res/BackgroundBirthday.png and res/BackgroundEaster.png |
|
367 |
//with an appropriate background |
|
368 |
switch (season) |
|
369 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
370 |
case SEASON_CHRISTMAS : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
371 |
fname = "christmas.css"; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
372 |
break; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
373 |
case SEASON_EASTER : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
374 |
fname = "easter.css"; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
375 |
break; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
376 |
case SEASON_HWBDAY : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
377 |
fname = "birthday.css"; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
378 |
break; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
379 |
default : |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6600
diff
changeset
|
380 |
fname = "qt.css"; |
8337
bf237f7f1d94
add a splashscreen while the main interface is loading (enabled on all platforms, disable if it doesn'n't look good
koda
parents:
8323
diff
changeset
|
381 |
break; |
6579 | 382 |
} |
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
|
383 |
|
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
|
384 |
// load external stylesheet if there is any |
8049 | 385 |
QFile extFile("physfs://css/" + fname); |
2898 | 386 |
|
6579 | 387 |
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
|
388 |
|
7724 | 389 |
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
|
390 |
|
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
391 |
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
7724 | 392 |
style.append(file.readAll()); |
2377 | 393 |
|
8651 | 394 |
qWarning("Starting Hedgewars %s-r%d (%s)", qPrintable(*cVersionString), cRevisionString->toInt(), qPrintable(*cHashString)); |
395 |
||
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
|
396 |
app.form = new HWForm(NULL, style); |
12661 | 397 |
#ifdef Q_OS_WIN |
398 |
splash.finish(app.form); |
|
399 |
#endif |
|
5252 | 400 |
app.form->show(); |
12661 | 401 |
|
8722
2dead6b84bca
this should supposedly add hwplay:// schemes to windows, after user presses file association
koda
parents:
8715
diff
changeset
|
402 |
if (app.urlString) |
2dead6b84bca
this should supposedly add hwplay:// schemes to windows, after user presses file association
koda
parents:
8715
diff
changeset
|
403 |
app.fakeEvent(); |
8223
14d9a3c33650
backout rea7541f77944 since development of frontlib is on another branch
koda
parents:
8206
diff
changeset
|
404 |
return app.exec(); |
2845 | 405 |
} |