-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.cpp
More file actions
121 lines (108 loc) · 3.28 KB
/
main.cpp
File metadata and controls
121 lines (108 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* Copyright (C) 2021 Jo2003 (olenka.joerg@gmail.com)
* This file is part of cd2netmd_gui
*
* cd2netmd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* cd2netmd is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*/
#include "mainwindow.h"
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QDateTime>
#include <QtGlobal>
#ifdef Q_OS_MAC
#include "cdrutil.h"
#endif // Q_OS_MAC
#include "defines.h"
const QString g_logFileName = QString("%1/cd2netmd_gui.log").arg(QDir::tempPath());
static QFile s_logFile(g_logFileName);
c2n::LogLevel g_LogFilter = c2n::LogLevel::INFO;
bool log(QtMsgType type)
{
bool ret = false;
switch(type)
{
case QtDebugMsg:
ret = (g_LogFilter == c2n::LogLevel::DEBUG);
break;
case QtInfoMsg:
ret = (g_LogFilter <= c2n::LogLevel::INFO);
break;
case QtWarningMsg:
ret = (g_LogFilter <= c2n::LogLevel::WARN);
break;
case QtCriticalMsg:
ret = (g_LogFilter <= c2n::LogLevel::CRITICAL);
break;
case QtFatalMsg:
ret = (g_LogFilter <= c2n::LogLevel::FATAL);
break;
}
return ret;
}
void logger(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
if (!log(type))
return;
QString t = QDateTime::currentDateTime().toLocalTime().toString("yyyy-MM-dd hh:mm:ss.zzz");
QString message;
QTextStream mss(&message);
QTextStream oss(&s_logFile);
if (context.file && context.function)
{
mss << context.file << ":" << context.line << "|" << context.function << "|";
}
mss << msg;
message.replace("\n\n", "\n");
message.replace("\r\n", "\n");
message = message.trimmed();
switch (type)
{
case QtDebugMsg:
oss << t << "|DEBUG|" << message << "\n";
break;
case QtInfoMsg:
oss << t << "|INFO|" << message << "\n";
break;
case QtWarningMsg:
oss << t << "|WARNING|" << message << "\n";
break;
case QtCriticalMsg:
oss << t << "|CRITICAL|" << message << "\n";
break;
case QtFatalMsg:
oss << t << "|FATAL|" << message << "\n";
abort();
}
}
int main(int argc, char *argv[])
{
int exitCode = 0;
// dark mode support
// qputenv("QT_QPA_PLATFORM", "windows:darkmode=2");
qRegisterMetaType<c2n::AudioTracks>("c2n::AudioTracks");
#ifdef Q_OS_MAC
qRegisterMetaType<CDRUtil::CDTextData>("CDRUtil::CDTextData");
#endif // Q_OS_MAC
s_logFile.open(QIODevice::Text | QIODevice::Truncate | QIODevice::WriteOnly);
qInstallMessageHandler(logger);
QApplication a(argc, argv);
QCoreApplication::setOrganizationName("Jo2003");
QCoreApplication::setOrganizationDomain("coujo.de");
QCoreApplication::setApplicationName(c2n::PROGRAM_NAME);
MainWindow w;
w.show();
exitCode = a.exec();
s_logFile.close();
return exitCode;
}