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"
|
2011-04-29 21:44:51 +02:00
|
|
|
#include "spotifyblob/common/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;
|
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:
|
2011-07-21 01:03:55 +02:00
|
|
|
SpotifyService(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,
|
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);
|
|
|
|
void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
|
2011-04-29 13:24:58 +02:00
|
|
|
void ItemDoubleClicked(QStandardItem* item);
|
2011-04-26 20:39:38 +02:00
|
|
|
PlaylistItem::Options playlistitem_options() const;
|
|
|
|
|
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-04-28 22:48:53 +02:00
|
|
|
void Search(const QString& text, Playlist* playlist, bool now = false);
|
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
|
|
|
|
2011-08-29 03:00:59 +02:00
|
|
|
static void SongFromProtobuf(const spotify_pb::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:
|
|
|
|
void ShowConfig();
|
|
|
|
|
2011-04-25 21:16:26 +02:00
|
|
|
protected:
|
|
|
|
virtual QModelIndex GetCurrentIndex();
|
|
|
|
|
2011-04-26 15:42:58 +02:00
|
|
|
private:
|
2011-04-29 21:44:51 +02:00
|
|
|
void StartBlobProcess();
|
2011-08-29 03:00:59 +02:00
|
|
|
void FillPlaylist(QStandardItem* item, const spotify_pb::LoadPlaylistResponse& response);
|
2011-04-27 18:38:28 +02:00
|
|
|
void EnsureMenuCreated();
|
|
|
|
|
|
|
|
QStandardItem* PlaylistBySpotifyIndex(int index) const;
|
2011-11-27 18:29:33 +01:00
|
|
|
bool DoPlaylistsDiffer(const spotify_pb::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,
|
2011-08-29 03:00:59 +02:00
|
|
|
spotify_pb::LoginResponse_Error error_code);
|
|
|
|
void PlaylistsUpdated(const spotify_pb::Playlists& response);
|
|
|
|
void InboxLoaded(const spotify_pb::LoadPlaylistResponse& response);
|
|
|
|
void StarredLoaded(const spotify_pb::LoadPlaylistResponse& response);
|
|
|
|
void UserPlaylistLoaded(const spotify_pb::LoadPlaylistResponse& response);
|
|
|
|
void SearchResults(const spotify_pb::SearchResponse& response);
|
|
|
|
void SyncPlaylistProgress(const spotify_pb::SyncPlaylistProgress& progress);
|
2011-04-27 18:38:28 +02:00
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
void OpenSearchTab();
|
|
|
|
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_;
|
|
|
|
QList<QStandardItem*> playlists_;
|
|
|
|
|
|
|
|
int login_task_id_;
|
2011-04-27 18:38:28 +02:00
|
|
|
QString pending_search_;
|
2011-04-28 19:50:45 +02:00
|
|
|
Playlist* pending_search_playlist_;
|
2011-04-27 18:38:28 +02:00
|
|
|
|
|
|
|
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
|
|
|
QModelIndex context_item_;
|
|
|
|
|
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_;
|
2011-11-27 18:29:33 +01:00
|
|
|
spotify_pb::Bitrate bitrate_;
|
|
|
|
bool volume_normalisation_;
|
2011-04-25 21:16:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|