From fb89df3ee609e9f3e63e0679b3635516603092b5 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Wed, 5 Aug 2020 19:01:12 +0200 Subject: [feat] load provider json in qml --- gui/gui.qrc | 8 +++++--- gui/main.cpp | 16 +++++++++++----- gui/providers/providers.json | 4 ++++ gui/qml/main.qml | 3 +++ 4 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 gui/providers/providers.json diff --git a/gui/gui.qrc b/gui/gui.qrc index 6bc3d8d..112a1ce 100644 --- a/gui/gui.qrc +++ b/gui/gui.qrc @@ -1,11 +1,12 @@ + qml/main.qml qml/AboutDialog.qml qml/DonateDialog.qml qml/LoginDialog.qml qml/LoginOKDialog.qml - + assets/icon/png/black/vpn_off.png assets/icon/png/black/vpn_on.png assets/icon/png/black/vpn_wait_0.png @@ -19,7 +20,8 @@ assets/icon/png/white/vpn_wait_1.png assets/icon/png/white/vpn_wait_2.png assets/icon/png/white/vpn_wait_3.png - - + providers/providers.json + + diff --git a/gui/main.cpp b/gui/main.cpp index e3b8530..8c7de4f 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -40,7 +40,6 @@ void signalHandler(int) { int main(int argc, char **argv) { signal(SIGINT, signalHandler); - bool debugQml = getEnv("DEBUG_QML_DATA") == "yes"; Backend backend; @@ -104,19 +103,27 @@ int main(int argc, char **argv) { QTranslator translator; translator.load(QLocale(), QLatin1String("main"), QLatin1String("_"), QLatin1String(":/i18n")); app.installTranslator(&translator); - + QQmlApplicationEngine engine; QQmlContext *ctx = engine.rootContext(); QJsonModel *model = new QJsonModel; + /* load providers json */ + QFile providerJson (":/providers.json"); + providerJson.open(QIODevice::ReadOnly | QIODevice::Text); + QJsonModel *providers = new QJsonModel; + providers->loadJson(providerJson.readAll()); + /* the backend handler has slots for calling back to Go when triggered by signals in Qml. */ ctx->setContextProperty("backend", &backend); - /* we pass the json model and set some useful flags */ + /* set the json model, load providers.json */ ctx->setContextProperty("jsonModel", model); - ctx->setContextProperty("debugQml", debugQml); + ctx->setContextProperty("providers", providers); + + /* set some useful flags */ ctx->setContextProperty("systrayVisible", !hideSystray); engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); @@ -133,7 +140,6 @@ int main(int argc, char **argv) { QGuiApplication::quit(); }); - /* register statusChanged callback with CGO */ const char *stCh = "OnStatusChanged"; GoString statusChangedEvt = {stCh, (long int)strlen(stCh)}; diff --git a/gui/providers/providers.json b/gui/providers/providers.json new file mode 100644 index 0000000..7ba0ef9 --- /dev/null +++ b/gui/providers/providers.json @@ -0,0 +1,4 @@ +[ + {"name": "provider1", "url": "https://example.com"}, + {"name": "provider2", "url": "https://foobar.com"} +] diff --git a/gui/qml/main.qml b/gui/qml/main.qml index 9f8bea3..da6b9ee 100644 --- a/gui/qml/main.qml +++ b/gui/qml/main.qml @@ -56,6 +56,9 @@ ApplicationWindow { Loaders as a placeholder for all the many dialogs, or to load a nice splash screen etc... */ + console.debug("Pre-seeded providers:"); + console.debug(providers.getJson()); + app.visible = true; show(); hide(); -- cgit v1.2.3