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

203 lines
5.3 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
namespace lastfm {
class RadioStation;
class Track;
}
#include <QtGlobal>
uint qHash(const lastfm::Track& track);
2010-03-23 15:07:05 +01:00
#include "fixlastfm.h"
#include <lastfm/Track>
#include <lastfm/ws.h>
#include "radiomodel.h"
#include "radioservice.h"
2009-12-30 03:15:38 +01:00
#include "lastfmstationdialog.h"
#include "core/song.h"
#include "playlist/playlistitem.h"
#include <QMap>
2010-03-02 13:30:14 +01:00
#include <QMenu>
#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;
class QNetworkAccessManager;
2009-12-26 18:19:14 +01:00
class LastFMService : public RadioService {
2009-12-26 18:19:14 +01:00
Q_OBJECT
public:
LastFMService(RadioModel* 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;
enum ItemType {
Type_Root = RadioModel::TypeCount,
Type_Artists,
Type_Tags,
Type_Custom,
Type_Friends,
Type_Neighbours,
Type_OtherUser,
};
2009-12-26 22:35:45 +01:00
// RadioService
QStandardItem* CreateRootItem();
void LazyPopulate(QStandardItem* parent);
2009-12-30 00:17:54 +01:00
void ShowContextMenu(const QModelIndex& index, const QPoint &global_pos);
2009-12-30 00:17:54 +01:00
PlaylistItem::SpecialLoadResult StartLoading(const QUrl& url);
PlaylistItem::SpecialLoadResult LoadNext(const QUrl& url);
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;
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_; }
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();
2009-12-29 21:48:50 +01:00
void FetchMoreTracks();
PlaylistItemPtr PlaylistItemForUrl(const QUrl& url);
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
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);
void ButtonVisibilityChanged(bool value);
void ScrobbleButtonVisibilityChanged(bool value);
void ScrobblerStatus(int value);
2009-12-26 18:19:14 +01:00
protected:
QModelIndex GetCurrentIndex();
2009-12-26 18:19:14 +01:00
private slots:
void AuthenticateReplyFinished();
2009-12-30 01:31:00 +01:00
void RefreshFriendsFinished();
void RefreshNeighboursFinished();
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 03:15:38 +01:00
void AddArtistRadio();
void AddTagRadio();
void AddCustomRadio();
void Remove();
2009-12-30 02:41:37 +01:00
// Radio tuner.
void FetchMoreTracksFinished();
void TuneFinished();
void StreamMetadataReady();
private:
QStandardItem* CreateStationItem(QStandardItem* parent,
const QString& name, const QString& icon, const QString& 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;
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,
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 lastfm::RadioStation& station);
void AddSelectedToPlaylist(bool clear_first);
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<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 03:15:38 +01:00
QAction* remove_action_;
QAction* add_artist_action_;
QAction* add_tag_action_;
QAction* add_custom_action_;
QStandardItem* context_item_;
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_;
2009-12-30 01:31:00 +01:00
QStandardItem* artist_list_;
QStandardItem* tag_list_;
QStandardItem* custom_list_;
QStandardItem* friends_list_;
QStandardItem* neighbours_list_;
QHash<lastfm::Track, QString> art_urls_;
};
#endif // LASTFMSERVICE_H