Clementine-audio-player-Mac.../src/internet/lastfm/lastfmservice.h

135 lines
3.9 KiB
C
Raw Normal View History

/* This file is part of Clementine.
Copyright 2009-2013, David Sansome <me@davidsansome.com>
Copyright 2010-2012, 2014, John Maguire <john.maguire@gmail.com>
Copyright 2011, Andrea Decorte <adecorte@gmail.com>
Copyright 2012, Kacper "mattrick" Banasik <mattrick@jabster.pl>
Copyright 2012, Harald Sitter <sitter@kde.org>
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
Clementine 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 3 of the License, or
(at your option) any later version.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
2014-12-18 23:54:21 +01:00
#ifndef INTERNET_LASTFM_LASTFMSERVICE_H_
#define INTERNET_LASTFM_LASTFMSERVICE_H_
#include <memory>
namespace lastfm {
class Track;
}
#include <QtGlobal>
uint qHash(const lastfm::Track& track);
#include "lastfmcompat.h"
#include "internet/core/scrobbler.h"
2009-12-26 22:35:45 +01:00
class Application;
class LastFMUrlHandler;
class QAction;
class QNetworkAccessManager;
class Song;
2009-12-26 18:19:14 +01:00
class LastFMService : public Scrobbler {
2009-12-26 18:19:14 +01:00
Q_OBJECT
public:
explicit LastFMService(Application* app, QObject* parent = nullptr);
2009-12-26 18:19:14 +01:00
~LastFMService();
2009-12-29 20:22:02 +01:00
static const char* kServiceName;
2009-12-26 18:19:14 +01:00
static const char* kSettingsGroup;
2009-12-29 20:22:02 +01:00
static const char* kAudioscrobblerClientId;
static const char* kApiKey;
static const char* kSecret;
static const char* kAuthLoginUrl;
2010-02-03 19:32:48 +01:00
void ReloadSettings();
virtual QString Icon() { return ":last.fm/lastfm.png"; }
2009-12-30 00:17:54 +01:00
// Last.fm specific stuff
2009-12-29 20:22:02 +01:00
bool IsAuthenticated() const;
bool IsSubscriber() const;
2009-12-29 21:48:50 +01:00
bool IsScrobblingEnabled() const { return scrobbling_enabled_; }
bool AreButtonsVisible() const { return buttons_visible_; }
bool IsScrobbleButtonVisible() const { return scrobble_button_visible_; }
bool PreferAlbumArtist() const { return prefer_albumartist_; }
bool HasConnectionProblems() const { return connection_problems_; }
2009-12-26 18:19:14 +01:00
void GetToken();
void Authenticate(const QString& token);
void SignOut();
void UpdateSubscriberStatus();
2009-12-29 21:48:50 +01:00
public slots:
2009-12-30 01:31:00 +01:00
void NowPlaying(const Song& song);
2009-12-29 21:11:03 +01:00
void Scrobble();
void Love();
void Ban();
void ShowConfig();
void ToggleScrobbling();
2009-12-29 20:22:02 +01:00
2016-02-04 18:13:01 +01:00
signals:
void TokenReceived(bool success, const QString& token);
void AuthenticationComplete(bool success, const QString& error_message);
2009-12-29 21:48:50 +01:00
void ScrobblingEnabledChanged(bool value);
void ButtonVisibilityChanged(bool value);
void ScrobbleButtonVisibilityChanged(bool value);
void PreferAlbumArtistChanged(bool value);
2012-06-25 12:30:53 +02:00
void ScrobbleSubmitted();
void ScrobbleError(int value);
void UpdatedSubscriberStatus(bool is_subscriber);
void ScrobbledRadioStream();
2009-12-26 18:19:14 +01:00
2011-09-24 18:01:18 +02:00
void SavedItemsChanged();
2009-12-26 18:19:14 +01:00
private slots:
void GetTokenReplyFinished(QNetworkReply* reply);
2012-10-12 14:31:31 +02:00
void AuthenticateReplyFinished(QNetworkReply* reply);
void UpdateSubscriberStatusFinished(QNetworkReply* reply);
2009-12-26 18:19:14 +01:00
void ScrobblerStatus(int value);
2009-12-26 22:35:45 +01:00
private:
2009-12-26 22:35:45 +01:00
QString ErrorString(lastfm::ws::Error error) const;
2009-12-29 20:22:02 +01:00
bool InitScrobbler();
lastfm::Track TrackFromSong(const Song& song) const;
static QUrl FixupUrl(const QUrl& url);
2009-12-26 18:19:14 +01:00
private:
2016-02-04 18:13:01 +01:00
std::unique_ptr<lastfm::Audioscrobbler> scrobbler_;
2009-12-29 20:22:02 +01:00
lastfm::Track last_track_;
lastfm::Track next_metadata_;
bool already_scrobbled_;
2009-12-26 22:35:45 +01:00
QUrl last_url_;
2009-12-29 21:48:50 +01:00
bool scrobbling_enabled_;
bool buttons_visible_;
bool scrobble_button_visible_;
bool prefer_albumartist_;
2009-12-30 01:31:00 +01:00
QHash<lastfm::Track, QString> art_urls_;
// Useful to inform the user that we can't scrobble right now
bool connection_problems_;
Application* app_;
};
2014-12-18 23:54:21 +01:00
#endif // INTERNET_LASTFM_LASTFMSERVICE_H_