QTfrontend/main.cpp
author Mitchell Kember <mk12360@gmail.com>
Fri, 30 Nov 2012 20:00:53 -0500
changeset 8175 2c233349df21
parent 8117 329d9756b57c
child 8187 fa725fe25708
permissions -rw-r--r--
Google Code-in: Center help text field Modifies the grid layout slightly so that the help text which appears when hovering over certain elements is centered with respect to the window, even when there are more buttons on one side. https://google-melange.appspot.com/gci/task/view/google/gci2012/7968226
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
6952
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6937
diff changeset
     3
 * Copyright (c) 2004-2012 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>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    23
#include <QMessageBox>
1416
60b86d6fe9ae Force plastique style, as others don't fully support stylesheets
unc0rr
parents: 1415
diff changeset
    24
#include <QPlastiqueStyle>
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    25
#include <QRegExp>
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    26
#include <QMap>
2898
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
    27
#include <QSettings>
5289
9d18b61bd3eb - Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents: 5276
diff changeset
    28
#include <QStringListModel>
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    29
#include <QDate>
1146
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    30
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    31
#include "hwform.h"
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    32
#include "hwconsts.h"
6721
7dbf8a0c1f5d - Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents: 6700
diff changeset
    33
#include "newnetclient.h"
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    34
6930
d187ea93fc4f renaming HWDataManager -> DataManager
sheepluva
parents: 6721
diff changeset
    35
#include "DataManager.h"
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents: 7724
diff changeset
    36
#include "FileEngine.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
    37
8078
ea7541f77944 Start port to frontlib
unc0rr
parents: 8052
diff changeset
    38
#include "frontlib.h"
ea7541f77944 Start port to frontlib
unc0rr
parents: 8052
diff changeset
    39
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    40
#ifdef _WIN32
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    41
#include <Shlobj.h>
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    42
#endif
5095
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
    43
#ifdef __APPLE__
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
    44
#include "CocoaInitializer.h"
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
    45
