1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-28 10:09:24 +01:00

Send closed playlists too if requested.

This commit is contained in:
Andreas 2013-04-16 13:57:04 +02:00
parent 3072a32fde
commit 8888cc410a
8 changed files with 65 additions and 7 deletions

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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

View File

@ -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)));

View File

@ -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<Playlist*> 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<Playlist*> 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) {

View File

@ -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*);

View File

@ -446,3 +446,7 @@ void PlaylistManager::SetCurrentOrOpen(int id) {
Open(id);
SetCurrentPlaylist(id);
}
bool PlaylistManager::IsPlaylistOpen(int id) {
return playlists_.contains(id);
}

View File

@ -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.