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

233 lines
6.4 KiB
C
Raw Normal View History

/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.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/>.
*/
#ifndef LASTFMSERVICE_H
#define LASTFMSERVICE_H
#include <memory>
namespace lastfm {
class RadioStation;
class Track;
}
#include <QtGlobal>
uint qHash(const lastfm::Track& track);
#include "lastfmcompat.h"
#include "internetmodel.h"
#include "internetservice.h"
2009-12-30 03:15:38 +01:00
#include "lastfmstationdialog.h"
#include "core/cachedlist.h"
#include "core/song.h"
#include "playlist/playlistitem.h"
#include <QDateTime>
#include <QMap>
2010-03-02 13:30:14 +01:00
#include <QMenu>
#include <QQueue>
2009-12-26 22:35:45 +01:00
class LastFMUrlHandler;
class QAction;
class QNetworkAccessManager;
2009-12-26 18:19:14 +01:00
class LastFMService : public InternetService {
2009-12-26 18:19:14 +01:00
Q_OBJECT
friend class LastFMUrlHandler;
2009-12-26 18:19:14 +01:00
public:
LastFMService(Application* app, InternetModel* parent);
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* kUrlArtist;
static const char* kUrlTag;
static const char* kUrlCustom;
static const char* kTitleArtist;
static const char* kTitleTag;
static const char* kTitleCustom;
static const int kFriendsCacheDurationSecs;
enum ItemType {
Type_Root = InternetModel::TypeCount,
Type_Artists,
Type_Tags,
Type_Custom,
Type_Friends,
Type_Neighbours,
Type_OtherUser,
};
// InternetService
QStandardItem* CreateRootItem();
void LazyPopulate(QStandardItem* parent);
2009-12-30 00:17:54 +01:00
void ShowContextMenu(const QPoint& global_pos);
2009-12-30 00:17:54 +01:00
PlaylistItem::Options playlistitem_options() const;
2009-12-29 17:12:08 +01:00
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
2009-12-30 01:31:00 +01:00
void Authenticate(const QString& username, const QString& password);
void SignOut();
void UpdateSubscriberStatus();
2009-12-29 21:48:50 +01:00
void FetchMoreTracks();
QUrl DeququeNextMediaUrl();
PlaylistItemPtr PlaylistItemForUrl(const QUrl& url);
bool IsFriendsListStale() const { return friend_names_.IsStale(); }
2011-09-24 18:01:18 +02:00
// Thread safe
QStringList FriendNames();
QStringList SavedArtistRadioNames() const;
QStringList SavedTagRadioNames() const;
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
signals:
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:
2012-10-12 14:31:31 +02:00
void AuthenticateReplyFinished(QNetworkReply* reply);
void UpdateSubscriberStatusFinished(QNetworkReply* reply);
void RefreshFriendsFinished(QNetworkReply* reply);
void RefreshNeighboursFinished(QNetworkReply* reply);
2009-12-26 18:19:14 +01:00
2009-12-26 22:35:45 +01:00
void TunerTrackAvailable();
void TunerError(lastfm::ws::Error error);
void ScrobblerStatus(int value);
2009-12-26 22:35:45 +01:00
2009-12-30 03:15:38 +01:00
void AddArtistRadio();
void AddTagRadio();
void AddCustomRadio();
void ForceRefreshFriends();
2011-09-24 18:01:18 +02:00
void RefreshFriends();
void Remove();
2009-12-30 02:41:37 +01:00
// Radio tuner.
2012-10-12 14:31:31 +02:00
void FetchMoreTracksFinished(QNetworkReply* reply);
void TuneFinished(QNetworkReply* reply);
void StreamMetadataReady();
private:
QStandardItem* CreateStationItem(QStandardItem* parent, const QString& name,
const QString& icon, const QUrl& url,
const QString& title);
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;
void RefreshFriends(bool force);
2009-12-30 01:31:00 +01:00
void RefreshNeighbours();
2009-12-30 03:15:38 +01:00
void AddArtistOrTag(const QString& name,
LastFMStationDialog::Type dialog_type,
const QString& url_pattern, const QString& title_pattern,
const QString& icon, QStandardItem* list);
void SaveList(const QString& name, QStandardItem* list) const;
void RestoreList(const QString& name, const QString& url_pattern,
const QString& title_pattern, const QIcon& icon,
QStandardItem* parent);
static QUrl FixupUrl(const QUrl& url);
void Tune(const QUrl& station);
void PopulateFriendsList();
void AddSelectedToPlaylist(bool clear_first);
2009-12-26 18:19:14 +01:00
private:
LastFMUrlHandler* url_handler_;
2009-12-29 20:22:02 +01:00
lastfm::Audioscrobbler* scrobbler_;
lastfm::Track last_track_;
lastfm::Track next_metadata_;
QQueue<lastfm::Track> playlist_;
bool already_scrobbled_;
std::unique_ptr<LastFMStationDialog> station_dialog_;
2009-12-30 02:41:37 +01:00
std::unique_ptr<QMenu> context_menu_;
2009-12-30 03:15:38 +01:00
QAction* remove_action_;
QAction* add_artist_action_;
QAction* add_tag_action_;
QAction* add_custom_action_;
QAction* refresh_friends_action_;
2009-12-30 00:01:07 +01:00
2009-12-26 22:35:45 +01:00
QUrl last_url_;
bool initial_tune_;
int tune_task_id_;
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
2011-09-24 18:01:18 +02:00
QStandardItem* root_item_;
QStandardItem* artist_list_;
QStandardItem* tag_list_;
QStandardItem* custom_list_;
QStandardItem* friends_list_;
QStandardItem* neighbours_list_;
QHash<lastfm::Track, QString> art_urls_;
CachedList<QString> friend_names_;
// Useful to inform the user that we can't scrobble right now
bool connection_problems_;
};
#endif // LASTFMSERVICE_H