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

164 lines
3.9 KiB
C
Raw Normal View History

#ifndef LASTFMSERVICE_H
#define LASTFMSERVICE_H
namespace lastfm {
class RadioStation;
class Track;
}
#include <QtGlobal>
uint qHash(const lastfm::Track& track);
#include <lastfm/Track>
#include <lastfm/ws.h>
#include "radioservice.h"
2009-12-29 20:22:02 +01:00
#include "song.h"
2010-03-02 13:30:14 +01:00
#include "lastfmconfigdialog.h"
2009-12-30 03:15:38 +01:00
#include "lastfmstationdialog.h"
#include <QMap>
2010-03-02 13:30:14 +01:00
#include <QMenu>
#include <QNetworkAccessManager>
#include <QQueue>
2009-12-26 22:35:45 +01:00
2010-03-02 13:30:14 +01:00
#include <boost/scoped_ptr.hpp>
2009-12-30 00:01:07 +01:00
2010-03-02 13:30:14 +01:00
class QAction;
2009-12-26 18:19:14 +01:00
class LastFMService : public RadioService {
2009-12-26 18:19:14 +01:00
Q_OBJECT
public:
LastFMService(QObject* parent = 0);
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;
enum ItemType {
Type_MyRecommendations = 1000,
Type_MyRadio,
Type_MyLoved,
Type_MyNeighbourhood,
2009-12-30 01:31:00 +01:00
Type_ArtistRadio,
Type_TagRadio,
Type_MyFriends,
Type_MyNeighbours,
Type_OtherUser,
Type_OtherUserRadio,
Type_OtherUserLoved,
Type_OtherUserNeighbourhood,
2009-12-30 03:15:38 +01:00
Type_Artist,
Type_Tag,
};
2009-12-26 22:35:45 +01:00
// RadioService
RadioItem* CreateRootItem(RadioItem* parent);
void LazyPopulate(RadioItem *item);
2009-12-30 00:17:54 +01:00
QUrl UrlForItem(const RadioItem* item) const;
QString TitleForItem(const RadioItem* item) const;
2009-12-30 00:01:07 +01:00
void ShowContextMenu(RadioItem *item, const QPoint &global_pos);
2009-12-30 00:17:54 +01:00
2009-12-26 22:35:45 +01:00
void StartLoading(const QUrl& url);
void LoadNext(const QUrl& url);
2009-12-30 00:17:54 +01:00
2009-12-29 17:12:08 +01:00
bool IsPauseAllowed() const { return false; }
bool ShowLastFmControls() const { return true; }
2010-02-03 19:32:48 +01:00
void ReloadSettings();
2009-12-30 00:17:54 +01:00
// Last.fm specific stuff
2009-12-29 20:22:02 +01:00
bool IsAuthenticated() const;
2009-12-29 21:48:50 +01:00
bool IsScrobblingEnabled() const { return scrobbling_enabled_; }
2009-12-26 18:19:14 +01:00
2009-12-30 01:31:00 +01:00
void Authenticate(const QString& username, const QString& password);
2009-12-29 21:48:50 +01:00
void FetchMoreTracks();
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();
2009-12-29 20:22:02 +01:00
2009-12-26 18:19:14 +01:00
signals:
void AuthenticationComplete(bool success);
2009-12-29 21:48:50 +01:00
void ScrobblingEnabledChanged(bool value);
2009-12-26 18:19:14 +01:00
private slots:
void AuthenticateReplyFinished();
2009-12-30 01:31:00 +01:00
void RefreshFriendsFinished();
void RefreshNeighboursFinished();
2010-02-03 19:32:48 +01:00
void ShowConfig();
2009-12-26 18:19:14 +01:00
2009-12-26 22:35:45 +01:00
void TunerTrackAvailable();
void TunerError(lastfm::ws::Error error);
2009-12-30 02:41:37 +01:00
void AddToPlaylist();
2009-12-30 03:15:38 +01:00
void AddArtistRadio();
void AddTagRadio();
void Remove();
2009-12-30 02:41:37 +01:00
// Radio tuner.
void FetchMoreTracksFinished();
void TuneFinished();
void StreamMetadataReady();
private:
RadioItem* CreateStationItem(ItemType type, const QString& name,
const QString& icon, RadioItem* parent);
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;
2009-12-30 01:31:00 +01:00
void RefreshFriends();
void RefreshNeighbours();
2009-12-30 03:15:38 +01:00
void AddArtistOrTag(const QString& name,
LastFMStationDialog::Type dialog_type, ItemType item_type,
const QIcon& icon, RadioItem* list);
void SaveList(const QString& name, RadioItem* list) const;
void RestoreList(const QString &name, ItemType item_type,
const QIcon& icon, RadioItem *list);
2009-12-26 18:19:14 +01:00
void Tune(const lastfm::RadioStation& station);
void FetchImage(const lastfm::Track& track, const QString& image_url);
QImage GetImageForTrack(const lastfm::Track& track);
2009-12-26 18:19:14 +01:00
private:
2009-12-29 20:22:02 +01:00
lastfm::Audioscrobbler* scrobbler_;
lastfm::Track last_track_;
lastfm::Track next_metadata_;
QQueue<lastfm::Track> playlist_;
2010-03-02 13:30:14 +01:00
boost::scoped_ptr<LastFMConfigDialog> config_;
boost::scoped_ptr<LastFMStationDialog> station_dialog_;
2009-12-30 02:41:37 +01:00
2010-03-02 13:30:14 +01:00
boost::scoped_ptr<QMenu> context_menu_;
2009-12-30 02:41:37 +01:00
QAction* play_action_;
2009-12-30 03:15:38 +01:00
QAction* remove_action_;
QAction* add_artist_action_;
QAction* add_tag_action_;
2009-12-30 02:41:37 +01:00
RadioItem* context_item_;
2009-12-30 00:01:07 +01:00
2009-12-26 22:35:45 +01:00
QUrl last_url_;
bool initial_tune_;
2009-12-29 21:48:50 +01:00
bool scrobbling_enabled_;
2009-12-30 01:31:00 +01:00
2009-12-30 03:15:38 +01:00
RadioItem* artist_list_;
RadioItem* tag_list_;
2009-12-30 01:31:00 +01:00
RadioItem* friends_list_;
RadioItem* neighbours_list_;
QNetworkAccessManager network_;
QHash<lastfm::Track, QNetworkReply*> image_requests_;
};
#endif // LASTFMSERVICE_H