Changeset View
Changeset View
Standalone View
Standalone View
scrobbler.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU General Public License along with | 14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "scrobbler.h" | 18 | #include "scrobbler.h" | ||
19 | 19 | | |||
20 | #include <QCryptographicHash> | 20 | #include <QCryptographicHash> | ||
21 | #include <QDir> | 21 | #include <QDir> | ||
22 | #include <QNetworkAccessManager> | | |||
23 | #include <QNetworkRequest> | 22 | #include <QNetworkRequest> | ||
24 | #include <QNetworkReply> | 23 | #include <QNetworkReply> | ||
25 | #include <QDomDocument> | 24 | #include <QDomDocument> | ||
26 | #include <QByteArray> | 25 | #include <QByteArray> | ||
27 | #include <QUrl> | 26 | #include <QUrl> | ||
28 | #include <QUrlQuery> | 27 | #include <QUrlQuery> | ||
29 | 28 | | |||
30 | #include <kconfiggroup.h> | 29 | #include <kconfiggroup.h> | ||
31 | #include <KSharedConfig> | 30 | #include <KSharedConfig> | ||
32 | 31 | | |||
33 | #include <memory> | 32 | #include <memory> | ||
34 | 33 | | |||
35 | #include "tag.h" | 34 | #include "tag.h" | ||
36 | #include "juk.h" | 35 | #include "juk.h" | ||
37 | #include "juk_debug.h" | 36 | #include "juk_debug.h" | ||
38 | 37 | | |||
39 | Scrobbler::Scrobbler(QObject* parent) | 38 | Scrobbler::Scrobbler(QObject* parent) | ||
40 | : QObject(parent) | 39 | : QObject(parent) | ||
41 | , m_networkAccessManager(nullptr) | 40 | , m_networkAccessManager(new QNetworkAccessManager(this)) | ||
42 | , m_wallet(Scrobbler::openKWallet()) | 41 | , m_wallet(Scrobbler::openKWallet()) | ||
43 | { | 42 | { | ||
44 | QByteArray sessionKey; | 43 | QByteArray sessionKey; | ||
45 | 44 | | |||
46 | if (m_wallet) { | 45 | if (m_wallet) { | ||
47 | m_wallet->readEntry("SessionKey", sessionKey); | 46 | m_wallet->readEntry("SessionKey", sessionKey); | ||
48 | } else { | 47 | } else { | ||
49 | KConfigGroup config(KSharedConfig::openConfig(), "Scrobbling"); | 48 | KConfigGroup config(KSharedConfig::openConfig(), "Scrobbling"); | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 131 | { | |||
145 | 144 | | |||
146 | QUrlQuery urlQuery; | 145 | QUrlQuery urlQuery; | ||
147 | foreach(QString key, params.keys()) { | 146 | foreach(QString key, params.keys()) { | ||
148 | urlQuery.addQueryItem(key, params[key]); | 147 | urlQuery.addQueryItem(key, params[key]); | ||
149 | } | 148 | } | ||
150 | 149 | | |||
151 | url.setQuery(urlQuery); | 150 | url.setQuery(urlQuery); | ||
152 | 151 | | |||
153 | if (!m_networkAccessManager) | | |||
154 | m_networkAccessManager = new QNetworkAccessManager(this); | | |||
155 | | ||||
156 | QNetworkReply *reply = m_networkAccessManager->get(QNetworkRequest(url)); | 152 | QNetworkReply *reply = m_networkAccessManager->get(QNetworkRequest(url)); | ||
157 | connect(reply, SIGNAL(finished()), this, SLOT(handleAuthenticationReply())); | 153 | connect(reply, SIGNAL(finished()), this, SLOT(handleAuthenticationReply())); | ||
158 | } | 154 | } | ||
159 | 155 | | |||
160 | void Scrobbler::getAuthToken() | 156 | void Scrobbler::getAuthToken() | ||
161 | { | 157 | { | ||
162 | QString username, password; | 158 | QString username, password; | ||
163 | 159 | | |||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Line(s) | 259 | { | |||
300 | params["duration"] = QString::number(m_file.tag()->seconds()); | 296 | params["duration"] = QString::number(m_file.tag()->seconds()); | ||
301 | 297 | | |||
302 | sign(params); | 298 | sign(params); | ||
303 | post(params); | 299 | post(params); | ||
304 | } | 300 | } | ||
305 | 301 | | |||
306 | void Scrobbler::post(QMap<QString, QString> ¶ms) | 302 | void Scrobbler::post(QMap<QString, QString> ¶ms) | ||
307 | { | 303 | { | ||
308 | if(!m_networkAccessManager) { | | |||
309 | return; | | |||
310 | } | | |||
311 | | ||||
312 | QUrl url("http://ws.audioscrobbler.com/2.0/"); | 304 | QUrl url("http://ws.audioscrobbler.com/2.0/"); | ||
313 | 305 | | |||
314 | QByteArray data; | 306 | QByteArray data; | ||
315 | foreach(QString key, params.keys()) { | 307 | foreach(QString key, params.keys()) { | ||
316 | data += QUrl::toPercentEncoding(key) + '=' + QUrl::toPercentEncoding(params[key]) + '&'; | 308 | data += QUrl::toPercentEncoding(key) + '=' + QUrl::toPercentEncoding(params[key]) + '&'; | ||
317 | } | 309 | } | ||
318 | 310 | | |||
319 | QNetworkRequest req(url); | 311 | QNetworkRequest req(url); | ||
Show All 12 Lines |