Files

62 lines
1.6 KiB
C++
Raw Permalink Normal View History

2017-12-21 21:16:37 +01:00
#include "devtoolsplugin.h"
2017-12-21 21:29:13 +01:00
#include <memory>
2017-12-21 21:16:37 +01:00
#include <QDebug>
#include <QDir>
#include <QCoreApplication>
#include <QLocale>
2017-12-21 21:29:13 +01:00
#include <QMenu>
#include <QAction>
2017-12-21 21:16:37 +01:00
#include "mainwindow.h"
2017-12-21 21:29:13 +01:00
#include "logmodel.h"
#include "logdialog.h"
std::shared_ptr<LogModel> model;
QtMessageHandler previousHandler;
void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
{
previousHandler(type, context, message);
model->log(type, context.file, context.line, context.function, context.category, message);
}
void registerMessageHandler()
{
model = std::make_shared<LogModel>();
2017-12-21 21:29:13 +01:00
previousHandler = qInstallMessageHandler(myMessageHandler);
}
Q_COREAPP_STARTUP_FUNCTION(registerMessageHandler)
2017-12-21 21:16:37 +01:00
DevToolsPlugin::DevToolsPlugin(QObject *parent) :
ZeiterfassungPlugin(parent)
{
qDebug() << "called";
static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations"));
if(m_translator.load(QLocale(), QStringLiteral("devtoolsplugin"), QStringLiteral("_"), dir))
{
if(!QCoreApplication::installTranslator(&m_translator))
{
qWarning() << "could not install translation devtoolsplugin";
}
}
else
{
qWarning() << "could not load translation devtoolsplugin";
}
}
void DevToolsPlugin::attachTo(MainWindow &mainWindow)
{
2017-12-21 21:29:13 +01:00
auto dialog = new LogDialog(&mainWindow);
dialog->setModel(model.get());
2017-12-21 21:33:46 +01:00
mainWindow.menuTools()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/devtoolsplugin/images/dev-tools.png")),
tr("Show log"), dialog, &QWidget::show);
2017-12-21 21:16:37 +01:00
}