QTfrontend/main.cpp
author Wuzzy <Wuzzy2@mail.ru>
Thu, 15 Mar 2018 21:15:16 +0100
changeset 13226 02bf6902eeb0
parent 13217 e9e4cc867b6e
child 13279 e381f5260b45
permissions -rw-r--r--
Remove Qt SVG and Qt OpenGL as hard dependencies Qt SVG is not used in the frontend (no SVGs are rendered). Neither is Qt OpenGL used. Qt OpenGL is discouraged anyway.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 579
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10488
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     4
 *
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     8
 *
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    13
 *
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    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
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    17
 */
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    18
5252
ded882439548 file association for mac!
koda
parents: 5238
diff changeset
    19
#include "HWApplication.h"
ded882439548 file association for mac!
koda
parents: 5238
diff changeset
    20
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    21
#include <QTranslator>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    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
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
    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
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    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>
11493
637fb0558a73 Load Qt library's translation
Wuzzy <almikes@aol.com>
parents: 11342
diff changeset
    30
#include <QLibraryInfo>
13183
b4f48e7a4953 seems to help styling some - some CSS tweaks may still be needed - lobby for example
nemo
parents: 12902
diff changeset
    31
#include <QStyle>
b4f48e7a4953 seems to help styling some - some CSS tweaks may still be needed - lobby for example
nemo
parents: 12902
diff changeset
    32
#include <QStyleFactory>
1146
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    33
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    34
#include "hwform.h"
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    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
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    37
6930
d187ea93fc4f renaming HWDataManager -> DataManager
sheepluva
parents: 6721
diff changeset
    38
#include "DataManager.h"
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents: 7724
diff changeset
    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
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    44
#ifdef _WIN32
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    45
#include <Shlobj.h>
8355
df0ea4323295 GCI2012: Unix Qt Signals
martin_bede
parents: 8344
diff changeset
    46
#elif defined __APPLE__
df0ea4323295 GCI2012: Unix Qt Signals
martin_bede
parents: 8344
diff changeset
    47
#include "CocoaInitializer.h"
12666
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
    48
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
    49
#endif
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
    50
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
    51
#ifdef Q_OS_WIN
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
    52
#include <QSplashScreen>
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    53
#endif
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    54
13091
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
    55
#include <QMessageBox>
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
    56
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
    57
// 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
    58
#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
    59
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
    60
#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
    61
static FileEngineHandler * engine = NULL;
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    62
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    63
//Determines the day of easter in year
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    64
//from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    65
QDate calculateEaster(long year)
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    66
{
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    67
    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
    68
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    69
    c = year/100;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    70
    n = year - 19*(year/19);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    71
    k = (c - 17)/25;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    72
    i = c - c/4 - (c - k)/3 + 19*n + 15;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    73
    i = i - 30*(i/30);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    74
    i = i - (i/28)*(1 - (i/28)*(29/(i + 1))*((21 - n)/11));
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    75
    j = year + year/4 + i + 2 - c + c/4;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    76
    j = j - 7*(j/7);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    77
    l = i - j;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    78
    m = 3 + (l + 40)/44;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    79
    d = l + 28 - 31*(m / 4);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    80
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    81
    return QDate(year, m, d);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    82
}
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    83
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    84
//Checks season and assigns it to the variable season in "hwconsts.h"
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    85
void checkSeason()
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    86
{
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    87
    QDate date = QDate::currentDate();
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    88
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    89
    //Christmas?
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    90
    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
    91
            && date.day() <= 26)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    92
        season = SEASON_CHRISTMAS;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    93
    //Hedgewars birthday?
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    94
    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
    95
    {
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    96
        season = SEASON_HWBDAY;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    97
        years_since_foundation = date.year() - 2004;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    98
    }
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    99
    //Easter?
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   100
    else if (calculateEaster(date.year()) == date)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   101
        season = SEASON_EASTER;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   102
    else
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   103
        season = SEASON_NONE;
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   104
}
8385
9e8924ff9813 Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents: 8355
diff changeset
   105
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   106
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   107
bool checkForDir(const QString & dir)
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   108
{
8206
1633a6510834 Create hedgewars.ini if not exists manually,
unc0rr
parents: 8187
diff changeset
   109
    QDir tmpdir(dir);
1633a6510834 Create hedgewars.ini if not exists manually,
unc0rr
parents: 8187
diff changeset
   110
    if (!tmpdir.exists())
1633a6510834 Create hedgewars.ini if not exists manually,
unc0rr
parents: 8187
diff changeset
   111
        if (!tmpdir.mkpath(dir))
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   112
        {
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8722
diff changeset
   113
            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
   114
            return false;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   115
        }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   116
    return true;
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   117
}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   118
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
   119
