Changed: #1206 log plugin saves changes now and loads/unloads displayer on the fly

This commit is contained in:
aquiles 2011-05-28 22:06:01 +02:00
parent c39bd25ef3
commit 16e379084f
7 changed files with 403 additions and 271 deletions

View file

@ -80,6 +80,13 @@ const char * const LEVELDESIGN_PATH = "LevelDesignPath";
const char * const ASSETS_PATH = "AssetsPath";
const char * const REMAP_EXTENSIONS = "RemapExtensions";
const char * const LOG_SECTION = "LogSettings";
const char * const LOG_ERROR = "LogError";
const char * const LOG_WARNING = "LogWarning";
const char * const LOG_DEBUG = "LogDebug";
const char * const LOG_ASSERT = "LogAssert";
const char * const LOG_INFO = "LogInfo";
//resources
const char * const ICON_NEL = ":/core/images/nel.png";
const char * const ICON_SETTINGS = ":/core/images/preferences.png";

View file

@ -1,24 +1,29 @@
/*
Log Plugin Qt
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Adrian Jaekel <aj at elane2k dot com>
//
// 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/>.
// Project includes
#include "log_plugin.h"
#include "log_settings_page.h"
#include "qt_displayer.h"
#include "../core/icore.h"
#include "../core/core_constants.h"
#include "../core/imenu_manager.h"
#include "../../extension_system/iplugin_spec.h"
// Qt includes
#include <QtCore/QObject>
@ -35,53 +40,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// NeL includes
#include <nel/misc/debug.h>
// Project includes
#include "../core/icore.h"
#include "../core/core_constants.h"
#include "../core/imenu_manager.h"
#include "qt_displayer.h"
using namespace Plugin;
namespace ExtensionSystem
namespace Plugin
{
class IPluginSpec;
}
CLogPlugin::CLogPlugin(QWidget *parent): QDockWidget(parent)
{
_ui.setupUi(this);
}
CLogPlugin::CLogPlugin(QWidget *parent): QDockWidget(parent)
{
m_ui.setupUi(this);
}
CLogPlugin::~CLogPlugin()
{
//_plugMan->removeObject(_logSettingsPage);
delete _logSettingsPage;
CLogPlugin::~CLogPlugin()
{
Q_FOREACH(QObject *obj, m_autoReleaseObjects)
{
m_plugMan->removeObject(obj);
}
qDeleteAll(m_autoReleaseObjects);
m_autoReleaseObjects.clear();
NLMISC::ErrorLog->removeDisplayer(_displayer);
NLMISC::WarningLog->removeDisplayer(_displayer);
NLMISC::DebugLog->removeDisplayer(_displayer);
NLMISC::AssertLog->removeDisplayer(_displayer);
NLMISC::InfoLog->removeDisplayer(_displayer);
delete _displayer;
}
NLMISC::ErrorLog->removeDisplayer(m_displayer);
NLMISC::WarningLog->removeDisplayer(m_displayer);
NLMISC::DebugLog->removeDisplayer(m_displayer);
NLMISC::AssertLog->removeDisplayer(m_displayer);
NLMISC::InfoLog->removeDisplayer(m_displayer);
delete m_displayer;
}
bool CLogPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString)
{
bool CLogPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString)
{
Q_UNUSED(errorString);
_plugMan = pluginManager;
_logSettingsPage = new CLogSettingsPage(this);
//_plugMan->addObject(_logSettingsPage);
m_plugMan = pluginManager;
m_logSettingsPage = new CLogSettingsPage(this);
addAutoReleasedObject(m_logSettingsPage);
return true;
}
}
void CLogPlugin::extensionsInitialized()
{
NLMISC::ErrorLog->addDisplayer(_displayer);
NLMISC::WarningLog->addDisplayer(_displayer);
NLMISC::DebugLog->addDisplayer(_displayer);
NLMISC::AssertLog->addDisplayer(_displayer);
NLMISC::InfoLog->addDisplayer(_displayer);
void CLogPlugin::extensionsInitialized()
{
setDisplayers();
Core::ICore *core = Core::ICore::instance();
Core::IMenuManager *menuManager = core->menuManager();
@ -92,46 +87,106 @@ void CLogPlugin::extensionsInitialized()
hide();
viewMenu->addAction(this->toggleViewAction());
}
}
void CLogPlugin::setNelContext(NLMISC::INelContext *nelContext)
{
void CLogPlugin::setNelContext(NLMISC::INelContext *nelContext)
{
#ifdef NL_OS_WINDOWS
// Ensure that a context doesn't exist yet.
// This only applies to platforms without PIC, e.g. Windows.
nlassert(!NLMISC::INelContext::isContextInitialised());
#endif // fdef NL_OS_WINDOWS^M
_LibContext = new NLMISC::CLibraryContext(*nelContext);
m_libContext = new NLMISC::CLibraryContext(*nelContext);
_displayer = new NLQT::CQtDisplayer(_ui.plainTextEdit);
m_displayer = new NLQT::CQtDisplayer(m_ui.plainTextEdit);
}
}
QString CLogPlugin::name() const
{
QString CLogPlugin::name() const
{
return "LogPlugin";
}
}
QString CLogPlugin::version() const
{
return "1.0";
}
QString CLogPlugin::version() const
{
return "1.1";
}
QString CLogPlugin::vendor() const
{
QString CLogPlugin::vendor() const
{
return "aquiles";
}
}
QString CLogPlugin::description() const
{
QString CLogPlugin::description() const
{
return "DockWidget to display all log messages from NeL.";
}
}
QStringList CLogPlugin::dependencies() const
{
QStringList CLogPlugin::dependencies() const
{
QStringList list;
list.append(Core::Constants::OVQT_CORE_PLUGIN);
return list;
}
}
Q_EXPORT_PLUGIN(CLogPlugin)
void CLogPlugin::addAutoReleasedObject(QObject *obj)
{
m_plugMan->addObject(obj);
m_autoReleaseObjects.prepend(obj);
}
void CLogPlugin::setDisplayers()
{
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(Core::Constants::LOG_SECTION);
bool error = settings->value(Core::Constants::LOG_ERROR, true).toBool();
bool warning = settings->value(Core::Constants::LOG_WARNING, true).toBool();
bool debug = settings->value(Core::Constants::LOG_DEBUG, true).toBool();
bool assert = settings->value(Core::Constants::LOG_ASSERT, true).toBool();
bool info = settings->value(Core::Constants::LOG_INFO, true).toBool();
settings->endGroup();
if (error) {
if (!NLMISC::ErrorLog->attached(m_displayer))
NLMISC::ErrorLog->addDisplayer(m_displayer);
} else {
if (m_displayer) {
NLMISC::ErrorLog->removeDisplayer(m_displayer);
}
}
if (warning) {
if (!NLMISC::WarningLog->attached(m_displayer))
NLMISC::WarningLog->addDisplayer(m_displayer);
} else {
if (m_displayer) {
NLMISC::WarningLog->removeDisplayer(m_displayer);
}
}
if (debug) {
if (!NLMISC::DebugLog->attached(m_displayer))
NLMISC::DebugLog->addDisplayer(m_displayer);
} else {
if (m_displayer) {
NLMISC::DebugLog->removeDisplayer(m_displayer);
}
}
if (assert) {
if (!NLMISC::AssertLog->attached(m_displayer))
NLMISC::AssertLog->addDisplayer(m_displayer);
} else {
if (m_displayer) {
NLMISC::AssertLog->removeDisplayer(m_displayer);
}
}
if (info) {
if (!NLMISC::InfoLog->attached(m_displayer))
NLMISC::InfoLog->addDisplayer(m_displayer);
} else {
if (m_displayer) {
NLMISC::InfoLog->removeDisplayer(m_displayer);
}
}
}
}
Q_EXPORT_PLUGIN(Plugin::CLogPlugin)

View file

@ -1,6 +1,6 @@
/*
Log Plugin Qt
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
Copyright (C) 2011 Adrian Jaekel <aj at elane2k dot com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -20,16 +20,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LOG_PLUGIN_H
#define LOG_PLUGIN_H
// Project includes
#include "ui_log_form.h"
#include "../../extension_system/iplugin.h"
// NeL includes
#include "nel/misc/app_context.h"
// Qt includes
#include <QDockWidget>
// Project includes
#include "ui_log_form.h"
namespace NLMISC
{
class CLibraryContext;
@ -61,7 +61,7 @@ namespace Plugin
void extensionsInitialized();
void setNelContext(NLMISC::INelContext *nelContext);
NLQT::CQtDisplayer* displayer() { return _displayer; }
NLQT::CQtDisplayer* displayer() { return m_displayer; }
QString name() const;
QString version() const;
@ -69,16 +69,21 @@ namespace Plugin
QString description() const;
QStringList dependencies() const;
void addAutoReleasedObject(QObject *obj);
void setDisplayers();
protected:
NLMISC::CLibraryContext *_LibContext;
NLMISC::CLibraryContext *m_libContext;
private:
ExtensionSystem::IPluginManager *_plugMan;
CLogSettingsPage *_logSettingsPage;
ExtensionSystem::IPluginManager *m_plugMan;
QList<QObject *> m_autoReleaseObjects;
CLogSettingsPage *m_logSettingsPage;
Ui::CLogPlugin _ui;
Ui::CLogPlugin m_ui;
NLQT::CQtDisplayer *_displayer;
NLQT::CQtDisplayer *m_displayer;
};

View file

@ -1,6 +1,6 @@
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
// Copyright (C) 2011 Adrian Jaekel <aj at elane2k dot com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
@ -15,14 +15,19 @@
// 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/>.
// Project includes
#include "log_settings_page.h"
// Qt includes
#include <QtGui/QWidget>
#include "log_plugin.h"
#include "../core/core_constants.h"
#include "../core/icore.h"
#include "../../extension_system/plugin_manager.h"
// NeL includes
// Project includes
// Qt includes
#include <QtGui/QWidget>
#include <QtCore/QSettings>
namespace ExtensionSystem
{
class IPluginManager;
@ -31,15 +36,22 @@ namespace ExtensionSystem
namespace Plugin
{
class CLogPlugin;
CLogSettingsPage::CLogSettingsPage(QObject *parent)
: IOptionsPage(parent),
_currentPage(NULL)
m_currentPage(NULL),
m_error(true),
m_warning(true),
m_debug(true),
m_assert(true),
m_info(true)
{
}
QString CLogSettingsPage::id() const
{
return QLatin1String("Log");
return QLatin1String("log");
}
QString CLogSettingsPage::trName() const
@ -49,32 +61,78 @@ namespace Plugin
QString CLogSettingsPage::category() const
{
return QLatin1String("General");
return QLatin1String(Core::Constants::SETTINGS_CATEGORY_GENERAL);
}
QString CLogSettingsPage::trCategory() const
{
return tr("General");
return tr(Core::Constants::SETTINGS_TR_CATEGORY_GENERAL);
}
QIcon CLogSettingsPage::categoryIcon() const
{
return QIcon();
}
QWidget *CLogSettingsPage::createPage(QWidget *parent)
{
_currentPage = new QWidget(parent);
_ui.setupUi(_currentPage);
return _currentPage;
m_currentPage = new QWidget(parent);
m_ui.setupUi(m_currentPage);
readSettings();
m_ui.errorCheck->setChecked(m_error);
m_ui.warningCheck->setChecked(m_warning);
m_ui.debugCheck->setChecked(m_debug);
m_ui.assertCheck->setChecked(m_assert);
m_ui.infoCheck->setChecked(m_info);
return m_currentPage;
}
void CLogSettingsPage::apply()
{
//ExtensionSystem::IPluginSpec *spec, _plugMan->plugins()
//ExtensionSystem::IPluginManager;
//if (_ui.errorCheck->isChecked()) {
//displayer();
//}
//if (_ui.warningCheck->isChecked());
//if (_ui.debugCheck->isChecked());
//if (_ui.assertCheck->isChecked());
//if (_ui.infoCheck->isChecked());
m_error = m_ui.errorCheck->isChecked();
m_warning = m_ui.warningCheck->isChecked();
m_debug = m_ui.debugCheck->isChecked();
m_assert = m_ui.assertCheck->isChecked();
m_info = m_ui.infoCheck->isChecked();
writeSettings();
ExtensionSystem::IPluginManager *p = Core::ICore::instance()->pluginManager();
ExtensionSystem::IPlugin *plugin = p->pluginByName("LogPlugin")->plugin();
CLogPlugin* lp = dynamic_cast<CLogPlugin*>(plugin);
if (lp)
{
lp->setDisplayers();
}
}
void CLogSettingsPage::readSettings()
{
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(Core::Constants::LOG_SECTION);
m_error = settings->value(Core::Constants::LOG_ERROR, true).toBool();
m_warning = settings->value(Core::Constants::LOG_WARNING, true).toBool();
m_debug = settings->value(Core::Constants::LOG_DEBUG, true).toBool();
m_assert = settings->value(Core::Constants::LOG_ASSERT, true).toBool();
m_info = settings->value(Core::Constants::LOG_INFO, true).toBool();
settings->endGroup();
}
void CLogSettingsPage::writeSettings()
{
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(Core::Constants::LOG_SECTION);
settings->setValue(Core::Constants::LOG_ERROR, m_error);
settings->setValue(Core::Constants::LOG_WARNING, m_warning);
settings->setValue(Core::Constants::LOG_DEBUG, m_debug);
settings->setValue(Core::Constants::LOG_ASSERT, m_assert);
settings->setValue(Core::Constants::LOG_INFO, m_info);
settings->endGroup();
settings->sync();
}
} /* namespace Plugin */

