QTfrontend/main.cpp
author sheepluva
Tue, 10 Nov 2015 17:45:14 +0100
branchsdl2transition
changeset 11360 7a7611adf715
parent 9711 7d0329f37181
child 11362 ed5a6478e710
permissions -rw-r--r--
drop support for SDL 1.2
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
9080
9b42757d7e71 bump copyright year for Andrey entries
unc0rr
parents: 9027
diff changeset
     3
 * Copyright (c) 2004-2013 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
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
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>
1416
60b86d6fe9ae Force plastique style, as others don't fully support stylesheets
unc0rr
parents: 1415
diff changeset
    23
#include <QPlastiqueStyle>
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    24
#include <QRegExp>
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    25
#include <QMap>
2898
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
    26
#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
    27
#include <QStringListModel>
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    28
#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
    29
#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
    30
#include <QLabel>
1146
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    31
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    32
#include "hwform.h"
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    33
#include "hwconsts.h"
6721
7dbf8a0c1f5d - Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents: 6700
diff changeset
    34
#include "newnetclient.h"
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    35
6930
d187ea93fc4f renaming HWDataManager -> DataManager
sheepluva
parents: 6721
diff changeset
    36
#include "DataManager.h"
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents: 7724
diff changeset
    37
#include "FileEngine.h"
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8722
diff changeset
    38
#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
    39
9711
7d0329f37181 To prevent that weird crash, you need to initialize SDL before Qt
unc0rr
parents: 9163
diff changeset
    40
#include "SDLInteraction.h"
7d0329f37181 To prevent that weird crash, you need to initialize SDL before Qt
unc0rr
parents: 9163
diff changeset
    41
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    42
#ifdef _WIN32
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    43
#include <Shlobj.h>
8355
df0ea4323295 GCI2012: Unix Qt Signals
martin_bede
parents: 8344
diff changeset
    44
#elif defined __APPLE__
df0ea4323295 GCI2012: Unix Qt Signals
martin_bede
parents: 8344
diff changeset
    45
#include "CocoaInitializer.h"
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    46
#endif
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    47
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
    48
// 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
    49
#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
    50
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
    51
#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
    52
static FileEngineHandler * engine = NULL;
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    53
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    54
//Determines the day of easter in year
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    55
//from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    56
QDate calculateEaster(long year)
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    57
{
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    58
    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
    59
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    60
    c = year/100;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    61
    n = year - 19*(year/19);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    62
    k = (c - 17)/25;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    63
    i = c - c/4 - (c - k)/3 + 19*n + 15;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    64
    i = i - 30*(i/30);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    65
    i = i - (i/28)*(1 - (i/28)*(29/(i + 1))*((21 - n)/11));
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    66
    j = year + year/4 + i + 2 - c + c/4;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    67
    j = j - 7*(j/7);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    68
    l = i - j;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    69
    m = 3 + (l + 40)/44;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    70
    d = l + 28 - 31*(m / 4);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    71
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    72
    return QDate(year, m, d);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    73
}
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    74
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    75
//Checks season and assigns it to the variable season in "hwconsts.h"
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    76
void checkSeason()
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    77
{
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    78
    QDate date = QDate::currentDate();
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    79
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    80
    //Christmas?
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    81
    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
    82
            && date.day() <= 26)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    83
        season = SEASON_CHRISTMAS;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    84
    //Hedgewars birthday?
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    85
    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
    86
    {
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    87
        season = SEASON_HWBDAY;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    88
        years_since_foundation = date.year() - 2004;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    89
    }
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    90
    //Easter?
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    91
    else if (calculateEaster(date.year()) == date)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    92
        season = SEASON_EASTER;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    93
    else
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    94
        season = SEASON_NONE;
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    95
}
8385
9e8924ff9813 Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents: 8355
diff changeset
    96
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    97
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    98
bool checkForDir(const QString & dir)
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    99
{
8206
1633a6510834 Create hedgewars.ini if not exists manually,
unc0rr
parents: 8187
diff changeset
   100
    QDir tmpdir(dir);
1633a6510834 Create hedgewars.ini if not exists manually,
unc0rr
parents: 8187
diff changeset
   101
    if (!tmpdir.exists())
1633a6510834 Create hedgewars.ini if not exists manually,
unc0rr
parents: 8187
diff changeset
   102
        if (!tmpdir.mkpath(dir))
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   103
        {
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8722
diff changeset
   104
            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
   105
            return false;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   106
        }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   107
    return true;
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   108
}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   109
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
   110