// 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
   120
// 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
   121
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
   122
{
8187
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   123
#ifdef __APPLE__
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   124
    if (cocoaInit != NULL)
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   125
    {
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   126
        delete cocoaInit;
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   127
        cocoaInit = NULL;
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   128
    }
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
   129
#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
   130
    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
   131
    {
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
        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
   133
        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
   134
    }
8187
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   135
}
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   136
10405
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   137
QString getUsage()
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   138
{
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   139
    return QString(
10407
012bb4b63117 mention the hwplay:// thing in --help
sheepluva
parents: 10405
diff changeset
   140
"%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
   141
"\n"
10407
012bb4b63117 mention the hwplay:// thing in --help
sheepluva
parents: 10405
diff changeset
   142
"%4:\n"
012bb4b63117 mention the hwplay:// thing in --help
sheepluva
parents: 10405
diff changeset
   143
"  --help              %5\n"
012bb4b63117 mention the hwplay:// thing in --help
sheepluva
parents: 10405
diff changeset
   144
"  --config-dir=PATH   %6\n"
012bb4b63117 mention the hwplay:// thing in --help
sheepluva
parents: 10405
diff changeset
   145
"  --data-dir=PATH     %7\n"
012bb4b63117 mention the hwplay:// thing in --help
sheepluva
parents: 10405
diff changeset
   146
"\n"
012bb4b63117 mention the hwplay:// thing in --help
sheepluva
parents: 10405
diff changeset
   147
"%8"
10405
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   148
"\n"
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   149
).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
   150
.arg(HWApplication::tr("OPTION", "command-line"))
10407
012bb4b63117 mention the hwplay:// thing in --help
sheepluva
parents: 10405
diff changeset
   151
.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
   152
.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
   153
.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
   154
.arg(HWApplication::tr("Custom path for configuration data and user data", "command-line"))
10407
012bb4b63117 mention the hwplay:// thing in --help
sheepluva
parents: 10405
diff changeset
   155
.arg(HWApplication::tr("Custom path to the game data folder", "command-line"))
10486
5e2d26bcafd6 fix one of my translation related brainfarts
sheepluva
parents: 10407
diff changeset
   156
.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
   157
}
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   158
13183
b4f48e7a4953 seems to help styling some - some CSS tweaks may still be needed - lobby for example
nemo
parents: 12902
diff changeset
   159
