2011-04-25 21:16:26 +02:00
|
|
|
#ifndef SPOTIFYSERVICE_H
|
|
|
|
#define SPOTIFYSERVICE_H
|
|
|
|
|
2011-04-26 15:42:58 +02:00
|
|
|
#include "radiomodel.h"
|
2011-04-25 21:16:26 +02:00
|
|
|
#include "radioservice.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-28 17:10:28 +02:00
|
|
|
class SpotifyUrlHandler;
|
2011-04-25 21:16:26 +02:00
|
|
|
|
2011-04-27 18:38:28 +02:00
|
|
|
class QMenu;
|
|
|
|
|
2011-04-25 21:16:26 +02:00
|
|
|
class SpotifyService : public RadioService {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2011-05-25 16:22:49 +02:00
|
|
|
SpotifyService(TaskManager* task_manager, RadioModel* parent);
|
2011-04-26 15:42:58 +02:00
|
|
|
~SpotifyService();
|
|
|
|
|
|
|
|
enum Type {
|
2011-04-27 18:38:28 +02:00
|
|
|
Type_SearchResults = RadioModel::TypeCount,
|
|
|
|
Type_StarredPlaylist,
|
2011-04-26 15:42:58 +02:00
|
|
|
Type_InboxPlaylist,
|
2011-04-26 19:06:36 +02:00
|
|
|
Type_UserPlaylist,
|
|
|
|
Type_Track,
|
2011-04-26 15:42:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Role {
|
2011-04-26 19:06:36 +02:00
|
|
|
Role_UserPlaylistIndex = RadioModel::RoleCount,
|
2011-04-26 15:42:58 +02:00
|
|
|
};
|
2011-04-25 21:16:26 +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-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-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-04-29 15:41:42 +02:00
|
|
|
Q_INVOKABLE void LoadImage(const QUrl& url);
|
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-06-01 17:53:05 +02:00
|
|
|
static void SongFromProtobuf(const protobuf::Track& track, Song* song);
|
|
|
|
|
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-04-29 15:41:42 +02:00
|
|
|
void ImageLoaded(const QUrl& url, const QImage& image);
|
2011-04-25 21:16:26 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual QModelIndex GetCurrentIndex();
|
|
|
|
|
2011-04-26 15:42:58 +02:00
|
|
|
private:
|
|
|
|
void EnsureServerCreated(const QString& username = QString(),
|
|
|
|
const QString& password = QString());
|
2011-04-29 21:44:51 +02:00
|
|
|
void StartBlobProcess();
|
2011-04-26 19:06:36 +02:00
|
|
|
void FillPlaylist(QStandardItem* item, const protobuf::LoadPlaylistResponse& response);
|
2011-04-27 18:38:28 +02:00
|
|
|
void EnsureMenuCreated();
|
|
|
|
|
|
|
|
QStandardItem* PlaylistBySpotifyIndex(int index) const;
|
|
|
|
bool DoPlaylistsDiffer(const protobuf::Playlists& response);
|
2011-04-26 15:42:58 +02:00
|
|
|
|
2011-04-25 21:16:26 +02:00
|
|
|
private slots:
|
|
|
|
void BlobProcessError(QProcess::ProcessError error);
|
2011-04-30 14:31:20 +02:00
|
|
|
void LoginCompleted(bool success, const QString& error);
|
2011-04-26 15:42:58 +02:00
|
|
|
void PlaylistsUpdated(const protobuf::Playlists& response);
|
2011-04-26 19:06:36 +02:00
|
|
|
void InboxLoaded(const protobuf::LoadPlaylistResponse& response);
|
|
|
|
void StarredLoaded(const protobuf::LoadPlaylistResponse& response);
|
|
|
|
void UserPlaylistLoaded(const protobuf::LoadPlaylistResponse& response);
|
2011-04-27 18:38:28 +02:00
|
|
|
void SearchResults(const protobuf::SearchResponse& response);
|
2011-04-29 15:41:42 +02:00
|
|
|
void ImageLoaded(const QString& id, const QImage& image);
|
2011-05-25 16:22:49 +02:00
|
|
|
void SyncPlaylistProgress(const protobuf::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-04-29 20:56:17 +02:00
|
|
|
void ShowConfig();
|
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-28 17:10:28 +02:00
|
|
|
SpotifyUrlHandler* url_handler_;
|
2011-04-25 21:16:26 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
TaskManager* task_manager_;
|
|
|
|
int inbox_sync_id_;
|
|
|
|
int starred_sync_id_;
|
|
|
|
QMap<int, int> playlist_sync_ids_;
|
2011-04-25 21:16:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|