View file

@ -29,13 +29,13 @@ class QWidget;
namespace Plugin
{
/**
@class CLogSettingsPage
*/
class CLogSettingsPage : public Core::IOptionsPage
{
/**
@class CLogSettingsPage
*/
class CLogSettingsPage : public Core::IOptionsPage
{
Q_OBJECT
public:
public:
CLogSettingsPage(QObject *parent = 0);
virtual ~CLogSettingsPage() {}
@ -43,15 +43,25 @@ public:
virtual QString trName() const;
virtual QString category() const;
virtual QString trCategory() const;
QIcon categoryIcon() const;
virtual QWidget *createPage(QWidget *parent);
virtual void apply();
virtual void finish() {}
private:
QWidget *_currentPage;
Ui::CLogSettingsPage _ui;
};
private:
void readSettings();
void writeSettings();
QWidget *m_currentPage;
Ui::CLogSettingsPage m_ui;
bool m_error;
bool m_warning;
bool m_debug;
bool m_assert;
bool m_info;
};
} // namespace Core

View file

@ -1,24 +1,21 @@
/*
Georges Editor Qt
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Adrian Jaekel <aj at elane2k dot com>
//
// 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/>.
// Nel includes
#include "qt_displayer.h"
#include <nel/misc/common.h>
#include <nel/misc/file.h>