2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.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/>.
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
2010-03-23 15:07:05 +01:00
|
|
|
#include "fixlastfm.h"
|
2010-02-25 01:18:32 +01:00
|
|
|
#include <lastfm/Track>
|
|
|
|
#include <lastfm/ws.h>
|
|
|
|
|
2011-01-09 19:27:41 +01:00
|
|
|
#include "radiomodel.h"
|
2009-12-26 16:13:38 +01:00
|
|
|
#include "radioservice.h"
|
2009-12-30 03:15:38 +01:00
|
|
|
#include "lastfmstationdialog.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/song.h"
|
2010-10-16 17:22:14 +02:00
|
|
|
#include "playlist/playlistitem.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 <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
|
|
|
|
2011-04-28 17:10:28 +02:00
|
|
|
class LastFMUrlHandler;
|
2010-05-10 15:15:52 +02:00
|
|
|
|
2011-04-28 17:10:28 +02:00
|
|
|
class QAction;
|
2010-05-10 13:12:44 +02:00
|
|
|
class QNetworkAccessManager;
|
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
|
2011-04-28 17:10:28 +02:00
|
|
|
friend class LastFMUrlHandler;
|
2009-12-26 18:19:14 +01:00
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
public:
|
2010-05-09 17:51:04 +02:00
|
|
|
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;
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2011-01-09 19:27:41 +01:00
|
|
|
static const char* kUrlArtist;
|
|
|
|
static const char* kUrlTag;
|
|
|
|
static const char* kUrlCustom;
|
|
|
|
|
|
|
|
static const char* kTitleArtist;
|
|
|
|
static const char* kTitleTag;
|
|
|
|
static const char* kTitleCustom;
|
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
enum ItemType {
|
2011-01-09 19:27:41 +01:00
|
|
|
Type_Root = RadioModel::TypeCount,
|
|
|
|
Type_Artists,
|
|
|
|
Type_Tags,
|
2010-10-07 15:59:24 +02:00
|
|
|
Type_Custom,
|
2011-01-09 19:27:41 +01:00
|
|
|
Type_Friends,
|
|
|
|
Type_Neighbours,
|
|
|
|
Type_OtherUser,
|
2009-12-26 16:13:38 +01:00
|
|
|
};
|
|
|
|
|
2009-12-26 22:35:45 +01:00
|
|
|
// RadioService
|
2011-01-09 19:27:41 +01:00
|
|
|
QStandardItem* CreateRootItem();
|
|
|
|
void LazyPopulate(QStandardItem* parent);
|
2009-12-30 00:17:54 +01:00
|
|
|
|
2011-01-09 19:27:41 +01:00
|
|
|
void ShowContextMenu(const QModelIndex& index, const QPoint &global_pos);
|
2009-12-30 00:17:54 +01:00
|
|
|
|
2010-05-18 22:43:10 +02:00
|
|
|
PlaylistItem::Options playlistitem_options() const;
|
2009-12-29 17:12:08 +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_; }
|
2011-04-28 12:32:56 +02:00
|
|
|
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);
|
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
|
|
|
|
2010-02-25 01:18:32 +01:00
|
|
|
void FetchMoreTracks();
|
2011-04-28 17:10:28 +02:00
|
|
|
QUrl DeququeNextMediaUrl();
|
2010-02-25 01:18:32 +01:00
|
|
|
|
2010-10-16 17:22:14 +02:00
|
|
|
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();
|
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
|
|
|
|
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);
|
2010-04-07 21:26:49 +02:00
|
|
|
void ButtonVisibilityChanged(bool value);
|
2011-04-07 18:25:52 +02:00
|
|
|
void ScrobbleButtonVisibilityChanged(bool value);
|
|
|
|
void ScrobblerStatus(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-02-10 23:24:17 +01:00
|
|
|
protected:
|
|
|
|
QModelIndex GetCurrentIndex();
|
|
|
|
|
2009-12-26 18:19:14 +01:00
|
|
|
private slots:
|
|
|
|
void AuthenticateReplyFinished();
|
2011-04-14 13:11:34 +02:00
|
|
|
void UpdateSubscriberStatusFinished();
|
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();
|
2010-10-07 15:59:24 +02:00
|
|
|
void AddCustomRadio();
|
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:
|
2011-01-09 19:27:41 +01:00
|
|
|
QStandardItem* CreateStationItem(QStandardItem* parent,
|
2011-04-28 14:27:53 +02:00
|
|
|
const QString& name, const QString& icon, const QUrl& url,
|
2011-01-09 19:27:41 +01:00
|
|
|
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,
|
2011-01-09 19:27:41 +01:00
|
|
|
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);
|
2011-04-28 17:10:28 +02:00
|
|
|
void Tune(const QUrl& station);
|
2010-02-25 01:18:32 +01:00
|
|
|
|
2010-12-04 16:49:43 +01:00
|
|
|
void AddSelectedToPlaylist(bool clear_first);
|
|
|
|
|
2009-12-26 18:19:14 +01:00
|
|
|
private:
|
2011-04-28 17:10:28 +02:00
|
|
|
LastFMUrlHandler* url_handler_;
|
|
|
|
|
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_;
|
2011-04-16 17:27:41 +02:00
|
|
|
bool already_scrobbled_;
|
2010-02-25 01:18:32 +01:00
|
|
|
|
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_;
|
2010-10-07 15:59:24 +02:00
|
|
|
QAction* add_custom_action_;
|
2011-01-09 19:27:41 +01:00
|
|
|
QStandardItem* 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_;
|
2010-06-23 15:21:30 +02:00
|
|
|
int tune_task_id_;
|
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_;
|
2009-12-30 01:31:00 +01:00
|
|
|
|
2011-01-09 19:27:41 +01:00
|
|
|
QStandardItem* artist_list_;
|
|
|
|
QStandardItem* tag_list_;
|
|
|
|
QStandardItem* custom_list_;
|
|
|
|
QStandardItem* friends_list_;
|
|
|
|
QStandardItem* neighbours_list_;
|
2010-02-25 01:18:32 +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_;
|
2009-12-26 16:13:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LASTFMSERVICE_H
|