From 8888cc410ab7ec95b6739e613cf4f935ef1b83b3 Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 16 Apr 2013 13:57:04 +0200 Subject: [PATCH] Send closed playlists too if requested. --- .../remotecontrolmessages.proto | 8 +++- src/networkremote/incomingdataparser.cpp | 11 ++++- src/networkremote/incomingdataparser.h | 2 + src/networkremote/networkremote.cpp | 2 + src/networkremote/outgoingdatacreator.cpp | 41 ++++++++++++++++--- src/networkremote/outgoingdatacreator.h | 2 + src/playlist/playlistmanager.cpp | 4 ++ src/playlist/playlistmanager.h | 2 + 8 files changed, 65 insertions(+), 7 deletions(-) diff --git a/ext/libclementine-remote/remotecontrolmessages.proto b/ext/libclementine-remote/remotecontrolmessages.proto index c4f7c4801..a1bcb3098 100644 --- a/ext/libclementine-remote/remotecontrolmessages.proto +++ b/ext/libclementine-remote/remotecontrolmessages.proto @@ -71,6 +71,7 @@ message Playlist { optional string name = 2; optional int32 item_count = 3; optional bool active = 4; + optional bool closed = 5; } // Valid Repeatmodes @@ -89,6 +90,10 @@ enum ShuffleMode { Shuffle_Albums = 3; } +message RequestPlaylists { + optional bool include_closed = 1; +} + // A Client requests songs from a specific playlist message RequestPlaylistSongs { optional int32 id = 1; @@ -196,10 +201,11 @@ message RequestRemoveSongs { // The message itself message Message { - optional int32 version = 1 [default=5]; + optional int32 version = 1 [default=6]; optional MsgType type = 2 [default=UNKNOWN]; // What data is in the message? optional RequestConnect request_connect = 21; + optional RequestPlaylists request_playlists = 27; optional RequestPlaylistSongs request_playlist_songs = 10; optional RequestChangeSong request_change_song = 11; optional RequestSetVolume request_set_volume = 12; diff --git a/src/networkremote/incomingdataparser.cpp b/src/networkremote/incomingdataparser.cpp index c0a91fc4a..20752b0b9 100644 --- a/src/networkremote/incomingdataparser.cpp +++ b/src/networkremote/incomingdataparser.cpp @@ -83,7 +83,7 @@ void IncomingDataParser::Parse(const pb::remote::Message& msg) { break; case pb::remote::DISCONNECT: close_connection_ = true; break; - case pb::remote::REQUEST_PLAYLISTS: emit SendAllPlaylists(); + case pb::remote::REQUEST_PLAYLISTS: SendPlaylists(msg); break; case pb::remote::REQUEST_PLAYLIST_SONGS: GetPlaylistSongs(msg); break; @@ -219,3 +219,12 @@ void IncomingDataParser::ClientConnect(const pb::remote::Message& msg) { emit SendFirstData(false); } } + +void IncomingDataParser::SendPlaylists(const pb::remote::Message &msg) { + if (!msg.has_request_playlists() + || !msg.request_playlists().include_closed()) { + emit SendAllActivePlaylists(); + } else { + emit SendAllPlaylists(); + } +} diff --git a/src/networkremote/incomingdataparser.h b/src/networkremote/incomingdataparser.h index 37d0e72df..c4d29eb0b 100644 --- a/src/networkremote/incomingdataparser.h +++ b/src/networkremote/incomingdataparser.h @@ -20,6 +20,7 @@ signals: void SendClementineInfo(); void SendFirstData(bool send_playlist_songs); void SendAllPlaylists(); + void SendAllActivePlaylists(); void SendPlaylistSongs(int id); void Play(); @@ -49,6 +50,7 @@ private: void InsertUrls(const pb::remote::Message& msg); void RemoveSongs(const pb::remote::Message& msg); void ClientConnect(const pb::remote::Message& msg); + void SendPlaylists(const pb::remote::Message& msg); }; #endif // INCOMINGDATAPARSER_H diff --git a/src/networkremote/networkremote.cpp b/src/networkremote/networkremote.cpp index f410b56a2..4e6525517 100644 --- a/src/networkremote/networkremote.cpp +++ b/src/networkremote/networkremote.cpp @@ -124,6 +124,8 @@ void NetworkRemote::AcceptConnection() { outgoing_data_creator_.get(), SLOT(SendFirstData(bool))); connect(incoming_data_parser_.get(), SIGNAL(SendAllPlaylists()), outgoing_data_creator_.get(), SLOT(SendAllPlaylists())); + connect(incoming_data_parser_.get(), SIGNAL(SendAllActivePlaylists()), + outgoing_data_creator_.get(), SLOT(SendAllActivePlaylists())); connect(incoming_data_parser_.get(), SIGNAL(SendPlaylistSongs(int)), outgoing_data_creator_.get(), SLOT(SendPlaylistSongs(int))); diff --git a/src/networkremote/outgoingdatacreator.cpp b/src/networkremote/outgoingdatacreator.cpp index 16beb95e7..64812d0c6 100644 --- a/src/networkremote/outgoingdatacreator.cpp +++ b/src/networkremote/outgoingdatacreator.cpp @@ -107,6 +107,36 @@ void OutgoingDataCreator::SendAllPlaylists() { pb::remote::ResponsePlaylists* playlists = msg.mutable_response_playlists(); + // Get all playlists, even ones that are hidden in the UI. + foreach (const PlaylistBackend::Playlist& p, + app_->playlist_backend()->GetAllPlaylists()) { + bool playlist_open = app_->playlist_manager()->IsPlaylistOpen(p.id); + int item_count = playlist_open ? + app_playlists.at(p.id)->rowCount() : 0; + + // Create a new playlist + pb::remote::Playlist* playlist = playlists->add_playlist(); + playlist->set_name(DataCommaSizeFromQString(p.name)); + playlist->set_id(p.id); + playlist->set_active((p.id == active_playlist)); + playlist->set_item_count(item_count); + playlist->set_closed(!playlist_open); + } + + SendDataToClients(&msg); +} + +void OutgoingDataCreator::SendAllActivePlaylists() { + // Get all Playlists + QList app_playlists = app_->playlist_manager()->GetAllPlaylists(); + int active_playlist = app_->playlist_manager()->active_id(); + + // Create message + pb::remote::Message msg; + msg.set_type(pb::remote::PLAYLISTS); + + pb::remote::ResponsePlaylists* playlists = msg.mutable_response_playlists(); + QListIterator it(app_playlists); while(it.hasNext()) { // Get the next Playlist @@ -119,6 +149,7 @@ void OutgoingDataCreator::SendAllPlaylists() { playlist->set_id(p->id()); playlist->set_active((p->id() == active_playlist)); playlist->set_item_count(p->rowCount()); + playlist->set_closed(false); } SendDataToClients(&msg); @@ -136,19 +167,19 @@ void OutgoingDataCreator::ActiveChanged(Playlist* playlist) { } void OutgoingDataCreator::PlaylistAdded(int id, const QString& name) { - SendAllPlaylists(); + SendAllActivePlaylists(); } void OutgoingDataCreator::PlaylistDeleted(int id) { - SendAllPlaylists(); + SendAllActivePlaylists(); } void OutgoingDataCreator::PlaylistClosed(int id) { - SendAllPlaylists(); + SendAllActivePlaylists(); } void OutgoingDataCreator::PlaylistRenamed(int id, const QString& new_name) { - SendAllPlaylists(); + SendAllActivePlaylists(); } void OutgoingDataCreator::SendFirstData(bool send_playlist_songs) { @@ -167,7 +198,7 @@ void OutgoingDataCreator::SendFirstData(bool send_playlist_songs) { UpdateTrackPosition(); // And the current playlists - SendAllPlaylists(); + SendAllActivePlaylists(); // Send the tracks of the active playlist if (send_playlist_songs) { diff --git a/src/networkremote/outgoingdatacreator.h b/src/networkremote/outgoingdatacreator.h index 73b18ece4..08563f438 100644 --- a/src/networkremote/outgoingdatacreator.h +++ b/src/networkremote/outgoingdatacreator.h @@ -12,6 +12,7 @@ #include "engines/engine_fwd.h" #include "playlist/playlist.h" #include "playlist/playlistmanager.h" +#include "playlist/playlistbackend.h" #include "remotecontrolmessages.pb.h" #include "remoteclient.h" @@ -26,6 +27,7 @@ public: public slots: void SendClementineInfo(); void SendAllPlaylists(); + void SendAllActivePlaylists(); void SendFirstData(bool send_playlist_songs); void SendPlaylistSongs(int id); void PlaylistChanged(Playlist*); diff --git a/src/playlist/playlistmanager.cpp b/src/playlist/playlistmanager.cpp index 1d60c585b..97c5f6670 100644 --- a/src/playlist/playlistmanager.cpp +++ b/src/playlist/playlistmanager.cpp @@ -446,3 +446,7 @@ void PlaylistManager::SetCurrentOrOpen(int id) { Open(id); SetCurrentPlaylist(id); } + +bool PlaylistManager::IsPlaylistOpen(int id) { + return playlists_.contains(id); +} diff --git a/src/playlist/playlistmanager.h b/src/playlist/playlistmanager.h index e2fd91260..99c125b9b 100644 --- a/src/playlist/playlistmanager.h +++ b/src/playlist/playlistmanager.h @@ -148,6 +148,8 @@ public: void InvalidateDeletedSongs(); // Removes all deleted songs from all playlists. void RemoveDeletedSongs(); + // Returns true if the playlist is open + bool IsPlaylistOpen(int id); // Returns a pretty automatic name for playlist created from the given list of // songs.