2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2014-12-17 19:02:21 +01:00
|
|
|
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>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
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_
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2010-02-25 01:18:32 +01:00
|
|
|
namespace lastfm {
|
|
|
|
class Track;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
uint qHash(const lastfm::Track& track);
|
|
|
|
|
2012-06-28 18:41:51 +02:00
|
|
|
#include "lastfmcompat.h"
|
2010-02-25 01:18:32 +01:00
|
|
|
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/core/scrobbler.h"
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2014-03-27 18:55:58 +01:00
|
|
|
class Application;
|
2011-04-28 17:10:28 +02:00
|
|
|
class LastFMUrlHandler;
|
2017-08-24 20:32:14 +02:00
|
|
|
class NetworkAccessManager;
|
2011-04-28 17:10:28 +02:00
|
|
|
class QAction;
|
2014-03-27 18:55:58 +01:00
|
|
|
class Song;
|
2009-12-26 18:19:14 +01:00
|
|
|
|
2014-03-27 18:55:58 +01:00
|
|
|
class LastFMService : public Scrobbler {
|
2009-12-26 18:19:14 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
public:
|
2014-12-17 19:02:21 +01:00
|
|
|
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;
|
2016-02-03 15:33:46 +01:00
|
|
|
static const char* kAuthLoginUrl;
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2010-02-03 19:32:48 +01:00
|
|
|
void ReloadSettings();
|
|
|
|
|
2010-03-25 19:38:20 +01:00
|
|
|
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;
|
2011-04-13 17:54:15 +02:00
|
|
|
bool IsSubscriber() const;
|
2009-12-29 21:48:50 +01:00
|
|
|
bool IsScrobblingEnabled() const { return scrobbling_enabled_; }
|
2010-04-07 21:26:49 +02:00
|
|
|
bool AreButtonsVisible() const { return buttons_visible_; }
|
2011-04-07 18:25:52 +02:00
|
|
|
bool IsScrobbleButtonVisible() const { return scrobble_button_visible_; }
|
2012-05-13 17:04:55 +02:00
|
|
|
bool PreferAlbumArtist() const { return prefer_albumartist_; }
|
2011-04-28 12:32:56 +02:00
|
|
|
bool HasConnectionProblems() const { return connection_problems_; }
|
2009-12-26 18:19:14 +01:00
|
|
|
|
2017-08-24 20:32:14 +02:00
|
|
|
void Authenticate();
|
2010-04-07 21:26:49 +02:00
|
|
|
void SignOut();
|
2011-04-14 13:11:34 +02:00
|
|
|
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);
|
2014-01-18 23:13:23 +01:00
|
|
|
void CacheSong(int scrobble_point);
|
2009-12-29 21:11:03 +01:00
|
|
|
void Scrobble();
|
|
|
|
void Love();
|
|
|
|
void Ban();
|
2010-10-16 17:22:14 +02:00
|
|
|
void ShowConfig();
|
2011-04-07 18:25:52 +02:00
|
|
|
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);
|
2010-04-07 21:26:49 +02:00
|
|
|
void ButtonVisibilityChanged(bool value);
|
2011-04-07 18:25:52 +02:00
|
|
|
void ScrobbleButtonVisibilityChanged(bool value);
|
2012-05-13 17:04:55 +02:00
|
|
|
void PreferAlbumArtistChanged(bool value);
|
2014-01-18 23:13:23 +01:00
|
|
|
void CachedToScrobble();
|
2012-06-25 12:30:53 +02:00
|
|
|
void ScrobbleError(int value);
|
2011-04-14 13:11:34 +02:00
|
|
|
void UpdatedSubscriberStatus(bool is_subscriber);
|
2011-04-16 17:27:34 +02:00
|
|
|
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
|
|
|
|
2012-06-28 18:41:51 +02:00
|
|
|
void ScrobblerStatus(int value);
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2009-12-26 16:13:38 +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;
|
2011-01-09 19:27:41 +01:00
|
|
|
|
|
|
|
static QUrl FixupUrl(const QUrl& url);
|
2010-12-04 16:49:43 +01:00
|
|
|
|
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_;
|
2010-02-26 15:50:02 +01:00
|
|
|
lastfm::Track next_metadata_;
|
2014-01-18 23:13:23 +01:00
|
|
|
bool already_cached_to_scrobble_{false};
|
2010-02-25 01:18:32 +01:00
|
|
|
|
2009-12-26 22:35:45 +01:00
|
|
|
QUrl last_url_;
|
2009-12-29 21:48:50 +01:00
|
|
|
|
|
|
|
bool scrobbling_enabled_;
|
2010-04-07 21:26:49 +02:00
|
|
|
bool buttons_visible_;
|
2011-04-07 18:25:52 +02:00
|
|
|
bool scrobble_button_visible_;
|
2012-05-13 17:04:55 +02:00
|
|
|
bool prefer_albumartist_;
|
2009-12-30 01:31:00 +01:00
|
|
|
|
2010-05-17 00:46:56 +02:00
|
|
|
QHash<lastfm::Track, QString> art_urls_;
|
2011-04-28 12:32:56 +02:00
|
|
|
|
|
|
|
// Useful to inform the user that we can't scrobble right now
|
|
|
|
bool connection_problems_;
|
2014-03-27 18:55:58 +01:00
|
|
|
|
|
|
|
Application* app_;
|
2017-08-24 20:32:14 +02:00
|
|
|
std::unique_ptr<NetworkAccessManager> network_;
|
2009-12-26 16:13:38 +01:00
|
|
|
};
|
|
|
|
|
2014-12-18 23:54:21 +01:00
|
|
|
#endif // INTERNET_LASTFM_LASTFMSERVICE_H_
|