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-26 15:42:58 +02:00
|
|
|
#include "spotifyblob/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>
|
|
|
|
|
|
|
|
class LibraryBackend;
|
|
|
|
class LibraryModel;
|
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;
|
|
|
|
class QSortFilterProxyModel;
|
|
|
|
class QTemporaryFile;
|
|
|
|
|
2011-04-25 21:16:26 +02:00
|
|
|
class SpotifyService : public RadioService {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2011-04-26 15:42:58 +02:00
|
|
|
SpotifyService(RadioModel* parent);
|
|
|
|
~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;
|
|
|
|
static const char* kSearchSongsTable;
|
|
|
|
static const char* kSearchFtsTable;
|
|
|
|
|
2011-04-25 21:16:26 +02:00
|
|
|
virtual QStandardItem* CreateRootItem();
|
|
|
|
virtual void LazyPopulate(QStandardItem* parent);
|
|
|
|
|
|
|
|
void Login(const QString& username, const QString& password);
|
|
|
|
|
2011-04-26 20:39:38 +02:00
|
|
|
PlaylistItem::Options playlistitem_options() const;
|
|
|
|
|
2011-04-27 18:38:28 +02:00
|
|
|
QWidget* HeaderWidget() const;
|
|
|
|
|
2011-04-28 17:10:28 +02:00
|
|
|
SpotifyServer* server() const;
|
2011-04-25 21:16:26 +02:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void LoginFinished(bool success);
|
|
|
|
|
|
|
|
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-26 19:06:36 +02:00
|
|
|
void FillPlaylist(QStandardItem* item, const protobuf::LoadPlaylistResponse& response);
|
|
|
|
void SongFromProtobuf(const protobuf::Track& track, Song* song) const;
|
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-26 15:42:58 +02:00
|
|
|
void LoginCompleted(bool success);
|
|
|
|
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);
|
|
|
|
|
|
|
|
void Search(const QString& text);
|
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
|
|
|
|
|
|
|
QString blob_path_;
|
|
|
|
QProcess* blob_process_;
|
|
|
|
|
2011-04-26 15:42:58 +02:00
|
|
|
QStandardItem* root_;
|
2011-04-27 18:38:28 +02:00
|
|
|
QStandardItem* search_results_;
|
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_;
|
|
|
|
|
|
|
|
QMenu* context_menu_;
|
|
|
|
QModelIndex context_item_;
|
|
|
|
|
|
|
|
QTemporaryFile* database_file_;
|
|
|
|
boost::shared_ptr<Database> database_;
|
|
|
|
LibraryBackend* library_backend_;
|
|
|
|
LibraryFilterWidget* library_filter_;
|
|
|
|
LibraryModel* library_model_;
|
|
|
|
QSortFilterProxyModel* library_sort_model_;
|
2011-04-25 21:16:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|