Add logging file and window

This commit is contained in:
woblight
2024-09-21 19:32:36 +02:00
parent 40c8ce2b4e
commit da461ef2ec
8 changed files with 93 additions and 20 deletions
-1
View File
@@ -22,7 +22,6 @@ import QtQuick.Layouts
Page {
title: "Addons"
header: ToolBar {
Layout.fillWidth: true
RowLayout {
anchors.fill: parent
ToolButton {
+1
View File
@@ -49,6 +49,7 @@ set(qml_files
Tray.qml
UniversalSettings.qml
Update.qml
LogWindow.qml
)
set(${PROJECT_NAME}_BUILD_NAME "" CACHE STRING "name of the build pipeline for self updates")
+3 -2
View File
@@ -20,9 +20,10 @@ import GitAddonsManager.engine
import QtQuick.Layouts
import QtCore
Pane {
ScrollView {
id: optPage
ColumnLayout {
width: parent.width
width: Math.max(optPage.availableWidth, implicitWidth)
Repeater {
model: Engine.addonsPaths.length
RowLayout {
+32 -2
View File
@@ -100,16 +100,19 @@ void Control::delegate(QString taskname, auto work, auto callback)
using ret_t = typename std::invoke_result<decltype(work)>::type;
QFuture<ret_t> fut = QtConcurrent::run(m_pool, work);
QFutureWatcher<ret_t> *fw = new QFutureWatcher<ret_t>();
connect(fw, &QFutureWatcher<ret_t>::finished, [this, callback, fw, lock=std::move(lock)](){
connect(fw, &QFutureWatcher<ret_t>::finished, [this, callback, taskname, fw, lock=std::move(lock)](){
m_lock = false;
TaskQueue old;
m_tasks.swap(old);
qInfo() << "Executing callback for " << taskname;
if constexpr (std::is_same<ret_t, void>::value)
callback();
else
callback(fw->result());
qInfo() << "Completed " << taskname;
m_tasks.append(old);
if (m_status != Status::Error) {
@@ -732,3 +735,30 @@ Control::BusyLock::~BusyLock()
if (!--count && m_locked->m_tasks.empty() && m_locked->status() != Status::Error)
m_locked->setStatus(Status::Ready);
}
void Control::log(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
QString message = QString("<span style=\" color:%1;\">%2</span>");
QString color;
switch(type)
{
case QtDebugMsg:
color = "silver";
break;
case QtInfoMsg:
color = "black";
break;
case QtWarningMsg:
color = "orange";
break;
case QtFatalMsg:
color = "red";
break;
case QtCriticalMsg:
color = "darkred";
break;
}
emit logMessage(message.arg(color, msg));
}
+4 -1
View File
@@ -79,7 +79,6 @@ public:
Q_PROPERTY(QStringList addonsPaths READ addonsPaths WRITE setAddonsPaths NOTIFY addonsPathsChanged)
Q_PROPERTY(bool useRepoDirectory READ useRepoDirectory WRITE setUseRepoDirectory NOTIFY useRepoDirectoryChanged)
static QStringList m_availableStyles;
~Control();
@@ -149,6 +148,8 @@ public:
QString version() const;
bool selfUpdates() const;
void log(QtMsgType type, const QMessageLogContext &context, const QString &msg);
private:
static Control *m_instance;
@@ -219,6 +220,8 @@ signals:
void useRepoDirectoryChanged(bool use);
void logMessage(QString log);
public slots:
void setAddons(QList<Addon *> addons);
void saveAddonsPaths();
+18
View File
@@ -26,11 +26,29 @@
#include <QProcess>
#include <QFontDatabase>
#include <QCommandLineParser>
#include <QtLogging>
QtMessageHandler originalHandler = nullptr;
void logger(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QString message = qFormatLogMessage(type, context, msg);
static FILE *f = fopen("log.txt", "w");
fprintf(f, "%s\n", qPrintable(message));
fflush(f);
Control::instance()->log(type, context, msg);
if (originalHandler)
originalHandler(type, context, msg);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
qSetMessagePattern("[%{time yyyyMMdd h:mm:ss.zzz t} %{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{message}");
originalHandler = qInstallMessageHandler(&logger);
QCommandLineParser parser;
parser.addOption({"update", "directory to update", "updateLocation"});
parser.process(app);
+34 -14
View File
@@ -95,7 +95,10 @@ ApplicationWindow {
Action {
id: exportList
icon.name: "export-symbolic"
onTriggered: exportListDialog.visible = true
onTriggered: {
exportListDialog.targetPath = null
exportListDialog.visible = true
}
enabled: Engine.status == Engine.Ready && addonsReady
shortcut: StandardKey.SaveAs
@@ -106,10 +109,30 @@ ApplicationWindow {
enabled: availableUpdates > 0
}
ColumnLayout{
Page {
anchors.fill: parent
TabBar {
Layout.fillWidth: true
footer: ToolBar {
height: messageLabel.implicitHeight
RowLayout
{
anchors.fill: parent
Label {
id: messageLabel
text: Engine.statusMessage
}
Label {
id: logButton
text: qsTr("[View log]")
MouseArea {
onClicked: logWindow.visible = !logWindow.visible
anchors.fill: parent
}
Layout.fillHeight: true
Layout.alignment: Qt.AlignRight
}
}
}
header: TabBar {
id: bar
TabButton {
text: qsTr("Addons")
@@ -122,19 +145,12 @@ ApplicationWindow {
}
}
StackLayout {
Layout.fillWidth: true
Layout.fillHeight: true
contentItem: StackLayout {
currentIndex: bar.currentIndex
AddonsPanel {
Layout.fillHeight: true
Layout.fillWidth: true
}
Options {
Layout.fillWidth: true
Layout.fillHeight: true
}
ColumnLayout {
@@ -304,7 +320,7 @@ ApplicationWindow {
x: (parent.width - width) / 2
y: (parent.height - height) / 2
title: "An error occourred"
id: errorDialong
id: errorDialog
Label {
text: Engine.statusMessage
}
@@ -437,8 +453,12 @@ ApplicationWindow {
}
FileDialog {
id: exportListDialog
onAccepted: Engine.exportAddonList(selectedFile)
property string targetPath
onAccepted: Engine.exportAddonList(selectedFile, targetPath)
fileMode: FileDialog.SaveFile
defaultSuffix: "txt"
}
LogWindow {
id: logWindow
}
}
+1
View File
@@ -5,6 +5,7 @@
<file>Options.qml</file>
<file>AddonUpdateButton.qml</file>
<file>AddonsPanel.qml</file>
<file>LogWindow.qml</file>
<file>github_clone_url.jpg</file>
<file>gitlab_clone_url.jpg</file>
<file>icons/breeze/svg/delete.svg</file>