scrobbler.h 1.86 KB
Newer Older
1 2
/**
 * Copyright (C) 2012 Martin Sandsmark <martin.sandsmark@kde.org>
3
 * Copyright (C) 2014 Arnold Dumas <contact@arnolddumas.fr>
4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
17

18 19
#ifndef JUK_SCROBBLER_H
#define JUK_SCROBBLER_H
20 21 22

#include <QObject>
#include <QMap>
23
#include <QDateTime>
24

Michael Pyne's avatar
Michael Pyne committed
25
#include <KWallet>
26

27 28
#include <memory>

29 30
#include "filehandle.h"

31 32
using namespace KWallet;

33 34 35
class QByteArray;
class QNetworkAccessManager;

36 37 38 39 40
/**
 * A class that handles scrobbling of tracks to last.fm
 */
class Scrobbler : public QObject {
    Q_OBJECT
41

42
public:
43
    explicit Scrobbler(QObject* parent = nullptr);
44

45
    static bool isScrobblingEnabled();
46
    static std::unique_ptr<Wallet> openKWallet();
47

48 49 50
public slots:
    void nowPlaying(const FileHandle&);
    void scrobble();
51
    void getAuthToken(QString username, QString password);
52

53 54 55
private slots:
    void handleAuthenticationReply();
    void handleResults();
56
    void getAuthToken();
57

58 59 60
signals:
    void invalidAuth();
    void validAuth();
61

62 63 64 65
private:
    void sign(QMap<QString, QString> &request);
    void post(QMap<QString, QString> &request);
    QByteArray md5(QByteArray data);
66

67
    QDateTime m_playbackTimer;
68 69
    FileHandle m_file;
    QNetworkAccessManager *m_networkAccessManager;
70

71
    std::unique_ptr<Wallet> m_wallet;
72 73
};

74
#endif /* JUK_SCROBBLER_H */