QTfrontend/main.cpp
author nemo
Sat, 22 Oct 2011 00:49:55 -0400
changeset 6179 b529f88d37d0
parent 6178 affa860f2983
child 6186 255aff92216d
permissions -rw-r--r--
Bit of an experiment with giving flakes a bit more depth. Might need to be theme flagged, or theme flakes reworked on some themes. Looks neat in stereo. Also finally use an array for the layers
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
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4888
diff changeset
     3
 * Copyright (c) 2005-2011 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>
1146
0bc17a69b3d8 Background for Hedgewars is ready
displacer
parents: 1066
diff changeset
    29
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    30
#include "hwform.h"
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    31
#include "hwconsts.h"
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    32
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
    33
#include "HWDataManager.h"
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
    34
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    35
#ifdef _WIN32
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    36
#include <Shlobj.h>
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    37
#endif
5095
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
    38
#ifdef __APPLE__
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
    39
#include "CocoaInitializer.h"
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
    40
#endif
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    41
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    42
bool checkForDir(const QString & dir)
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    43
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    44
    QDir tmpdir;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    45
    if (!tmpdir.exists(dir))
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    46
        if (!tmpdir.mkdir(dir))
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    47
        {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    48
            QMessageBox::critical(0,
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    49
                    QObject::tr("Error"),
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    50
                    QObject::tr("Cannot create directory %1").arg(dir),
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    51
                    QObject::tr("OK"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    52
            return false;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    53
        }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    54
    return true;
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    55
}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    56
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3681
diff changeset
    57
int main(int argc, char *argv[]) {
5252
ded882439548 file association for mac!
koda
parents: 5238
diff changeset
    58
    HWApplication app(argc, argv);
4888
3c96e99468c5 activate icon display in menus
sheepluva
parents: 4513
diff changeset
    59
    app.setAttribute(Qt::AA_DontShowIconsInMenus,false);
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    60
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    61
    QStringList arguments = app.arguments();
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    62
    QMap<QString, QString> parsedArgs;
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    63
    {
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    64
        QList<QString>::iterator i = arguments.begin();
2035
70734c4f52a7 patch to prior checkin
nemo
parents: 2034
diff changeset
    65
        while(i != arguments.end()) {
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    66
            QString arg = *i;
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    67
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    68
            QRegExp opt("--(\\S+)=(.+)");
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    69
            if(opt.exactMatch(arg)) {
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    70
                parsedArgs[opt.cap(1)] = opt.cap(2);
2035
70734c4f52a7 patch to prior checkin
nemo
parents: 2034
diff changeset
    71
                i = arguments.erase(i);
70734c4f52a7 patch to prior checkin
nemo
parents: 2034
diff changeset
    72
            } else {
70734c4f52a7 patch to prior checkin
nemo
parents: 2034
diff changeset
    73
              ++i;
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    74
            }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    75
        }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    76
    }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    77
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    78
    if(parsedArgs.contains("data-dir")) {
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    79
        QFileInfo f(parsedArgs["data-dir"]);
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    80
        if(!f.exists()) {
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    81
            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
    82
        }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    83
        *cDataDir = f.absoluteFilePath();
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
    84
        custom_data = true;
2034
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    85
    }
decdf48cffd7 david_ac adding a commandline parameter for the data dir, as requested by svenstaro
nemo
parents: 1969
diff changeset
    86
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    87
    if(parsedArgs.contains("config-dir")) {
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    88
        QFileInfo f(parsedArgs["config-dir"]);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    89
        *cConfigDir = f.absoluteFilePath();
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
    90
        custom_config = true;
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    91
    }
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
    92
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    93
    app.setStyle(new QPlastiqueStyle);
2377
f3fab2b09e0c And in frontend
nemo
parents: 2261
diff changeset
    94
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    95
    QDateTime now = QDateTime::currentDateTime();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    96
    srand(now.toTime_t());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    97
    rand();
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    98
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
    99
    Q_INIT_RESOURCE(hedgewars);
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   100
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   101
    bindir->cd("bin"); // workaround over NSIS installer
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   102
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   103
    if(cConfigDir->length() == 0)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   104
        cfgdir->setPath(cfgdir->homePath());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   105
    else
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   106
        cfgdir->setPath(*cConfigDir);
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   107
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   108
    if(cConfigDir->length() == 0)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   109
    {
1965
340bfd438ca5 - Apply koda's patch
unc0rr
parents: 1940
diff changeset
   110
#ifdef __APPLE__
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   111
        checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   112
        cfgdir->cd("Library/Application Support/Hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   113
#elif defined _WIN32
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   114
        char path[1024];
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   115
        if(!SHGetFolderPathA(0, CSIDL_PERSONAL, NULL, 0, path))
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   116
        {
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   117
            cfgdir->cd(path);
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   118
            checkForDir(cfgdir->absolutePath() + "/Hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   119
            cfgdir->cd("Hedgewars");
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   120
        }
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   121
        else // couldn't retrieve documents folder? almost impossible, but in case fall back to classic path
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   122
        {
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   123
            checkForDir(cfgdir->absolutePath() + "/.hedgewars");
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   124
            cfgdir->cd(".hedgewars");
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
   125
        }
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   126
#else
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   127
        checkForDir(cfgdir->absolutePath() + "/.hedgewars");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   128
        cfgdir->cd(".hedgewars");
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2418
diff changeset
   129
#endif
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   130
    }
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   131
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   132
    if (checkForDir(cfgdir->absolutePath()))
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   133
    {
3758
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   134
        // alternative loading/lookup paths
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   135
        // TODO: Uncomment paths as they're implemented
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   136
        checkForDir(cfgdir->absolutePath() + "/Data");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   137
        //checkForDir(cfgdir->absolutePath() + "/Data/Forts");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   138
        //checkForDir(cfgdir->absolutePath() + "/Data/Graphics");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   139
        //checkForDir(cfgdir->absolutePath() + "/Data/Graphics/Flags");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   140
        //checkForDir(cfgdir->absolutePath() + "/Data/Graphics/Graves");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   141
        //checkForDir(cfgdir->absolutePath() + "/Data/Graphics/Hats");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   142
        //checkForDir(cfgdir->absolutePath() + "/Data/Maps");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   143
        //checkForDir(cfgdir->absolutePath() + "/Data/Missions");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   144
        //checkForDir(cfgdir->absolutePath() + "/Data/Missions/Campaign");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   145
        //checkForDir(cfgdir->absolutePath() + "/Data/Missions/Training");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   146
        //checkForDir(cfgdir->absolutePath() + "/Data/Sounds");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   147
        //checkForDir(cfgdir->absolutePath() + "/Data/Sounds/voices");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   148
        //checkForDir(cfgdir->absolutePath() + "/Data/Themes");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   149
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   150
        // config/save paths
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   151
        checkForDir(cfgdir->absolutePath() + "/Demos");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   152
        checkForDir(cfgdir->absolutePath() + "/Saves");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   153
        checkForDir(cfgdir->absolutePath() + "/Screenshots");
80007c41c35e Frontend:
smaxx
parents: 3714
diff changeset
   154
        checkForDir(cfgdir->absolutePath() + "/Teams");
3914
c5c903c6225b Engine:
smaxx
parents: 3865
diff changeset
   155
        checkForDir(cfgdir->absolutePath() + "/Logs");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   156
    }
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   157
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   158
    datadir->cd(bindir->absolutePath());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   159
    datadir->cd(*cDataDir);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   160
    if(!datadir->cd("hedgewars/Data")) {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   161
        QMessageBox::critical(0, QMessageBox::tr("Error"),
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   162
            QMessageBox::tr("Failed to open data directory:\n%1\n"
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   163
                    "Please check your installation").
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   164
                    arg(datadir->absolutePath()+"/hedgewars/Data"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   165
        return 1;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   166
    }
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   167
5276
562070d3f978 Derive themes list from list of dirs in Themes folder which have icon.png inside
unc0rr
parents: 5257
diff changeset
   168
    {
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
   169
        QStringList themes;
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
   170
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
   171
        themes.append(HWDataManager::instance().entryList(
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
   172
                         "Themes",
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
   173
                         QDir::AllDirs | QDir::NoDotAndDotDot)
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
   174
                     );
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
   175
9d18b61bd3eb - Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents: 5276
diff changeset
   176
        QList<QPair<QIcon, QIcon> > icons;
9d18b61bd3eb - Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents: 5276
diff changeset
   177
5307
dd53755e0fca Fix broken theme icon loading from user dir
unc0rr
parents: 5300
diff changeset
   178
        themes.sort();
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
   179
        for(int i = themes.size() - 1; i >= 0; --i)
5276
562070d3f978 Derive themes list from list of dirs in Themes folder which have icon.png inside
unc0rr
parents: 5257
diff changeset
   180
        {
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   181
            QString file = HWDataManager::instance().findFileForRead(
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   182
                QString("Themes/%1/icon.png").arg(themes.at(i))
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   183
            );
5307
dd53755e0fca Fix broken theme icon loading from user dir
unc0rr
parents: 5300
diff changeset
   184
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   185
            if(QFile::exists(file))
5307
dd53755e0fca Fix broken theme icon loading from user dir
unc0rr
parents: 5300
diff changeset
   186
            { // load icon
dd53755e0fca Fix broken theme icon loading from user dir
unc0rr
parents: 5300
diff changeset
   187
                QPair<QIcon, QIcon> ic;
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   188
                ic.first = QIcon(file);
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
   189
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   190
                // load preview icon
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   191
                ic.second = QIcon(
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
   192
                    HWDataManager::instance().findFileForRead(
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   193
                        QString("Themes/%1/icon@2x.png").arg(themes.at(i))
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   194
                    )
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   195
                );
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
   196
5307
dd53755e0fca Fix broken theme icon loading from user dir
unc0rr
parents: 5300
diff changeset
   197
                icons.prepend(ic);
dd53755e0fca Fix broken theme icon loading from user dir
unc0rr
parents: 5300
diff changeset
   198
            }
dd53755e0fca Fix broken theme icon loading from user dir
unc0rr
parents: 5300
diff changeset
   199
            else
dd53755e0fca Fix broken theme icon loading from user dir
unc0rr
parents: 5300
diff changeset
   200
            {
dd53755e0fca Fix broken theme icon loading from user dir
unc0rr
parents: 5300
diff changeset
   201
                themes.removeAt(i);
5276
562070d3f978 Derive themes list from list of dirs in Themes folder which have icon.png inside
unc0rr
parents: 5257
diff changeset
   202
            }
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   203
        }
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
   204
9d18b61bd3eb - Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents: 5276
diff changeset
   205
        themesModel = new ThemesModel(themes);
5307
dd53755e0fca Fix broken theme icon loading from user dir
unc0rr
parents: 5300
diff changeset
   206
        Q_ASSERT(themes.size() == icons.size());
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
   207
        for(int i = 0; i < icons.size(); ++i)
9d18b61bd3eb - Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents: 5276
diff changeset
   208
        {
9d18b61bd3eb - Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents: 5276
diff changeset
   209
            themesModel->setData(themesModel->index(i), icons[i].first, Qt::DecorationRole);
9d18b61bd3eb - Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents: 5276
diff changeset
   210
            themesModel->setData(themesModel->index(i), icons[i].second, Qt::UserRole);
9d18b61bd3eb - Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents: 5276
diff changeset
   211
        }
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   212
    }
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   213
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
   214
    mapList = new QStringList(HWDataManager::instance().entryList(
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
   215
                                 QString("Maps"),
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
   216
                                 QDir::Dirs | QDir::NoDotAndDotDot
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
   217
                                 )
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
   218
                             );
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5095
diff changeset
   219
 
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
   220
    scriptList = new QStringList(HWDataManager::instance().entryList(
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
   221
                                     QString("Scripts/Multiplayer"),
6174
2d5717595471 fix multiplayer script loading
sheepluva
parents: 6167
diff changeset
   222
                                     QDir::Files,
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
   223
                                     QStringList("*.lua")
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
   224
                                     )
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
   225
                                 );
2898
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
   226
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   227
    QTranslator Translator;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   228
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   229
        QSettings settings(cfgdir->absolutePath() + "/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
   230
        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
   231
        if(cc.isEmpty())
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   232
            cc = QLocale::system().name();
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   233
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   234
        // load locale file into translator
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   235
        Translator.load(
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   236
            HWDataManager::instance().findFileForRead(
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   237
                QString("Locale/hedgewars_" + cc)
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   238
            )
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   239
        );
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   240
        app.installTranslator(&Translator);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   241
    }
2898
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
   242
5756
b451fd21ff4c Extract downloaded content into temp dir
unc0rr
parents: 5307
diff changeset
   243
#ifdef _WIN32
3679
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   244
    // 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
   245
    if(!custom_config)
3679
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   246
    {
3932
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   247
        QSettings registry_hklm("HKEY_LOCAL_MACHINE", QSettings::NativeFormat);
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   248
        registry_hklm.setValue("Software/Hedgewars/Frontend", bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe");
2fc211f60015 Engine:
smaxx
parents: 3914
diff changeset
   249
        registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\"));
3679
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   250
    }
acf5acc18522 Frontend:
smaxx
parents: 3350
diff changeset
   251
#endif
5095
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
   252
#ifdef __APPLE__
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
   253
    // 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
   254
    CocoaInitializer initializer;
15dd764b728c fix autorelease pools not being set (issue 209) and format code a little
koda
parents: 4976
diff changeset
   255
#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
   256
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   257
    QString style = "";
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   258
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
   259
    // load external stylesheet if there is any
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
   260
    QFile extFile(HWDataManager::instance().findFileForRead("css/qt.css"));
2898
c53636f556f8 Frontend:
smxx
parents: 2897
diff changeset
   261
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
   262
    QFile resFile(":/res/css/qt.css");
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   263
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   264
    QFile & file = (extFile.exists()?extFile:resFile);
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   265
affa860f2983 BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents: 6177
diff changeset
   266
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
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
   267
    {
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
   268
        QTextStream in(&file);
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
   269
        while (!in.atEnd())
19ef039a8474 frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents: 6174
diff changeset
   270
        {
19ef039a8474 frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents: 6174
diff changeset
   271
            QString line = in.readLine();
19ef039a8474 frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents: 6174
diff changeset
   272
            if(!line.isEmpty())
19ef039a8474 frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents: 6174
diff changeset
   273
                style.append(line);
19ef039a8474 frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents: 6174
diff changeset
   274
        }
19ef039a8474 frontend will use the data file misc/qt_style.css instead of hardcoded stylesheet - if the file exists
sheepluva
parents: 6174
diff changeset
   275
    }
2377
f3fab2b09e0c And in frontend
nemo
parents: 2261
diff changeset
   276
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
   277
    app.form = new HWForm(NULL, style);
5252
ded882439548 file association for mac!
koda
parents: 5238
diff changeset
   278
    app.form->show();
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2913
diff changeset
   279
    return app.exec();
2845
19db164dd20d Frontend:
smxx
parents: 2798
diff changeset
   280
}