added url parser and did some refactoring
This commit is contained in:
parent
6b87344bf1
commit
229732762c
10 changed files with 58 additions and 51 deletions
|
@ -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 \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -25,11 +25,11 @@
|
|||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
|
||||
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
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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<QString, QString> 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();
|
|
@ -22,8 +22,9 @@
|
|||
#include <QQmlApplicationEngine>
|
||||
#include <QIcon>
|
||||
#include <QStyleFactory>
|
||||
#include <QUrl>
|
||||
|
||||
#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<ServerConn>("com.itsblue.digitalRockRanking", 1, 0, "ServerConn");
|
||||
qmlRegisterType<AppSettings>("com.itsblue.digitalRockRanking", 1, 0, "AppSettings");
|
||||
qmlRegisterType<BlueRockBackend>("de.itsblue.blueROCK", 1, 0, "BlueRockBackend");
|
||||
qmlRegisterType<AppSettings>("de.itsblue.blueROCK", 1, 0, "AppSettings");
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
|
||||
|
|
Loading…
Reference in a new issue