int main(int argc, char *argv[]) {
13185
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   160
    /* Qt5 Base removed Motif, Plastique. These are now in the Qt style plugins
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   161
    (Ubuntu: qt5-style-plugins, which was NOT backported by Debian/Ubuntu to stable/LTS).
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   162
    Windows appears to render best of the remaining options but still isn't quite right. */
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   163
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   164
    // Try setting Plastique if available
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   165
    QStyle* coreStyle;
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   166
    coreStyle = QStyleFactory::create("Plastique");
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   167
    if(coreStyle != 0) {
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   168
        QApplication::setStyle(coreStyle);
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   169
        qDebug("Qt style set: Plastique");
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   170
    } else {
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   171
        // Use Windows as fallback.
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   172
        // FIXME: Under Windows style, some widgets like scrollbars don't render as nicely
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   173
        coreStyle = QStyleFactory::create("Windows");
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   174
        if(coreStyle != 0) {
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   175
            QApplication::setStyle(coreStyle);
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   176
            qDebug("Qt style set: Windows");
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   177
        } else {
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   178
            // Windows style should not be missing in Qt5 Base. If it does, something went terribly wrong!
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   179
            qWarning("No Qt style could be set! Using the default one.");
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   180
        }
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   181
    }
3961f9d0c7e4 Fix buggy Qt5 style detection causing segfault on Arch Linux w/ qt5-style-plugins
Wuzzy <Wuzzy2@mail.ru>
parents: 13184
diff changeset
   182
8406
8a834943609d Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents: 8405
diff changeset
   183
    // 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
   184
    atexit(closeResources);
8a834943609d Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents: 8405
diff changeset
   185
8187
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   186
#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
   187
    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
   188
#endif
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   189
9711
7d0329f37181 To prevent that weird crash, you need to initialize SDL before Qt
unc0rr
parents: 9163
diff changeset
   190
    SDLInteraction::instance();
7d0329f37181 To prevent that weird crash, you need to initialize SDL before Qt
unc0rr
parents: 9163
diff changeset
   191
5252
ded882439548 file association for mac!
koda
parents: 5238
diff changeset
   192
    HWApplication app(argc, argv);
10405
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   193
    app.setAttribute(Qt::AA_DontShowIconsInMenus,false);
7130
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6958
diff changeset
   194
12666
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
   195
    // 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
   196
    engine = NULL;
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
    // parse arguments
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   199
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   200
    QStringList arguments = app.arguments();
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   201
    QMap<QString, QString> parsedArgs;
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   202
    {
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   203
        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
   204
        while(i != arguments.end())
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   205
        {
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   206
            QString arg = *i;
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
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   209
            QRegExp opt("--(\\S+)=(.+)");
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   210
            if(opt.exactMatch(arg))
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
                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
   213
                i = arguments.erase(i);
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
            else
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
                if(arg.startsWith("--")) {
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   218
                    if(arg == "--help")
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   219
                    {
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   220
                        printf("%s", getUsage().toUtf8().constData());
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   221
                        return 0;
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
                    // argument is something wrong
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   224
                    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
   225
                        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
   226
                        getUsage().toUtf8().constData());
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   227
                    return 1;
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
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   230
                // 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
   231
                // (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
   232
                ++i;
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
        }
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
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   237
    if(parsedArgs.contains("data-dir"))
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
        QFileInfo f(parsedArgs["data-dir"]);
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   240
        parsedArgs.remove("data-dir");
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   241
        if(!f.exists())
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
            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
   244
        }
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   245
        *cDataDir = f.absoluteFilePath();
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   246
        custom_data = true;
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
    if(parsedArgs.contains("config-dir"))
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   250
    {
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   251
        QFileInfo f(parsedArgs["config-dir"]);
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   252
        parsedArgs.remove("config-dir");
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   253
        cfgdir->setPath(f.absoluteFilePath());
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   254
        custom_config = true;
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   255
    }
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   256
    else
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   257
    {
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   258
        cfgdir->setPath(QDir::homePath());
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   259
        custom_config = false;
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   260
    }
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   261
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   262
    if (!parsedArgs.isEmpty()) {
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   263
        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
   264
        {
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   265
            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
   266
        }
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   267
        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
   268
        return 1;
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   269
    }
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   270
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   271
    // end of parameter parsing
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   272
12666
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
   273
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
   274
#ifdef Q_OS_WIN
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
   275
    QPixmap pixmap(":/res/splash.png");
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
   276
    QSplashScreen splash(pixmap);
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
   277
    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
   278
#endif
12666
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
   279
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   280
    QDateTime now = QDateTime::currentDateTime();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   281
    srand(now.toTime_t());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   282
    rand();
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   283
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   284
    Q_INIT_RESOURCE(hedgewars);
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   285
6721
7dbf8a0c1f5d - Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents: 6700
diff changeset
   286
    qRegisterMetaType<HWTeam>("HWTeam");
7dbf8a0c1f5d - Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents: 6700
diff changeset
   287
8323
ab0b618bdf13 get executable directory at runtime rather than configure time
koda
parents: 8316
diff changeset
   288
    bindir->cd(QCoreApplication::applicationDirPath());
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   289
8323
ab0b618bdf13 get executable directory at runtime rather than configure time
koda
parents: 8316
diff changeset
   290
    if(custom_config == false)
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   291
    {
1965
340bfd438ca5 - Apply koda's patch
unc0rr
parents: 1940
diff changeset
   292
#ifdef __APPLE__
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   293
        checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   294
        cfgdir->cd("Library/Application Support/Hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   295
#elif defined _WIN32
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   296
        char path[1024];
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   297
        if(!SHGetFolderPathA(0, CSIDL_PERSONAL, NULL, 0, path))
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   298
        {
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   299
            cfgdir->cd(path);
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   300
            checkForDir(cfgdir->absolutePath() + "/Hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   301
            cfgdir->cd("Hedgewars");
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   302
        }
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   303
        else // couldn't retrieve documents folder? almost impossible, but in case fall back to classic path
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   304
        {
9094
2cdb0ed3813a Merge 0.9.19
nemo
parents: 9093
diff changeset
   305
            checkForDir(cfgdir->absolutePath() + "/.hedgewars");
2cdb0ed3813a Merge 0.9.19
nemo
parents: 9093
diff changeset
   306
            cfgdir->cd(".hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   307
        }
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   308
#else
9094
2cdb0ed3813a Merge 0.9.19
nemo
parents: 9093
diff changeset
   309
        checkForDir(cfgdir->absolutePath() + "/.hedgewars");
2cdb0ed3813a Merge 0.9.19
nemo
parents: 9093
diff changeset
   310
        cfgdir->cd(".hedgewars");
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   311
#endif
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   312
    }
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   313
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   314
    if (checkForDir(cfgdir->absolutePath()))
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   315
    {
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   316
        // alternative loading/lookup paths
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   317
        checkForDir(cfgdir->absolutePath() + "/Data");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   318
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   319
        // config/save paths
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   320
        checkForDir(cfgdir->absolutePath() + "/Demos");
13217
e9e4cc867b6e Add default directory DrawnMaps to put hand-drawn maps into
Wuzzy <Wuzzy2@mail.ru>
parents: 13193
diff changeset
   321
        checkForDir(cfgdir->absolutePath() + "/DrawnMaps");
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   322
        checkForDir(cfgdir->absolutePath() + "/Saves");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   323
        checkForDir(cfgdir->absolutePath() + "/Screenshots");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   324
        checkForDir(cfgdir->absolutePath() + "/Teams");
3914
c5c903c6225b Engine:
smaxx
parents: 3865
diff changeset
   325
        checkForDir(cfgdir->absolutePath() + "/Logs");
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents: 7130
diff changeset
   326
        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
   327
        checkForDir(cfgdir->absolutePath() + "/VideoTemp");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   328
    }
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   329
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   330
    datadir->cd(bindir->absolutePath());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   331
    datadir->cd(*cDataDir);
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8722
diff changeset
   332
    if (!datadir->cd("Data"))
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   333
    {
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8722
diff changeset
   334
        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
   335
        return 1;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   336
    }
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   337
13091
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   338
    bool isProbablyNewPlayer = false;
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   339
7931
5a27ed7f17b7 Wee, now frontend is able to load translation file
unc0rr
parents: 7928
diff changeset
   340
    // setup PhysFS
10405
469ce70ba163 fix for < LocutusOfBorg1> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760776
sheepluva
parents: 10108
diff changeset
   341
    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
   342
    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
   343
    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
   344
    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
   345
    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
   346
    engine->mountPacks();
7772
a33077239712 Oops, forgot this
unc0rr
parents: 7768
diff changeset
   347
11493
637fb0558a73 Load Qt library's translation
Wuzzy <almikes@aol.com>
parents: 11342
diff changeset
   348
    QTranslator TranslatorHedgewars;
637fb0558a73 Load Qt library's translation
Wuzzy <almikes@aol.com>
parents: 11342
diff changeset
   349
    QTranslator TranslatorQt;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   350
    {
8918
512753ea4b1b Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents: 8882
diff changeset
   351
        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
   352
        settings.setIniCodec("UTF-8");
512753ea4b1b Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents: 8882
diff changeset
   353
13091
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   354
        // Heuristic to figure out if the user is (probably) a first-time player.
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   355
        // If nickname is not set, then probably yes.
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   356
        // The hidden setting firstLaunch is, if present, used to force HW to
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   357
        // treat iself as if it were launched the first time.
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   358
        QString nick = settings.value("net/nick", QString()).toString();
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   359
        if (settings.contains("frontend/firstLaunch"))
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   360
        {
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   361
            isProbablyNewPlayer = settings.value("frontend/firstLaunch").toBool();
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   362
        }
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   363
        else
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   364
        {
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   365
            isProbablyNewPlayer = nick.isNull();
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   366
        }
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   367
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   368
        // Set firstLaunch to false to make sure we remember we have been launched before.
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   369
        settings.setValue("frontend/firstLaunch", false);
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   370
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
   371
        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
   372
        if (cc.isEmpty())
9027
4b8e326251b3 Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents: 8918
diff changeset
   373
        {
4b8e326251b3 Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents: 8918
diff changeset
   374
            cc = QLocale::system().name();
4b8e326251b3 Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents: 8918
diff changeset
   375
4b8e326251b3 Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents: 8918
diff changeset
   376
            // 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
   377
            if(cc == "C")
12902
fc47fc4af6bd Finish porting. Seems to work, but no thorough testing has been performed
unc0rr
parents: 12666
diff changeset
   378
                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
   379
        }
13187
d2f8dafdb080 Frontend: Fix built-in Qt translations not loaded properly
Wuzzy <Wuzzy2@mail.ru>
parents: 13185
diff changeset
   380
        qDebug("Frontend uses locale: %s", qPrintable(cc));
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   381
11493
637fb0558a73 Load Qt library's translation
Wuzzy <almikes@aol.com>
parents: 11342
diff changeset
   382
        // Load locale files into translators
13187
d2f8dafdb080 Frontend: Fix built-in Qt translations not loaded properly
Wuzzy <Wuzzy2@mail.ru>
parents: 13185
diff changeset
   383
        if (!TranslatorHedgewars.load(QString("hedgewars_%1").arg(cc), QString("physfs://Locale")))
11493
637fb0558a73 Load Qt library's translation
Wuzzy <almikes@aol.com>
parents: 11342
diff changeset
   384
            qWarning("Failed to install Hedgewars translation (%s)", qPrintable(cc));
13187
d2f8dafdb080 Frontend: Fix built-in Qt translations not loaded properly
Wuzzy <Wuzzy2@mail.ru>
parents: 13185
diff changeset
   385
        if (!TranslatorQt.load(QString("qt_%1").arg(cc), QString(QLibraryInfo::location(QLibraryInfo::TranslationsPath))))
11493
637fb0558a73 Load Qt library's translation
Wuzzy <almikes@aol.com>
parents: 11342
diff changeset
   386
            qWarning("Failed to install Qt translation (%s)", qPrintable(cc));
637fb0558a73 Load Qt library's translation
Wuzzy <almikes@aol.com>
parents: 11342
diff changeset
   387
        app.installTranslator(&TranslatorHedgewars);
637fb0558a73 Load Qt library's translation
Wuzzy <almikes@aol.com>
parents: 11342
diff changeset
   388
        app.installTranslator(&TranslatorQt);
10488
c5735d0fcc50 automatic RTL based on locale
Safa
parents: 10486
diff changeset
   389
        app.setLayoutDirection(QLocale(cc).textDirection());
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   390
    }
2898
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
   391
5756
b451fd21ff4c Extract downloaded content into temp dir
unc0rr
parents: 5307
diff changeset
   392
#ifdef _WIN32
11856
5edd66c2d422 Drop xfire module
koda
parents: 11493
diff changeset
   393
    // Win32 registry setup (used for external software detection etc.
5edd66c2d422 Drop xfire module
koda
parents: 11493
diff changeset
   394
    // don't set it if running in "portable" mode with a custom config dir)
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   395
    if(!custom_config)
3679
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   396
    {
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   397
        QSettings registry_hklm("HKEY_LOCAL_MACHINE", QSettings::NativeFormat);
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   398
        registry_hklm.setValue("Software/Hedgewars/Frontend", bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe");
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   399
        registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\"));
3679
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   400
    }
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   401
#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
   402
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   403
    QString style = "";
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   404
    QString fname;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   405
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   406
    checkSeason();
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   407
    //For each season, there is an extra stylesheet
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   408
    //Todo: change background for easter and birthday
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   409
    //(simply replace res/BackgroundBirthday.png and res/BackgroundEaster.png
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   410
    //with an appropriate background
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   411
    switch (season)
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   412
    {
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   413
        case SEASON_CHRISTMAS :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   414
            fname = "christmas.css";
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   415
            break;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   416
        case SEASON_EASTER :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   417
            fname = "easter.css";
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   418
            break;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   419
        case SEASON_HWBDAY :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   420
            fname = "birthday.css";
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   421
            break;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   422
        default :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   423
            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
   424
            break;
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   425
    }
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
   426
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
   427
    // load external stylesheet if there is any
8049
133e22b5c410 Get rid of DataManager::findFileForRead
unc0rr
parents: 7955
diff changeset
   428
    QFile extFile("physfs://css/" + fname);
2898
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
   429
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   430
    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
   431
7724
36c539c9cfb1 Simplify file loading procedure
unc0rr
parents: 7278
diff changeset
   432
    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
   433
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   434
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
7724
36c539c9cfb1 Simplify file loading procedure
unc0rr
parents: 7278
diff changeset
   435
        style.append(file.readAll());
2377
f3fab2b09e0c And in frontend
nemo
parents: 2261
diff changeset
   436
8651
da384b09eb2b add version info to frontend output too
koda
parents: 8508
diff changeset
   437
    qWarning("Starting Hedgewars %s-r%d (%s)", qPrintable(*cVersionString), cRevisionString->toInt(), qPrintable(*cHashString));
da384b09eb2b add version info to frontend output too
koda
parents: 8508
diff changeset
   438
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
   439
    app.form = new HWForm(NULL, style);
12666
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
   440
#ifdef Q_OS_WIN
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
   441
    splash.finish(app.form);
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
   442
#endif
5252
ded882439548 file association for mac!
koda
parents: 5238
diff changeset
   443
    app.form->show();
12666
1dc160048a0c Fix splash screen on Windows
alfadur
parents: 11856
diff changeset
   444
13091
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   445
    // Show welcome message for (suspected) first-time player and
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   446
    // point towards the Training menu.
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   447
    if(isProbablyNewPlayer) {
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   448
        QMessageBox questionTutorialMsg(app.form);
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   449
        questionTutorialMsg.setIcon(QMessageBox::Question);
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   450
        questionTutorialMsg.setWindowTitle(QMessageBox::tr("Welcome to Hedgewars"));
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   451
        questionTutorialMsg.setText(QMessageBox::tr("Welcome to Hedgewars!\n\nYou seem to be new around here. Would you like to play some training missions first to learn the basics of Hedgewars?"));
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   452
        questionTutorialMsg.setWindowModality(Qt::WindowModal);
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   453
        questionTutorialMsg.addButton(QMessageBox::Yes);
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   454
        questionTutorialMsg.addButton(QMessageBox::No);
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   455
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   456
        int answer = questionTutorialMsg.exec();
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   457
        if (answer == QMessageBox::Yes) {
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   458
            app.form->GoToTraining();
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   459
        }
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   460
    }
8d569c7b36a2 Frontend: Lead first-time player to training page on start
Wuzzy <Wuzzy2@mail.ru>
parents: 12666
diff changeset
   461
8722
2dead6b84bca this should supposedly add hwplay:// schemes to windows, after user presses file association
koda
parents: 8715
diff changeset
   462
    if (app.urlString)
2dead6b84bca this should supposedly add hwplay:// schemes to windows, after user presses file association
koda
parents: 8715
diff changeset
   463
        app.fakeEvent();
8223
14d9a3c33650 backout rea7541f77944 since development of frontlib is on another branch
koda
parents: 8206
diff changeset
   464
    return app.exec();
2845
19db164dd20d Frontend:
smxx
parents: 2798
diff changeset
   465
}