1 // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Winch Gate Property Limited
6 // Copyright (C) 2014-2015 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // Copyright (C) 2014-2015 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU Affero General Public License as
11 // published by the Free Software Foundation, either version 3 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU Affero General Public License for more details.
19 // You should have received a copy of the GNU Affero General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "extension_system/iplugin_spec.h"
24 #include "extension_system/plugin_manager.h"
27 #include <nel/misc/types_nl.h>
28 #include <nel/misc/app_context.h>
29 #include <nel/misc/debug.h>
30 #include <nel/misc/common.h>
31 #include <nel/misc/file.h>
32 #include <nel/misc/dynloadlib.h>
33 #include <nel/misc/path.h>
34 #include <nel/misc/command.h>
37 #include <QtCore/QDir>
38 #include <QtCore/QTranslator>
39 #include <QtCore/QLibraryInfo>
40 #include <QtCore/QLocale>
41 #include <QtCore/QSettings>
42 #include <QtGui/QMessageBox>
43 #include <QtGui/QApplication>
44 //#include <QtGui/QSplashScreen>
45 #include <QtGui/QFileDialog>
46 #include <QtGui/QInputDialog>
48 #include "startup_settings_dlg.h"
49 #include "splash_screen.h"
50 #include "pm_watcher.h"
52 #ifdef HAVE_OVQT_CONFIG_H
53 #include "ovqt_config.h"
56 static const char *appNameC
= "RyzomCoreStudio";
58 // nel_qt log file name
59 #define NLQT_LOG_FILE "nel_qt.log"
61 // clear nel_qt log before use
62 #define NLQT_ERASE_LOG true
64 #if !defined (NLQT_USE_LOG_LOG)
65 # define NLQT_USE_LOG_LOG true
67 #if !defined (NLQT_USE_LOG)
68 # define NLQT_USE_LOG 1
76 NLMISC::CFileDisplayer
*s_FileDisplayer
= NULL
;
77 } /* anonymous namespace */
79 } /* namespace NLQT */
88 # define tstring wstring
90 # define tstring string
96 static void displayError(const QString
&t
) // No console on Windows.
98 QMessageBox::critical(0, QLatin1String(appNameC
), t
);
103 static void displayError(const QString
&t
)
105 qCritical("%s", qPrintable(t
));
110 static inline QString
msgCoreLoadFailure(const QString
&why
)
112 return QCoreApplication::translate("Application", "Failed to load Core plugin: %1").arg(why
);
117 int __stdcall
WinMain(void *hInstance
, void *hPrevInstance
, void *lpCmdLine
, int nShowCmd
)
118 #else // NL_OS_WINDOWS
119 int main(int argc
, char **argv
)
120 #endif // NL_OS_WINDOWS
123 new NLMISC::CApplicationContext
;
125 // use log.log if NEL_LOG_IN_FILE and NLQT_USE_LOG_LOG defined as 1
126 NLMISC::createDebug(NULL
, NLQT_USE_LOG_LOG
, false);
127 NLMISC::INelContext::getInstance().setWindowedApplication(true);
129 // create NLQT_LOG_FILE
130 // filedisplayer only deletes the 001 etc
131 if (NLQT_ERASE_LOG
&& NLMISC::CFile::isExists(NLQT_LOG_FILE
))
132 NLMISC::CFile::deleteFile(NLQT_LOG_FILE
);
133 // initialize the log file
134 NLQT::s_FileDisplayer
= new NLMISC::CFileDisplayer();
135 NLQT::s_FileDisplayer
->setParam(NLQT_LOG_FILE
, NLQT_ERASE_LOG
);
136 NLMISC::DebugLog
->addDisplayer(NLQT::s_FileDisplayer
);
137 NLMISC::InfoLog
->addDisplayer(NLQT::s_FileDisplayer
);
138 NLMISC::WarningLog
->addDisplayer(NLQT::s_FileDisplayer
);
139 NLMISC::AssertLog
->addDisplayer(NLQT::s_FileDisplayer
);
140 NLMISC::ErrorLog
->addDisplayer(NLQT::s_FileDisplayer
);
143 nlinfo("Welcome to NeL Object Viewer Qt!");
145 QApplication::setGraphicsSystem("raster");
147 QApplication
app(__argc
, __argv
);
148 #else // NL_OS_WINDOWS
149 QApplication
app(argc
, argv
);
150 #endif // NL_OS_WINDOWS
152 SplashScreen
*splash
= new SplashScreen();
153 splash
->setPixmap(QPixmap(":/images/studio_splash.png"));
154 splash
->setProgressBarEnabled( true );
155 splash
->setText( "Starting up..." );
156 splash
->setProgress( 0 );
159 QSettings::setDefaultFormat(QSettings::IniFormat
);
160 QSettings
*settings
= new QSettings(QSettings::IniFormat
, QSettings::UserScope
,
161 QLatin1String("RyzomCore"), QLatin1String(appNameC
));
163 bool firstRun
= settings
->value( "FirstRun", true ).toBool();
166 settings
->setValue( "FirstRun", false );
168 StartupSettingsDlg sd
;
169 sd
.setSettings( settings
);
174 QTranslator translator
;
175 QTranslator qtTranslator
;
176 QString locale
= settings
->value("Language", QLocale::system().name()).toString();
177 QString qtTrPath
= QLibraryInfo::location(QLibraryInfo::TranslationsPath
);
178 // translator.load("object_viewer_qt_" + locale, ":/");
179 qtTranslator
.load("qt_" + locale
, qtTrPath
);
180 app
.installTranslator(&translator
);
181 app
.installTranslator(&qtTranslator
);
183 splash
->setText( "Loading plugins..." );
184 splash
->setProgress( 20 );
186 #if defined(NL_OS_MAC)
187 QDir::setCurrent(qApp
->applicationDirPath() + QString("/../Resources"));
188 NLMISC::CLibrary::addLibPath((qApp
->applicationDirPath() + QString("/../PlugIns/nel")).toUtf8().constData());
191 ExtensionSystem::PluginManager pluginManager
;
192 pluginManager
.setSettings(settings
);
193 QStringList pluginPaths
;
194 #if defined(NL_OS_MAC)
195 pluginPaths
<< settings
->value("PluginPath", qApp
->applicationDirPath() + QString("/../PlugIns/studio")).toString();
197 pluginPaths
<< settings
->value("PluginPath", QString("%1/plugins").arg(DATA_DIR
)).toString();
200 pluginManager
.setPluginPaths(pluginPaths
);
202 PluginManagerWatcher watcher
;
203 watcher
.setPluginManager( &pluginManager
);
204 watcher
.setSplashScreen( splash
);
207 pluginManager
.loadPlugins();
209 watcher
.disconnect();
212 ExtensionSystem::IPluginSpec
*corePlugin
= pluginManager
.pluginByName("Core");
216 QDir
absolutePluginPaths(pluginPaths
.join(QLatin1String(",")));
217 QString absolutePaths
= absolutePluginPaths
.absolutePath();
218 const QString reason
= QCoreApplication::translate("Application", "Could not find studio_plugin_core in %1").arg(absolutePaths
);
219 displayError(msgCoreLoadFailure(reason
));
221 QString newPath
= QFileDialog::getExistingDirectory(0, QCoreApplication::translate("Application", "Change the plugins path"), QDir::homePath());
223 QString text
= QInputDialog::getText(0, QCoreApplication::translate("Application", "Enter the plugins path"),
224 QCoreApplication::translate("Application", "Plugin path:"), QLineEdit::Normal
,
226 if (ok
&& !text
.isEmpty())
227 settings
->setValue("PluginPath", text
);
231 if (corePlugin
->hasError())
233 displayError(msgCoreLoadFailure(corePlugin
->errorString()));
238 Q_FOREACH (ExtensionSystem::IPluginSpec
*spec
, pluginManager
.plugins())
239 if (spec
->hasError())
240 errors
.append(spec
->fileName() + " : " + spec
->errorString());
242 if (!errors
.isEmpty())
243 QMessageBox::warning(0, QCoreApplication::translate("Application", "Studio - Plugin loader messages"),
244 errors
.join(QString::fromLatin1("\n\n")));
246 int result
= app
.exec();