Files
pokerth/src/pokerth.cpp
T

151 lines
5.2 KiB
C++
Raw Normal View History

/*****************************************************************************
* PokerTH - The open source texas holdem engine *
* Copyright (C) 2006-2011 Felix Hammer, Florian Thauer, Lothar May *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#include <boost/asio.hpp>
#include <iostream>
#include <cstdlib>
#include <ctime>
2007-01-13 02:40:33 +00:00
#include <qapplication.h>
#include <QtGui>
#include <QtCore>
2007-04-30 23:18:31 +00:00
#ifdef __APPLE__
#include <QMacStyle>
2007-04-30 23:18:31 +00:00
#endif
2007-01-13 02:40:33 +00:00
#include <curl/curl.h>
2007-01-13 02:40:33 +00:00
#include "session.h"
2008-09-02 22:04:18 +00:00
#include "startwindowimpl.h"
2007-05-05 19:02:11 +00:00
#include "configfile.h"
#include "log.h"
2008-06-08 10:50:08 +00:00
#include "startsplash.h"
#include "game_defs.h"
#include <net/socket_startup.h>
#include <third_party/qtsingleapplication/qtsingleapplication.h>
2007-01-13 02:40:33 +00:00
#ifdef _MSC_VER
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#define ENABLE_LEAK_CHECK() \
{ \
int tmpFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); \
tmpFlag |= _CRTDBG_LEAK_CHECK_DF; \
_CrtSetDbgFlag(tmpFlag); \
}
#endif
#endif
#ifndef ENABLE_LEAK_CHECK
#define ENABLE_LEAK_CHECK()
#endif
using namespace std;
2008-09-02 22:04:18 +00:00
class startWindowImpl;
class Game;
2007-01-13 02:40:33 +00:00
int main( int argc, char **argv )
{
//ENABLE_LEAK_CHECK();
//_CrtSetBreakAlloc(49937);
socket_startup();
2008-04-24 22:11:43 +00:00
curl_global_init(CURL_GLOBAL_NOTHING);
2007-01-16 22:42:02 +00:00
/////// can be removed for non-qt-guis ////////////
2010-07-23 17:35:18 +00:00
QtSingleApplication a( argc, argv );
2010-07-23 17:35:18 +00:00
if (a.sendMessage("Wake up!")) {
return 0;
2010-07-23 17:35:18 +00:00
}
2007-06-25 00:25:52 +00:00
#ifdef __APPLE__
// The following needs to be done directly after the application is created.
QDir dir(QApplication::applicationDirPath());
dir.cdUp();
dir.cd("plugins");
QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
#endif
//create defaultconfig
ConfigFile *myConfig = new ConfigFile(argv[0], false);
Log *myLog = new Log(myConfig);
#ifndef ANDROID
2007-06-25 00:25:52 +00:00
// set PlastiqueStyle even for mac-version to prevent artefacts on styled widgets
a.setStyle(new QPlastiqueStyle);
#endif
QString myAppDataPath = QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str());
//set QApplication default font
2007-12-04 22:41:38 +00:00
2007-12-05 00:39:51 +00:00
QFontDatabase::addApplicationFont (myAppDataPath +"fonts/n019003l.pfb");
QFontDatabase::addApplicationFont (myAppDataPath +"fonts/VeraBd.ttf");
2007-12-05 00:39:51 +00:00
QFontDatabase::addApplicationFont (myAppDataPath +"fonts/c059013l.pfb");
QFontDatabase::addApplicationFont (myAppDataPath +"fonts/DejaVuSans-Bold.ttf");
2007-12-05 00:39:51 +00:00
2007-09-04 22:54:07 +00:00
#ifdef _WIN32
QString font1String("QApplication, QWidget, QDialog { font-size: 12px; }");
2010-07-22 20:35:11 +00:00
#else
#ifdef __APPLE__
2010-07-22 20:35:11 +00:00
// QString font1String("font-family: \"Lucida Grande\";");
QString font1String("QApplication, QWidget, QDialog { font-size: 11px; }");
#else
QString font1String("QApplication, QWidget, QDialog { font-family: \"Nimbus Sans L\"; font-size: 12px; }");
2010-07-22 20:35:11 +00:00
#endif
#endif
a.setStyleSheet(font1String + " QDialogButtonBox, QMessageBox { dialogbuttonbox-buttons-have-icons: 1; dialog-ok-icon: url(:/gfx/dialog_ok_apply.png); dialog-cancel-icon: url(:/gfx/dialog_close.png); dialog-close-icon: url(:/gfx/dialog_close.png); dialog-yes-icon: url(:/gfx/dialog_ok_apply.png); dialog-no-icon: url(:/gfx/dialog_close.png) }");
2008-06-08 10:50:08 +00:00
2012-05-06 14:02:00 +00:00
#ifndef ANDROID
2008-06-08 10:50:08 +00:00
QPixmap *pixmap = new QPixmap(myAppDataPath + "gfx/gui/misc/welcomepokerth.png");
2009-06-07 20:23:06 +00:00
StartSplash splash(*pixmap);
if(!myConfig->readConfigInt("DisableSplashScreenOnStartup")) {
splash.show();
2011-12-29 11:30:44 +00:00
splash.showMessage(QString("Version %1").arg(POKERTH_BETA_RELEASE_STRING), 0x0042, QColor(240,240,240));
}
#endif
2007-09-04 22:54:07 +00:00
//Set translations
2007-06-15 18:59:28 +00:00
QTranslator qtTranslator;
qtTranslator.load(QString(myAppDataPath +"translations/qt_") + QString::fromStdString(myConfig->readConfigString("Language")));
a.installTranslator(&qtTranslator);
2007-06-15 18:59:28 +00:00
QTranslator translator;
2007-09-08 22:01:30 +00:00
translator.load(QString(myAppDataPath +"translations/pokerth_") + QString::fromStdString(myConfig->readConfigString("Language")));
2007-06-15 18:59:28 +00:00
a.installTranslator(&translator);
2007-12-13 19:52:48 +00:00
qRegisterMetaType<unsigned>("unsigned");
qRegisterMetaType<boost::shared_ptr<Game> >("boost::shared_ptr<Game>");
qRegisterMetaType<ServerStats>("ServerStats");
2010-07-23 17:36:11 +00:00
qRegisterMetaType<DenyGameInvitationReason>("DenyGameInvitationReason");
///////////////////////////////////////////////////
2007-05-20 13:03:43 +00:00
startWindowImpl mainWin(myConfig,myLog);
2010-07-23 17:36:11 +00:00
a.setActivationWindow(&mainWin, true);
int retVal = a.exec();
curl_global_cleanup();
socket_cleanup();
return retVal;
2007-01-13 02:40:33 +00:00
}