QTfrontend/main.cpp.in
author unc0rr
Fri, 26 Jan 2007 18:05:49 +0000
changeset 366 dc50b7933390
parent 321 1148eeb0557e
child 400 450ff6326084
permissions -rw-r--r--
Show rope
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
277
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     1
/*
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     3
 * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     4
 *
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     8
 *
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    12
 * GNU General Public License for more details.
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    13
 *
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    17
 */
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    18
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    19
#include <QApplication>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    20
#include <QTranslator>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    21
#include <QLocale>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    22
#include <QMessageBox>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    23
#include <QFileInfo>
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    24
#include <QDateTime>
321
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    25
#include <QTextStream>
277
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    26
#include "hwform.h"
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    27
#include "hwconsts.h"
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    28
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    29
QDir * bindir;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    30
QDir * cfgdir;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    31
QDir * datadir;
321
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    32
QStringList * Themes;
277
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    33
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    34
bool checkForDir(const QString & dir)
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    35
{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    36
	QDir tmpdir;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    37
	if (!tmpdir.exists(dir))
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    38
		if (!tmpdir.mkdir(dir))
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    39
		{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    40
			QMessageBox::critical(0,
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    41
					QObject::tr("Error"),
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    42
					QObject::tr("Cannot create directory %1").arg(dir),
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    43
					QObject::tr("OK"));
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    44
			return false;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    45
		}
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    46
	return true;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    47
}
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    48
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    49
int main(int argc, char *argv[])
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    50
{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    51
	QApplication app(argc, argv);
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    52
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    53
	QDateTime now = QDateTime::currentDateTime();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    54
	QDateTime zero;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    55
	srand(now.secsTo(zero));
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    56
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    57
	Q_INIT_RESOURCE(hedgewars);
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    58
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    59
	QTranslator Translator;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    60
	Translator.load(":/translations/hedgewars_" + QLocale::system().name());
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    61
	app.installTranslator(&Translator);
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    62
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    63
	QDir mydir("${HEDGEWARS_BINDIR}");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    64
	mydir.cd("bin");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    65
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    66
	bindir = new QDir(mydir);
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    67
	cfgdir = new QDir();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    68
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    69
	cfgdir->setPath(cfgdir->homePath());
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    70
	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    71
	{
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    72
		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    73
	}
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    74
	cfgdir->cd(".hedgewars");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    75
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    76
	datadir = new QDir("${HEDGEWARS_DATADIR}");
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    77
	if(!datadir->cd("hedgewars/Data")) {
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    78
		QMessageBox::critical(0, QMessageBox::tr("Error"), 
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    79
			QMessageBox::tr("Failed to open data directory:\n%1\n"
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    80
					"Please check your installation").
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    81
					arg(datadir->absolutePath()+"/hedgewars/Data"));
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    82
		return 1;
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    83
	}
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    84
321
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    85
	Themes = new QStringList();
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    86
	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    87
	if (themesfile.open(QIODevice::ReadOnly)) {
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    88
		QTextStream stream(&themesfile);
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    89
		QString str;
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    90
		while (!stream.atEnd())
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    91
		{
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    92
			Themes->append(stream.readLine());
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    93
		}
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    94
		themesfile.close();
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    95
	} else {
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    96
		QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    97
	}
1148eeb0557e Oops, fix the build
unc0rr
parents: 277
diff changeset
    98
277
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
    99
	HWForm *Form = new HWForm();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
   100
	Form->show();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
   101
	return app.exec();
04a613bab65c rollback to main.cpp.in
displacer
parents:
diff changeset
   102
}