defuze.me  Client
starter.cpp
00001 /**************************************************************************
00002 ** defuze.me Epitech Innovative Project
00003 **
00004 ** Copyright 2010
00005 **   Athena Calmettes - Jocelyn De La Rosa - Francois Gaillard
00006 **   Adrien Jarthon - Alexandre Moore - Luc Peres - Arnaud Sellier
00007 **
00008 ** All rights reserved.
00009 **************************************************************************/
00010 
00011 #include "main.hpp"
00012 #include "starter.hpp"
00013 #include "guicore.hpp"
00014 #include "logger.hpp"
00015 #include <QtCore/QResource>
00016 #include <QtCore/QVariant>
00017 #include <QtCore/QStringList>
00018 #include <QtCore/QTime>
00019 #include <QtCore/QDebug>
00020 #include <QtGui/QApplication>
00021 #include <QtGui/QMessageBox>
00022 #include <QDesktopServices>
00023 
00024 Starter::Starter()
00025 {
00026     qApp->setApplicationName(gl_APPLICATION_NAME);
00027     qApp->setApplicationVersion(gl_APPLICATION_VERSION);
00028     qApp->setOrganizationDomain(gl_ORGANIZATION_DOMAIN);
00029     qApp->setOrganizationName(gl_ORGANIZATION_NAME);
00030 
00031     Logger::log("Starting at   " + QTime::currentTime().toString());
00032     Logger::log("Version       " + qApp->applicationVersion());
00033     Logger::log("Lauching from " + QApplication::applicationDirPath());
00034     Logger::log("Command line  " + QApplication::arguments().join(" "));
00035     Logger::log("PID           " + QVariant(QApplication::applicationPid()).toString());
00036 
00037     arguments = qApp->arguments();
00038     QResource::registerResource("/usr/local/lib/defuze.me/starter.rcc");
00039     QResource::registerResource("resources/starter.rcc");
00040     QResource::registerResource("../resources/starter.rcc");
00041     QResource::registerResource("/Applications/defuze.me.app/Contents/resources/starter.rcc");
00042 
00043     splashScreen = new QSplashScreen(QPixmap(":/images/defuze-me-splash"));
00044     splashScreen->show();
00045 }
00046 
00047 Starter::~Starter()
00048 {
00049     if (cores)
00050     {
00051         splashScreen->finish(cores->gui()->getMainWindow());
00052         cores->gui()->showAll();
00053     }
00054     delete splashScreen;
00055     QResource::unregisterResource("/usr/lib/defuze.me/starter.rcc");
00056     QResource::unregisterResource("resources/starter.rcc");
00057     QResource::unregisterResource("../Resources/starter.rcc");
00058     QResource::unregisterResource("/Applications/defuze.me.app/Contents/Resources/starter.rcc");
00059 }
00060 
00061 Cores* Starter::loadCores()
00062 {
00063     try
00064     {
00065         message("Loading cores");
00066         cores = new Cores(arguments);
00067         message("Initializing cores");
00068         cores->init();
00069     }
00070     catch (Exception &e)
00071     {
00072         initializationError(e);
00073         return 0;
00074     }
00075     return cores;
00076 }
00077 
00078 Plugins* Starter::loadPlugins()
00079 {
00080     try
00081     {
00082         message("Loading plugins");
00083         plugins = new Plugins(cores);
00084         message("Initializing plugins");
00085         connect(plugins, SIGNAL(message(QString)), SLOT(message(QString)));
00086         plugins->init();
00087     }
00088     catch (Exception &e)
00089     {
00090         initializationError(e);
00091         return 0;
00092     }
00093     return plugins;
00094 }
00095 
00096 void    Starter::initializationError(Exception &e)
00097 {
00098     qDebug() << "STARTER: " << e.description();
00099     QMessageBox::critical(NULL, "defuze.me", "An fatal error occurred while initializing defuze.me.<br><i>" +
00100                           e.msg() + " (error " + e.hexCode() +
00101                           ")</i><br><br>Get online support about this error <a href='http://defuze.me/support/errors/" +
00102                           e.hexCode() + "'>here</a>.");
00103 }
00104 
00105 void    Starter::message(const QString& msg) const
00106 {
00107     splashScreen->showMessage(msg, Qt::AlignCenter | Qt::AlignBottom, Qt::white);
00108     qApp->processEvents();
00109 }