61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
#include "devtoolsplugin.h"
|
|
|
|
#include <QDebug>
|
|
#include <QDir>
|
|
#include <QCoreApplication>
|
|
#include <QLocale>
|
|
#include <QMenu>
|
|
#include <QAction>
|
|
|
|
#include "utils/fileutils.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "logmodel.h"
|
|
#include "logdialog.h"
|
|
|
|
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()
|
|
{
|
|
previousHandler = qInstallMessageHandler(myMessageHandler);
|
|
}
|
|
|
|
Q_COREAPP_STARTUP_FUNCTION(registerMessageHandler)
|
|
|
|
DevToolsPlugin::DevToolsPlugin(QObject *parent) :
|
|
ZeiterfassungPlugin(parent)
|
|
{
|
|
qDebug() << "called";
|
|
|
|
if(m_translator.load(QLocale(), QStringLiteral("devtoolsplugin"), QStringLiteral("_"), translationsDir()))
|
|
{
|
|
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")),
|
|
tr("Show log"), &mainWindow, [&mainWindow](){
|
|
LogDialog dialog(&mainWindow);
|
|
dialog.setModel(&model);
|
|
dialog.exec();
|
|
});
|
|
}
|