QTfrontend/main.cpp
author unc0rr
Thu, 05 Oct 2006 16:33:18 +0000
changeset 183 57c2ef19f719
parent 173 004493dd60e4
child 184 f97a7a3dc8f6
permissions -rw-r--r--
Relicense to GPL
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     1
/*
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
128
223522298250 Update file headers & delete unneeded files
unc0rr
parents: 127
diff changeset
     3
 * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     4
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     8
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
    12
 * GNU General Public License for more details.
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    13
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
    14
 * You should have received a copy of the GNU General Public License
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
    15
 * along with this program; if not, write to the Free Software
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    17
 */
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    18
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    19
#include <QApplication>
52
ae2950c5465c - Rename frontend to hedgewars and compile it to engine directory
unc0rr
parents: 21
diff changeset
    20
#include <QTranslator>
ae2950c5465c - Rename frontend to hedgewars and compile it to engine directory
unc0rr
parents: 21
diff changeset
    21
#include <QLocale>
97
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    22
#include <QMessageBox>
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    23
#include <QFileInfo>
127
ca70467bd0a8 Use QUuid to generate seed, rand() to choose theme
unc0rr
parents: 123
diff changeset
    24
#include <QDateTime>
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    25
#include "hwform.h"
97
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    26
#include "hwconsts.h"
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    27
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    28
QDir * bindir;
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    29
QDir * cfgdir;
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    30
QDir * datadir;
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    31
148
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    32
bool checkForDir(const QString & dir)
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    33
{
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    34
	QDir tmpdir;
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    35
	if (!tmpdir.exists(dir))
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    36
		if (!tmpdir.mkdir(dir))
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    37
		{
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    38
			QMessageBox::critical(0,
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    39
					QObject::tr("Error"),
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    40
					QObject::tr("Cannot create directory %1").arg(dir),
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    41
					QObject::tr("OK"));
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    42
			return false;
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    43
		}
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    44
	return true;
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    45
}
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    46
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    47
int main(int argc, char *argv[])
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    48
{
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    49
	QApplication app(argc, argv);
52
ae2950c5465c - Rename frontend to hedgewars and compile it to engine directory
unc0rr
parents: 21
diff changeset
    50
127
ca70467bd0a8 Use QUuid to generate seed, rand() to choose theme
unc0rr
parents: 123
diff changeset
    51
	QDateTime now = QDateTime::currentDateTime();
ca70467bd0a8 Use QUuid to generate seed, rand() to choose theme
unc0rr
parents: 123
diff changeset
    52
	QDateTime zero;
ca70467bd0a8 Use QUuid to generate seed, rand() to choose theme
unc0rr
parents: 123
diff changeset
    53
	srand(now.secsTo(zero));
ca70467bd0a8 Use QUuid to generate seed, rand() to choose theme
unc0rr
parents: 123
diff changeset
    54
109
ab0340f580c2 - Initialize translations earlier
unc0rr
parents: 97
diff changeset
    55
	Q_INIT_RESOURCE(hedgewars);
ab0340f580c2 - Initialize translations earlier
unc0rr
parents: 97
diff changeset
    56
ab0340f580c2 - Initialize translations earlier
unc0rr
parents: 97
diff changeset
    57
	QTranslator Translator;
ab0340f580c2 - Initialize translations earlier
unc0rr
parents: 97
diff changeset
    58
	Translator.load(":/translations/hedgewars_" + QLocale::system().name());
ab0340f580c2 - Initialize translations earlier
unc0rr
parents: 97
diff changeset
    59
	app.installTranslator(&Translator);
ab0340f580c2 - Initialize translations earlier
unc0rr
parents: 97
diff changeset
    60
173
004493dd60e4 - Better landgen
unc0rr
parents: 168
diff changeset
    61
	QDir mydir(".");
123
6987769ced3d Various small fixes
unc0rr
parents: 119
diff changeset
    62
	mydir.cd("bin");
127
ca70467bd0a8 Use QUuid to generate seed, rand() to choose theme
unc0rr
parents: 123
diff changeset
    63
97
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    64
	bindir = new QDir(mydir);
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    65
	cfgdir = new QDir();
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    66
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    67
	cfgdir->setPath(cfgdir->homePath());
148
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    68
	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
97
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    69
	{
148
c0355acf07c8 Don't save demos in 'bin' dir
unc0rr
parents: 128
diff changeset
    70
		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
97
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    71
	}
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    72
	cfgdir->cd(".hedgewars");
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    73
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    74
	datadir = new QDir(mydir);
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    75
	datadir->cd("../share/hedgewars/Data");
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    76
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 52
diff changeset
    77
	HWForm *Form = new HWForm();
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    78
	Form->show();
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    79
	return app.exec();
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    80
}