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

134 lines
3.8 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;
2017-08-24 20:32:14 +02:00
class NetworkAccessManager;
class QAction;
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
2017-08-24 20:32:14 +02:00
void Authenticate();
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);
void CacheSong(int scrobble_point);
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:
2017-08-24 20:32:14 +02:00
void AuthenticationComplete(bool success);
2009-12-29 21:48:50 +01:00
void ScrobblingEnabledChanged(bool value);
void ButtonVisibilityChanged(bool value);
void ScrobbleButtonVisibilityChanged(bool value);
void PreferAlbumArtistChanged(bool value);
void CachedToScrobble();
2012-06-25 12:30:53 +02:00
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:
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_cached_to_scrobble_{false};
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_;
2017-08-24 20:32:14 +02:00
std::unique_ptr<NetworkAccessManager> network_;
};
2014-12-18 23:54:21 +01:00
#endif // INTERNET_LASTFM_LASTFMSERVICE_H_