diff options
author | Marvin Borner | 2020-04-10 17:44:23 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-10 17:44:23 +0200 |
commit | 17927de45e769d4dbac5b1547464b2618150cfb4 (patch) | |
tree | 610a5e82ebecd8289343b6247f78f7d0378f9211 | |
parent | 71e4befa76e91721df2baeab99fff1b4987b0cdb (diff) |
Implemented login page
-rw-r--r-- | harbour-sailchess.pro | 3 | ||||
-rw-r--r-- | qml/Square.qml | 2 | ||||
-rw-r--r-- | qml/harbour-sailchess.qml | 9 | ||||
-rw-r--r-- | qml/pages/Board.qml | 24 | ||||
-rw-r--r-- | qml/pages/Login.qml | 45 | ||||
-rw-r--r-- | qml/resources/css/external.css | 3 | ||||
-rw-r--r-- | qml/resources/images/bb.svg (renamed from qml/images/bb.svg) | 0 | ||||
-rw-r--r-- | qml/resources/images/bk.svg (renamed from qml/images/bk.svg) | 0 | ||||
-rw-r--r-- | qml/resources/images/bn.svg (renamed from qml/images/bn.svg) | 0 | ||||
-rw-r--r-- | qml/resources/images/bp.svg (renamed from qml/images/bp.svg) | 0 | ||||
-rw-r--r-- | qml/resources/images/bq.svg (renamed from qml/images/bq.svg) | 0 | ||||
-rw-r--r-- | qml/resources/images/br.svg (renamed from qml/images/br.svg) | 0 | ||||
-rw-r--r-- | qml/resources/images/wb.svg (renamed from qml/images/wb.svg) | 0 | ||||
-rw-r--r-- | qml/resources/images/wk.svg (renamed from qml/images/wk.svg) | 0 | ||||
-rw-r--r-- | qml/resources/images/wn.svg (renamed from qml/images/wn.svg) | 0 | ||||
-rw-r--r-- | qml/resources/images/wp.svg (renamed from qml/images/wp.svg) | 0 | ||||
-rw-r--r-- | qml/resources/images/wq.svg (renamed from qml/images/wq.svg) | 0 | ||||
-rw-r--r-- | qml/resources/images/wr.svg (renamed from qml/images/wr.svg) | 0 | ||||
-rw-r--r-- | qml/resources/resources.qrc | 17 | ||||
-rw-r--r-- | rpm/harbour-sailchess.spec | 1 | ||||
-rw-r--r-- | rpm/harbour-sailchess.yaml | 3 | ||||
-rw-r--r-- | translations/harbour-sailchess-de.ts | 4 | ||||
-rw-r--r-- | translations/harbour-sailchess.ts | 4 |
23 files changed, 112 insertions, 3 deletions
diff --git a/harbour-sailchess.pro b/harbour-sailchess.pro index 2e954fc..bcd00e7 100644 --- a/harbour-sailchess.pro +++ b/harbour-sailchess.pro @@ -21,6 +21,7 @@ DISTFILES += qml/harbour-sailchess.qml \ qml/pages/Board.qml \ qml/Square.qml \ qml/Functions.qml \ + qml/pages/Login.qml \ rpm/harbour-sailchess.changes.in \ rpm/harbour-sailchess.changes.run.in \ rpm/harbour-sailchess.spec \ @@ -39,3 +40,5 @@ CONFIG += sailfishapp_i18n # following TRANSLATIONS line. And also do not forget to # modify the localized app name in the the .desktop file. TRANSLATIONS += translations/harbour-sailchess-de.ts + +RESOURCES += qml/resources/resources.qrc diff --git a/qml/Square.qml b/qml/Square.qml index b1e3e0c..2169290 100644 --- a/qml/Square.qml +++ b/qml/Square.qml @@ -3,7 +3,7 @@ import QtQuick 2.0 Rectangle { property int i: 0 property string piece: "" - property string image: piece !== "" ? "images/" + piece + ".svg" : "" + property string image: piece !== "" ? "qrc:///images/" + piece + ".svg" : "" width: page.width / 8 height: this.width diff --git a/qml/harbour-sailchess.qml b/qml/harbour-sailchess.qml index ddc0046..6142693 100644 --- a/qml/harbour-sailchess.qml +++ b/qml/harbour-sailchess.qml @@ -1,10 +1,17 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 +import org.nemomobile.configuration 1.0 import "pages" ApplicationWindow { - initialPage: Component { Board { } } + initialPage: Qt.resolvedUrl(access_token.value === "" ? "pages/Login.qml" : "pages/Board.qml") cover: Qt.resolvedUrl("cover/CoverPage.qml") allowedOrientations: Orientation.Portrait + + ConfigurationValue { + id: access_token + key: "/com/sailchess/access_token" + defaultValue: "" + } } diff --git a/qml/pages/Board.qml b/qml/pages/Board.qml index 4bb5d9c..35e2e5e 100644 --- a/qml/pages/Board.qml +++ b/qml/pages/Board.qml @@ -1,5 +1,6 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 +import org.nemomobile.configuration 1.0 import ".." Page { @@ -14,6 +15,17 @@ Page { anchors.fill: parent contentHeight: column.height + PullDownMenu { + MenuItem { + text: qsTr("Login") + onClicked: { + access_token.value = ""; + refresh_token.value = ""; + pageStack.push(Qt.resolvedUrl("Login.qml")) + } + } + } + Column { id: column @@ -44,4 +56,16 @@ Page { } } } + + ConfigurationValue { + id: access_token + key: "/com/sailchess/access_token" + defaultValue: "" + } + + ConfigurationValue { + id: refresh_token + key: "/com/sailchess/refresh_token" + defaultValue: "" + } } diff --git a/qml/pages/Login.qml b/qml/pages/Login.qml new file mode 100644 index 0000000..2f57e39 --- /dev/null +++ b/qml/pages/Login.qml @@ -0,0 +1,45 @@ +import QtQuick 2.2 +import Sailfish.Silica 1.0 +import QtWebKit 3.0 +import org.nemomobile.configuration 1.0 + +Page { + SilicaWebView { + property real device_ratio: Math.round(1.5 * Theme.pixelRatio * 10) / 10.0 + + id: login + anchors.fill: parent + experimental.preferences.javascriptEnabled: false + experimental.userStyleSheets: [Qt.resolvedUrl("qrc:///css/external.css")] + experimental.customLayoutWidth: parent.width / device_ratio + url: "https://marvinborner.de/lichess/" + + onNavigationRequested: { + if (request.url.toString().lastIndexOf("https://marvinborner.de/lichess/callback", 0) === 0) { + request.action = WebView.IgnoreRequest; + + var xhr = new XMLHttpRequest(); + xhr.open("GET", request.url, false); + xhr.send(); + if (xhr.status === 200) { + const data = JSON.parse(xhr.responseText); + access_token.value = data["access_token"]; + refresh_token.value = data["refresh_token"]; + pageStack.push(Qt.resolvedUrl("Board.qml")) + } + } + } + + ConfigurationValue { + id: access_token + key: "/com/sailchess/access_token" + defaultValue: "" + } + + ConfigurationValue { + id: refresh_token + key: "/com/sailchess/refresh_token" + defaultValue: "" + } + } +} diff --git a/qml/resources/css/external.css b/qml/resources/css/external.css new file mode 100644 index 0000000..b1281e1 --- /dev/null +++ b/qml/resources/css/external.css @@ -0,0 +1,3 @@ +nav, .alternative, header { + display: none; +} diff --git a/qml/images/bb.svg b/qml/resources/images/bb.svg index 4ce248f..4ce248f 100644 --- a/qml/images/bb.svg +++ b/qml/resources/images/bb.svg diff --git a/qml/images/bk.svg b/qml/resources/images/bk.svg index d90dc73..d90dc73 100644 --- a/qml/images/bk.svg +++ b/qml/resources/images/bk.svg diff --git a/qml/images/bn.svg b/qml/resources/images/bn.svg index 02b0894..02b0894 100644 --- a/qml/images/bn.svg +++ b/qml/resources/images/bn.svg diff --git a/qml/images/bp.svg b/qml/resources/images/bp.svg index 072f2fe..072f2fe 100644 --- a/qml/images/bp.svg +++ b/qml/resources/images/bp.svg diff --git a/qml/images/bq.svg b/qml/resources/images/bq.svg index 6f1e4a5..6f1e4a5 100644 --- a/qml/images/bq.svg +++ b/qml/resources/images/bq.svg diff --git a/qml/images/br.svg b/qml/resources/images/br.svg index 337af8f..337af8f 100644 --- a/qml/images/br.svg +++ b/qml/resources/images/br.svg diff --git a/qml/images/wb.svg b/qml/resources/images/wb.svg index 0f28d08..0f28d08 100644 --- a/qml/images/wb.svg +++ b/qml/resources/images/wb.svg diff --git a/qml/images/wk.svg b/qml/resources/images/wk.svg index 8b2d7b7..8b2d7b7 100644 --- a/qml/images/wk.svg +++ b/qml/resources/images/wk.svg diff --git a/qml/images/wn.svg b/qml/resources/images/wn.svg index 644d6e8..644d6e8 100644 --- a/qml/images/wn.svg +++ b/qml/resources/images/wn.svg diff --git a/qml/images/wp.svg b/qml/resources/images/wp.svg index 1142516..1142516 100644 --- a/qml/images/wp.svg +++ b/qml/resources/images/wp.svg diff --git a/qml/images/wq.svg b/qml/resources/images/wq.svg index 97043c5..97043c5 100644 --- a/qml/images/wq.svg +++ b/qml/resources/images/wq.svg diff --git a/qml/images/wr.svg b/qml/resources/images/wr.svg index 8d2d932..8d2d932 100644 --- a/qml/images/wr.svg +++ b/qml/resources/images/wr.svg diff --git a/qml/resources/resources.qrc b/qml/resources/resources.qrc new file mode 100644 index 0000000..629a705 --- /dev/null +++ b/qml/resources/resources.qrc @@ -0,0 +1,17 @@ +<RCC> + <qresource prefix="/"> + <file>images/bb.svg</file> + <file>images/bk.svg</file> + <file>images/bn.svg</file> + <file>images/bp.svg</file> + <file>images/bq.svg</file> + <file>images/br.svg</file> + <file>images/wb.svg</file> + <file>images/wk.svg</file> + <file>images/wn.svg</file> + <file>images/wp.svg</file> + <file>images/wq.svg</file> + <file>images/wr.svg</file> + <file>css/external.css</file> + </qresource> +</RCC> diff --git a/rpm/harbour-sailchess.spec b/rpm/harbour-sailchess.spec index 86a2217..0d6c2af 100644 --- a/rpm/harbour-sailchess.spec +++ b/rpm/harbour-sailchess.spec @@ -17,6 +17,7 @@ URL: http://example.org/ Source0: %{name}-%{version}.tar.bz2 Source100: harbour-sailchess.yaml Requires: sailfishsilica-qt5 >= 0.10.9 +Requires: nemo-qml-plugin-configuration-qt5 BuildRequires: pkgconfig(sailfishapp) >= 1.0.2 BuildRequires: pkgconfig(Qt5Core) BuildRequires: pkgconfig(Qt5Qml) diff --git a/rpm/harbour-sailchess.yaml b/rpm/harbour-sailchess.yaml index 7c36f06..65c623e 100644 --- a/rpm/harbour-sailchess.yaml +++ b/rpm/harbour-sailchess.yaml @@ -30,7 +30,8 @@ PkgConfigBR: # Runtime dependencies which are not automatically detected Requires: - - sailfishsilica-qt5 >= 0.10.9 + - sailfishsilica-qt5 >= 0.10.9 + - nemo-qml-plugin-configuration-qt5 # All installed files Files: diff --git a/translations/harbour-sailchess-de.ts b/translations/harbour-sailchess-de.ts index df2aa7b..5f446ba 100644 --- a/translations/harbour-sailchess-de.ts +++ b/translations/harbour-sailchess-de.ts @@ -7,6 +7,10 @@ <source>Chess</source> <translation type="unfinished"></translation> </message> + <message> + <source>Login</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>CoverPage</name> diff --git a/translations/harbour-sailchess.ts b/translations/harbour-sailchess.ts index dd3cf7f..f50285a 100644 --- a/translations/harbour-sailchess.ts +++ b/translations/harbour-sailchess.ts @@ -7,6 +7,10 @@ <source>Chess</source> <translation type="unfinished"></translation> </message> + <message> + <source>Login</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>CoverPage</name> |