Files

61 lines
1.5 KiB
C++
Raw Permalink Normal View History

2018-09-17 19:37:34 +02:00
#include "devtoolsplugin.h"
#include <QDebug>
#include <QDir>
#include <QCoreApplication>
#include <QLocale>
#include <QMenu>
#include <QAction>
2018-10-14 15:35:02 +02:00
#include "utils/fileutils.h"
2018-09-17 19:37:34 +02:00
#include "mainwindow.h"
#include "logmodel.h"
#include "logdialog.h"
2018-11-18 15:22:09 +01:00
LogModel model;
2018-09-17 19:37:34 +02:00
QtMessageHandler previousHandler;
void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
{
previousHandler(type, context, message);
2018-11-18 15:22:09 +01:00
model.log(type, context.file, context.line, context.function, context.category, message);
2018-09-17 19:37:34 +02:00
}
void registerMessageHandler()
{
previousHandler = qInstallMessageHandler(myMessageHandler);
}
Q_COREAPP_STARTUP_FUNCTION(registerMessageHandler)
DevToolsPlugin::DevToolsPlugin(QObject *parent) :
ZeiterfassungPlugin(parent)
{
qDebug() << "called";
2018-10-14 15:35:02 +02:00
if(m_translator.load(QLocale(), QStringLiteral("devtoolsplugin"), QStringLiteral("_"), translationsDir()))
2018-09-17 19:37:34 +02:00
{
if(!QCoreApplication::installTranslator(&m_translator))
{
qWarning() << "could not install translation devtoolsplugin";
}
}
else
{
qWarning() << "could not load translation devtoolsplugin";
}
}
void DevToolsPlugin::attachTo(MainWindow &mainWindow)
{
mainWindow.menuTools()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/devtoolsplugin/images/dev-tools.png")),
2018-11-18 15:22:09 +01:00
tr("Show log"), &mainWindow, [&mainWindow](){
LogDialog dialog(&mainWindow);
dialog.setModel(&model);
dialog.exec();
});
2018-09-17 19:37:34 +02:00
}