#endif
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    46
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    47
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    48
//Determines the day of easter in year
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    49
//from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    50
QDate calculateEaster(long year)
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    51
{
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    52
    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
    53
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    54
    c = year/100;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    55
    n = year - 19*(year/19);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    56
    k = (c - 17)/25;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    57
    i = c - c/4 - (c - k)/3 + 19*n + 15;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    58
    i = i - 30*(i/30);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    59
    i = i - (i/28)*(1 - (i/28)*(29/(i + 1))*((21 - n)/11));
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    60
    j = year + year/4 + i + 2 - c + c/4;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    61
    j = j - 7*(j/7);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    62
    l = i - j;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    63
    m = 3 + (l + 40)/44;
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    64
    d = l + 28 - 31*(m / 4);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    65
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    66
    return QDate(year, m, d);
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    67
}
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    68
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    69
//Checks season and assigns it to the variable season in "hwconsts.h"
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    70
void checkSeason()
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    71
{
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    72
    QDate date = QDate::currentDate();
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    73
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    74
    //Christmas?
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    75
    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
    76
            && date.day() <= 26)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    77
        season = SEASON_CHRISTMAS;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    78
    //Hedgewars birthday?
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    79
    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
    80
    {
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    81
        season = SEASON_HWBDAY;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    82
        years_since_foundation = date.year() - 2004;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    83
    }
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    84
    //Easter?
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    85
    else if (calculateEaster(date.year()) == date)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    86
        season = SEASON_EASTER;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    87
    else
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
    88
        season = SEASON_NONE;
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    89
}
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
    90
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    91
bool checkForDir(const QString & dir)
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    92
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    93
    QDir tmpdir;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    94
    if (!tmpdir.exists(dir))
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    95
        if (!tmpdir.mkdir(dir))
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    96
        {
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
    97
            QMessageBox directoryMsg(QApplication::activeWindow());
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
    98
            directoryMsg.setIcon(QMessageBox::Warning);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
    99
            directoryMsg.setWindowTitle(QMessageBox::tr("Main - Error"));
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
   100
            directoryMsg.setText(QMessageBox::tr("Cannot create directory %1").arg(dir));
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
   101
            directoryMsg.setWindowModality(Qt::WindowModal);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
   102
            directoryMsg.exec();
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   103
            return false;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   104
        }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   105
    return true;
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   106
}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   107
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   108
int main(int argc, char *argv[])
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   109
{
5252
ded882439548 file association for mac!
koda
parents: 5238
diff changeset
   110
    HWApplication app(argc, argv);
7130
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6958
diff changeset
   111
7772
a33077239712 Oops, forgot this
unc0rr
parents: 7768
diff changeset
   112
    FileEngineHandler engine(argv[0]);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents: 7724
diff changeset
   113
8078
ea7541f77944 Start port to frontlib
unc0rr
parents: 8052
diff changeset
   114
    flib_init();
ea7541f77944 Start port to frontlib
unc0rr
parents: 8052
diff changeset
   115
4888
3c96e99468c5 activate icon display in menus
sheepluva
parents: 4513
diff changeset
   116
    app.setAttribute(Qt::AA_DontShowIconsInMenus,false);
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   117
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   118
    QStringList arguments = app.arguments();
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   119
    QMap<QString, QString> parsedArgs;
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   120
    {
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   121
        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
   122
        while(i != arguments.end())
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   123
        {
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   124
            QString arg = *i;
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   125
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   126
            QRegExp opt("--(\\S+)=(.+)");
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   127
            if(opt.exactMatch(arg))
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   128
            {
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   129
                parsedArgs[opt.cap(1)] = opt.cap(2);
2035
70734c4f52a7 patch to prior checkin
nemo
parents: 2034
diff changeset
   130
                i = arguments.erase(i);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   131
            }
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   132
            else
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   133
            {
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   134
                ++i;
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   135
            }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   136
        }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   137
    }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   138
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   139
    if(parsedArgs.contains("data-dir"))
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   140
    {
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   141
        QFileInfo f(parsedArgs["data-dir"]);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   142
        if(!f.exists())
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   143
        {
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   144
            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
   145
        }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   146
        *cDataDir = f.absoluteFilePath();
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   147
        custom_data = true;
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   148
    }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
   149
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   150
    if(parsedArgs.contains("config-dir"))
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   151
    {
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   152
        QFileInfo f(parsedArgs["config-dir"]);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   153
        *cConfigDir = f.absoluteFilePath();
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   154
        custom_config = true;
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   155
    }
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   156
7772
a33077239712 Oops, forgot this
unc0rr
parents: 7768
diff changeset
   157
    app.setStyle(new QPlastiqueStyle());
2377
f3fab2b09e0c And in frontend
nemo
parents: 2261
diff changeset
   158
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   159
    QDateTime now = QDateTime::currentDateTime();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   160
    srand(now.toTime_t());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   161
    rand();
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   162
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   163
    Q_INIT_RESOURCE(hedgewars);
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   164
6721
7dbf8a0c1f5d - Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents: 6700
diff changeset
   165
    qRegisterMetaType<HWTeam>("HWTeam");
7dbf8a0c1f5d - Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents: 6700
diff changeset
   166
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   167
    bindir->cd("bin"); // workaround over NSIS installer
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   168
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   169
    if(cConfigDir->length() == 0)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   170
        cfgdir->setPath(cfgdir->homePath());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   171
    else
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   172
        cfgdir->setPath(*cConfigDir);
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   173
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   174
    if(cConfigDir->length() == 0)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   175
    {
1965
340bfd438ca5 - Apply koda's patch
unc0rr
parents: 1940
diff changeset
   176
#ifdef __APPLE__
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   177
        checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   178
        cfgdir->cd("Library/Application Support/Hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   179
#elif defined _WIN32
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   180
        char path[1024];
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   181
        if(!SHGetFolderPathA(0, CSIDL_PERSONAL, NULL, 0, path))
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   182
        {
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   183
            cfgdir->cd(path);
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   184
            checkForDir(cfgdir->absolutePath() + "/Hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   185
            cfgdir->cd("Hedgewars");
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   186
        }
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   187
        else // couldn't retrieve documents folder? almost impossible, but in case fall back to classic path
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   188
        {
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   189
            checkForDir(cfgdir->absolutePath() + "/.hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   190
            cfgdir->cd(".hedgewars");
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   191
        }
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   192
#else
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   193
        checkForDir(cfgdir->absolutePath() + "/.hedgewars");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   194
        cfgdir->cd(".hedgewars");
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   195
#endif
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   196
    }
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   197
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   198
    if (checkForDir(cfgdir->absolutePath()))
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   199
    {
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   200
        // alternative loading/lookup paths
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   201
        checkForDir(cfgdir->absolutePath() + "/Data");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   202
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   203
        // config/save paths
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   204
        checkForDir(cfgdir->absolutePath() + "/Demos");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   205
        checkForDir(cfgdir->absolutePath() + "/Saves");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   206
        checkForDir(cfgdir->absolutePath() + "/Screenshots");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   207
        checkForDir(cfgdir->absolutePath() + "/Teams");
3914
c5c903c6225b Engine:
smaxx
parents: 3865
diff changeset
   208
        checkForDir(cfgdir->absolutePath() + "/Logs");
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents: 7130
diff changeset
   209
        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
   210
        checkForDir(cfgdir->absolutePath() + "/VideoTemp");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   211
    }
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   212
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   213
    datadir->cd(bindir->absolutePath());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   214
    datadir->cd(*cDataDir);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   215
    if(!datadir->cd("hedgewars/Data"))
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   216
    {
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
   217
        QMessageBox missingMsg(QApplication::activeWindow());
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
   218
        missingMsg.setIcon(QMessageBox::Critical);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
   219
        missingMsg.setWindowTitle(QMessageBox::tr("Main - Error"));
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
   220
        missingMsg.setText(QMessageBox::tr("Failed to open data directory:\n%1\n\n"
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
   221
                                           "Please check your installation!").
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
   222
                                            arg(datadir->absolutePath()+"/hedgewars/Data"));
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
   223
        missingMsg.setWindowModality(Qt::WindowModal);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7724
diff changeset
   224
        missingMsg.exec();
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   225
        return 1;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   226
    }
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   227
7931
5a27ed7f17b7 Wee, now frontend is able to load translation file
unc0rr
parents: 7928
diff changeset
   228
    // setup PhysFS
7772
a33077239712 Oops, forgot this
unc0rr
parents: 7768
diff changeset
   229
    engine.mount(datadir->absolutePath());
a33077239712 Oops, forgot this
unc0rr
parents: 7768
diff changeset
   230
    engine.mount(cfgdir->absolutePath() + "/Data");
8098
4efee370e2de - Fix saving .ini files
unc0rr
parents: 8078
diff changeset
   231
    engine.mount(cfgdir->absolutePath());
7772
a33077239712 Oops, forgot this
unc0rr
parents: 7768
diff changeset
   232
    engine.setWriteDir(cfgdir->absolutePath());
8052
845b5ae03841 Mount .hwt files found in Data folder
unc0rr
parents: 8049
diff changeset
   233
    engine.mountPacks();
7772
a33077239712 Oops, forgot this
unc0rr
parents: 7768
diff changeset
   234
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   235
    QTranslator Translator;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   236
    {
8098
4efee370e2de - Fix saving .ini files
unc0rr
parents: 8078
diff changeset
   237
        QSettings settings("physfs://hedgewars.ini", QSettings::IniFormat);
5289
9d18b61bd3eb - Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents: 5276
diff changeset
   238
        QString cc = settings.value("misc/locale", QString()).toString();
9d18b61bd3eb - Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents: 5276
diff changeset
   239
        if(cc.isEmpty())
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   240
            cc = QLocale::system().name();
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   241
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   242
        // load locale file into translator
7931
5a27ed7f17b7 Wee, now frontend is able to load translation file
unc0rr
parents: 7928
diff changeset
   243
        if(!Translator.load(QString("physfs://Locale/hedgewars_%1").arg(cc)))
5a27ed7f17b7 Wee, now frontend is able to load translation file
unc0rr
parents: 7928
diff changeset
   244
            qWarning("Failed to install translation");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   245
        app.installTranslator(&Translator);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   246
    }
2898
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
   247
5756
b451fd21ff4c Extract downloaded content into temp dir
unc0rr
parents: 5307
diff changeset
   248
#ifdef _WIN32
3679
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   249
    // 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
   250
    if(!custom_config)
3679
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   251
    {
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   252
        QSettings registry_hklm("HKEY_LOCAL_MACHINE", QSettings::NativeFormat);
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   253
        registry_hklm.setValue("Software/Hedgewars/Frontend", bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe");
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   254
        registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\"));
3679
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   255
    }
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   256
#endif
5095
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
   257
#ifdef __APPLE__
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
   258
    // this creates the autoreleasepool that prevents leaking
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
   259
    CocoaInitializer initializer;
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
   260
#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
   261
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   262
    QString style = "";
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   263
    QString fname;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   264
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   265
    checkSeason();
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   266
    //For each season, there is an extra stylesheet
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   267
    //Todo: change background for easter and birthday
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   268
    //(simply replace res/BackgroundBirthday.png and res/BackgroundEaster.png
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   269
    //with an appropriate background
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   270
    switch (season)
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   271
    {
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   272
        case SEASON_CHRISTMAS :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   273
            fname = "christmas.css";
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   274
            break;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   275
        case SEASON_EASTER :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   276
            fname = "easter.css";
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   277
            break;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   278
        case SEASON_HWBDAY :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   279
            fname = "birthday.css";
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   280
            break;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   281
        default :
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6600
diff changeset
   282
            fname = "qt.css";
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   283
    }
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
   284
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
   285
    // load external stylesheet if there is any
8049
133e22b5c410 Get rid of DataManager::findFileForRead
unc0rr
parents: 7955
diff changeset
   286
    QFile extFile("physfs://css/" + fname);
2898
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
   287
6579
fc52f7c22c9b GCI task: season greetings
valnut
parents: 6376
diff changeset
   288
    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
   289
7724
36c539c9cfb1 Simplify file loading procedure
unc0rr
parents: 7278
diff changeset
   290
    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
   291
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   292
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
7724
36c539c9cfb1 Simplify file loading procedure
unc0rr
parents: 7278
diff changeset
   293
        style.append(file.readAll());
2377
f3fab2b09e0c And in frontend
nemo
parents: 2261
diff changeset
   294
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
   295
    app.form = new HWForm(NULL, style);
5252
ded882439548 file association for mac!
koda
parents: 5238
diff changeset
   296
    app.form->show();
8078
ea7541f77944 Start port to frontlib
unc0rr
parents: 8052
diff changeset
   297
    int r = app.exec();
ea7541f77944 Start port to frontlib
unc0rr
parents: 8052
diff changeset
   298
ea7541f77944 Start port to frontlib
unc0rr
parents: 8052
diff changeset
   299
    flib_quit();
ea7541f77944 Start port to frontlib
unc0rr
parents: 8052
diff changeset
   300
ea7541f77944 Start port to frontlib
unc0rr
parents: 8052
diff changeset
   301
    return r;
2845
19db164dd20d Frontend:
smxx
parents: 2798
diff changeset
   302
}