Fix game:addSpawnShapesByZone
[ryzomcore.git] / studio / src / plugins / log / log_plugin.cpp
blobb5cdec4be3f28f9dcf847cd451b15307f9505f59
1 // Object Viewer Qt - Log Plugin - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2011 Adrian JAEKEL <aj@elane2k.com>
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2011 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
6 // Copyright (C) 2013 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // Copyright (C) 2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
8 //
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/>.
22 // Project includes
23 #include "log_plugin.h"
24 #include "log_settings_page.h"
25 #include "qt_displayer.h"
27 #include "../core/icore.h"
28 #include "../core/core_constants.h"
29 #include "../core/menu_manager.h"
30 #include "../../extension_system/iplugin_spec.h"
32 // Qt includes
33 #include <QtCore/QObject>
34 #include <QtGui/QMessageBox>
35 #include <QtGui/QMainWindow>
36 #include <QtGui/QMenu>
37 #include <QtGui/QAction>
38 #include <QtGui/QMenuBar>
39 #include <QtGui/QWidget>
40 #include <QFile>
41 #include <QDateTime>
42 #include <QTextStream>
44 // NeL includes
45 #include <nel/misc/debug.h>
47 namespace Plugin
50 CLogPlugin::CLogPlugin(QWidget *parent): QDockWidget(parent)
52 m_ui.setupUi(this);
53 logMenu = NULL;
56 CLogPlugin::~CLogPlugin()
58 Q_FOREACH(QObject *obj, m_autoReleaseObjects)
60 m_plugMan->removeObject(obj);
62 qDeleteAll(m_autoReleaseObjects);
63 m_autoReleaseObjects.clear();
65 NLMISC::ErrorLog->removeDisplayer(m_displayer);
66 NLMISC::WarningLog->removeDisplayer(m_displayer);
67 NLMISC::DebugLog->removeDisplayer(m_displayer);
68 NLMISC::AssertLog->removeDisplayer(m_displayer);
69 NLMISC::InfoLog->removeDisplayer(m_displayer);
70 delete m_displayer;
72 delete logMenu;
73 logMenu = NULL;
75 delete m_libContext;
76 m_libContext = NULL;
79 bool CLogPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString)
81 Q_UNUSED(errorString);
82 m_plugMan = pluginManager;
83 m_logSettingsPage = new CLogSettingsPage(this, this);
84 addAutoReleasedObject(m_logSettingsPage);
85 return true;
88 void CLogPlugin::extensionsInitialized()
90 setDisplayers();
92 Core::ICore *core = Core::ICore::instance();
93 Core::MenuManager *menuManager = core->menuManager();
95 QMainWindow *wnd = Core::ICore::instance()->mainWindow();
96 wnd->addDockWidget(Qt::RightDockWidgetArea, this);
97 hide();
99 logMenu = menuManager->menuBar()->addMenu( "Log" );
100 QAction *a = toggleViewAction();
101 a->setText( tr( "View log" ) );
102 logMenu->addAction( a );
105 void CLogPlugin::setNelContext(NLMISC::INelContext *nelContext)
107 #ifdef NL_OS_WINDOWS
108 // Ensure that a context doesn't exist yet.
109 // This only applies to platforms without PIC, e.g. Windows.
110 nlassert(!NLMISC::INelContext::isContextInitialised());
111 #endif // fdef NL_OS_WINDOWS^M
112 m_libContext = new NLMISC::CLibraryContext(*nelContext);
114 m_displayer = new NLQT::CQtDisplayer(m_ui.plainTextEdit);
118 QString CLogPlugin::name() const
120 return "LogPlugin";
123 QString CLogPlugin::version() const
125 return "1.1";
128 QString CLogPlugin::vendor() const
130 return "aquiles";
133 QString CLogPlugin::description() const
135 return tr("DockWidget to display all log messages from NeL.");
138 QStringList CLogPlugin::dependencies() const
140 QStringList list;
141 list.append(Core::Constants::OVQT_CORE_PLUGIN);
142 return list;
145 void CLogPlugin::addAutoReleasedObject(QObject *obj)
147 m_plugMan->addObject(obj);
148 m_autoReleaseObjects.prepend(obj);
151 void CLogPlugin::setDisplayers()
153 QSettings *settings = Core::ICore::instance()->settings();
155 settings->beginGroup(Core::Constants::LOG_SECTION);
156 bool error = settings->value(Core::Constants::LOG_ERROR, true).toBool();
157 bool warning = settings->value(Core::Constants::LOG_WARNING, true).toBool();
158 bool debug = settings->value(Core::Constants::LOG_DEBUG, true).toBool();
159 bool assert = settings->value(Core::Constants::LOG_ASSERT, true).toBool();
160 bool info = settings->value(Core::Constants::LOG_INFO, true).toBool();
161 settings->endGroup();
163 if (error) {
164 if (!NLMISC::ErrorLog->attached(m_displayer))
165 NLMISC::ErrorLog->addDisplayer(m_displayer);
166 } else {
167 if (m_displayer) {
168 NLMISC::ErrorLog->removeDisplayer(m_displayer);
171 if (warning) {
172 if (!NLMISC::WarningLog->attached(m_displayer))
173 NLMISC::WarningLog->addDisplayer(m_displayer);
174 } else {
175 if (m_displayer) {
176 NLMISC::WarningLog->removeDisplayer(m_displayer);
179 if (debug) {
180 if (!NLMISC::DebugLog->attached(m_displayer))
181 NLMISC::DebugLog->addDisplayer(m_displayer);
182 } else {
183 if (m_displayer) {
184 NLMISC::DebugLog->removeDisplayer(m_displayer);
187 if (assert) {
188 if (!NLMISC::AssertLog->attached(m_displayer))
189 NLMISC::AssertLog->addDisplayer(m_displayer);
190 } else {
191 if (m_displayer) {
192 NLMISC::AssertLog->removeDisplayer(m_displayer);
195 if (info) {
196 if (!NLMISC::InfoLog->attached(m_displayer))
197 NLMISC::InfoLog->addDisplayer(m_displayer);
198 } else {
199 if (m_displayer) {
200 NLMISC::InfoLog->removeDisplayer(m_displayer);
205 Q_EXPORT_PLUGIN(Plugin::CLogPlugin)