-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.cpp
56 lines (43 loc) · 1.82 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
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QStandardPaths>
#include <QtQml>
class CachingFactory : public QQmlNetworkAccessManagerFactory
{
public:
virtual QNetworkAccessManager *create(QObject *parent);
};
QNetworkAccessManager *CachingFactory::create(QObject *parent)
{
QNetworkAccessManager *manager = new QNetworkAccessManager(parent);
QNetworkDiskCache *diskCache = new QNetworkDiskCache(parent);
const QDir writeDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
diskCache->setCacheDirectory(writeDir.absolutePath() + "/cache");
manager->setCache(diskCache);
return manager;
}
void noMessageOutput(QtMsgType, const QMessageLogContext &, const QString &) {}
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setApplicationName("Gitteraqt");
QCoreApplication::setApplicationVersion("1.0");
QCoreApplication::setOrganizationDomain("eklavya.com");
QCoreApplication::setOrganizationName("Eklavya");
const QDir writeDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
if (!writeDir.mkpath("."))
qFatal("Failed to create writable directory at %s", qPrintable(writeDir.absolutePath()));
const QString writePath = writeDir.absolutePath();
QSettings::setPath(QSettings::defaultFormat(), QSettings::UserScope, writePath);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.setNetworkAccessManagerFactory(new CachingFactory);
#ifndef QT_DEBUG
qInstallMessageHandler(noMessageOutput);
#endif
engine.rootContext()->setContextProperty("appdir", writeDir.absolutePath());
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}