// 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
   111
// 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
   112
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
   113
{
8187
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   114
#ifdef __APPLE__
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   115
    if (cocoaInit != NULL)
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   116
    {
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   117
        delete cocoaInit;
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   118
        cocoaInit = NULL;
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   119
    }
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
   120
#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
   121
    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
   122
    {
becac012d502 Moved FileEngineHandler instance in main() to be a pointer released "atexit". (Fixes issue 509)
dag10 <gottlieb.drew@gmail.com>
parents: 8385
diff changeset
   123
        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
   124
        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
   125
    }
8187
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   126
}
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   127
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   128
int main(int argc, char *argv[])
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   129
{
8406
8a834943609d Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents: 8405
diff changeset
   130
    // 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
   131
    atexit(closeResources);
8a834943609d Accidentally left atexit() inside a mac-only section in last revision (rbecac012d502)
dag10 <gottlieb.drew@gmail.com>
parents: 8405
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
#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
   134
    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
   135
#endif
fa725fe25708 GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
Drew Gottlieb
parents: 8117
diff changeset
   136
9711
7d0329f37181 To prevent that weird crash, you need to initialize SDL before Qt
unc0rr
parents: 9163
diff changeset
   137
    SDLInteraction::instance();
7d0329f37181 To prevent that weird crash, you need to initialize SDL before Qt
unc0rr
parents: 9163
diff changeset
   138
5252
ded882439548 file association for mac!
koda
parents: 5238
diff changeset
   139
    HWApplication app(argc, argv);
7130
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6958
diff changeset
   140
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
   141
    QLabel *splash = NULL;
9163
67334acaaac7 port all Q_WS_* to Q_OS_* so that we are forward compatible with Qt5
koda
parents: 9094
diff changeset
   142
#if defined Q_OS_WIN
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
   143
    QPixmap pixmap(":res/splash.png");
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
   144
    splash = new QLabel(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
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
   145
    splash->setAttribute(Qt::WA_TranslucentBackground);
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8722
diff changeset
   146
    const QRect deskSize = HWApplication::desktop()->screenGeometry(-1);
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
   147
    QPoint splashCenter = QPoint( (deskSize.width() - pixmap.width())/2,
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
   148
                                  (deskSize.height() - pixmap.height())/2 );
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
   149
    splash->move(splashCenter);
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
   150
    splash->setPixmap(pixmap);
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
   151
    splash->show();
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
   152
#endif
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
   153
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
   154
    engine = new FileEngineHandler(argv[0]);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents: 7724
diff changeset
   155
4888
3c96e99468c5 activate icon display in menus
sheepluva
parents: 4513
diff changeset
   156
    app.setAttribute(Qt::AA_DontShowIconsInMenus,false);
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   157
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   158
    QStringList arguments = app.arguments();
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   159
    QMap<QString, QString> parsedArgs;
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   160
    {
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   161
        QList<QString>::iterator i = arguments.begin();
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   162
        while(i != arguments.end())
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   163
        {
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   164
            QString arg = *i;
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   165
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   166
            QRegExp opt("--(\\S+)=(.+)");
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   167
            if(opt.exactMatch(arg))
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   168
            {
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   169
                parsedArgs[opt.cap(1)] = opt.cap(2);
2035
70734c4f52a7 patch to prior checkin
nemo
parents: 2034
diff changeset
   170
                i = arguments.erase(i);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   171
            }
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   172
            else
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   173
            {
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   174
                ++i;
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   175
            }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   176
        }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   177
    }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   178
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   179
    if(parsedArgs.contains("data-dir"))
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   180
    {
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   181
        QFileInfo f(parsedArgs["data-dir"]);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   182
        if(!f.exists())
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   183
        {
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   184
            qWarning() << "WARNING: Cannot open DATA_PATH=" << f.absoluteFilePath();
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   185
        }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   186
        *cDataDir = f.absoluteFilePath();
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   187
        custom_data = true;
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   188
    }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   189
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   190
    if(parsedArgs.contains("config-dir"))
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   191
    {
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   192
        QFileInfo f(parsedArgs["config-dir"]);
8323
ab0b618bdf13 get executable directory at runtime rather than configure time
koda
parents: 8316
diff changeset
   193
        cfgdir->setPath(f.absoluteFilePath());
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   194
        custom_config = true;
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   195
    }
8323
ab0b618bdf13 get executable directory at runtime rather than configure time
koda
parents: 8316
diff changeset
   196
    else
ab0b618bdf13 get executable directory at runtime rather than configure time
koda
parents: 8316
diff changeset
   197
    {
ab0b618bdf13 get executable directory at runtime rather than configure time
koda
parents: 8316
diff changeset
   198
        cfgdir->setPath(QDir::homePath());
ab0b618bdf13 get executable directory at runtime rather than configure time
koda
parents: 8316
diff changeset
   199
        custom_config = false;
ab0b618bdf13 get executable directory at runtime rather than configure time
koda
parents: 8316
diff changeset
   200
    }
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   201
7772
a33077239712 Oops, forgot this
unc0rr
parents: 7768
diff changeset
   202
    app.setStyle(new QPlastiqueStyle());
2377
f3fab2b09e0c And in frontend
nemo
parents: 2261
diff changeset
   203
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   204
    QDateTime now = QDateTime::currentDateTime();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   205
    srand(now.toTime_t());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   206
    rand();
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   207
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   208
    Q_INIT_RESOURCE(hedgewars);
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   209
6721
7dbf8a0c1f5d - Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents: 6700
diff changeset
   210
    qRegisterMetaType<HWTeam>("HWTeam");
7dbf8a0c1f5d - Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents: 6700
diff changeset
   211
8323
ab0b618bdf13 get executable directory at runtime rather than configure time
koda
parents: 8316
diff changeset
   212
    bindir->cd(QCoreApplication::applicationDirPath());
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   213
8323
ab0b618bdf13 get executable directory at runtime rather than configure time
koda
parents: 8316
diff changeset
   214
    if(custom_config == false)
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   215
    {
1965
340bfd438ca5 - Apply koda's patch
unc0rr
parents: 1940
diff changeset
   216
#ifdef __APPLE__
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   217
        checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   218
        cfgdir->cd("Library/Application Support/Hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   219
#elif defined _WIN32
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   220
        char path[1024];
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   221
        if(!SHGetFolderPathA(0, CSIDL_PERSONAL, NULL, 0, path))
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   222
        {
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   223
            cfgdir->cd(path);
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   224
            checkForDir(cfgdir->absolutePath() + "/Hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   225
            cfgdir->cd("Hedgewars");
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   226
        }
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   227
        else // couldn't retrieve documents folder? almost impossible, but in case fall back to classic path
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   228
        {
9094
2cdb0ed3813a Merge 0.9.19
nemo
parents: 9093
diff changeset
   229
            checkForDir(cfgdir->absolutePath() + "/.hedgewars");
2cdb0ed3813a Merge 0.9.19
nemo
parents: 9093
diff changeset
   230
            cfgdir->cd(".hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   231
        }
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   232
#else
9094
2cdb0ed3813a Merge 0.9.19
nemo
parents: 9093
diff changeset
   233
        checkForDir(cfgdir->absolutePath() + "/.hedgewars");
2cdb0ed3813a Merge 0.9.19
nemo
parents: 9093
diff changeset
   234
        cfgdir->cd(".hedgewars");
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   235
#endif
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   236
    }
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   237
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   238
    if (checkForDir(cfgdir->absolutePath()))
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   239
    {
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   240
        // alternative loading/lookup paths
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   241
        checkForDir(cfgdir->absolutePath() + "/Data");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   242
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   243
        // config/save paths
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   244
        checkForDir(cfgdir->absolutePath() + "/Demos");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   245
        checkForDir(cfgdir->absolutePath() + "/Saves");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   246
        checkForDir(cfgdir->absolutePath() + "/Screenshots");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   247
        checkForDir(cfgdir->absolutePath() + "/Teams");
3914
c5c903c6225b Engine:
smaxx
parents: 3865
diff changeset
   248
        checkForDir(cfgdir->absolutePath() + "/Logs");
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents: 7130
diff changeset
   249
        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
   250
        checkForDir(cfgdir->absolutePath() + "/VideoTemp");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   251
    }
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   252
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   253
    datadir->cd(bindir->absolutePath());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   254
    datadir->cd(*cDataDir);
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8722
diff changeset
   255
    if (!datadir->cd("Data"))
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   256
    {
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8722
diff changeset
   257
        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
   258
        return 1;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   259
    }
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   260
7931
5a27ed7f17b7 Wee, now frontend is able to load translation file
unc0rr
parents: 7928
diff changeset
   261
    // setup PhysFS
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
   262
    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
   263
    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
   264
    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
   265
    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
   266
    engine->mountPacks();
7772
a33077239712 Oops, forgot this
unc0rr
parents: 7768
diff changeset
   267
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   268
    QTranslator Translator;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   269
    {
8918
512753ea4b1b Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents: 8882
diff changeset
   270
        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
   271
        settings.setIniCodec("UTF-8");
512753ea4b1b Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents: 8882
diff changeset
   272
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
   273
        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
   274
        if (cc.isEmpty())
9027
4b8e326251b3 Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents: 8918
diff changeset
   275
        {
4b8e326251b3 Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents: 8918
diff changeset
   276
            cc = QLocale::system().name();
4b8e326251b3 Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents: 8918
diff changeset
   277
4b8e326251b3 Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents: 8918
diff changeset
   278
            // 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
   279
            if(cc == "C")
4b8e326251b3 Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents: 8918
diff changeset
   280
                cc = HWApplication::keyboardInputLocale().name();
4b8e326251b3 Use old method of locale detection, fallback to new one in case of problems
unc0rr
parents: 8918
diff changeset
   281
        }
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   282
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   283
        // load locale file into translator
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
   284
        if (!Translator.load(QString("physfs://Locale/hedgewars_%1").arg(cc)))
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
   285
            qWarning("Failed to install translation (%s)", qPrintable(cc));
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   286
        app.installTranslator(&Translator);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   287
    }
2898
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
   288
5756
b451fd21ff4c Extract downloaded content into temp dir
unc0rr
parents: 5307
diff changeset
   289
#ifdef _WIN32
3679
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   290
    // Win32 registry setup (used for xfire detection etc. - don't set it if we're running in "portable" mode with a custom config dir)
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   291
    if(!custom_config)
3679
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   292
    {
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   293
        QSettings registry_hklm("HKEY_LOCAL_MACHINE", QSettings::NativeFormat);
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   294
        registry_hklm.setValue("Software/Hedgewars/Frontend", bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe");
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   295
        registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\"));
3679
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   296
    }
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   297
#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
   298
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   299
    QString style = "";
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   300
    QString fname;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   301
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   302
    checkSeason();
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   303
    //For each season, there is an extra stylesheet
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   304
    //Todo: change background for easter and birthday
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   305
    //(simply replace res/BackgroundBirthday.png and res/BackgroundEaster.png
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   306
    //with an appropriate background
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   307
    switch (season)
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   308
    {
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   309
        case SEASON_CHRISTMAS :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   310
            fname = "christmas.css";
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   311
            break;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   312
        case SEASON_EASTER :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   313
            fname = "easter.css";
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   314
            break;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   315
        case SEASON_HWBDAY :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   316
            fname = "birthday.css";
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   317
            break;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   318
        default :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   319
            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
   320
            break;
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   321
    }
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
   322
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
   323
    // load external stylesheet if there is any
8049
133e22b5c410 Get rid of DataManager::findFileForRead
unc0rr
parents: 7955
diff changeset
   324
    QFile extFile("physfs://css/" + fname);
2898
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
   325
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   326
    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
   327
7724
36c539c9cfb1 Simplify file loading procedure
unc0rr
parents: 7278
diff changeset
   328
    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
   329
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   330
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
7724
36c539c9cfb1 Simplify file loading procedure
unc0rr
parents: 7278
diff changeset
   331
        style.append(file.readAll());
2377
f3fab2b09e0c And in frontend
nemo
parents: 2261
diff changeset
   332
8651
da384b09eb2b add version info to frontend output too
koda
parents: 8508
diff changeset
   333
    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
   334
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
   335
    app.form = new HWForm(NULL, style);
5252
ded882439548 file association for mac!
koda
parents: 5238
diff changeset
   336
    app.form->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
   337
    if(splash)
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
   338
        splash->close();
8722
2dead6b84bca this should supposedly add hwplay:// schemes to windows, after user presses file association
koda
parents: 8715
diff changeset
   339
    if (app.urlString)
2dead6b84bca this should supposedly add hwplay:// schemes to windows, after user presses file association
koda
parents: 8715
diff changeset
   340
        app.fakeEvent();
8223
14d9a3c33650 backout rea7541f77944 since development of frontlib is on another branch
koda
parents: 8206
diff changeset
   341
    return app.exec();
2845
19db164dd20d Frontend:
smxx
parents: 2798
diff changeset
   342
}