Commit 6e770a2c authored by Mike Sheldon's avatar Mike Sheldon

Make the MeeGo client remember user details and login automatically.

parent 685f606a
......@@ -4,7 +4,7 @@ This package was debianized by:
It was downloaded from:
<url://example.com or remove>
http://libre.fm
Upstream Author(s):
......@@ -16,11 +16,9 @@ Copyright:
License:
<specify license>
GPL 3.0 or later
The Debian packaging is:
Copyright C) 2011, Michael Sheldon <elleo@gnu.org>
<specify license of debianized version or remove>
#############################################################################
# Makefile for building: librefm
# Generated by qmake (2.01a) (Qt 4.7.4) on: Fri Jul 1 02:15:31 2011
# Generated by qmake (2.01a) (Qt 4.7.4) on: Fri Jul 1 12:21:52 2011
# Project: src.pro
# Template: app
# Command: /usr/bin/qmake -o Makefile src.pro
......@@ -243,16 +243,6 @@ uninstall_desktop: FORCE
-$(DEL_DIR) $(INSTALL_ROOT)/usr/share/applications/
install_icon64: first FORCE
@$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/usr/share/icons/hicolor/64x64/apps/ || $(MKDIR) $(INSTALL_ROOT)/usr/share/icons/hicolor/64x64/apps/
-$(INSTALL_FILE) /scratchbox/users/mike/home/mike/scratchbox/src/Libre.fm/librefm-0.1/data/64x64/librefm.png $(INSTALL_ROOT)/usr/share/icons/hicolor/64x64/apps/
uninstall_icon64: FORCE
-$(DEL_FILE) -r $(INSTALL_ROOT)/usr/share/icons/hicolor/64x64/apps/librefm.png
-$(DEL_DIR) $(INSTALL_ROOT)/usr/share/icons/hicolor/64x64/apps/
install_iconScale: first FORCE
@$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/usr/share/icons/hicolor/scalable/apps/ || $(MKDIR) $(INSTALL_ROOT)/usr/share/icons/hicolor/scalable/apps/
-$(INSTALL_FILE) /scratchbox/users/mike/home/mike/scratchbox/src/Libre.fm/librefm-0.1/data/scalable/librefm.svg $(INSTALL_ROOT)/usr/share/icons/hicolor/scalable/apps/
......@@ -279,9 +269,9 @@ uninstall_image: FORCE
-$(DEL_DIR) $(INSTALL_ROOT)/usr/share/librefm/
install: install_target install_qmlgui install_desktop install_icon64 install_iconScale install_image FORCE
install: install_target install_qmlgui install_desktop install_iconScale install_image FORCE
uninstall: uninstall_target uninstall_qmlgui uninstall_desktop uninstall_icon64 uninstall_iconScale uninstall_image FORCE
uninstall: uninstall_target uninstall_qmlgui uninstall_desktop uninstall_iconScale uninstall_image FORCE
FORCE:
......@@ -100,7 +100,7 @@ Page {
anchors.fill: background
onClicked: {
rootWin.openFile("StationPage.qml")
rootWin.launchStation(station)
rootWin.tuneStation(station)
}
}
}
......
......@@ -7,7 +7,7 @@ PageStackWindow {
initialPage: LoginPage { }
signal login(string username, string password)
signal launchStation(string station)
signal tuneStation(string station)
function openFile(file) {
var component = Qt.createComponent(file)
......
#include <QApplication>
#include <QDeclarativeContext>
#include <QDeclarativeView>
#include <QDebug>
#include <iostream>
#include "servercomm.h"
void msgHandler( QtMsgType type, const char* msg )
{
const char symbols[] = { 'I', 'E', '!', 'X' };
QString output = QString("[%1] %2").arg( symbols[type] ).arg( msg );
std::cerr << output.toStdString() << std::endl;
if( type == QtFatalMsg ) abort();
}
int main(int argc, char *argv[])
{
qInstallMsgHandler( msgHandler );
QApplication app(argc, argv);
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("src/librefm.qml"));
......@@ -15,7 +27,7 @@ int main(int argc, char *argv[])
ServerComm sc;
view.rootContext()->setContextProperty("serverComm", &sc);
QObject::connect(root, SIGNAL(login(QString, QString)), &sc, SLOT(login(QString, QString)));
QObject::connect(root, SIGNAL(launchStation(QString, QString)), &sc, SLOT(launchStation(QString, QString)));
QObject::connect(root, SIGNAL(tuneStation(QString)), &sc, SLOT(tuneStation(QString)));
QObject::connect((QObject*)view.engine(), SIGNAL(quit()), &app, SLOT(quit()));
view.showFullScreen();
......
......@@ -12,10 +12,23 @@ ServerComm::ServerComm(QObject *parent) :
{
hs_url = "http://turtle.libre.fm/";
ws_url = "http://alpha.libre.fm/2.0/";
settings = new QSettings("Libre.fm", "Libre.fm");
// Check login details
qDebug() << "Checking settings...";
if (settings->contains("Auth/username") && settings->contains("Auth/password")) {
qDebug() << "Logging in...";
login(settings->value("Auth/username").toString(), settings->value("Auth/password").toString());
qDebug() << "Username:" << settings->value("Auth/username").toString();
}
}
void ServerComm::login(const QString &username, const QString &password) {
qDebug() << "Logging in...";
if(username.isEmpty() || password.isEmpty()) {
loginFailed();
return;
}
QString passMD5 = QCryptographicHash::hash(QByteArray(password.toAscii()), QCryptographicHash::Md5).toHex();
long timestamp = QDateTime::currentDateTime().toTime_t();
QString token = QCryptographicHash::hash(QByteArray(QString(QString(passMD5) + QString::number(timestamp)).toAscii()), QCryptographicHash::Md5).toHex();
......@@ -41,6 +54,10 @@ void ServerComm::login(const QString &username, const QString &password) {
url.addQueryItem("authToken", wstoken);
qDebug() << "AuthToken:" << wstoken;
ws_netman->get(QNetworkRequest(url));
// Save authentication details
settings->setValue("Auth/username", username);
settings->setValue("Auth/password", password);
}
void ServerComm::scrobbleLoginReply(QNetworkReply *reply) {
......@@ -72,7 +89,6 @@ void ServerComm::wsLoginReply(QNetworkReply *reply) {
for(QDomNode n = root.firstChild(); !n.isNull(); n = n.nextSibling()) {
QDomElement e = n.toElement();
if(!e.isNull()) {
qDebug() << "Tag:" << e.tagName();
if(e.tagName() == "error") {
loginFailed();
return;
......@@ -94,6 +110,14 @@ void ServerComm::wsLoginReply(QNetworkReply *reply) {
}
}
void ServerComm::launchStation(const QString &station) {
qDebug() << "Launching station: " << station;
void ServerComm::tuneStation(const QString &station) {
qDebug() << "Tuning to station: " << station;
QNetworkAccessManager *tune_netman = new QNetworkAccessManager(this);
connect(tune_netman, SIGNAL(finished(QNetworkReply*)), this, SLOT(tuneReply(QNetworkReply*)));
QUrl url = QUrl(ws_url);
url.addQueryItem("method", "radio.tune");
url.addQueryItem("sk", ws_sk);
url.addQueryItem("station", station);
tune_netman->get(QNetworkRequest(url));
}
......@@ -3,6 +3,7 @@
#include <QObject>
#include <QString>
#include <QSettings>
#include <QtNetwork/QNetworkAccessManager>
class ServerComm : public QObject
......@@ -18,6 +19,7 @@ private:
QString scr_url;
QString hs_url;
QString ws_url;
QSettings *settings;
signals:
void loginFailed();
......@@ -25,7 +27,7 @@ signals:
public slots:
void login(const QString &username, const QString &password);
void launchStation(const QString &station);
void tuneStation(const QString &station);
void wsLoginReply(QNetworkReply *reply);
void scrobbleLoginReply(QNetworkReply *reply);
};
......
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