git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit c33110fe authored by Mike Sheldon's avatar Mike Sheldon

Parse playlists in MeeGo client

parent 96501a39
#############################################################################
# Makefile for building: librefm
# Generated by qmake (2.01a) (Qt 4.7.4) on: Fri Jul 1 12:21:52 2011
# Generated by qmake (2.01a) (Qt 4.7.4) on: Fri Jul 1 17:37:58 2011
# Project: src.pro
# Template: app
# Command: /usr/bin/qmake -o Makefile src.pro
......@@ -44,10 +44,14 @@ OBJECTS_DIR = ./
####### Files
SOURCES = main.cpp \
servercomm.cpp moc_servercomm.cpp
servercomm.cpp \
track.cpp moc_servercomm.cpp \
moc_track.cpp
OBJECTS = main.o \
servercomm.o \
moc_servercomm.o
track.o \
moc_servercomm.o \
moc_track.o
DIST = /targets/HARMATTAN_X86/usr/share/qt4/mkspecs/common/g++.conf \
/targets/HARMATTAN_X86/usr/share/qt4/mkspecs/common/unix.conf \
/targets/HARMATTAN_X86/usr/share/qt4/mkspecs/common/linux.conf \
......@@ -149,7 +153,7 @@ qmake: FORCE
dist:
@$(CHK_DIR_EXISTS) .tmp/librefm1.0.0 || $(MKDIR) .tmp/librefm1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/librefm1.0.0/ && $(COPY_FILE) --parents servercomm.h .tmp/librefm1.0.0/ && $(COPY_FILE) --parents main.cpp servercomm.cpp .tmp/librefm1.0.0/ && (cd `dirname .tmp/librefm1.0.0` && $(TAR) librefm1.0.0.tar librefm1.0.0 && $(COMPRESS) librefm1.0.0.tar) && $(MOVE) `dirname .tmp/librefm1.0.0`/librefm1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/librefm1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/librefm1.0.0/ && $(COPY_FILE) --parents servercomm.h track.h .tmp/librefm1.0.0/ && $(COPY_FILE) --parents main.cpp servercomm.cpp track.cpp .tmp/librefm1.0.0/ && (cd `dirname .tmp/librefm1.0.0` && $(TAR) librefm1.0.0.tar librefm1.0.0 && $(COMPRESS) librefm1.0.0.tar) && $(MOVE) `dirname .tmp/librefm1.0.0`/librefm1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/librefm1.0.0
clean:compiler_clean
......@@ -170,12 +174,15 @@ mocclean: compiler_moc_header_clean compiler_moc_source_clean
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
compiler_moc_header_make_all: moc_servercomm.cpp
compiler_moc_header_make_all: moc_servercomm.cpp moc_track.cpp
compiler_moc_header_clean:
-$(DEL_FILE) moc_servercomm.cpp
-$(DEL_FILE) moc_servercomm.cpp moc_track.cpp
moc_servercomm.cpp: servercomm.h
/usr/bin/moc $(DEFINES) $(INCPATH) servercomm.h -o moc_servercomm.cpp
moc_track.cpp: track.h
/usr/bin/moc $(DEFINES) $(INCPATH) track.h -o moc_track.cpp
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
......@@ -201,9 +208,15 @@ main.o: main.cpp servercomm.h
servercomm.o: servercomm.cpp servercomm.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o servercomm.o servercomm.cpp
track.o: track.cpp track.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o track.o track.cpp
moc_servercomm.o: moc_servercomm.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_servercomm.o moc_servercomm.cpp
moc_track.o: moc_track.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_track.o moc_track.cpp
####### Install
install_target: first FORCE
......
......@@ -12,6 +12,7 @@ ServerComm::ServerComm(QObject *parent) :
{
hs_url = "http://turtle.libre.fm/";
ws_url = "http://alpha.libre.fm/2.0/";
playlist = new QList<Track>();
settings = new QSettings("Libre.fm", "Libre.fm");
// Check login details
......@@ -85,7 +86,6 @@ void ServerComm::wsLoginReply(QNetworkReply *reply) {
QDomDocument xml("wsresponse");
xml.setContent(reply);
QDomElement root = xml.documentElement();
QDomNode n = root.firstChild();
for(QDomNode n = root.firstChild(); !n.isNull(); n = n.nextSibling()) {
QDomElement e = n.toElement();
if(!e.isNull()) {
......@@ -127,7 +127,6 @@ void ServerComm::tuneReply(QNetworkReply *reply) {
QDomDocument xml("tuneresponse");
xml.setContent(reply);
QDomElement root = xml.documentElement();
QDomNode n = root.firstChild();
for(QDomNode n = root.firstChild(); !n.isNull(); n = n.nextSibling()) {
QDomElement e = n.toElement();
if(!e.isNull()) {
......@@ -142,9 +141,66 @@ void ServerComm::tuneReply(QNetworkReply *reply) {
QString stationName = ce.text().remove(0, 9); // Remove 'Libre.fm' from the start of station names
qDebug() << "Tuned to:" << stationName;
tuned(stationName);
getPlaylist();
}
}
}
}
}
}
void ServerComm::getPlaylist() {
qDebug() << "Fetching playlist";
QNetworkAccessManager *playlist_netman = new QNetworkAccessManager(this);
connect(playlist_netman, SIGNAL(finished(QNetworkReply*)), this, SLOT(playlistReply(QNetworkReply*)));
QUrl url = QUrl(ws_url);
url.addQueryItem("method", "radio.getPlaylist");
url.addQueryItem("sk", ws_sk);
playlist_netman->get(QNetworkRequest(url));
}
void ServerComm::playlistReply(QNetworkReply *reply) {
qDebug() << "Playlist retrieved";
QDomDocument xml("playlist");
xml.setContent(reply);
QDomElement root = xml.documentElement();
for(QDomNode n = root.firstChild(); !n.isNull(); n = n.nextSibling()) {
QDomElement e = n.toElement();
if(!e.isNull()) {
if(e.tagName() == "trackList") {
for(QDomNode c = n.firstChild(); !c.isNull(); c = c.nextSibling()) {
QDomElement ce = c.toElement();
if(ce.tagName() == "track") {
parseTrack(c);
}
}
}
}
}
}
void ServerComm::parseTrack(QDomNode trackNode) {
Track *t = new Track();
for(QDomNode n = trackNode.firstChild(); !n.isNull(); n = n.nextSibling()) {
QDomElement e = n.toElement();
if(!e.isNull()) {
if(e.tagName() == "artist") {
t->artist = e.text();
} else if(e.tagName() == "album") {
t->album = e.text();
} else if(e.tagName() == "title") {
t->title = e.text();
} else if(e.tagName() == "location") {
t->location = e.text();
} else if(e.tagName() == "image") {
t->image = e.text();
}
}
}
playlist->append(*t);
}
void ServerComm::play(int song) {
}
......@@ -4,7 +4,10 @@
#include <QObject>
#include <QString>
#include <QSettings>
#include <QtXml/QDomDocument>
#include <QtNetwork/QNetworkAccessManager>
#include <QList>
#include "track.h"
class ServerComm : public QObject
{
......@@ -20,18 +23,26 @@ private:
QString hs_url;
QString ws_url;
QSettings *settings;
QList<Track> *playlist;
void parseTrack(QDomNode trackNode);
signals:
void loginFailed();
void loginSuccessful();
void tuned(QString stationName);
public slots:
void login(const QString &username, const QString &password);
void tuneStation(const QString &station);
private slots:
void wsLoginReply(QNetworkReply *reply);
void scrobbleLoginReply(QNetworkReply *reply);
void tuneReply(QNetworkReply *reply);
void playlistReply(QNetworkReply *reply);
public slots:
void login(const QString &username, const QString &password);
void tuneStation(const QString &station);
void getPlaylist();
void play(int song);
};
#endif // SERVERCOMM_H
......@@ -7,9 +7,11 @@ INCLUDEPATH += .
# Input
HEADERS += \
servercomm.h
servercomm.h \
track.h
SOURCES += main.cpp \
servercomm.cpp
servercomm.cpp \
track.cpp
#FORMS#
unix {
......
#include "track.h"
Track::Track() {
}
#ifndef TRACK_H
#define TRACK_H
#include <QObject>
#include <QString>
class Track
{
public:
explicit Track();
QString location;
QString title;
QString album;
QString artist;
QString image;
signals:
public slots:
};
#endif // TRACK_H
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