diff --git a/CMakeLists.txt b/CMakeLists.txt index 5aa3e3d58..364c9b015 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -643,11 +643,11 @@ endif (X11_FOUND) if (WIN32) install(FILES context/ultimate_providers.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/lyrics/) - install(FILES context/weblinks.xml online/podcast_directories.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/config/) + install(FILES context/weblinks.xml online/podcast_directories.xml scrobbling/scrobblers.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/config/) install(FILES tags/fixes.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/config/ RENAME tag-fixes.xml) elseif (NOT ENABLE_UBUNTU) install(FILES context/ultimate_providers.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${CMAKE_PROJECT_NAME}/lyrics) - install(FILES context/weblinks.xml online/podcast_directories.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${CMAKE_PROJECT_NAME}/config/) + install(FILES context/weblinks.xml online/podcast_directories.xml scrobbling/scrobblers.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${CMAKE_PROJECT_NAME}/config/) install(FILES tags/fixes.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${CMAKE_PROJECT_NAME}/config/ RENAME tag-fixes.xml) endif (WIN32) diff --git a/scrobbling/scrobbler.cpp b/scrobbling/scrobbler.cpp index a842c07d1..6986c990a 100644 --- a/scrobbling/scrobbler.cpp +++ b/scrobbling/scrobbler.cpp @@ -61,7 +61,6 @@ static const QLatin1String constBadSession("BADSESSION"); static const QLatin1String constFailed("FAILED"); static const QLatin1String constSettingsGroup("Scrobbling"); static const QString constSecretKey=QLatin1String("0753a75ccded9b17b872744d4bb60b35"); -static const QString constUrl=QLatin1String("http://ws.audioscrobbler.com/2.0/"); static const int constMaxBatchSize=50; GLOBAL_STATIC(Scrobbler, instance) @@ -208,10 +207,7 @@ void Scrobbler::setActive() } else { disconnect(MPDStatus::self(), SIGNAL(updated()), this, SLOT(mpdStateUpdated())); disconnect(MPDConnection::self(), SIGNAL(currentSongUpdated(Song)), this, SLOT(setSong(Song))); - songQueue.clear(); - lastScrobbledSongs.clear(); - saveCache(); - cancelJobs(); + reset(); } if (!isAuthenticated()) { @@ -229,21 +225,25 @@ void Scrobbler::loadSettings() // password=cfg.get("password", password); sessionKey=cfg.get("sessionKey", sessionKey); scrobblingEnabled=cfg.get("enabled", scrobblingEnabled); - DBUG << userName << sessionKey << scrobblingEnabled; + scrobbler=cfg.get("scrobbler", scrobbler); + DBUG << scrobbler << userName << sessionKey << scrobblingEnabled; emit authenticated(isAuthenticated()); emit enabled(isEnabled()); setActive(); } -void Scrobbler::setDetails(const QString &u, const QString &p) +void Scrobbler::setDetails(const QString &s, const QString &u, const QString &p) { - if (u!=userName || p!=password) { + if (u!=scrobbler || u!=userName || p!=password) { DBUG << "details changed"; Configuration cfg(constSettingsGroup); + scrobbler=s; userName=u; password=p; sessionKey=QString(); + reset(); + cfg.set("scrobbler", scrobbler); cfg.set("userName", userName); // cfg.set("password", password); setActive(); @@ -334,7 +334,7 @@ void Scrobbler::scrobbleNowPlaying() params["sk"] = sessionKey; sign(params); DBUG << currentSong.title << currentSong.artist; - QNetworkReply *job=NetworkAccessManager::self()->postFormData(QUrl(constUrl), format(params)); + QNetworkReply *job=NetworkAccessManager::self()->postFormData(scrobblerUrl(), format(params)); connect(job, SIGNAL(finished()), this, SLOT(nowPlayingResp())); nowPlayingSent=true; } @@ -399,7 +399,7 @@ void Scrobbler::scrobbleQueued() } params["sk"] = sessionKey; sign(params); - scrobbleJob=NetworkAccessManager::self()->postFormData(QUrl(constUrl), format(params)); + scrobbleJob=NetworkAccessManager::self()->postFormData(scrobblerUrl(), format(params)); connect(scrobbleJob, SIGNAL(finished()), this, SLOT(scrobbleFinished())); } } @@ -454,7 +454,7 @@ void Scrobbler::authenticate() DBUG << "no login details"; return; } - QUrl url(constUrl); + QUrl url=scrobblerUrl(); QMap params; params["method"] = "auth.getMobileSession"; params["username"] = userName; @@ -659,3 +659,43 @@ void Scrobbler::cancelJobs() scrobbleJob=0; } } + +void Scrobbler::reset() +{ + songQueue.clear(); + lastScrobbledSongs.clear(); + saveCache(); + cancelJobs(); +} + +void Scrobbler::loadScrobblers() +{ + if (scrobblers.isEmpty()) { + QFile f(CANTATA_SYS_CONFIG_DIR+"scrobblers.xml"); + if (f.open(QIODevice::ReadOnly)) { + QXmlStreamReader doc(&f); + while (!doc.atEnd()) { + doc.readNext(); + if (doc.isStartElement() && QLatin1String("scrobbler")==doc.name()) { + QString name=doc.attributes().value("name").toString(); + QString url=doc.attributes().value("url").toString(); + if (!name.isEmpty() && !url.isEmpty()) { + scrobblers.insert(name, QUrl(url)); + } + } + } + } + } +} + +QUrl Scrobbler::scrobblerUrl() const +{ + if (scrobblers.isEmpty()) { + return QString(); + } + + if (!scrobblers.contains(scrobbler)) { + return scrobblers.constBegin().value(); + } + return scrobblers[scrobbler]; +} diff --git a/scrobbling/scrobbler.h b/scrobbling/scrobbler.h index 225ce6e8c..5b9fc2bbb 100644 --- a/scrobbling/scrobbler.h +++ b/scrobbling/scrobbler.h @@ -29,9 +29,11 @@ #define SCROBBLER_H #include +#include #include #include #include +#include #include class QTimer; @@ -66,12 +68,14 @@ public: Scrobbler(); ~Scrobbler(); + QStringList availableScrobblers() { loadScrobblers(); return scrobblers.keys(); } void stop(); bool isEnabled() const { return scrobblingEnabled; } bool haveLoginDetails() const { return !userName.isEmpty() && !password.isEmpty(); } - void setDetails(const QString &u, const QString &p); + void setDetails(const QString &s, const QString &u, const QString &p); const QString & user() const { return userName; } const QString & pass() const { return password; } + const QString & activeScrobbler() const { return scrobbler; } bool isAuthenticated() const { return !sessionKey.isEmpty(); } Q_SIGNALS: @@ -102,15 +106,17 @@ private: void loadCache(); void saveCache(); void cancelJobs(); + void reset(); + void loadScrobblers(); + QUrl scrobblerUrl() const; private: bool scrobblingEnabled; + QMap scrobblers; QString scrobbler; QString userName; QString password; QString sessionKey; - QString nowPlayingUrl; - QString scrobbleUrl; QQueue songQueue; QQueue lastScrobbledSongs; Track currentSong; diff --git a/scrobbling/scrobblers.xml b/scrobbling/scrobblers.xml new file mode 100644 index 000000000..7cb094b9f --- /dev/null +++ b/scrobbling/scrobblers.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/scrobbling/scrobblingsettings.cpp b/scrobbling/scrobblingsettings.cpp index 97b7366b2..a3ef4cf49 100644 --- a/scrobbling/scrobblingsettings.cpp +++ b/scrobbling/scrobblingsettings.cpp @@ -41,6 +41,14 @@ ScrobblingSettings::ScrobblingSettings(QWidget *parent) connect(enableScrobbling, SIGNAL(toggled(bool)), Scrobbler::self(), SLOT(setEnabled(bool))); connect(Scrobbler::self(), SIGNAL(enabled(bool)), enableScrobbling, SLOT(setChecked(bool))); loginButton->setEnabled(false); + + QStringList scrobblers=Scrobbler::self()->availableScrobblers(); + scrobblers.sort(); + foreach (const QString &s, scrobblers) { + scrobbler->addItem(s); + } + scrobbler->setVisible(scrobbler->count()>1); + scrobblerLabel->setVisible(scrobbler->count()>1); } void ScrobblingSettings::load() @@ -48,6 +56,13 @@ void ScrobblingSettings::load() showStatus(Scrobbler::self()->isAuthenticated()); user->setText(Scrobbler::self()->user().trimmed()); pass->setText(Scrobbler::self()->pass().trimmed()); + QString s=Scrobbler::self()->activeScrobbler(); + for (int i=0; icount(); ++i) { + if (scrobbler->itemText(i)==s) { + scrobbler->setCurrentIndex(i); + break; + } + } enableScrobbling->setChecked(Scrobbler::self()->isEnabled()); controlLoginButton(); } @@ -56,7 +71,7 @@ void ScrobblingSettings::save() { messageWidget->close(); loginStatusLabel->setText(i18n("Authenticating...")); - Scrobbler::self()->setDetails(user->text().trimmed(), pass->text().trimmed()); + Scrobbler::self()->setDetails(scrobbler->currentText(), user->text().trimmed(), pass->text().trimmed()); } void ScrobblingSettings::showStatus(bool status) diff --git a/scrobbling/scrobblingsettings.ui b/scrobbling/scrobblingsettings.ui index 6aa7d71f5..fd7b33934 100644 --- a/scrobbling/scrobblingsettings.ui +++ b/scrobbling/scrobblingsettings.ui @@ -11,7 +11,32 @@ + + 0 + + + 0 + + + 0 + + + 0 + + + + Scrobble to: + + + scrobbler + + + + + + + Username: @@ -21,10 +46,10 @@ - + - + Password: @@ -34,14 +59,14 @@ - + QLineEdit::Password - + Status: @@ -51,7 +76,7 @@ - + @@ -81,7 +106,7 @@ - + QFrame::StyledPanel @@ -91,14 +116,14 @@ - + Scrobble tracks - + Qt::Vertical