-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
78 lines (61 loc) · 2.45 KB
/
main.cpp
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
#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QFileInfo>
#include <QMessageBox>
#include "mainwindow.h"
#include "r3ctlsettings.h"
namespace {
bool loadTheme(R3CtlSettings &settings);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
qSetMessagePattern(QStringLiteral("%{time dd.MM.yyyy HH:mm:ss.zzz} "
"["
"%{if-debug}D%{endif}"
"%{if-info}I%{endif}"
"%{if-warning}W%{endif}"
"%{if-critical}C%{endif}"
"%{if-fatal}F%{endif}"
"] "
"%{function}(): "
"%{message}"));
QCoreApplication::setOrganizationDomain(QStringLiteral("brunner.ninja"));
QCoreApplication::setOrganizationName(QStringLiteral("db-software"));
QCoreApplication::setApplicationName(QStringLiteral("r3ctl"));
QCoreApplication::setApplicationVersion(QStringLiteral("1.0"));
R3CtlSettings settings{&app};
loadTheme(settings);
MainWindow mainWindow{settings};
mainWindow.show();
return app.exec();
}
namespace {
bool loadTheme(R3CtlSettings &settings)
{
qDebug() << "Loading theme...";
if(settings.theme().isEmpty())
return true;
auto themePath = QDir{QDir{QCoreApplication::applicationDirPath()}.absoluteFilePath(QStringLiteral("themes"))}.absoluteFilePath(settings.theme());
QFile file{themePath + ".qss"};
if(!file.exists())
{
QMessageBox::warning(nullptr, QCoreApplication::translate("main", "Could not load theme!"),
QCoreApplication::translate("main", "Could not load theme!") + "\n\n" +
QCoreApplication::translate("main", "Theme file does not exist!"));
return false;
}
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox::warning(nullptr, QCoreApplication::translate("main", "Could not load theme!"),
QCoreApplication::translate("main", "Could not load theme!") + "\n\n" +
file.errorString());
return false;
}
QTextStream textStream(&file);
qApp->setStyleSheet(textStream.readAll().replace(QStringLiteral("@THEME_RESOURCES@"), themePath));
return true;
}
}