Use JSON to store the engine configurations
[sloppygui.git] / projects / cli / src / cutechesscoreapp.cpp
blob09679253373b4b3bb8594023bd6a9bafaf27d8a2
1 /*
2 This file is part of Cute Chess.
4 Cute Chess is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 Cute Chess is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
18 #include "cutechesscoreapp.h"
19 #include <QSettings>
20 #include <QTime>
21 #include <QFileInfo>
22 #include <enginemanager.h>
23 #include <cstdlib>
24 #include <cstdio>
27 CuteChessCoreApplication::CuteChessCoreApplication(int& argc, char* argv[])
28 : QCoreApplication(argc, argv), m_engineManager(0)
30 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
32 QCoreApplication::setOrganizationName(QLatin1String("cutechess"));
33 QCoreApplication::setOrganizationDomain(QLatin1String("cutechess.org"));
34 QCoreApplication::setApplicationName(QLatin1String("cutechess"));
36 // Use Ini format on all platforms
37 QSettings::setDefaultFormat(QSettings::IniFormat);
39 qInstallMsgHandler(CuteChessCoreApplication::messageHandler);
41 // Load the engines
42 // Note that we can't use QDesktopServices because of dependencies
43 QSettings settings;
44 QFileInfo fi(settings.fileName());
45 engineManager()->loadEngines(fi.absolutePath() +
46 QLatin1String("/engines.json"));
49 CuteChessCoreApplication::~CuteChessCoreApplication()
53 void CuteChessCoreApplication::messageHandler(QtMsgType type,
54 const char* message)
56 switch (type)
58 case QtDebugMsg:
59 fprintf(stdout, "%s\n", message);
60 break;
62 case QtWarningMsg:
63 fprintf(stderr, "Warning: %s\n", message);
64 break;
66 case QtCriticalMsg:
67 fprintf(stderr, "Critical: %s\n", message);
68 break;
70 case QtFatalMsg:
71 fprintf(stderr, "Fatal: %s\n", message);
72 abort();
76 EngineManager* CuteChessCoreApplication::engineManager()
78 if (m_engineManager == 0)
79 m_engineManager = new EngineManager(this);
81 return m_engineManager;
84 CuteChessCoreApplication* CuteChessCoreApplication::instance()
86 return static_cast<CuteChessCoreApplication*>(QCoreApplication::instance());