From ab030aa3915a48a7590a194bd680157958be4d54 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Tue, 29 Jan 2013 17:07:27 +0000 Subject: lastfm scrobbler: enabled 'check session' button git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3194 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/scrobbler/lastfmscrobbler.cpp | 52 ++++++++++++++++++++++ src/plugins/General/scrobbler/lastfmscrobbler.h | 4 +- src/plugins/General/scrobbler/settingsdialog.cpp | 34 ++++++++++++++ src/plugins/General/scrobbler/settingsdialog.h | 2 + .../scrobbler/translations/scrobbler_plugin_cs.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_de.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_es.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_fr.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_he.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_hu.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_it.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_ja.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_kk.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_lt.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_nl.ts | 40 +++++++++++------ .../translations/scrobbler_plugin_pl_PL.ts | 40 +++++++++++------ .../translations/scrobbler_plugin_pt_BR.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_ru.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_sk.ts | 40 +++++++++++------ .../scrobbler/translations/scrobbler_plugin_tr.ts | 40 +++++++++++------ .../translations/scrobbler_plugin_uk_UA.ts | 40 +++++++++++------ .../translations/scrobbler_plugin_zh_CN.ts | 40 +++++++++++------ .../translations/scrobbler_plugin_zh_TW.ts | 40 +++++++++++------ 23 files changed, 604 insertions(+), 248 deletions(-) (limited to 'src') diff --git a/src/plugins/General/scrobbler/lastfmscrobbler.cpp b/src/plugins/General/scrobbler/lastfmscrobbler.cpp index be327ae0a..ba414f58b 100644 --- a/src/plugins/General/scrobbler/lastfmscrobbler.cpp +++ b/src/plugins/General/scrobbler/lastfmscrobbler.cpp @@ -428,6 +428,39 @@ void LastfmAuth::getSession() m_getSessionReply = m_http->get(request); } +void LastfmAuth::checkSession(const QString &session) +{ + qDebug("LastfmAuth: checking session..."); + QMap params; + params.insert("api_key", API_KEY); + params.insert("sk", session); + params.insert("method", "user.getRecommendedArtists"); + params.insert("limit", "1"); + + QUrl url(SCROBBLER_LASTFM_URL); + url.setPort(80); + + QUrl body(""); + QByteArray data; + foreach (QString key, params.keys()) + { + body.addQueryItem(key, params.value(key)); + data.append(key.toUtf8() + params.value(key).toUtf8()); + } + data.append(SECRET); + body.addQueryItem("api_sig", QCryptographicHash::hash(data, QCryptographicHash::Md5).toHex()); + QByteArray bodyData = body.toEncoded().remove(0,1); + bodyData.replace("+", QUrl::toPercentEncoding("+")); + + QNetworkRequest request(url); + request.setRawHeader("User-Agent", m_ua); + request.setRawHeader("Host", url.host().toAscii()); + request.setRawHeader("Accept", "*/*"); + request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); + request.setHeader(QNetworkRequest::ContentLengthHeader, bodyData.size()); + m_checkSessionReply = m_http->post(request, bodyData); +} + QString LastfmAuth::session() const { return m_session; @@ -520,5 +553,24 @@ void LastfmAuth::processResponse(QNetworkReply *reply) emit sessionRequestFinished(LASTFM_ERROR); } } + else if(reply == m_checkSessionReply) + { + m_checkSessionReply = 0; + if(response.status == "ok") + { + qDebug("LastfmAuth: session ok"); + emit checkSessionFinished(NO_ERROR); + } + else if(error_code.isEmpty()) + { + qWarning("LastfmAuth: network error"); + emit checkSessionFinished(NETWORK_ERROR); + } + else + { + qWarning("LastfmAuth: received last.fm error (code=%s)", qPrintable(error_code)); + emit checkSessionFinished(LASTFM_ERROR); + } + } reply->deleteLater(); } diff --git a/src/plugins/General/scrobbler/lastfmscrobbler.h b/src/plugins/General/scrobbler/lastfmscrobbler.h index cf0c2609e..c9385670e 100644 --- a/src/plugins/General/scrobbler/lastfmscrobbler.h +++ b/src/plugins/General/scrobbler/lastfmscrobbler.h @@ -94,6 +94,7 @@ public: explicit LastfmAuth(QObject *parent = 0); void getToken(); void getSession(); + void checkSession(const QString &session); QString session() const; enum ErrorType @@ -106,6 +107,7 @@ public: signals: void tokenRequestFinished(int error); void sessionRequestFinished(int error); + void checkSessionFinished(int error); private slots: void processResponse(QNetworkReply *reply); @@ -114,7 +116,7 @@ private: QString m_token, m_session; QByteArray m_ua; QNetworkAccessManager *m_http; - QNetworkReply *m_getTokenReply, *m_getSessionReply; + QNetworkReply *m_getTokenReply, *m_getSessionReply, *m_checkSessionReply; }; #endif diff --git a/src/plugins/General/scrobbler/settingsdialog.cpp b/src/plugins/General/scrobbler/settingsdialog.cpp index 29ff3b8b5..c5ca85cc7 100644 --- a/src/plugins/General/scrobbler/settingsdialog.cpp +++ b/src/plugins/General/scrobbler/settingsdialog.cpp @@ -30,6 +30,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent) m_lastfmAuth = new LastfmAuth(this); connect(m_lastfmAuth, SIGNAL(tokenRequestFinished(int)), SLOT(processTokenResponse(int))); connect(m_lastfmAuth, SIGNAL(sessionRequestFinished(int)), SLOT(processSessionResponse(int))); + connect(m_lastfmAuth, SIGNAL(checkSessionFinished(int)), SLOT(processCheckResponse(int))); QSettings settings(Qmmp::configFile(), QSettings::IniFormat); settings.beginGroup("Scrobbler"); m_ui.lastfmGroupBox->setChecked(settings.value("use_lastfm", false).toBool()); @@ -58,11 +59,13 @@ void SettingsDialog::accept() void SettingsDialog::on_newSessionButton_lastfm_clicked() { + m_ui.newSessionButton_lastfm->setEnabled(false); m_lastfmAuth->getToken(); } void SettingsDialog::processTokenResponse(int error) { + m_ui.newSessionButton_lastfm->setEnabled(true); switch(error) { case LastfmAuth::NO_ERROR: @@ -71,6 +74,7 @@ void SettingsDialog::processTokenResponse(int error) tr("1. Wait for browser startup.") + "\n" + tr("2. Allow Qmmp to scrobble tracks to your Last.fm account.") + "\n" + tr("3. Press \"OK\".")); + m_ui.newSessionButton_lastfm->setEnabled(false); m_lastfmAuth->getSession(); break; case LastfmAuth::NETWORK_ERROR: @@ -84,6 +88,7 @@ void SettingsDialog::processTokenResponse(int error) void SettingsDialog::processSessionResponse(int error) { + m_ui.newSessionButton_lastfm->setEnabled(true); switch(error) { case LastfmAuth::NO_ERROR: @@ -103,3 +108,32 @@ void SettingsDialog::processSessionResponse(int error) QMessageBox::warning(this, tr("Error"), tr("Unable to register new session.")); } } + +void SettingsDialog::on_checkButton_lastfm_clicked() +{ + if(!m_ui.sessionLineEdit_lastfm->text().isEmpty()) + { + m_ui.checkButton_lastfm->setEnabled(false); + m_lastfmAuth->checkSession(m_ui.sessionLineEdit_lastfm->text()); + } +} + +void SettingsDialog::processCheckResponse(int error) +{ + m_ui.checkButton_lastfm->setEnabled(true); + switch(error) + { + case LastfmAuth::NO_ERROR: + { + QMessageBox::information(this, tr("Message"), tr("Permission granted.")); + m_ui.sessionLineEdit_lastfm->setText(m_lastfmAuth->session()); + break; + } + case LastfmAuth::NETWORK_ERROR: + QMessageBox::warning(this, tr("Error"), tr("Network error.")); + break; + case LastfmAuth::LASTFM_ERROR: + default: + QMessageBox::warning(this, tr("Error"), tr("Permission denied.")); + } +} diff --git a/src/plugins/General/scrobbler/settingsdialog.h b/src/plugins/General/scrobbler/settingsdialog.h index 182ef1cfe..41f81c73a 100644 --- a/src/plugins/General/scrobbler/settingsdialog.h +++ b/src/plugins/General/scrobbler/settingsdialog.h @@ -43,6 +43,8 @@ private slots: void on_newSessionButton_lastfm_clicked(); void processTokenResponse(int error); void processSessionResponse(int error); + void on_checkButton_lastfm_clicked(); + void processCheckResponse(int error); private: Ui::SettingsDialog m_ui; diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_cs.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_cs.ts index b17abc378..6068ac083 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_cs.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_cs.ts @@ -67,50 +67,64 @@ Libre.fm - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_de.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_de.ts index 2f56a1cc3..72be3396d 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_de.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_de.ts @@ -67,50 +67,64 @@ Libre.fm - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_es.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_es.ts index 9b64ebb9b..c7a8d924e 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_es.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_es.ts @@ -67,50 +67,64 @@ Libre.fm - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_fr.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_fr.ts index bbd3fc1fe..ceec52c98 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_fr.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_fr.ts @@ -67,50 +67,64 @@ - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_he.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_he.ts index 58899a1e2..d1a878379 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_he.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_he.ts @@ -67,50 +67,64 @@ סיסמה: - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_hu.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_hu.ts index af8701b82..a3eef8444 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_hu.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_hu.ts @@ -67,50 +67,64 @@ - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_it.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_it.ts index d01e36acd..4e92de1ad 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_it.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_it.ts @@ -67,50 +67,64 @@ Libre.fm - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_ja.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_ja.ts index f1b00167f..f87591793 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_ja.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_ja.ts @@ -67,50 +67,64 @@ Libre.fm - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_kk.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_kk.ts index 168e9af30..eea2e1638 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_kk.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_kk.ts @@ -67,50 +67,64 @@ - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_lt.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_lt.ts index 40f010a8a..f566cc009 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_lt.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_lt.ts @@ -67,50 +67,64 @@ Libre.fm - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_nl.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_nl.ts index 35b8cad4e..95a409870 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_nl.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_nl.ts @@ -67,50 +67,64 @@ - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_pl_PL.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_pl_PL.ts index 0a6d44800..7c81fd8c9 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_pl_PL.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_pl_PL.ts @@ -67,50 +67,64 @@ - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_pt_BR.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_pt_BR.ts index 2f2bfca98..73e539a09 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_pt_BR.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_pt_BR.ts @@ -67,50 +67,64 @@ - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_ru.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_ru.ts index ec535de4e..5e7d0d653 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_ru.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_ru.ts @@ -67,50 +67,64 @@ - - + + + Message Сообщение - + 1. Wait for browser startup. 1. Подождите, пока запустится браузер. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. 2. Разрешите доступ Qmmp к вашей учётной записи на Last.fm. - + 3. Press "OK". 3. Нажмите "OK". - - - + + + + + Error Ошибка - - + + + Network error. Ошибка соединения. - - + + Unable to register new session. Невозможно зарегистрировать новую сессию. - + New session has been received successfully. Новая сессия успешно получена. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_sk.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_sk.ts index 2a2422a58..91f8f9385 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_sk.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_sk.ts @@ -67,50 +67,64 @@ - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_tr.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_tr.ts index 9043e17b8..69317ac41 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_tr.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_tr.ts @@ -67,50 +67,64 @@ Libre.fm - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_uk_UA.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_uk_UA.ts index 8cf0f2a47..36d7f43d5 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_uk_UA.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_uk_UA.ts @@ -67,50 +67,64 @@ Libre.fm - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_zh_CN.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_zh_CN.ts index a37c06438..23cea77ce 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_zh_CN.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_zh_CN.ts @@ -67,50 +67,64 @@ Libre.fm - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + diff --git a/src/plugins/General/scrobbler/translations/scrobbler_plugin_zh_TW.ts b/src/plugins/General/scrobbler/translations/scrobbler_plugin_zh_TW.ts index bb3631cde..3a598b96a 100644 --- a/src/plugins/General/scrobbler/translations/scrobbler_plugin_zh_TW.ts +++ b/src/plugins/General/scrobbler/translations/scrobbler_plugin_zh_TW.ts @@ -67,50 +67,64 @@ Libre.fm - - + + + Message - + 1. Wait for browser startup. - + 2. Allow Qmmp to scrobble tracks to your Last.fm account. - + 3. Press "OK". - - - + + + + + Error - - + + + Network error. - - + + Unable to register new session. - + New session has been received successfully. + + + Permission granted. + + + + + Permission denied. + + -- cgit v1.2.3-13-gbd6f