forked from AdunanzA/Tsunami
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
130 lines (105 loc) · 4.23 KB
/
main.cpp
File metadata and controls
130 lines (105 loc) · 4.23 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
122
123
124
125
126
127
128
129
#include "mainwindow.h"
#include <QApplication>
#include <QSplashScreen>
#include <QtDebug>
#include <QFile>
#include <QTextStream>
#include <QSettings>
#include <tsumanager.h>
#include <settingswindow.h>
#define SPLASH_DURATION 3000
//#define ORGANIZATION_NAME "Adunanza"
//#define ORGANIZATION_DOMAIN "adunanza.com"
//#define PROJECT_NAME "tsunami"
void showSplashScreen(const MainWindow & w);
void logMessageHandler(QtMsgType type, const QMessageLogContext & context, const QString & msg)
{
QString txt;
QString txtContext = QString("");
QString funcName = QString::fromUtf8(context.function);
QString message = QString(msg);
// strip out all chars after '(' like '(class QWidget *)' from function name
funcName = funcName.left(funcName.indexOf("("));
// strip out all chars like 'void __cdecl ' before function name
funcName = funcName.right(funcName.length() - funcName.lastIndexOf(" ") - 1);
// strip out double quotes around string message (if present)
if (message.left(1) == "\"") {
message = message.right(message.length() - 1);
if (message.right(1) == "\"") {
message = message.left(message.length() - 1);
}
}
txtContext = QString("%0::%1").arg(funcName).arg(context.line);
//if (QLibraryInfo::isDebugBuild()) {
// txtContext = QString("%0::%1::%2").arg(context.file).arg(context.function).arg(context.line);
//}
QString date = QDateTime::currentDateTime().toString(Qt::SystemLocaleDate);
QSettings settings(QSettings::IniFormat, QSettings::SystemScope, QStringLiteral(APP_ORGANIZATION_NAME), QStringLiteral(APP_PROJECT_NAME));
int debugLevel = settings.value("Debug/Level", 1).toInt();
switch (type) {
case QtDebugMsg:
if (debugLevel == 0)
txt = QString("%0 - %1 - %2 -> %3").arg(date).arg("Debug ").arg(txtContext).arg(message);
break;
case QtInfoMsg:
if (debugLevel >= 1)
txt = QString("%0 - %1 - %2 -> %3").arg(date).arg("Info ").arg(txtContext).arg(message);
break;
case QtWarningMsg:
if (debugLevel >= 2)
txt = QString("%0 - %1 - %2 -> %3").arg(date).arg("Warning ").arg(txtContext).arg(message);
break;
case QtCriticalMsg:
if (debugLevel >= 3)
txt = QString("%0 - %1 - %2 -> %3").arg(date).arg("Critical").arg(txtContext).arg(message);
break;
case QtFatalMsg:
if (debugLevel >= 4)
txt = QString("%0 - %1 - %2 -> %3").arg(date).arg("Fatal ").arg(txtContext).arg(message);
break;
}
if (!txt.isNull()) {
QFile outFile("Tsunami.log");
outFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
QTextStream ts(&outFile);
ts << txt << endl;
QTextStream out(stdout);
out << txt << endl;
}
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qRegisterMetaType<tsuEvents::tsuEvent>();
qRegisterMetaType<std::string>();
qRegisterMetaType<QVector<tsuEvents::tsuEvent>>();
qRegisterMetaType<QPair<int,int>>();
// https://stackoverflow.com/questions/4954140/how-to-redirect-qdebug-qwarning-qcritical-etc-output
qInstallMessageHandler(logMessageHandler);
MainWindow w;
QApplication::setOrganizationName(QStringLiteral(APP_ORGANIZATION_NAME));
QApplication::setOrganizationDomain(QStringLiteral(APP_ORGANIZATION_DOMAIN));
QApplication::setApplicationName(QStringLiteral(APP_PROJECT_NAME));
//if (!params.noSplash) {
showSplashScreen(w);
//} else {
//w.show();
//}
return a.exec();
}
void showSplashScreen(const MainWindow &w)
{
QPixmap splash_img(":/images/adunanza.jpg");
QPainter painter(&splash_img);
QString version = VERSION;
painter.setPen(QPen(Qt::white));
painter.setFont(QFont("Arial", 12, QFont::Black));
int paddingRight = 9;
int paddingBottom = 9;
painter.drawText(splash_img.width() - paddingRight - painter.fontMetrics().width(version), splash_img.height() - paddingBottom, version);
QSplashScreen *splash = new QSplashScreen(splash_img);
splash->show();
QTimer::singleShot(SPLASH_DURATION, splash, SLOT(close()));
QTimer::singleShot(SPLASH_DURATION, &w, SLOT(show()));
// qApp->processEvents();
}