-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9ad9c5
commit 47f8a30
Showing
12 changed files
with
625 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
load("@rules_qt//:qt.bzl", "qt_cc_binary", "qt_cc_library", "qt_resource") | ||
|
||
qt_resource( | ||
name = "qrc", | ||
files = [ | ||
"SpotifyOAuth.qmltypes", | ||
"qmldir", | ||
], | ||
) | ||
|
||
qt_resource( | ||
name = "qrc2", | ||
files = [ | ||
"main.qml" | ||
], | ||
) | ||
|
||
qt_cc_library( | ||
name = "spotify", | ||
srcs = [ | ||
"spotifyapi.cpp", | ||
"spotifymodel.cpp", | ||
], | ||
hdrs = [ | ||
"spotifyapi.h", | ||
"spotifymodel.h", | ||
], | ||
deps = [ | ||
"@rules_qt//:qt", | ||
], | ||
) | ||
|
||
qt_cc_binary( | ||
name = "SpotifyOAuth", | ||
srcs = [ | ||
"main.cpp", | ||
], | ||
deps = [ | ||
":qrc", | ||
":qrc2", | ||
":spotify", | ||
"@rules_qt//:qt", | ||
], | ||
data = [ | ||
":qrc", | ||
":qrc2", | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
cmake_minimum_required(VERSION 3.16.0) | ||
|
||
project(SpotifyOAuth VERSION 1.0.0 LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
set(CMAKE_AUTOUIC ON) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
find_package(Qt6 COMPONENTS Core Quick QuickControls2 Network NetworkAuth REQUIRED) | ||
|
||
qt_add_executable(SpotifyOAuth main.cpp) | ||
|
||
qt_add_qml_module(SpotifyOAuth | ||
VERSION 1.0.0 | ||
URI Spotify | ||
QML_FILES | ||
main.qml | ||
SOURCES | ||
spotifyapi.h spotifyapi.cpp | ||
spotifymodel.h spotifymodel.cpp | ||
) | ||
|
||
set_target_properties(SpotifyOAuth PROPERTIES | ||
WIN32_EXECUTABLE TRUE | ||
MACOSX_BUNDLE TRUE | ||
) | ||
|
||
target_link_libraries(SpotifyOAuth PRIVATE Qt6::Core Qt6::Quick Qt6::QuickControls2 Qt6::Network Qt6::NetworkAuth) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2012-2021, Juergen Bocklage Ryannel and Johan Thelin | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors | ||
may be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Spotify Demo | ||
|
||
The code for this demo was copied from [Qt QML Book](https://www.qt.io/product/qt6/qml-book/ch13-networking-authentication) and can be found [here](https://github.com/qmlbook/qt6book/blob/main/docs/ch13-networking/src/oauth/main.cpp). | ||
The code is available under the following license ([BSD-3-Clause](https://opensource.org/license/bsd-3-clause/)): | ||
|
||
``` | ||
Copyright (c) 2012-2021, Juergen Bocklage Ryannel and Johan Thelin | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its contributors | ||
may be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
``` | ||
|
||
A copy of the LICNESE file can be found [here](LICENSE). | ||
|
||
## Current state | ||
|
||
This demo does currently not working and shows a limitation of these Bazel rules | ||
|
||
The CMake variant of | ||
|
||
```python | ||
qt_add_qml_module(SpotifyOAuth | ||
VERSION 1.0.0 | ||
URI Spotify | ||
QML_FILES | ||
main.qml | ||
SOURCES | ||
spotifyapi.h spotifyapi.cpp | ||
spotifymodel.h spotifymodel.cpp | ||
) | ||
``` | ||
|
||
is missing in these rules. | ||
|
||
Maybe there is some workaround to work with the generated file (i.e. `qmldir` and `SpotifyOAuth.qmltypes`) | ||
|
||
## How to run? | ||
|
||
### macOS | ||
|
||
```bash | ||
bazel run --config=macos //Spotify:SpotifyOAuth | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import QtQuick.tooling 1.2 | ||
|
||
// This file describes the plugin-supplied types contained in the library. | ||
// It is used for QML tooling purposes only. | ||
// | ||
// This file was auto-generated by qmltyperegistrar. | ||
|
||
Module { | ||
Component { | ||
file: "spotifyapi.h" | ||
name: "SpotifyAPI" | ||
accessSemantics: "reference" | ||
prototype: "QObject" | ||
exports: ["Spotify/SpotifyAPI 1.0"] | ||
exportMetaObjectRevisions: [256] | ||
Property { | ||
name: "isAuthenticated" | ||
type: "bool" | ||
read: "isAuthenticated" | ||
write: "setAuthenticated" | ||
notify: "isAuthenticatedChanged" | ||
index: 0 | ||
} | ||
Signal { name: "isAuthenticatedChanged" } | ||
Method { | ||
name: "setCredentials" | ||
Parameter { name: "clientId"; type: "QString" } | ||
Parameter { name: "clientSecret"; type: "QString" } | ||
} | ||
Method { name: "authorize" } | ||
} | ||
Component { | ||
file: "spotifymodel.h" | ||
name: "SpotifyModel" | ||
accessSemantics: "reference" | ||
prototype: "QAbstractListModel" | ||
exports: ["Spotify/SpotifyModel 1.0"] | ||
exportMetaObjectRevisions: [256] | ||
Property { | ||
name: "spotifyApi" | ||
type: "SpotifyAPI" | ||
isPointer: true | ||
read: "spotifyApi" | ||
write: "setSpotifyApi" | ||
notify: "spotifyApiChanged" | ||
index: 0 | ||
} | ||
Signal { name: "spotifyApiChanged" } | ||
Signal { | ||
name: "error" | ||
Parameter { name: "errorString"; type: "QString" } | ||
} | ||
Method { name: "update" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <QGuiApplication> | ||
#include <QQmlApplicationEngine> | ||
|
||
#include "spotifyapi.h" | ||
|
||
int main(int argc, char *argv[]) { | ||
QGuiApplication app(argc, argv); | ||
|
||
QQmlApplicationEngine engine; | ||
const QUrl url(QStringLiteral("qrc:/Spotify/main.qml")); | ||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { | ||
if (!obj && url == objUrl) { | ||
QCoreApplication::exit(-1); | ||
} | ||
}, Qt::QueuedConnection); | ||
|
||
engine.load(url); | ||
|
||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
Copyright (c) 2012-2021, Juergen Bocklage Ryannel and Johan Thelin | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its contributors | ||
may be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
// #region global | ||
// #region imports | ||
import QtQuick | ||
import QtQuick.Window | ||
import QtQuick.Controls | ||
|
||
import Spotify | ||
// #endregion imports | ||
|
||
// #region setup | ||
ApplicationWindow { | ||
width: 320 | ||
height: 568 | ||
visible: true | ||
title: qsTr("Spotify OAuth2") | ||
|
||
BusyIndicator { | ||
visible: !spotifyApi.isAuthenticated | ||
anchors.centerIn: parent | ||
} | ||
|
||
SpotifyAPI { | ||
id: spotifyApi | ||
onIsAuthenticatedChanged: if(isAuthenticated) spotifyModel.update() | ||
} | ||
// #endregion setup | ||
|
||
// #region model-view | ||
SpotifyModel { | ||
id: spotifyModel | ||
spotifyApi: spotifyApi | ||
} | ||
|
||
ListView { | ||
visible: spotifyApi.isAuthenticated | ||
width: parent.width | ||
height: parent.height | ||
model: spotifyModel | ||
delegate: Pane { | ||
id: delegate | ||
required property var model | ||
topPadding: 0 | ||
Column { | ||
width: 300 | ||
spacing: 10 | ||
|
||
Rectangle { | ||
height: 1 | ||
width: parent.width | ||
color: delegate.model.index > 0 ? "#3d3d3d" : "transparent" | ||
} | ||
|
||
Row { | ||
spacing: 10 | ||
|
||
Item { | ||
width: 20 | ||
height: width | ||
|
||
Rectangle { | ||
width: 20 | ||
height: 20 | ||
anchors.top: parent.top | ||
anchors.right: parent.right | ||
color: "black" | ||
|
||
Label { | ||
anchors.centerIn: parent | ||
font.pointSize: 16 | ||
text: delegate.model.index + 1 | ||
color: "white" | ||
} | ||
} | ||
} | ||
|
||
Image { | ||
width: 80 | ||
height: width | ||
source: delegate.model.imageURL | ||
fillMode: Image.PreserveAspectFit | ||
} | ||
|
||
Column { | ||
Label { | ||
text: delegate.model.name | ||
font.pointSize: 16 | ||
font.bold: true | ||
} | ||
Label { text: "Followers: " + delegate.model.followersCount } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// #endregion model-view | ||
|
||
// #region on-completed | ||
Component.onCompleted: { | ||
spotifyApi.setCredentials("CLIENT_ID", "CLIENT_SECRET") | ||
spotifyApi.authorize() | ||
} | ||
// #endregion on-completed | ||
} | ||
// #endregion global |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Spotify | ||
typeinfo SpotifyOAuth.qmltypes | ||
prefer :/Spotify/ |
Oops, something went wrong.