1 // Object Viewer Qt - Log Plugin - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2011 Adrian JAEKEL <aj@elane2k.com>
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>
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 "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"
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>
42 #include <QTextStream>
45 #include <nel/misc/debug.h>
50 CLogPlugin::CLogPlugin(QWidget
*parent
): QDockWidget(parent
)
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
);
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
);
88 void CLogPlugin::extensionsInitialized()
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);
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
)
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
123 QString
CLogPlugin::version() const
128 QString
CLogPlugin::vendor() const
133 QString
CLogPlugin::description() const
135 return tr("DockWidget to display all log messages from NeL.");
138 QStringList
CLogPlugin::dependencies() const
141 list
.append(Core::Constants::OVQT_CORE_PLUGIN
);
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();
164 if (!NLMISC::ErrorLog
->attached(m_displayer
))
165 NLMISC::ErrorLog
->addDisplayer(m_displayer
);
168 NLMISC::ErrorLog
->removeDisplayer(m_displayer
);
172 if (!NLMISC::WarningLog
->attached(m_displayer
))
173 NLMISC::WarningLog
->addDisplayer(m_displayer
);
176 NLMISC::WarningLog
->removeDisplayer(m_displayer
);
180 if (!NLMISC::DebugLog
->attached(m_displayer
))
181 NLMISC::DebugLog
->addDisplayer(m_displayer
);
184 NLMISC::DebugLog
->removeDisplayer(m_displayer
);
188 if (!NLMISC::AssertLog
->attached(m_displayer
))
189 NLMISC::AssertLog
->addDisplayer(m_displayer
);
192 NLMISC::AssertLog
->removeDisplayer(m_displayer
);
196 if (!NLMISC::InfoLog
->attached(m_displayer
))
197 NLMISC::InfoLog
->addDisplayer(m_displayer
);
200 NLMISC::InfoLog
->removeDisplayer(m_displayer
);
205 Q_EXPORT_PLUGIN(Plugin::CLogPlugin
)