-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpotifyCredentialsScreen.qml
More file actions
189 lines (161 loc) · 5.13 KB
/
Copy pathSpotifyCredentialsScreen.qml
File metadata and controls
189 lines (161 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import QtQuick 2.1
import qb.components 1.0
import BasicUIControls 1.0;
Screen {
id: spotifyCredentialsScreen
screenTitle: "Configureren Spotify link"
onShown: {
spotifyClientIdLabel.inputText = app.spotifyToken["spotifyClientId"];
spotifyClientSecretLabel.inputText = app.spotifyToken["spotifyClientSecret"];
}
function saveSpotifyClientIdLabel(text) {
if (text) {
app.spotifyToken["spotifyClientId"] = text;
spotifyClientIdLabel.inputText = text;
}
}
function saveSpotifyClientSecretLabel(text) {
if (text) {
app.spotifyToken["spotifyClientSecret"] = text;
spotifyClientSecretLabel.inputText = text;
}
}
function validateCredentials() {
var xmlhttpSpot = new XMLHttpRequest();
xmlhttpSpot.onreadystatechange=function() {
if (xmlhttpSpot.readyState == 4) {
if (xmlhttpSpot.status == 200) {
var response = JSON.parse(xmlhttpSpot.responseText);
if (response["access_token"]) {
app.spotifyToken["access_token"] = response["access_token"];
app.spotifyStatus = "configured";
app.saveSettings();
qdialog.showDialog(qdialog.SizeLarge, "Spotify configuratie", "De connectie met Spotify is succesvol getest. U kunt nu via het Sonos menu item meerdere spotify accounts toevoegen." , "Sluiten");
app.getSpotifyBearerToken();
hide();
}
}
if (xmlhttpSpot.status == 400) {
var response = JSON.parse(xmlhttpSpot.responseText);
if (response["error"]) {
qdialog.showDialog(qdialog.SizeLarge, "Spotify configuratie", "De connectie met Spotify is niet gelukt. Controleer het ClientId en de ClientSecret." , "Sluiten");
}
}
}
}
xmlhttpSpot.open("POST", "https://accounts.spotify.com/api/token");
xmlhttpSpot.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttpSpot.setRequestHeader("Authorization", 'Basic ' + app.customBtoa(app.spotifyToken["spotifyClientId"] + ":" + app.spotifyToken["spotifyClientSecret"]));
xmlhttpSpot.send('grant_type=client_credentials');
}
Text {
id: headerText
text: "Invoer Spotify app credentials:"
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 20 : 16
anchors {
top: parent.top
left: parent.left
leftMargin: isNxt ? 38 : 30
}
}
EditTextLabel4421 {
id: spotifyClientIdLabel
width: isNxt ? 625 : 500
height: isNxt ? 44 : 35
leftTextAvailableWidth: isNxt ? 200 : 160
leftText: "Client Id:"
x: isNxt ? 38 : 30
y: 10
anchors {
left: headerText.left
top: parent.top
topMargin: isNxt ? 30 : 24
}
onClicked: {
qkeyboard.open("Voer de client Id in", spotifyClientIdLabel.inputText, saveSpotifyClientIdLabel)
}
}
IconButton {
id: spotifyClientIdLabelButton;
width: isNxt ? 50 : 40
iconSource: "qrc:/tsc/edit.png"
anchors {
left: spotifyClientIdLabel.right
leftMargin: 6
top: spotifyClientIdLabel.top
}
bottomClickMargin: 3
onClicked: {
qkeyboard.open("Voer de client Id in", spotifyClientIdLabel.inputText, saveSpotifyClientIdLabel)
}
}
EditTextLabel4421 {
id: spotifyClientSecretLabel
width: spotifyClientIdLabel.width
height: isNxt ? 44 : 35
leftTextAvailableWidth: isNxt ? 200 : 160
leftText: "Client Secret:"
anchors {
left: spotifyClientIdLabel.left
top: spotifyClientIdLabel.bottom
topMargin: 6
}
onClicked: {
qkeyboard.open("Voer de client Id in", spotifyClientSecretLabel.inputText, saveSpotifyClientSecretLabel)
}
}
IconButton {
id: spotifyClientSecretLabelButton;
width: isNxt ? 50 : 40
iconSource: "qrc:/tsc/edit.png"
anchors {
left: spotifyClientSecretLabel.right
leftMargin: 6
top: spotifyClientSecretLabel.top
}
topClickMargin: 3
onClicked: {
qkeyboard.open("Voer de client Id in", spotifyClientSecretLabel.inputText, saveSpotifyClientSecretLabel)
}
}
StandardButton {
id: editSpotifyCredentialsButton
width: isNxt ? 375 : 300
radius: 5
text: "Valideer gegevens"
fontPixelSize: isNxt ? 25 : 20
color: colors.background
anchors {
top: spotifyClientSecretLabel.bottom
topMargin: 20
left: spotifyClientSecretLabel.left
}
visible: (app.spotifyStatus !== "configured")
onClicked: {
validateCredentials()
}
}
Text {
id: explainerText
text: "1: Ga met een browser naar https://developer.spotify.com/\n" +
"2: Log in met je eigen Spotify account\n" +
"3: Klik op je inlognaam rechtsboven en ga naar het Dashboard\n" +
"4: Klik op de knop 'Create App'\n" +
"5: Vul in : App name, bijvoorbeeld 'Toon Sonos client' en een 'App description'\n" +
"6: Vul een 'Redirect URL'in , maakt niet uit wat, bijvoorbeeld: https://localhost:8080\n" +
"7: Selekteer de checkbox Web API\n" +
"8: Ga akkoord met de 'terms of service'\n" +
"9: Druk op 'Save'\n" +
"10: Je krijgt nu een scherm met basic information waaronder het Client Id.\n" +
"11: Click op de link 'View client secret' om de Client Secret te tonen\n" +
"12: Vul beide velden in hier op de Toon en druk op 'Valideer gegevens'"
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 15 : 12
anchors {
top: editSpotifyCredentialsButton.bottom
left: editSpotifyCredentialsButton.left
topMargin: isNxt ? 38 : 30
}
}
}