From 229732762c690dbba9145d56f68ba8a9e6c9bf3a Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Fri, 11 Jun 2021 11:49:09 +0200 Subject: [PATCH] added url parser and did some refactoring --- blueROCK.pro | 6 ++--- headers/appsettings.h | 6 ----- headers/{serverconn.h => bluerockbackend.h} | 6 +++-- resources/qml/Components/PullRefresher.qml | 9 +++---- .../qml/Components/SpeedFlowChartLocker.qml | 24 ++++------------- resources/qml/Pages/WidgetPage.qml | 8 +++++- resources/qml/main.qml | 11 +++++--- sources/appsettings.cpp | 6 ++--- .../{serverconn.cpp => bluerockbackend.cpp} | 26 ++++++++++++++++--- sources/main.cpp | 7 ++--- 10 files changed, 58 insertions(+), 51 deletions(-) rename headers/{serverconn.h => bluerockbackend.h} (88%) rename sources/{serverconn.cpp => bluerockbackend.cpp} (85%) diff --git a/blueROCK.pro b/blueROCK.pro index 8319b36..5708afc 100644 --- a/blueROCK.pro +++ b/blueROCK.pro @@ -17,8 +17,8 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ sources/appsettings.cpp \ - sources/main.cpp \ - sources/serverconn.cpp + sources/bluerockbackend.cpp \ + sources/main.cpp RESOURCES += resources/qml/qml.qrc \ resources/shared/shared.qrc \ @@ -42,7 +42,7 @@ DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\" HEADERS += \ headers/appsettings.h \ - headers/serverconn.h + headers/bluerockbackend.h DISTFILES += \ CHANGELOG.md \ diff --git a/headers/appsettings.h b/headers/appsettings.h index 9b92aba..13b502f 100644 --- a/headers/appsettings.h +++ b/headers/appsettings.h @@ -21,12 +21,6 @@ private: QSettings *settingsManager; // QSettings object which cares about our settings.ini file - QSettings *themeSettingsManager; - // QSettings object which cares about the themes - -signals: - void themeChanged(); - public slots: Q_INVOKABLE QString read(const QString &key); // function to read values from the settings file diff --git a/headers/serverconn.h b/headers/bluerockbackend.h similarity index 88% rename from headers/serverconn.h rename to headers/bluerockbackend.h index 2630af3..091b9be 100644 --- a/headers/serverconn.h +++ b/headers/bluerockbackend.h @@ -25,11 +25,11 @@ #include #include -class ServerConn : public QObject +class BlueRockBackend : public QObject { Q_OBJECT public: - explicit ServerConn(QObject *parent = nullptr); + explicit BlueRockBackend(QObject *parent = nullptr); private: QVariantMap senddata(QUrl serviceUrl, QUrlQuery pdata = QUrlQuery()); @@ -40,6 +40,8 @@ public slots: QVariant getWidgetData(QVariantMap params); + QVariantMap getParamsFromUrl(QString url); + }; #endif // SERVERCONN_H diff --git a/resources/qml/Components/PullRefresher.qml b/resources/qml/Components/PullRefresher.qml index 9004143..781106a 100644 --- a/resources/qml/Components/PullRefresher.qml +++ b/resources/qml/Components/PullRefresher.qml @@ -18,6 +18,7 @@ import QtQuick 2.9 import QtQuick.Controls 2.4 +import QtQuick.Controls.Material 2.12 import QtGraphicalEffects 1.0 Item { @@ -37,10 +38,6 @@ Item { property double dragRefreshPositionMultiplier: 0.6 // position of the item when starting to refresh - property color backgroundColor: "white" // color for the pre-defined background - property color pullIndicatorColor: "black" // color for the pre-defined pull indicator - //property color busyIndicatorColor: "pink" // color for the pre-defined busy indicator - readonly property double dragProgress: Math.min( userPosition / dragOutPosition, 1) property Component background: Item { @@ -61,7 +58,7 @@ Item { anchors.fill: parent radius: width * 0.5 - color: control.backgroundColor + color: Material.dialogColor } } property Component busyIndicator: BusyIndicator { running: true } @@ -107,7 +104,7 @@ Item { ctx.reset() ctx.lineWidth = lineWidth; - ctx.strokeStyle = control.pullIndicatorColor; + ctx.strokeStyle = control.Material.foreground; // middle line ctx.moveTo(width/2, topMargin); diff --git a/resources/qml/Components/SpeedFlowChartLocker.qml b/resources/qml/Components/SpeedFlowChartLocker.qml index 68d2984..21afbdf 100644 --- a/resources/qml/Components/SpeedFlowChartLocker.qml +++ b/resources/qml/Components/SpeedFlowChartLocker.qml @@ -1,5 +1,6 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 +import QtQuick.Controls.Material 2.12 import QtQuick.Layouts 1.15 import QtPurchasing 1.12 @@ -9,7 +10,7 @@ Rectangle { anchors.fill: parent anchors.margins: -20 - color: "white" + color: Material.background Connections { target: speedFlowChartProduct @@ -47,30 +48,15 @@ Rectangle { //spacing: parent.height * 0.05 - Image { - id: name - - Layout.alignment: Layout.Center - Layout.preferredHeight: height - Layout.preferredWidth: width - - width: lockedLayout.height * 0.05 - height: width - - mipmap: true - - source: "qrc:/icons/lock.png" - } - - Text { + Label { Layout.fillWidth: true - height: parent.height * 0.05 + height: parent.height * 0.015 text: qsTr("This is a premium feature.") font.bold: true - font.pixelSize: parent.height * 0.05 + font.pixelSize: height fontSizeMode: Text.Fit minimumPixelSize: 1 diff --git a/resources/qml/Pages/WidgetPage.qml b/resources/qml/Pages/WidgetPage.qml index fd28cb8..651dadd 100644 --- a/resources/qml/Pages/WidgetPage.qml +++ b/resources/qml/Pages/WidgetPage.qml @@ -88,7 +88,13 @@ Page { root.ready = false } } - else if(ret["status"] === 404 && [WidgetPage.WidgetType.Registration, WidgetPage.WidgetType.Startlist, WidgetPage.WidgetType.Result].includes(root.widgetType) && root.params["route"] !== "") { + else if(ret["status"] === 404 && + [ + WidgetPage.WidgetType.Registration, + WidgetPage.WidgetType.Startlist, + WidgetPage.WidgetType.Result + ].includes(root.widgetType) && + root.params["route"] !== "") { // if we get a 404 and have startlist, results or registration, the route was not found -> remove round and try again root.params["route"] = "" loadData(root.params) diff --git a/resources/qml/main.qml b/resources/qml/main.qml index dddcf92..a9b8ee1 100644 --- a/resources/qml/main.qml +++ b/resources/qml/main.qml @@ -23,7 +23,7 @@ import QtQuick.Layouts 1.3 import QtQuick.Controls.Material 2.12 import QtPurchasing 1.12 -import com.itsblue.digitalRockRanking 1.0 +import de.itsblue.blueROCK 1.0 import "./Pages" import "./Components" @@ -142,8 +142,13 @@ Window { onActivated: app.goBack() } - ServerConn { + BlueRockBackend { id: serverConn + + Component.onCompleted: { + var params = serverConn.getParamsFromUrl("https://www.digitalrock.de/egroupware/ranking/sitemgr/digitalrock/eliste.html#!comp=11471&cat=GER_F_A") + app.openWidget(params) + } } AppSettings { @@ -484,7 +489,7 @@ Window { Product { id: speedFlowChartProduct //identifier: "speed_flowchart" - identifier: "android.test.purchased" + identifier: QT_DEBUG ? "android.test.purchased":"speed_flowchart" //identifier: "android.test.canceled" //identifier: "android.test.refunded" diff --git a/sources/appsettings.cpp b/sources/appsettings.cpp index 9d98c94..b0f377c 100644 --- a/sources/appsettings.cpp +++ b/sources/appsettings.cpp @@ -15,8 +15,6 @@ AppSettings::AppSettings(QObject* parent) // set the values to their defaults if they haven't been created yet - // create or open the settings.ini file - this->themeSettingsManager = new QSettings(":/themes/" + this->read("theme") + ".ini", QSettings::IniFormat); } QString AppSettings::read(const QString &key) @@ -26,7 +24,7 @@ QString AppSettings::read(const QString &key) // open the value-group this->settingsManager->beginGroup("AppSettings"); // read the value - QString value = this->settingsManager->value(key , false).toString(); + QString value = this->settingsManager->value(key, false).toString(); // close the value-group this->settingsManager->endGroup(); // return the value @@ -51,7 +49,7 @@ void AppSettings::setDefault(const QString &key, const QVariant &defaultValue) // read the current value QString value = this->read(key); - if(value == "false"){ + if(value == "false") { // if it is nor defined yet, the read function will return "false" (as a string) // -> if that is the case -> create the key with the default value this->write(key, defaultValue); diff --git a/sources/serverconn.cpp b/sources/bluerockbackend.cpp similarity index 85% rename from sources/serverconn.cpp rename to sources/bluerockbackend.cpp index 2279dec..b4f9ef8 100644 --- a/sources/serverconn.cpp +++ b/sources/bluerockbackend.cpp @@ -16,13 +16,13 @@ along with this program. If not, see . */ -#include "headers/serverconn.h" +#include "headers/bluerockbackend.h" -ServerConn::ServerConn(QObject *parent) : QObject(parent) +BlueRockBackend::BlueRockBackend(QObject *parent) : QObject(parent) { } -QVariant ServerConn::getWidgetData(QVariantMap params) { +QVariant BlueRockBackend::getWidgetData(QVariantMap params) { QString requestUrl; if(params["nation"].toString() == "ICC") { requestUrl = "https://www.digitalrock.de/egroupware/ranking/json.php?"; @@ -61,11 +61,29 @@ QVariant ServerConn::getWidgetData(QVariantMap params) { return data; } + +QVariantMap BlueRockBackend::getParamsFromUrl(QString stringUrl) { + stringUrl = stringUrl.replace("#!", "?"); + QUrl url(stringUrl); + QUrlQuery query(url.query()); + + QVariantMap params; + + for(QPair pair : query.queryItems()) { + if(params.contains(pair.first)) + params[pair.first] = pair.second; + else + params.insert(pair.first, pair.second); + } + + return params; +} + // ------------------------ // --- Helper functions --- // ------------------------ -QVariantMap ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata) +QVariantMap BlueRockBackend::senddata(QUrl serviceUrl, QUrlQuery pdata) { // create network manager QNetworkAccessManager * networkManager = new QNetworkAccessManager(); diff --git a/sources/main.cpp b/sources/main.cpp index e099c5c..c86a4b9 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -22,8 +22,9 @@ #include #include #include +#include -#include "headers/serverconn.h" +#include "headers/bluerockbackend.h" #include "headers/appsettings.h" int main(int argc, char *argv[]) @@ -37,8 +38,8 @@ int main(int argc, char *argv[]) QIcon::setFallbackSearchPaths(QIcon::fallbackSearchPaths() << ":/resources/shared/icons"); QIcon::setThemeName("bluerock"); - qmlRegisterType("com.itsblue.digitalRockRanking", 1, 0, "ServerConn"); - qmlRegisterType("com.itsblue.digitalRockRanking", 1, 0, "AppSettings"); + qmlRegisterType("de.itsblue.blueROCK", 1, 0, "BlueRockBackend"); + qmlRegisterType("de.itsblue.blueROCK", 1, 0, "AppSettings"); QQmlApplicationEngine engine;