2011-01-15 12:45:35 +00:00
|
|
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
|
|
|
// Copyright (C) 2010 Winch Gate Property Limited
|
|
|
|
// Copyright (C) 2010 Dzmitry Kamiahin <dnk-88@tut.by>
|
|
|
|
//
|
|
|
|
// 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/>.
|
|
|
|
|
2011-02-28 13:17:16 +00:00
|
|
|
// Project includes
|
|
|
|
#include "extension_system/iplugin_spec.h"
|
|
|
|
#include "extension_system/plugin_manager.h"
|
|
|
|
|
|
|
|
// NeL includes
|
2010-10-22 03:34:26 +00:00
|
|
|
#include <nel/misc/types_nl.h>
|
|
|
|
#include <nel/misc/app_context.h>
|
2011-02-28 13:17:16 +00:00
|
|
|
#include <nel/misc/debug.h>
|
|
|
|
#include <nel/misc/common.h>
|
|
|
|
#include <nel/misc/file.h>
|
|
|
|
#include <nel/misc/dynloadlib.h>
|
|
|
|
#include <nel/misc/path.h>
|
|
|
|
#include <nel/misc/command.h>
|
2010-10-22 03:34:26 +00:00
|
|
|
|
|
|
|
// Qt includes
|
2010-12-12 20:56:56 +00:00
|
|
|
#include <QtCore/QDir>
|
2011-02-20 13:00:15 +00:00
|
|
|
#include <QtCore/QTranslator>
|
|
|
|
#include <QtCore/QLibraryInfo>
|
|
|
|
#include <QtCore/QLocale>
|
2011-02-12 16:07:05 +00:00
|
|
|
#include <QtCore/QSettings>
|
2010-12-02 10:52:22 +00:00
|
|
|
#include <QtGui/QMessageBox>
|
2010-10-22 03:34:26 +00:00
|
|
|
#include <QtGui/QApplication>
|
|
|
|
#include <QtGui/QSplashScreen>
|
2011-05-09 12:13:59 +00:00
|
|
|
#include <QtGui/QFileDialog>
|
|
|
|
#include <QtGui/QInputDialog>
|
2010-10-22 03:34:26 +00:00
|
|
|
|
2011-02-21 14:26:24 +00:00
|
|
|
static const char *appNameC = "ObjectViewerQt";
|
2010-10-22 03:34:26 +00:00
|
|
|
|
|
|
|
// nel_qt log file name
|
|
|
|
#define NLQT_LOG_FILE "nel_qt.log"
|
|
|
|
|
|
|
|
// clear nel_qt log before use
|
|
|
|
#define NLQT_ERASE_LOG true
|
|
|
|
|
|
|
|
#if !defined (NLQT_USE_LOG_LOG)
|
|
|
|
# define NLQT_USE_LOG_LOG true
|
|
|
|
#endif
|
|
|
|
#if !defined (NLQT_USE_LOG)
|
|
|
|
# define NLQT_USE_LOG 1
|
|
|
|
#endif
|
|
|
|
|
2010-11-26 11:54:06 +00:00
|
|
|
namespace NLQT
|
|
|
|
{
|
2010-10-22 03:34:26 +00:00
|
|
|
|
2010-11-26 11:54:06 +00:00
|
|
|
namespace
|
|
|
|
{
|
2011-02-28 13:17:16 +00:00
|
|
|
NLMISC::CFileDisplayer *s_FileDisplayer = NULL;
|
2010-10-22 03:34:26 +00:00
|
|
|
} /* anonymous namespace */
|
|
|
|
|
|
|
|
} /* namespace NLQT */
|
|
|
|
|
|
|
|
#ifndef DATA_DIR
|
|
|
|
# define DATA_DIR "."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
# ifdef _UNICODE
|
|
|
|
# define tstring wstring
|
|
|
|
# else
|
|
|
|
# define tstring string
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2011-02-21 14:26:24 +00:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
|
|
|
static void displayError(const QString &t) // No console on Windows.
|
|
|
|
{
|
|
|
|
QMessageBox::critical(0, QLatin1String(appNameC), t);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static void displayError(const QString &t)
|
|
|
|
{
|
|
|
|
qCritical("%s", qPrintable(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline QString msgCoreLoadFailure(const QString &why)
|
|
|
|
{
|
|
|
|
return QCoreApplication::translate("Application", "Failed to load Core plugin: %1").arg(why);
|
|
|
|
}
|
|
|
|
|
2010-10-22 03:34:26 +00:00
|
|
|
sint main(int argc, char **argv)
|
|
|
|
{
|
2010-11-26 11:54:06 +00:00
|
|
|
// go nel!
|
2010-12-07 12:40:45 +00:00
|
|
|
new NLMISC::CApplicationContext;
|
2010-10-22 03:34:26 +00:00
|
|
|
{
|
|
|
|
// use log.log if NEL_LOG_IN_FILE and NLQT_USE_LOG_LOG defined as 1
|
2011-02-28 13:17:16 +00:00
|
|
|
NLMISC::createDebug(NULL, NLQT_USE_LOG_LOG, false);
|
2010-10-22 03:34:26 +00:00
|
|
|
#if NLQT_USE_LOG
|
2010-12-04 12:03:31 +00:00
|
|
|
// create NLQT_LOG_FILE
|
2010-10-22 03:34:26 +00:00
|
|
|
// filedisplayer only deletes the 001 etc
|
2011-02-28 13:17:16 +00:00
|
|
|
if (NLQT_ERASE_LOG && NLMISC::CFile::isExists(NLQT_LOG_FILE))
|
|
|
|
NLMISC::CFile::deleteFile(NLQT_LOG_FILE);
|
2010-10-22 03:34:26 +00:00
|
|
|
// initialize the log file
|
2011-02-28 13:17:16 +00:00
|
|
|
NLQT::s_FileDisplayer = new NLMISC::CFileDisplayer();
|
2010-10-22 03:34:26 +00:00
|
|
|
NLQT::s_FileDisplayer->setParam(NLQT_LOG_FILE, NLQT_ERASE_LOG);
|
2011-02-28 13:17:16 +00:00
|
|
|
NLMISC::DebugLog->addDisplayer(NLQT::s_FileDisplayer);
|
|
|
|
NLMISC::InfoLog->addDisplayer(NLQT::s_FileDisplayer);
|
|
|
|
NLMISC::WarningLog->addDisplayer(NLQT::s_FileDisplayer);
|
|
|
|
NLMISC::AssertLog->addDisplayer(NLQT::s_FileDisplayer);
|
|
|
|
NLMISC::ErrorLog->addDisplayer(NLQT::s_FileDisplayer);
|
2010-11-26 11:54:06 +00:00
|
|
|
#endif
|
2010-10-22 03:34:26 +00:00
|
|
|
|
2010-12-04 12:03:31 +00:00
|
|
|
nlinfo("Welcome to NeL Object Viewer Qt!");
|
2010-10-22 03:34:26 +00:00
|
|
|
}
|
2011-07-09 22:10:41 +00:00
|
|
|
QApplication::setGraphicsSystem("raster");
|
2010-10-22 03:34:26 +00:00
|
|
|
QApplication app(argc, argv);
|
|
|
|
QSplashScreen *splash = new QSplashScreen();
|
|
|
|
splash->setPixmap(QPixmap(":/images/nel_ide_load.png"));
|
|
|
|
splash->show();
|
2010-11-26 11:54:06 +00:00
|
|
|
|
2011-02-21 14:26:24 +00:00
|
|
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
2011-02-20 13:00:15 +00:00
|
|
|
QSettings *settings = new QSettings(QSettings::IniFormat, QSettings::UserScope,
|
2011-02-21 14:26:24 +00:00
|
|
|
QLatin1String("RyzomCore"), QLatin1String(appNameC));
|
2011-02-20 13:00:15 +00:00
|
|
|
|
|
|
|
QTranslator translator;
|
|
|
|
QTranslator qtTranslator;
|
|
|
|
QString locale = settings->value("Language", QLocale::system().name()).toString();
|
|
|
|
QString qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
2011-05-09 12:13:59 +00:00
|
|
|
// translator.load("object_viewer_qt_" + locale, ":/");
|
2011-02-20 13:00:15 +00:00
|
|
|
qtTranslator.load("qt_" + locale, qtTrPath);
|
|
|
|
app.installTranslator(&translator);
|
|
|
|
app.installTranslator(&qtTranslator);
|
|
|
|
|
2010-12-12 20:56:56 +00:00
|
|
|
#if defined(NL_OS_MAC)
|
|
|
|
QDir::setCurrent(qApp->applicationDirPath() + QString("/../Resources"));
|
2011-03-09 23:37:16 +00:00
|
|
|
NLMISC::CLibrary::addLibPath((qApp->applicationDirPath() + QString("/../PlugIns/nel")).toStdString());
|
2010-12-12 20:56:56 +00:00
|
|
|
#endif
|
|
|
|
|
2011-02-21 14:26:24 +00:00
|
|
|
ExtensionSystem::CPluginManager pluginManager;
|
|
|
|
pluginManager.setSettings(settings);
|
|
|
|
QStringList pluginPaths;
|
|
|
|
#if !defined(NL_OS_MAC)
|
2011-05-09 12:13:59 +00:00
|
|
|
pluginPaths << settings->value("PluginPath", "./plugins").toString();
|
2011-02-21 14:26:24 +00:00
|
|
|
#else
|
2011-05-09 17:51:29 +00:00
|
|
|
pluginPaths << settings->value("PluginPath", qApp->applicationDirPath() + QString("/../PlugIns/ovqt")).toString();
|
2011-02-21 14:26:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
pluginManager.setPluginPaths(pluginPaths);
|
|
|
|
pluginManager.loadPlugins();
|
|
|
|
|
|
|
|
splash->hide();
|
|
|
|
|
|
|
|
const QList<ExtensionSystem::IPluginSpec *> plugins = pluginManager.plugins();
|
|
|
|
ExtensionSystem::IPluginSpec *corePlugin = 0;
|
|
|
|
Q_FOREACH(ExtensionSystem::IPluginSpec *spec, plugins)
|
|
|
|
{
|
|
|
|
if (spec->name() == QLatin1String("Core"))
|
|
|
|
{
|
|
|
|
corePlugin = spec;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!corePlugin)
|
|
|
|
{
|
|
|
|
QDir absolutePluginPaths(pluginPaths.join(QLatin1String(",")));
|
|
|
|
QString absolutePaths = absolutePluginPaths.absolutePath();
|
|
|
|
const QString reason = QCoreApplication::translate("Application", "Could not find ovqt_plugin_core in %1").arg(absolutePaths);
|
|
|
|
displayError(msgCoreLoadFailure(reason));
|
2011-05-09 12:13:59 +00:00
|
|
|
|
|
|
|
QString newPath = QFileDialog::getExistingDirectory(0, QCoreApplication::translate("Application", "Change the plugins path"), QDir::homePath());
|
|
|
|
bool ok;
|
|
|
|
QString text = QInputDialog::getText(0, QCoreApplication::translate("Application", "Enter the plugins path"),
|
|
|
|
QCoreApplication::translate("Application", "Plugin path:"), QLineEdit::Normal,
|
|
|
|
newPath, &ok);
|
|
|
|
if (ok && !text.isEmpty())
|
|
|
|
settings->setValue("PluginPath", text);
|
|
|
|
settings->sync();
|
2011-02-21 14:26:24 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (corePlugin->hasError())
|
|
|
|
{
|
|
|
|
displayError(msgCoreLoadFailure(corePlugin->errorString()));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList errors;
|
|
|
|
Q_FOREACH (ExtensionSystem::IPluginSpec *spec, pluginManager.plugins())
|
|
|
|
if (spec->hasError())
|
|
|
|
errors.append(spec->fileName() + " : " + spec->errorString());
|
|
|
|
|
|
|
|
if (!errors.isEmpty())
|
|
|
|
QMessageBox::warning(0, QCoreApplication::translate("Application", "Object Viewer Qt - Plugin loader messages"),
|
|
|
|
errors.join(QString::fromLatin1("\n\n")));
|
|
|
|
|
|
|
|
int result = app.exec();
|
2010-10-22 03:34:26 +00:00
|
|
|
return result;
|
2011-02-21 14:26:24 +00:00
|
|
|
}
|