18
18
* You should have received a copy of the GNU General Public License
19
19
* along with Wintermute. If not, see <http://www.gnu.org/licenses/>.
22
22
#include "application.hpp"
23
23
#include "arguments.hpp"
24
24
#include "logging.hpp"
25
#include "Wintermute/globals.hpp"
25
#include "factory.hpp"
26
#include "version.hpp"
26
27
#include <QtCore/QCoreApplication>
27
28
#include <QtCore/QDebug>
29
#include <QtCore/QSharedPointer>
29
31
using Wintermute::Arguments;
30
32
using Wintermute::Logging;
33
using Wintermute::Version;
34
using Wintermute::Factory;
31
35
using Wintermute::Application;
32
36
using Wintermute::ApplicationPrivate;
34
class ApplicationPrivate {
36
QSharedPointer<QCoreApplication> app;
38
ApplicationPrivate(int &argc, char **argv) {
39
app = QSharedPointer<QCoreApplication>(new QCoreApplication(argc,argv));
44
// Allocate necessary variables for logging and arguments.
45
Logging* logging = Logging::self = new Logging;
46
Arguments* arguments = Arguments::self = new Arguments;
38
namespace Wintermute {
39
class ApplicationPrivate {
41
QSharedPointer<QCoreApplication> app;
43
ApplicationPrivate(int &argc, char **argv) {
44
app = QSharedPointer<QCoreApplication>(new QCoreApplication(argc,argv));
49
// Allocate necessary variables for logging and arguments.
51
Arguments::instance();
54
// Add library paths for plug-ins.
55
app->addLibraryPath(WINTERMUTE_LIBRARY_DIR);
55
66
Application* Application::self = 0;
63
74
// Define the application in Qt.
64
75
d->app->setApplicationName("Wintermute");
65
d->app->setApplicationVersion(WINTERMUTE_VERSION_EXACT);
76
d->app->setApplicationVersion(this->version().toString());
66
77
d->app->setOrganizationName("Synthetic Intellect Institute");
67
78
d->app->setOrganizationDomain("thesii.org");
71
82
Application::run(int &argc, char **argv){
72
85
if (Application::instance() == 0){
73
86
// Define the application.
74
87
Application::self = new Application(argc,argv);
88
Logger* log = wlog(Application::self);
76
90
// Invoke the initialization code.
77
91
self->d_ptr->initialize();
78
Logging::obtainLogger(Application::self)->debug("Completed initialization phase.");
92
log->debug("Completed initialization phase.");
82
Logging::obtainLogger(Application::self)->debug("Started.");
84
97
// Begin the event loop.
85
Logging::obtainLogger(Application::self)->debug("Beginning event loop.");
86
int returnCode = self->d_ptr->exec();
87
Logging::obtainLogger(Application::self)->info("Event loop ended. Ended with exit code " + QString::number(returnCode));
98
log->debug("Beginning event loop.");
99
returnCode = self->d_ptr->exec();
100
log->info(QString("Event loop ended; ended with exit code %1").arg(returnCode));
96
107
Application::start(){
97
Logger* log = Logging::obtainLogger(this);
109
Logger* log = wlog(this);
110
log->info("Starting.");
112
// Privately start the Factory.
113
Factory::instance()->start();
116
log->info("Started.");
102
120
Application::stop(){
123
// Privately clean up the Factory.
124
Factory::instance()->stop();
128
Application::version() const {
130
ver.major = WINTERMUTE_VERSION_MAJOR;
131
ver.minor = WINTERMUTE_VERSION_MINOR;
132
ver.patch = WINTERMUTE_VERSION_PATCH;
133
ver.state = (Wintermute::Version::DevelopmentStage) WINTERMUTE_VERSION_STAGE;
134
ver.stage = WINTERMUTE_VERSION_STAGE_REVISION;
105
139
Application::~Application(){