Changeset View
Changeset View
Standalone View
Standalone View
src/app/uicontroller.cpp
Show All 23 Lines | |||||
24 | 24 | | |||
25 | #include "core.h" | 25 | #include "core.h" | ||
26 | 26 | | |||
27 | #include <QStandardPaths> | 27 | #include <QStandardPaths> | ||
28 | 28 | | |||
29 | #include <QQmlContext> | 29 | #include <QQmlContext> | ||
30 | #include <QQmlApplicationEngine> | 30 | #include <QQmlApplicationEngine> | ||
31 | 31 | | |||
32 | #include <QGuiApplication> | ||||
33 | #include <QQmlApplicationEngine> | ||||
34 | #include <QDebug> | ||||
35 | #include <QFile> | ||||
36 | #include <QDir> | ||||
37 | #include <QStandardPaths> | ||||
38 | #include <QQmlContext> | ||||
39 | #include <QJsonArray> | ||||
40 | #include <QJsonObject> | ||||
41 | #include <QJsonDocument> | ||||
42 | | ||||
32 | #ifndef Q_OS_ANDROID | 43 | #ifndef Q_OS_ANDROID | ||
33 | #include <KLocalizedContext> | 44 | #include <KLocalizedContext> | ||
34 | #endif | 45 | #endif | ||
35 | 46 | | |||
36 | namespace Minuet | 47 | namespace Minuet | ||
37 | { | 48 | { | ||
38 | 49 | | |||
39 | UiController::UiController(QObject *parent) | 50 | UiController::UiController(QObject *parent) | ||
40 | : IUiController(parent) | 51 | : IUiController(parent) | ||
41 | { | 52 | { | ||
42 | } | 53 | } | ||
43 | 54 | | |||
44 | UiController::~UiController() | 55 | UiController::~UiController() | ||
45 | { | 56 | { | ||
46 | } | 57 | } | ||
47 | 58 | | |||
59 | bool UiController::initialize2(QQmlApplicationEngine *engine) | ||||
60 | { | ||||
61 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | ||||
62 | | ||||
63 | QDir dir(qApp->applicationDirPath()); | ||||
64 | dir.cd("plugins"); | ||||
65 | qDebug()<<qApp->applicationDirPath(); | ||||
66 | QString contents; | ||||
67 | QJsonArray mergedArray; | ||||
68 | foreach(const QString &fileName, dir.entryList(QStringList() << "*.json")) { | ||||
69 | QFile dfile(dir.absoluteFilePath(fileName)); | ||||
70 | dfile.open(QIODevice::ReadOnly); | ||||
71 | QJsonObject jsonObject = QJsonDocument::fromJson(dfile.readAll()).object(); | ||||
72 | QDir pluginDir(dir); | ||||
73 | pluginDir.cd(fileName.split('.').first()); | ||||
74 | jsonObject["pluginName"] = pluginDir.absolutePath(); | ||||
75 | mergedArray.append(jsonObject); | ||||
76 | dfile.close(); | ||||
77 | } | ||||
78 | engine->rootContext()->setContextProperty("contents", mergedArray); | ||||
79 | } | ||||
80 | | ||||
48 | bool UiController::initialize(Core *core) | 81 | bool UiController::initialize(Core *core) | ||
49 | { | 82 | { | ||
50 | m_errorString.clear(); | 83 | m_errorString.clear(); | ||
51 | QQmlApplicationEngine *engine = new QQmlApplicationEngine(this); | 84 | QQmlApplicationEngine *engine = new QQmlApplicationEngine(this); | ||
52 | QQmlContext *rootContext = engine->rootContext(); | 85 | QQmlContext *rootContext = engine->rootContext(); | ||
53 | rootContext->setContextProperty(QStringLiteral("core"), core); | 86 | rootContext->setContextProperty(QStringLiteral("core"), core); | ||
54 | #ifndef Q_OS_ANDROID | 87 | #ifndef Q_OS_ANDROID | ||
55 | rootContext->setContextObject(new KLocalizedContext(engine)); | 88 | rootContext->setContextObject(new KLocalizedContext(engine)); | ||
56 | #else | 89 | #else | ||
57 | rootContext->setContextObject(new DummyAndroidLocalizer(engine)); | 90 | rootContext->setContextObject(new DummyAndroidLocalizer(engine)); | ||
58 | #endif | 91 | #endif | ||
92 | | ||||
93 | initialize2(engine); | ||||
59 | engine->load(QUrl("qrc:/Main.qml")); | 94 | engine->load(QUrl("qrc:/Main.qml")); | ||
60 | 95 | | |||
61 | return true; | 96 | return true; | ||
62 | } | 97 | } | ||
63 | 98 | | |||
64 | QString UiController::errorString() const | 99 | QString UiController::errorString() const | ||
65 | { | 100 | { | ||
66 | return m_errorString; | 101 | return m_errorString; | ||
67 | } | 102 | } | ||
68 | 103 | | |||
69 | } | 104 | } | ||
70 | 105 | |