mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-28 10:09:24 +01:00
Clementine will offer a song before download first. The client can deceide if it want to download it or not. Only when the client accepted the file, Clementine sends it.
This commit is contained in:
parent
66df83fa84
commit
cf1dfe0d58
@ -16,7 +16,7 @@ enum MsgType {
|
||||
CLOSE_PLAYLIST = 11;
|
||||
GET_LYRICS = 14;
|
||||
DOWNLOAD_SONGS = 15;
|
||||
SEND_NEXT_SONG = 16;
|
||||
SONG_OFFER_RESPONSE = 16;
|
||||
// Lastfm
|
||||
LOVE = 12;
|
||||
BAN = 13;
|
||||
@ -254,6 +254,10 @@ message ResponseSongFileChunk {
|
||||
optional int32 size = 8;
|
||||
}
|
||||
|
||||
message ResponseSongOffer {
|
||||
optional bool accepted = 1; // true = client wants to download item
|
||||
}
|
||||
|
||||
// The message itself
|
||||
message Message {
|
||||
optional int32 version = 1 [default=9];
|
||||
@ -284,4 +288,5 @@ message Message {
|
||||
optional ResponseActiveChanged response_active_changed = 24;
|
||||
optional ResponseLyrics response_lyrics = 30;
|
||||
optional ResponseSongFileChunk response_song_file_chunk = 32;
|
||||
optional ResponseSongOffer response_song_offer = 33;
|
||||
}
|
||||
|
@ -153,8 +153,9 @@ void IncomingDataParser::Parse(const pb::remote::Message& msg) {
|
||||
case pb::remote::DOWNLOAD_SONGS:
|
||||
emit SendSongs(msg.request_download_songs(), client);
|
||||
break;
|
||||
case pb::remote::SEND_NEXT_SONG:
|
||||
emit SendNextSong(client);
|
||||
case pb::remote::SONG_OFFER_RESPONSE:
|
||||
emit ResponseSongOffer(client,
|
||||
msg.response_song_offer().accepted());
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ signals:
|
||||
void RemoveSongs(const QList<int>& indices);
|
||||
void SeekTo(int seconds);
|
||||
void SendSongs(const pb::remote::RequestDownloadSongs& request, RemoteClient* client);
|
||||
void SendNextSong(RemoteClient* client);
|
||||
void ResponseSongOffer(RemoteClient* client, bool accepted);
|
||||
|
||||
private:
|
||||
Application* app_;
|
||||
|
@ -164,9 +164,9 @@ void NetworkRemote::AcceptConnection() {
|
||||
outgoing_data_creator_.get(),
|
||||
SLOT(SendSongs(pb::remote::RequestDownloadSongs,RemoteClient*)));
|
||||
connect(incoming_data_parser_.get(),
|
||||
SIGNAL(SendNextSong(RemoteClient*)),
|
||||
SIGNAL(ResponseSongOffer(RemoteClient*, bool)),
|
||||
outgoing_data_creator_.get(),
|
||||
SLOT(SendNextSong(RemoteClient*)));
|
||||
SLOT(ResponseSongOffer(RemoteClient*, bool)));
|
||||
}
|
||||
|
||||
QTcpServer* server = qobject_cast<QTcpServer*>(sender());
|
||||
|
@ -570,10 +570,37 @@ void OutgoingDataCreator::SendSongs(const pb::remote::RequestDownloadSongs &requ
|
||||
}
|
||||
|
||||
// Send first file
|
||||
SendNextSong(client);
|
||||
OfferNextSong(client);
|
||||
}
|
||||
|
||||
void OutgoingDataCreator::SendNextSong(RemoteClient *client) {
|
||||
void OutgoingDataCreator::OfferNextSong(RemoteClient *client) {
|
||||
if (!download_queue_.contains(client))
|
||||
return;
|
||||
|
||||
if (download_queue_.value(client).isEmpty())
|
||||
return;
|
||||
|
||||
// Get the item and send the single song
|
||||
DownloadItem item = download_queue_[client].head();
|
||||
|
||||
pb::remote::Message msg;
|
||||
msg.set_type(pb::remote::SONG_FILE_CHUNK);
|
||||
pb::remote::ResponseSongFileChunk* chunk = msg.mutable_response_song_file_chunk();
|
||||
|
||||
// Song offer is chunk no 0
|
||||
chunk->set_chunk_count(0);
|
||||
chunk->set_chunk_number(0);
|
||||
chunk->set_file_count(item.song_count_);
|
||||
chunk->set_file_number(item.song_no_);
|
||||
|
||||
CreateSong(item.song_, item.song_.image(), -1,
|
||||
chunk->mutable_song_metadata());
|
||||
|
||||
msg.set_version(msg.default_instance().version());
|
||||
client->SendData(&msg);
|
||||
}
|
||||
|
||||
void OutgoingDataCreator::ResponseSongOffer(RemoteClient *client, bool accepted) {
|
||||
if (!download_queue_.contains(client))
|
||||
return;
|
||||
|
||||
@ -582,7 +609,11 @@ void OutgoingDataCreator::SendNextSong(RemoteClient *client) {
|
||||
|
||||
// Get the item and send the single song
|
||||
DownloadItem item = download_queue_[client].dequeue();
|
||||
SendSingleSong(client, item.song_, item.song_no_, item.song_count_);
|
||||
if (accepted)
|
||||
SendSingleSong(client, item.song_, item.song_no_, item.song_count_);
|
||||
|
||||
// And offer the next song
|
||||
OfferNextSong(client);
|
||||
}
|
||||
|
||||
void OutgoingDataCreator::SendSingleSong(RemoteClient* client, const Song &song,
|
||||
|
@ -71,7 +71,7 @@ public slots:
|
||||
void GetLyrics();
|
||||
void SendLyrics(int id, const SongInfoFetcher::Result& result);
|
||||
void SendSongs(const pb::remote::RequestDownloadSongs& request, RemoteClient* client);
|
||||
void SendNextSong(RemoteClient* client);
|
||||
void ResponseSongOffer(RemoteClient* client, bool accepted);
|
||||
|
||||
private:
|
||||
Application* app_;
|
||||
@ -102,6 +102,7 @@ private:
|
||||
void SendSingleSong(RemoteClient* client, const Song& song, int song_no, int song_count);
|
||||
void SendAlbum(RemoteClient* client, const Song& song);
|
||||
void SendPlaylist(RemoteClient* client, int playlist_id);
|
||||
void OfferNextSong(RemoteClient* client);
|
||||
};
|
||||
|
||||
#endif // OUTGOINGDATACREATOR_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user