QTfrontend/main.cpp
author displacer
Mon, 06 Nov 2006 22:51:09 +0000
changeset 229 91043d0c2247
parent 184 f97a7a3dc8f6
child 267 bf7c1503f569
permissions -rw-r--r--
more pretty color choose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     1
/*
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     2
 * Hedgewars, a worms-like game
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     3
 * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     4
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     8
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    12
 * GNU General Public License for more details.
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    13
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    15
 * along with this program; if not, write to the Free Software
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    17
 */
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    18
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    19
#include <QApplication>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    20
#include <QTranslator>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    21
#include <QLocale>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    22
#include <QMessageBox>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    23
#include <QFileInfo>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    24
#include <QDateTime>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    25
#include "hwform.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    26
#include "hwconsts.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    27
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    28
QDir * bindir;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    29
QDir * cfgdir;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    30
QDir * datadir;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    31
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    32
bool checkForDir(const QString & dir)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    33
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    34
	QDir tmpdir;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    35
	if (!tmpdir.exists(dir))
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    36
		if (!tmpdir.mkdir(dir))
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    37
		{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    38
			QMessageBox::critical(0,
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    39
					QObject::tr("Error"),
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    40
					QObject::tr("Cannot create directory %1").arg(dir),
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    41
					QObject::tr("OK"));
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    42
			return false;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    43
		}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    44
	return true;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    45
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    46
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    47
int main(int argc, char *argv[])
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    48
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    49
	QApplication app(argc, argv);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    50
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    51
	QDateTime now = QDateTime::currentDateTime();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    52
	QDateTime zero;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    53
	srand(now.secsTo(zero));
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    54
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    55
	Q_INIT_RESOURCE(hedgewars);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    56
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    57
	QTranslator Translator;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    58
	Translator.load(":/translations/hedgewars_" + QLocale::system().name());
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    59
	app.installTranslator(&Translator);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    60
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    61
	QDir mydir(".");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    62
	mydir.cd("bin");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    63
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    64
	bindir = new QDir(mydir);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    65
	cfgdir = new QDir();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    66
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    67
	cfgdir->setPath(cfgdir->homePath());
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    68
	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    69
	{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    70
		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    71
	}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    72
	cfgdir->cd(".hedgewars");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    73
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    74
	datadir = new QDir(mydir);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    75
	datadir->cd("../share/hedgewars/Data");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    76
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    77
	HWForm *Form = new HWForm();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    78
	Form->show();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    79
	return app.exec();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    80
}