File indexing completed on 2023-05-30 11:30:51
0001 /** 0002 * Copyright (C) 2012 Martin Sandsmark <martin.sandsmark@kde.org> 0003 * Copyright (C) 2014 Arnold Dumas <contact@arnolddumas.fr> 0004 * 0005 * This program is free software; you can redistribute it and/or modify it under 0006 * the terms of the GNU General Public License as published by the Free Software 0007 * Foundation; either version 2 of the License, or (at your option) any later 0008 * version. 0009 * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License along with 0015 * this program. If not, see <http://www.gnu.org/licenses/>. 0016 */ 0017 0018 #ifndef JUK_SCROBBLER_H 0019 #define JUK_SCROBBLER_H 0020 0021 #include <QObject> 0022 #include <QMap> 0023 #include <QNetworkAccessManager> 0024 #include <QDateTime> 0025 0026 #include <KWallet> 0027 0028 #include <memory> 0029 0030 #include "filehandle.h" 0031 0032 using namespace KWallet; 0033 0034 class QByteArray; 0035 class QNetworkAccessManager; 0036 0037 /** 0038 * A class that handles scrobbling of tracks to last.fm 0039 */ 0040 class Scrobbler : public QObject { 0041 Q_OBJECT 0042 0043 public: 0044 explicit Scrobbler(QObject* parent = nullptr); 0045 0046 static bool isScrobblingEnabled(); 0047 static std::unique_ptr<Wallet> openKWallet(); 0048 0049 public slots: 0050 void nowPlaying(const FileHandle&); 0051 void scrobble(); 0052 void getAuthToken(QString username, QString password); 0053 0054 private slots: 0055 void handleAuthenticationReply(); 0056 void handleResults(); 0057 void getAuthToken(); 0058 0059 signals: 0060 void invalidAuth(); 0061 void validAuth(); 0062 0063 private: 0064 void sign(QMap<QString, QString> &request); 0065 void post(QMap<QString, QString> &request); 0066 QByteArray md5(QByteArray data); 0067 0068 QDateTime m_playbackTimer; 0069 FileHandle m_file; 0070 0071 std::unique_ptr<QNetworkAccessManager> m_networkAccessManager; 0072 std::unique_ptr<Wallet> m_wallet; 0073 }; 0074 0075 #endif /* JUK_SCROBBLER_H */