2014-12-17 19:02:21 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2011, Tyler Rhodes <tyler.s.rhodes@gmail.com>
|
|
|
|
Copyright 2011-2012, 2014, Arnaud Bienner <arnaud.bienner@gmail.com>
|
|
|
|
Copyright 2011-2012, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2011-2012, 2014, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2014-12-18 23:54:21 +01:00
|
|
|
#ifndef INTERNET_SPOTIFY_SPOTIFYSERVICE_H_
|
|
|
|
#define INTERNET_SPOTIFY_SPOTIFYSERVICE_H_
|
2011-04-25 21:16:26 +02:00
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
#include <QProcess>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/core/internetmodel.h"
|
|
|
|
#include "internet/core/internetservice.h"
|
2012-01-08 00:26:27 +01:00
|
|
|
#include "spotifymessages.pb.h"
|
2011-04-25 21:16:26 +02:00
|
|
|
|
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
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
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,
|
2012-06-12 15:53:23 +02:00
|
|
|
Type_Toplist,
|
2011-04-26 15:42:58 +02:00
|
|
|
};
|
|
|
|
|
2014-12-17 19:02:21 +01:00
|
|
|
enum Role {
|
|
|
|
Role_UserPlaylistIndex = InternetModel::RoleCount,
|
|
|
|
};
|
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
|
|
|
|
2014-12-03 22:27:43 +01:00
|
|
|
void ReloadSettings() override;
|
2011-08-27 23:01:28 +02:00
|
|
|
|
2014-12-03 22:27:43 +01:00
|
|
|
QStandardItem* CreateRootItem() override;
|
|
|
|
void LazyPopulate(QStandardItem* parent) override;
|
|
|
|
void ShowContextMenu(const QPoint& global_pos) override;
|
|
|
|
void DropMimeData(const QMimeData* data, const QModelIndex& index) override;
|
2014-09-26 12:33:02 +02:00
|
|
|
QList<QAction*> playlistitem_actions(const Song& song) override;
|
2014-12-03 23:58:09 +01:00
|
|
|
PlaylistItem::Options playlistitem_options() const override;
|
|
|
|
QWidget* HeaderWidget() const override;
|
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);
|
2014-09-21 16:13:00 +02:00
|
|
|
Q_INVOKABLE void SetPaused(bool paused);
|
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
|
|
|
|
2021-07-07 08:07:55 +02:00
|
|
|
bool ConfigRequired() override { return !IsLoggedIn(); }
|
|
|
|
|
2021-02-20 22:20:04 +01:00
|
|
|
static void SongFromProtobuf(const cpb::spotify::Track& track, Song* song);
|
2011-06-01 17:53:05 +02:00
|
|
|
|
2016-12-20 14:02:06 +01: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
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public slots:
|
2012-06-28 23:57:51 +02:00
|
|
|
void Search(const QString& text, bool now = false);
|
2016-12-20 14:02:06 +01:00
|
|
|
void ShowConfig() override;
|
2014-09-28 02:00:32 +02:00
|
|
|
void RemoveCurrentFromPlaylist();
|
2011-10-20 15:03:47 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-04-29 21:44:51 +02:00
|
|
|
void StartBlobProcess();
|
2012-06-12 15:53:23 +02:00
|
|
|
void FillPlaylist(
|
|
|
|
QStandardItem* item,
|
2021-02-20 22:20:04 +01:00
|
|
|
const google::protobuf::RepeatedPtrField<cpb::spotify::Track>& tracks);
|
2014-02-07 16:34:20 +01:00
|
|
|
void FillPlaylist(QStandardItem* item,
|
2021-02-20 22:20:04 +01:00
|
|
|
const cpb::spotify::LoadPlaylistResponse& response);
|
2015-01-14 22:55:20 +01:00
|
|
|
void AddSongsToUserPlaylist(int playlist_index,
|
|
|
|
const QList<QUrl>& songs_urls);
|
2015-01-14 22:49:36 +01:00
|
|
|
void AddSongsToStarred(const QList<QUrl>& songs_urls);
|
2011-04-27 18:38:28 +02:00
|
|
|
void EnsureMenuCreated();
|
2014-09-28 02:00:32 +02:00
|
|
|
// Create a new "show config" action. The caller is responsible for deleting
|
|
|
|
// the pointer (or adding it to menu or anything else that will take ownership
|
|
|
|
// of it)
|
|
|
|
QAction* GetNewShowConfigAction();
|
2017-03-28 18:38:55 +02:00
|
|
|
void InitSearch();
|
2012-06-28 23:57:51 +02:00
|
|
|
void ClearSearchResults();
|
2011-04-27 18:38:28 +02:00
|
|
|
QStandardItem* PlaylistBySpotifyIndex(int index) const;
|
2021-02-20 22:20:04 +01:00
|
|
|
bool DoPlaylistsDiffer(const cpb::spotify::Playlists& response) const;
|
2011-04-26 15:42:58 +02:00
|
|
|
|
2014-02-07 16:34:20 +01: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,
|
2021-02-20 22:20:04 +01:00
|
|
|
cpb::spotify::LoginResponse_Error error_code);
|
2015-01-14 22:49:36 +01:00
|
|
|
void AddCurrentSongToUserPlaylist(QAction* action);
|
|
|
|
void AddCurrentSongToStarredPlaylist();
|
|
|
|
void RemoveSongsFromUserPlaylist(int playlist_index,
|
2015-01-14 22:55:20 +01:00
|
|
|
const QList<int>& songs_indices_to_remove);
|
2015-01-14 22:49:36 +01:00
|
|
|
void RemoveSongsFromStarred(const QList<int>& songs_indices_to_remove);
|
2021-02-20 22:20:04 +01:00
|
|
|
void PlaylistsUpdated(const cpb::spotify::Playlists& response);
|
|
|
|
void InboxLoaded(const cpb::spotify::LoadPlaylistResponse& response);
|
|
|
|
void StarredLoaded(const cpb::spotify::LoadPlaylistResponse& response);
|
|
|
|
void UserPlaylistLoaded(const cpb::spotify::LoadPlaylistResponse& response);
|
|
|
|
void SearchResults(const cpb::spotify::SearchResponse& response);
|
|
|
|
void SyncPlaylistProgress(const cpb::spotify::SyncPlaylistProgress& progress);
|
|
|
|
void ToplistLoaded(const cpb::spotify::BrowseToplistResponse& response);
|
2014-12-27 16:40:13 +01:00
|
|
|
void GetCurrentSongUrlToShare() const;
|
2014-12-27 18:05:04 +01:00
|
|
|
void GetCurrentPlaylistUrlToShare() const;
|
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
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-04-25 21:16:26 +02:00
|
|
|
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_;
|
|
|
|
|
2011-05-25 16:22:49 +02:00
|
|
|
QMenu* playlist_context_menu_;
|
2014-09-28 02:00:32 +02:00
|
|
|
QMenu* song_context_menu_;
|
2011-05-25 16:22:49 +02:00
|
|
|
QAction* playlist_sync_action_;
|
2014-12-27 18:05:04 +01:00
|
|
|
QAction* get_url_to_share_playlist_;
|
2014-09-22 22:40:21 +02:00
|
|
|
QList<QAction*> playlistitem_actions_;
|
2014-09-28 02:00:32 +02:00
|
|
|
QAction* remove_from_playlist_;
|
2014-09-22 22:40:21 +02:00
|
|
|
QUrl current_song_url_;
|
2014-12-27 18:05:04 +01:00
|
|
|
QUrl current_playlist_url_;
|
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_;
|
2021-02-20 22:20:04 +01:00
|
|
|
cpb::spotify::Bitrate bitrate_;
|
2011-11-27 18:29:33 +01:00
|
|
|
bool volume_normalisation_;
|
2011-04-25 21:16:26 +02:00
|
|
|
};
|
|
|
|
|
2014-12-18 23:54:21 +01:00
|
|
|
#endif // INTERNET_SPOTIFY_SPOTIFYSERVICE_H_
|