Commit 7afd3238 authored by Mike Sheldon's avatar Mike Sheldon

Implement login for sailfish client and add main menu

parent fb629fd5
......@@ -23,7 +23,9 @@ OTHER_FILES += qml/harbour-librefm.qml \
qml/images/librefm-tower.png \
qml/images/librefm-logo.png \
qml/images/librefm.svg \
qml/images/empty-album.png
qml/images/empty-album.png \
qml/pages/MenuPage.qml \
qml/pages/RadioPage.qml
HEADERS += \
src/settings.h
......
This diff is collapsed.
......@@ -6,9 +6,18 @@ ApplicationWindow
{
property string wsUrl: "http://libre.fm/2.0/";
property string wsKey: "";
initialPage: LoginPage { }
property string wsUser: "";
initialPage: Component { LoginPage { } }
cover: Qt.resolvedUrl("cover/CoverPage.qml")
Component {
id: menuPage
MenuPage {
}
}
Rectangle {
id: errorRect
color: Theme.highlightColor
......@@ -32,21 +41,39 @@ ApplicationWindow
}
}
function request(url, callback) {
function request(params, method, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = (function(mxhr) {
return function() { if(mxhr.readyState === XMLHttpRequest.DONE) { callback(mxhr); } }
})(xhr);
xhr.open('GET', url, true);
xhr.send('');
if(method === "post") {
xhr.open('POST', wsUrl, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-length", params.length);
xhr.setRequestHeader("Connection", "close");
xhr.send(params);
} else {
xhr.open('GET', wsUrl + "/?" + params, true);
xhr.send('');
}
}
function showError(e) {
console.log(e.text);
errorBanner.text = e.nodeValue;
errorBanner.text = e.childNodes[0].nodeValue;
errorRect.visible = true;
errorRectFadeOut.stop();
errorRectFadeOut.start();
console.log(e.nodeValue);
}
function playStation(s) {
console.log("Lodaing station: " + s);
var component = Qt.createComponent("pages/RadioPage.qml");
if( component.status === Component.Error ) {
console.debug("Error: "+ component.errorString() );
}
var radioPage = component.createObject(pageStack, { station: s });
pageStack.push(radioPage);
}
}
......@@ -2,12 +2,11 @@ import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: page
property bool loggingIn: false;
Component.onCompleted: {
if(settings.value("user", false) !== false) {
doLogin(settings.value("user"), settings.value("auth"));
if(settings.value("username", false) !== false) {
doLogin(settings.value("username"), settings.value("authToken"));
}
}
......@@ -16,7 +15,7 @@ Page {
source: "../images/librefm-logo.png"
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 100
anchors.topMargin: 50
}
Column {
......@@ -28,7 +27,7 @@ Page {
anchors.leftMargin: 10
anchors.rightMargin: 10
anchors.top: logo.bottom
anchors.topMargin: 100
anchors.topMargin: 50
TextField {
id: username
......@@ -58,11 +57,6 @@ Page {
}
}
Item {
height: 10
width: 1
}
Button {
id: button
text: "Log in"
......@@ -85,7 +79,7 @@ Page {
Label {
width: parent.width
wrapMode: Text.WordWrap
font.pixelSize: 20
font.pointSize: 12
onLinkActivated: Qt.openUrlExternally(link)
horizontalAlignment: Text.AlignHCenter
textFormat: Text.RichText
......@@ -97,19 +91,26 @@ Page {
function doLogin(user, auth) {
loggingIn = true;
request(wsUrl + "?method=auth.getmobilesession&username=" + user + "&authToken=" + auth, function (doc) {
request("method=auth.getmobilesession&username=" + user + "&authToken=" + auth, "get", function (doc) {
loggingIn = false;
console.log(doc.responseText)
var e = doc.responseXML.documentElement;
for(var i = 0; i < e.childNodes.length; i++) {
console.log(e.childNodes[i]);
if(e.childNodes[i].nodeName === "error") {
showError(e.childNodes[i]);
}
if(e.childNodes[i].nodeName === "key") {
settings.setValue("username", user);
settings.setValue("authToken", auth);
wsKey = e.childNodes[i].nodeValue;
if(e.childNodes[i].nodeName === "session") {
var sess = e.childNodes[i];
for(var j = 0; j < sess.childNodes.length; j++ ) {
if(sess.childNodes[j].nodeName === "key") {
settings.setValue("username", user);
settings.setValue("authToken", auth);
wsKey = sess.childNodes[j].childNodes[0].nodeValue;
wsUser = user;
pageStack.clear();
pageStack.push(menuPage);
console.log(wsKey);
}
}
}
}
......@@ -125,7 +126,7 @@ Page {
Column {
anchors.centerIn: parent
anchors.verticalCenterOffset: 20
anchors.verticalCenterOffset: 100
visible: loggingIn
spacing: 20
......
import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
SilicaFlickable {
anchors.fill: parent;
contentHeight: col.height + logo.height;
contentWidth: parent.width;
Image {
id: logo
source: "../images/librefm-logo.png"
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 50
}
Column {
id: col;
anchors.top: logo.bottom
anchors.topMargin: 50;
width: parent.width
Button {
text: "Your Loved Station"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
playStation("librefm://user/" + wsUser + "/loved");
}
}
Button {
text: "Your Recommendations Station"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
playStation("librefm://user/" + wsUser + "/recommended");
}
}
Button {
text: "Your Mix Station"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
playStation("librefm://user/" + wsUser + "/mix");
}
}
Button {
text: "Tag Station"
anchors.horizontalCenter: parent.horizontalCenter
}
Button {
text: "Community Station"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
playStation("librefm://community/loved");
}
}
}
}
}
import QtQuick 2.0
import QtMultimedia 5.0
import Sailfish.Silica 1.0
Page {
property string station: "";
Component.onCompleted: {
tune(station);
}
MediaPlayer {
id: player
}
Column {
anchors.fill: parent
Label {
id: stationName
anchors.horizontalCenter: parent.horizontalCenter;
}
}
Row {
id: controls
spacing: 30
anchors.bottom: parent.bottom
Item {
width: 80; height: 100
anchors.verticalCenter: parent.verticalCenter
Image {
id: favIcon
anchors.centerIn: parent
opacity: enabled ? (starArea.pressed ? 0.4 : 1.0) : 0.2
source: "image://theme/icon-m-favorite"
}
MouseArea {
id: starArea
anchors.fill: parent
anchors.margins: -15
}
}
Item {
width: 80; height: 100
anchors.verticalCenter: parent.verticalCenter
Image {
anchors.centerIn: parent
source: "image://theme/icon-m-previous-song"
opacity: previous.pressed ? 0.4 : 1.0
}
MouseArea {
id: previous
anchors.fill: parent
}
}
Item {
width: 80; height: 100
anchors.verticalCenter: parent.verticalCenter
Image {
anchors.centerIn: parent
source: player.playing ? "image://theme/icon-m-pause"
: "image://theme/icon-m-play"
opacity: play.pressed ? 0.4 : 1.0
}
MouseArea {
id: play
anchors.fill: parent
}
}
Item {
width: 80; height: 100
anchors.verticalCenter: parent.verticalCenter
Image {
anchors.centerIn: parent
source: "image://theme/icon-m-next-song"
opacity: next.pressed ? 0.4 : 1.0
}
MouseArea {
id: next
anchors.fill: parent
}
}
}
function tune(s) {
console.log("Tuning to: " + s);
request("method=radio.tune&station=" + s + "&sk=" + wsKey, "post", function(doc) {
var e = doc.responseXML.documentElement;
console.log(doc.responseText);
for(var i = 0; i < e.childNodes.length; i++) {
if(e.childNodes[i].nodeName === "error") {
showError(e.childNodes[i]);
}
if(e.childNodes[i].nodeName === "station") {
var st = e.childNodes[i];
for(var j = 0; j < st.childNodes.length; j++ ) {
if(st.childNodes[j].nodeName === "name") {
stationName.text = st.childNodes[j].childNodes[0].nodeValue;
}
}
fetchPlaylist();
}
}
});
}
function fetchPlaylist() {
request("method=radio.getplaylist&sk=" + wsKey, "post", function(doc) {
console.log(doc.responseText) ;
var e = doc.responseXML.documentElement;
for(var i = 0; i < e.childNodes.length; i++) {
console.log(e.childNodes[i].nodeName);
}
});
}
}
......@@ -12,18 +12,18 @@ Description: |
Configure: none
Builder: qtc5
PkgConfigBR:
- Qt5Quick
- Qt5Qml
- Qt5Core
- sailfishapp >= 0.0.10
- Qt5Core
- Qt5Qml
- Qt5Quick
Requires:
- sailfishsilica-qt5 >= 0.10.9
Files:
- '%{_bindir}'
- '%{_datadir}/%{name}/qml'
- '%{_datadir}/applications/%{name}.desktop'
- '%{_datadir}/icons/hicolor/86x86/apps/%{name}.png'
- /usr/bin
- /usr/share/harbour-librefm
- /usr/share/applications
- /usr/share/icons/hicolor/86x86/apps
- /usr/share/applications
- /usr/share/harbour-librefm
- /usr/bin
- '%{_datadir}/icons/hicolor/86x86/apps/%{name}.png'
- '%{_datadir}/applications/%{name}.desktop'
- '%{_datadir}/%{name}/qml'
- '%{_bindir}'
......@@ -9,7 +9,7 @@
int main(int argc, char *argv[])
{
QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, "/home/nemo/.local/share/harbour-librefm/");
QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, "/home/nemo/.local/share/harbour-librefm");
Settings settings;
QGuiApplication *app = SailfishApp::application(argc, argv);
QQuickWindow::setDefaultAlphaBuffer(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment