Add logging file and window
This commit is contained in:
@@ -22,7 +22,6 @@ import QtQuick.Layouts
|
|||||||
Page {
|
Page {
|
||||||
title: "Addons"
|
title: "Addons"
|
||||||
header: ToolBar {
|
header: ToolBar {
|
||||||
Layout.fillWidth: true
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
ToolButton {
|
ToolButton {
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ set(qml_files
|
|||||||
Tray.qml
|
Tray.qml
|
||||||
UniversalSettings.qml
|
UniversalSettings.qml
|
||||||
Update.qml
|
Update.qml
|
||||||
|
LogWindow.qml
|
||||||
)
|
)
|
||||||
|
|
||||||
set(${PROJECT_NAME}_BUILD_NAME "" CACHE STRING "name of the build pipeline for self updates")
|
set(${PROJECT_NAME}_BUILD_NAME "" CACHE STRING "name of the build pipeline for self updates")
|
||||||
|
|||||||
+3
-2
@@ -20,9 +20,10 @@ import GitAddonsManager.engine
|
|||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import QtCore
|
import QtCore
|
||||||
|
|
||||||
Pane {
|
ScrollView {
|
||||||
|
id: optPage
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
width: parent.width
|
width: Math.max(optPage.availableWidth, implicitWidth)
|
||||||
Repeater {
|
Repeater {
|
||||||
model: Engine.addonsPaths.length
|
model: Engine.addonsPaths.length
|
||||||
RowLayout {
|
RowLayout {
|
||||||
|
|||||||
+32
-2
@@ -100,16 +100,19 @@ void Control::delegate(QString taskname, auto work, auto callback)
|
|||||||
using ret_t = typename std::invoke_result<decltype(work)>::type;
|
using ret_t = typename std::invoke_result<decltype(work)>::type;
|
||||||
QFuture<ret_t> fut = QtConcurrent::run(m_pool, work);
|
QFuture<ret_t> fut = QtConcurrent::run(m_pool, work);
|
||||||
QFutureWatcher<ret_t> *fw = new QFutureWatcher<ret_t>();
|
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;
|
m_lock = false;
|
||||||
TaskQueue old;
|
TaskQueue old;
|
||||||
m_tasks.swap(old);
|
m_tasks.swap(old);
|
||||||
|
|
||||||
|
qInfo() << "Executing callback for " << taskname;
|
||||||
if constexpr (std::is_same<ret_t, void>::value)
|
if constexpr (std::is_same<ret_t, void>::value)
|
||||||
callback();
|
callback();
|
||||||
else
|
else
|
||||||
callback(fw->result());
|
callback(fw->result());
|
||||||
|
|
||||||
|
qInfo() << "Completed " << taskname;
|
||||||
|
|
||||||
m_tasks.append(old);
|
m_tasks.append(old);
|
||||||
|
|
||||||
if (m_status != Status::Error) {
|
if (m_status != Status::Error) {
|
||||||
@@ -732,3 +735,30 @@ Control::BusyLock::~BusyLock()
|
|||||||
if (!--count && m_locked->m_tasks.empty() && m_locked->status() != Status::Error)
|
if (!--count && m_locked->m_tasks.empty() && m_locked->status() != Status::Error)
|
||||||
m_locked->setStatus(Status::Ready);
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ public:
|
|||||||
Q_PROPERTY(QStringList addonsPaths READ addonsPaths WRITE setAddonsPaths NOTIFY addonsPathsChanged)
|
Q_PROPERTY(QStringList addonsPaths READ addonsPaths WRITE setAddonsPaths NOTIFY addonsPathsChanged)
|
||||||
Q_PROPERTY(bool useRepoDirectory READ useRepoDirectory WRITE setUseRepoDirectory NOTIFY useRepoDirectoryChanged)
|
Q_PROPERTY(bool useRepoDirectory READ useRepoDirectory WRITE setUseRepoDirectory NOTIFY useRepoDirectoryChanged)
|
||||||
|
|
||||||
|
|
||||||
static QStringList m_availableStyles;
|
static QStringList m_availableStyles;
|
||||||
|
|
||||||
~Control();
|
~Control();
|
||||||
@@ -149,6 +148,8 @@ public:
|
|||||||
QString version() const;
|
QString version() const;
|
||||||
|
|
||||||
bool selfUpdates() const;
|
bool selfUpdates() const;
|
||||||
|
|
||||||
|
void log(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Control *m_instance;
|
static Control *m_instance;
|
||||||
@@ -219,6 +220,8 @@ signals:
|
|||||||
|
|
||||||
void useRepoDirectoryChanged(bool use);
|
void useRepoDirectoryChanged(bool use);
|
||||||
|
|
||||||
|
void logMessage(QString log);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setAddons(QList<Addon *> addons);
|
void setAddons(QList<Addon *> addons);
|
||||||
void saveAddonsPaths();
|
void saveAddonsPaths();
|
||||||
|
|||||||
@@ -26,11 +26,29 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QCommandLineParser>
|
#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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, 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;
|
QCommandLineParser parser;
|
||||||
parser.addOption({"update", "directory to update", "updateLocation"});
|
parser.addOption({"update", "directory to update", "updateLocation"});
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
|
|||||||
@@ -95,7 +95,10 @@ ApplicationWindow {
|
|||||||
Action {
|
Action {
|
||||||
id: exportList
|
id: exportList
|
||||||
icon.name: "export-symbolic"
|
icon.name: "export-symbolic"
|
||||||
onTriggered: exportListDialog.visible = true
|
onTriggered: {
|
||||||
|
exportListDialog.targetPath = null
|
||||||
|
exportListDialog.visible = true
|
||||||
|
}
|
||||||
|
|
||||||
enabled: Engine.status == Engine.Ready && addonsReady
|
enabled: Engine.status == Engine.Ready && addonsReady
|
||||||
shortcut: StandardKey.SaveAs
|
shortcut: StandardKey.SaveAs
|
||||||
@@ -106,10 +109,30 @@ ApplicationWindow {
|
|||||||
enabled: availableUpdates > 0
|
enabled: availableUpdates > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout{
|
Page {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
TabBar {
|
footer: ToolBar {
|
||||||
Layout.fillWidth: true
|
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
|
id: bar
|
||||||
TabButton {
|
TabButton {
|
||||||
text: qsTr("Addons")
|
text: qsTr("Addons")
|
||||||
@@ -122,19 +145,12 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StackLayout {
|
contentItem: StackLayout {
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.fillHeight: true
|
|
||||||
currentIndex: bar.currentIndex
|
currentIndex: bar.currentIndex
|
||||||
AddonsPanel {
|
AddonsPanel {
|
||||||
Layout.fillHeight: true
|
|
||||||
Layout.fillWidth: true
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Options {
|
Options {
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.fillHeight: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
@@ -304,7 +320,7 @@ ApplicationWindow {
|
|||||||
x: (parent.width - width) / 2
|
x: (parent.width - width) / 2
|
||||||
y: (parent.height - height) / 2
|
y: (parent.height - height) / 2
|
||||||
title: "An error occourred"
|
title: "An error occourred"
|
||||||
id: errorDialong
|
id: errorDialog
|
||||||
Label {
|
Label {
|
||||||
text: Engine.statusMessage
|
text: Engine.statusMessage
|
||||||
}
|
}
|
||||||
@@ -437,8 +453,12 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
FileDialog {
|
FileDialog {
|
||||||
id: exportListDialog
|
id: exportListDialog
|
||||||
onAccepted: Engine.exportAddonList(selectedFile)
|
property string targetPath
|
||||||
|
onAccepted: Engine.exportAddonList(selectedFile, targetPath)
|
||||||
fileMode: FileDialog.SaveFile
|
fileMode: FileDialog.SaveFile
|
||||||
defaultSuffix: "txt"
|
defaultSuffix: "txt"
|
||||||
}
|
}
|
||||||
|
LogWindow {
|
||||||
|
id: logWindow
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<file>Options.qml</file>
|
<file>Options.qml</file>
|
||||||
<file>AddonUpdateButton.qml</file>
|
<file>AddonUpdateButton.qml</file>
|
||||||
<file>AddonsPanel.qml</file>
|
<file>AddonsPanel.qml</file>
|
||||||
|
<file>LogWindow.qml</file>
|
||||||
<file>github_clone_url.jpg</file>
|
<file>github_clone_url.jpg</file>
|
||||||
<file>gitlab_clone_url.jpg</file>
|
<file>gitlab_clone_url.jpg</file>
|
||||||
<file>icons/breeze/svg/delete.svg</file>
|
<file>icons/breeze/svg/delete.svg</file>
|
||||||
|
|||||||
Reference in New Issue
Block a user