2009-12-26 16:13:38 +01:00
|
|
|
#ifndef LASTFMSERVICE_H
|
|
|
|
#define LASTFMSERVICE_H
|
|
|
|
|
2010-02-25 01:18:32 +01:00
|
|
|
namespace lastfm {
|
|
|
|
class RadioStation;
|
|
|
|
class Track;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
uint qHash(const lastfm::Track& track);
|
|
|
|
|
|
|
|
#include <lastfm/Track>
|
|
|
|
#include <lastfm/ws.h>
|
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
#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"
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2010-02-25 01:18:32 +01:00
|
|
|
#include <QMap>
|
2010-03-02 13:30:14 +01:00
|
|
|
#include <QMenu>
|
2010-02-25 01:18:32 +01:00
|
|
|
#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
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
class LastFMService : public RadioService {
|
2009-12-26 18:19:14 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
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;
|
2009-12-26 16:13:38 +01:00
|
|
|
|
|
|
|
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,
|
2009-12-30 02:29:47 +01:00
|
|
|
Type_OtherUser,
|
|
|
|
Type_OtherUserRadio,
|
|
|
|
Type_OtherUserLoved,
|
|
|
|
Type_OtherUserNeighbourhood,
|
2009-12-30 03:15:38 +01:00
|
|
|
Type_Artist,
|
|
|
|
Type_Tag,
|
2009-12-26 16:13:38 +01:00
|
|
|
};
|
|
|
|
|
2009-12-26 22:35:45 +01:00
|
|
|
// RadioService
|
2009-12-26 16:13:38 +01:00
|
|
|
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);
|
2009-12-26 23:59:11 +01:00
|
|
|
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
|
|
|
|
2010-02-25 01:18:32 +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();
|
2009-12-30 03:23:09 +01:00
|
|
|
void Remove();
|
2009-12-30 02:41:37 +01:00
|
|
|
|
2010-02-25 01:18:32 +01:00
|
|
|
// Radio tuner.
|
|
|
|
void FetchMoreTracksFinished();
|
|
|
|
void TuneFinished();
|
|
|
|
|
2010-02-26 15:50:02 +01:00
|
|
|
void StreamMetadataReady();
|
2010-02-25 01:18:32 +01:00
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
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
|
|
|
|
2010-02-25 01:18:32 +01:00
|
|
|
void Tune(const lastfm::RadioStation& station);
|
2010-02-26 15:50:02 +01:00
|
|
|
void FetchImage(const lastfm::Track& track, const QString& image_url);
|
|
|
|
QImage GetImageForTrack(const lastfm::Track& track);
|
2010-02-25 01:18:32 +01:00
|
|
|
|
2009-12-26 18:19:14 +01:00
|
|
|
private:
|
2009-12-29 20:22:02 +01:00
|
|
|
lastfm::Audioscrobbler* scrobbler_;
|
|
|
|
lastfm::Track last_track_;
|
2010-02-26 15:50:02 +01:00
|
|
|
lastfm::Track next_metadata_;
|
|
|
|
QQueue<lastfm::Track> playlist_;
|
2010-02-25 01:18:32 +01:00
|
|
|
|
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_;
|
2009-12-26 23:59:11 +01:00
|
|
|
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_;
|
2010-02-25 01:18:32 +01:00
|
|
|
|
|
|
|
QNetworkAccessManager network_;
|
2010-02-26 15:50:02 +01:00
|
|
|
QHash<lastfm::Track, QNetworkReply*> image_requests_;
|
2009-12-26 16:13:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LASTFMSERVICE_H
|