2011-04-25 21:16:26 +02:00
|
|
|
#ifndef SPOTIFYSERVICE_H
|
|
|
|
#define SPOTIFYSERVICE_H
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
#include "internetmodel.h"
|
|
|
|
#include "internetservice.h"
|
2012-01-08 00:26:27 +01:00
|
|
|
#include "spotifymessages.pb.h"
|
2011-04-25 21:16:26 +02:00
|
|
|
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2011-04-27 18:38:28 +02:00
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
class Playlist;
|
2012-06-28 23:57:51 +02:00
|
|
|
class SearchBoxWidget;
|
2011-04-25 21:16:26 +02:00
|
|
|
class SpotifyServer;
|
|
|
|
|
2011-04-27 18:38:28 +02:00
|
|
|
class QMenu;
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
class SpotifyService : public InternetService {
|
2011-04-25 21:16:26 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2012-02-12 14:41:50 +01:00
|
|
|
SpotifyService(Application* app, InternetModel* parent);
|
2011-04-26 15:42:58 +02:00
|
|
|
~SpotifyService();
|
|
|
|
|
|
|
|
enum Type {
|
2011-07-15 15:27:50 +02:00
|
|
|
Type_SearchResults = InternetModel::TypeCount,
|
2011-04-27 18:38:28 +02:00
|
|
|
Type_StarredPlaylist,
|
2011-04-26 15:42:58 +02:00
|
|
|
Type_InboxPlaylist,
|
2011-04-26 19:06:36 +02:00
|
|
|
Type_Track,
|
2012-06-12 15:53:23 +02:00
|
|
|
Type_Toplist,
|
2011-04-26 15:42:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Role {
|
2011-07-15 15:27:50 +02:00
|
|
|
Role_UserPlaylistIndex = InternetModel::RoleCount,
|
2011-04-26 15:42:58 +02:00
|
|
|
};
|
2011-04-25 21:16:26 +02:00
|
|
|
|
2011-08-27 23:01:28 +02:00
|
|
|
// Values are persisted - don't change.
|
|
|
|
enum LoginState {
|
|
|
|
LoginState_LoggedIn = 1,
|
|
|
|
LoginState_Banned = 2,
|
|
|
|
LoginState_BadCredentials = 3,
|
|
|
|
LoginState_NoPremium = 4,
|
2011-11-28 13:32:45 +01:00
|
|
|
LoginState_OtherError = 5,
|
|
|
|
LoginState_ReloginFailed = 6
|
2011-08-27 23:01:28 +02:00
|
|
|
};
|
|
|
|
|
2011-04-28 17:10:28 +02:00
|
|
|
static const char* kServiceName;
|
|
|
|
static const char* kSettingsGroup;
|
2011-04-29 21:44:51 +02:00
|
|
|
static const char* kBlobDownloadUrl;
|
2011-04-28 19:50:45 +02:00
|
|
|
static const int kSearchDelayMsec;
|
2011-04-25 21:16:26 +02:00
|
|
|
|
2011-08-27 23:01:28 +02:00
|
|
|
void ReloadSettings();
|
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
QStandardItem* CreateRootItem();
|
|
|
|
void LazyPopulate(QStandardItem* parent);
|
2012-03-11 15:44:43 +01:00
|
|
|
void ShowContextMenu(const QPoint& global_pos);
|
2011-04-29 13:24:58 +02:00
|
|
|
void ItemDoubleClicked(QStandardItem* item);
|
2012-01-04 12:50:19 +01:00
|
|
|
void DropMimeData(const QMimeData* data, const QModelIndex& index);
|
2011-04-26 20:39:38 +02:00
|
|
|
PlaylistItem::Options playlistitem_options() const;
|
2012-06-28 23:57:51 +02:00
|
|
|
QWidget* HeaderWidget() const;
|
2011-04-26 20:39:38 +02:00
|
|
|
|
2011-08-27 23:01:28 +02:00
|
|
|
void Logout();
|
2011-04-28 19:50:45 +02:00
|
|
|
void Login(const QString& username, const QString& password);
|
2011-11-29 11:20:23 +01:00
|
|
|
Q_INVOKABLE void LoadImage(const QString& id);
|
2011-04-27 18:38:28 +02:00
|
|
|
|
2011-04-28 17:10:28 +02:00
|
|
|
SpotifyServer* server() const;
|
2011-04-25 21:16:26 +02:00
|
|
|
|
2011-04-30 14:31:20 +02:00
|
|
|
bool IsBlobInstalled() const;
|
|
|
|
void InstallBlob();
|
|
|
|
|
2011-08-27 23:01:28 +02:00
|
|
|
// Persisted in the settings and updated on each Login().
|
|
|
|
LoginState login_state() const { return login_state_; }
|
2011-10-20 15:03:47 +02:00
|
|
|
bool IsLoggedIn() const { return login_state_ == LoginState_LoggedIn; }
|
2011-08-27 23:01:28 +02:00
|
|
|
|
2012-01-08 00:26:27 +01:00
|
|
|
static void SongFromProtobuf(const pb::spotify::Track& track, Song* song);
|
2011-06-01 17:53:05 +02:00
|
|
|
|
2011-04-25 21:16:26 +02:00
|
|
|
signals:
|
2011-04-30 14:31:20 +02:00
|
|
|
void BlobStateChanged();
|
2011-04-25 21:16:26 +02:00
|
|
|
void LoginFinished(bool success);
|
2011-11-29 11:20:23 +01:00
|
|
|
void ImageLoaded(const QString& id, const QImage& image);
|
2011-04-25 21:16:26 +02:00
|
|
|
|
2011-10-20 15:03:47 +02:00
|
|
|
public slots:
|
2012-06-28 23:57:51 +02:00
|
|
|
void Search(const QString& text, bool now = false);
|
2011-10-20 15:03:47 +02:00
|
|
|
void ShowConfig();
|
|
|
|
|
2011-04-26 15:42:58 +02:00
|
|
|
private:
|
2011-04-29 21:44:51 +02:00
|
|
|
void StartBlobProcess();
|
2012-06-12 15:53:23 +02:00
|
|
|
void FillPlaylist(
|
|
|
|
QStandardItem* item,
|
|
|
|
const google::protobuf::RepeatedPtrField<pb::spotify::Track>& tracks);
|
2012-01-08 00:26:27 +01:00
|
|
|
void FillPlaylist(QStandardItem* item, const pb::spotify::LoadPlaylistResponse& response);
|
2011-04-27 18:38:28 +02:00
|
|
|
void EnsureMenuCreated();
|
2012-06-28 23:57:51 +02:00
|
|
|
void ClearSearchResults();
|
2011-04-27 18:38:28 +02:00
|
|
|
|
|
|
|
QStandardItem* PlaylistBySpotifyIndex(int index) const;
|
2012-01-08 00:26:27 +01:00
|
|
|
bool DoPlaylistsDiffer(const pb::spotify::Playlists& response) const;
|
2011-04-26 15:42:58 +02:00
|
|
|
|
2011-04-25 21:16:26 +02:00
|
|
|
private slots:
|
2011-09-25 20:24:44 +02:00
|
|
|
void EnsureServerCreated(const QString& username = QString(),
|
|
|
|
const QString& password = QString());
|
2011-04-25 21:16:26 +02:00
|
|
|
void BlobProcessError(QProcess::ProcessError error);
|
2011-08-27 23:01:28 +02:00
|
|
|
void LoginCompleted(bool success, const QString& error,
|
2012-01-08 00:26:27 +01:00
|
|
|
pb::spotify::LoginResponse_Error error_code);
|
|
|
|
void PlaylistsUpdated(const pb::spotify::Playlists& response);
|
|
|
|
void InboxLoaded(const pb::spotify::LoadPlaylistResponse& response);
|
|
|
|
void StarredLoaded(const pb::spotify::LoadPlaylistResponse& response);
|
|
|
|
void UserPlaylistLoaded(const pb::spotify::LoadPlaylistResponse& response);
|
|
|
|
void SearchResults(const pb::spotify::SearchResponse& response);
|
|
|
|
void SyncPlaylistProgress(const pb::spotify::SyncPlaylistProgress& progress);
|
2012-06-12 15:53:23 +02:00
|
|
|
void ToplistLoaded(const pb::spotify::BrowseToplistResponse& response);
|
2011-04-27 18:38:28 +02:00
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
void DoSearch();
|
2011-04-25 21:16:26 +02:00
|
|
|
|
2011-05-25 16:22:49 +02:00
|
|
|
void SyncPlaylist();
|
2011-04-29 21:44:51 +02:00
|
|
|
void BlobDownloadFinished();
|
2011-04-29 20:56:17 +02:00
|
|
|
|
2011-04-25 21:16:26 +02:00
|
|
|
private:
|
|
|
|
SpotifyServer* server_;
|
|
|
|
|
2011-04-30 14:31:20 +02:00
|
|
|
QString system_blob_path_;
|
2011-04-29 21:44:51 +02:00
|
|
|
QString local_blob_version_;
|
|
|
|
QString local_blob_path_;
|
2011-04-25 21:16:26 +02:00
|
|
|
QProcess* blob_process_;
|
|
|
|
|
2011-04-26 15:42:58 +02:00
|
|
|
QStandardItem* root_;
|
2011-04-29 13:24:58 +02:00
|
|
|
QStandardItem* search_;
|
2011-04-26 15:42:58 +02:00
|
|
|
QStandardItem* starred_;
|
|
|
|
QStandardItem* inbox_;
|
2012-06-12 15:53:23 +02:00
|
|
|
QStandardItem* toplist_;
|
2011-04-26 15:42:58 +02:00
|
|
|
QList<QStandardItem*> playlists_;
|
|
|
|
|
|
|
|
int login_task_id_;
|
2011-04-27 18:38:28 +02:00
|
|
|
QString pending_search_;
|
|
|
|
|
|
|
|
QMenu* context_menu_;
|
2011-05-25 16:22:49 +02:00
|
|
|
QMenu* playlist_context_menu_;
|
|
|
|
QAction* playlist_sync_action_;
|
2011-04-27 18:38:28 +02:00
|
|
|
|
2012-06-28 23:57:51 +02:00
|
|
|
SearchBoxWidget* search_box_;
|
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
QTimer* search_delay_;
|
2011-05-25 16:22:49 +02:00
|
|
|
|
|
|
|
int inbox_sync_id_;
|
|
|
|
int starred_sync_id_;
|
|
|
|
QMap<int, int> playlist_sync_ids_;
|
2011-08-27 23:01:28 +02:00
|
|
|
|
|
|
|
LoginState login_state_;
|
2012-01-08 00:26:27 +01:00
|
|
|
pb::spotify::Bitrate bitrate_;
|
2011-11-27 18:29:33 +01:00
|
|
|
bool volume_normalisation_;
|
2011-04-25 21:16:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|