2013-01-03 21:40:47 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, Andreas Muttscheller <asfa194@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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "incomingdataparser.h"
|
2013-04-14 00:58:49 +02:00
|
|
|
|
2020-11-27 13:05:53 +01:00
|
|
|
#include <QDir>
|
2013-04-14 00:58:49 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2013-01-03 21:40:47 +01:00
|
|
|
#include "core/logging.h"
|
2020-11-27 13:05:53 +01:00
|
|
|
#include "core/mimedata.h"
|
2015-06-13 16:00:15 +02:00
|
|
|
#include "core/timeconstants.h"
|
2013-01-03 21:40:47 +01:00
|
|
|
#include "engines/enginebase.h"
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/core/internetmodel.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "playlist/playlist.h"
|
2013-01-03 21:40:47 +01:00
|
|
|
#include "playlist/playlistmanager.h"
|
2013-01-15 14:43:02 +01:00
|
|
|
#include "playlist/playlistsequence.h"
|
2013-01-03 21:40:47 +01:00
|
|
|
|
2013-05-07 19:09:31 +02:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/lastfm/lastfmservice.h"
|
2013-05-07 19:09:31 +02:00
|
|
|
#endif
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
IncomingDataParser::IncomingDataParser(Application* app) : app_(app) {
|
2019-08-22 05:43:16 +02:00
|
|
|
// load settings initially and sign up for updates
|
2018-06-13 22:03:23 +02:00
|
|
|
ReloadSettings();
|
|
|
|
connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()));
|
|
|
|
|
2020-11-27 13:05:53 +01:00
|
|
|
Player* player = app_->player();
|
|
|
|
PlaylistManager* playlist_manager = app_->playlist_manager();
|
|
|
|
|
2013-01-03 21:40:47 +01:00
|
|
|
// Connect all the signals
|
2014-02-07 16:34:20 +01:00
|
|
|
// due the player is in a different thread, we cannot access these functions
|
|
|
|
// directly
|
2020-11-27 13:05:53 +01:00
|
|
|
connect(this, SIGNAL(Play()), player, SLOT(Play()));
|
|
|
|
connect(this, SIGNAL(PlayPause()), player, SLOT(PlayPause()));
|
|
|
|
connect(this, SIGNAL(Pause()), player, SLOT(Pause()));
|
|
|
|
connect(this, SIGNAL(Stop()), player, SLOT(Stop()));
|
|
|
|
connect(this, SIGNAL(StopAfterCurrent()), player, SLOT(StopAfterCurrent()));
|
|
|
|
connect(this, SIGNAL(Next()), player, SLOT(Next()));
|
|
|
|
connect(this, SIGNAL(Previous()), player, SLOT(Previous()));
|
|
|
|
connect(this, SIGNAL(SetVolume(int)), player, SLOT(SetVolume(int)));
|
|
|
|
connect(this, SIGNAL(PlayAt(int, Engine::TrackChangeFlags, bool)), player,
|
|
|
|
SLOT(PlayAt(int, Engine::TrackChangeFlags, bool)));
|
|
|
|
connect(this, SIGNAL(SeekTo(int)), player, SLOT(SeekTo(int)));
|
|
|
|
connect(this, SIGNAL(Enque(int, int)), playlist_manager,
|
2018-06-13 22:37:13 +02:00
|
|
|
SLOT(Enque(int, int)));
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2020-11-27 13:05:53 +01:00
|
|
|
connect(this, SIGNAL(SetActivePlaylist(int)), playlist_manager,
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(SetActivePlaylist(int)));
|
2020-11-27 13:05:53 +01:00
|
|
|
connect(this, SIGNAL(ShuffleCurrent()), playlist_manager,
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(ShuffleCurrent()));
|
2013-01-15 14:43:02 +01:00
|
|
|
connect(this, SIGNAL(SetRepeatMode(PlaylistSequence::RepeatMode)),
|
2020-11-27 13:05:53 +01:00
|
|
|
playlist_manager->sequence(),
|
2013-01-15 14:43:02 +01:00
|
|
|
SLOT(SetRepeatMode(PlaylistSequence::RepeatMode)));
|
|
|
|
connect(this, SIGNAL(SetShuffleMode(PlaylistSequence::ShuffleMode)),
|
2020-11-27 13:05:53 +01:00
|
|
|
playlist_manager->sequence(),
|
2013-01-15 14:43:02 +01:00
|
|
|
SLOT(SetShuffleMode(PlaylistSequence::ShuffleMode)));
|
2013-07-31 19:06:29 +02:00
|
|
|
connect(this, SIGNAL(InsertUrls(int, const QList<QUrl>&, int, bool, bool)),
|
2020-11-27 13:05:53 +01:00
|
|
|
playlist_manager,
|
2013-07-31 19:06:29 +02:00
|
|
|
SLOT(InsertUrls(int, const QList<QUrl>&, int, bool, bool)));
|
2015-06-13 16:00:15 +02:00
|
|
|
connect(this, SIGNAL(InsertSongs(int, const SongList&, int, bool, bool)),
|
2020-11-27 13:05:53 +01:00
|
|
|
playlist_manager,
|
2015-06-13 16:00:15 +02:00
|
|
|
SLOT(InsertSongs(int, const SongList&, int, bool, bool)));
|
2020-11-27 13:05:53 +01:00
|
|
|
connect(this, SIGNAL(RemoveSongs(int, const QList<int>&)), playlist_manager,
|
2013-07-31 19:06:29 +02:00
|
|
|
SLOT(RemoveItemsWithoutUndo(int, const QList<int>&)));
|
2020-11-27 13:05:53 +01:00
|
|
|
connect(this, SIGNAL(New(const QString&)), playlist_manager,
|
|
|
|
SLOT(New(const QString&)));
|
|
|
|
connect(this, SIGNAL(Open(int)), playlist_manager, SLOT(Open(int)));
|
|
|
|
connect(this, SIGNAL(Close(int)), playlist_manager, SLOT(Close(int)));
|
|
|
|
connect(this, SIGNAL(Clear(int)), playlist_manager, SLOT(Clear(int)));
|
|
|
|
connect(this, SIGNAL(Rename(int, const QString&)), playlist_manager,
|
|
|
|
SLOT(Rename(int, const QString&)));
|
|
|
|
connect(this, SIGNAL(Favorite(int, bool)), playlist_manager,
|
|
|
|
SLOT(Favorite(int, bool)));
|
|
|
|
|
|
|
|
connect(this, SIGNAL(RateCurrentSong(double)), playlist_manager,
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(RateCurrentSong(double)));
|
2013-08-15 20:52:12 +02:00
|
|
|
|
2013-05-07 19:09:31 +02:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
2014-03-27 18:55:58 +01:00
|
|
|
connect(this, SIGNAL(Love()), app_->scrobbler(), SLOT(Love()));
|
2013-05-07 19:09:31 +02:00
|
|
|
#endif
|
2013-01-03 21:40:47 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
IncomingDataParser::~IncomingDataParser() {}
|
2013-01-03 21:40:47 +01:00
|
|
|
|
2018-06-13 22:03:23 +02:00
|
|
|
void IncomingDataParser::ReloadSettings() {
|
2018-06-13 22:37:13 +02:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(MainWindow::kSettingsGroup);
|
|
|
|
doubleclick_playlist_addmode_ = MainWindow::PlaylistAddBehaviour(
|
|
|
|
s.value("doubleclick_playlist_addmode",
|
|
|
|
MainWindow::PlaylistAddBehaviour_Enqueue)
|
|
|
|
.toInt());
|
2018-06-13 22:03:23 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
bool IncomingDataParser::close_connection() { return close_connection_; }
|
2013-01-03 21:40:47 +01:00
|
|
|
|
2013-01-23 20:02:12 +01:00
|
|
|
void IncomingDataParser::Parse(const pb::remote::Message& msg) {
|
2014-02-07 16:34:20 +01:00
|
|
|
close_connection_ = false;
|
2013-07-12 12:31:27 +02:00
|
|
|
RemoteClient* client = qobject_cast<RemoteClient*>(sender());
|
|
|
|
|
2013-01-03 21:40:47 +01:00
|
|
|
// Now check what's to do
|
2013-01-15 13:05:43 +01:00
|
|
|
switch (msg.type()) {
|
2013-08-01 18:13:14 +02:00
|
|
|
case pb::remote::CONNECT:
|
2015-04-24 17:30:21 +02:00
|
|
|
ClientConnect(msg, client);
|
2013-08-01 18:13:14 +02:00
|
|
|
break;
|
|
|
|
case pb::remote::DISCONNECT:
|
|
|
|
close_connection_ = true;
|
|
|
|
break;
|
|
|
|
case pb::remote::REQUEST_PLAYLISTS:
|
|
|
|
SendPlaylists(msg);
|
|
|
|
break;
|
|
|
|
case pb::remote::REQUEST_PLAYLIST_SONGS:
|
|
|
|
GetPlaylistSongs(msg);
|
|
|
|
break;
|
|
|
|
case pb::remote::SET_VOLUME:
|
|
|
|
emit SetVolume(msg.request_set_volume().volume());
|
|
|
|
break;
|
|
|
|
case pb::remote::PLAY:
|
|
|
|
emit Play();
|
|
|
|
break;
|
|
|
|
case pb::remote::PLAYPAUSE:
|
|
|
|
emit PlayPause();
|
|
|
|
break;
|
|
|
|
case pb::remote::PAUSE:
|
|
|
|
emit Pause();
|
|
|
|
break;
|
|
|
|
case pb::remote::STOP:
|
|
|
|
emit Stop();
|
|
|
|
break;
|
|
|
|
case pb::remote::STOP_AFTER:
|
|
|
|
emit StopAfterCurrent();
|
|
|
|
break;
|
|
|
|
case pb::remote::NEXT:
|
|
|
|
emit Next();
|
|
|
|
break;
|
|
|
|
case pb::remote::PREVIOUS:
|
|
|
|
emit Previous();
|
|
|
|
break;
|
|
|
|
case pb::remote::CHANGE_SONG:
|
|
|
|
ChangeSong(msg);
|
|
|
|
break;
|
|
|
|
case pb::remote::SHUFFLE_PLAYLIST:
|
|
|
|
emit ShuffleCurrent();
|
|
|
|
break;
|
|
|
|
case pb::remote::REPEAT:
|
|
|
|
SetRepeatMode(msg.repeat());
|
|
|
|
break;
|
|
|
|
case pb::remote::SHUFFLE:
|
|
|
|
SetShuffleMode(msg.shuffle());
|
|
|
|
break;
|
2013-01-23 20:02:12 +01:00
|
|
|
case pb::remote::SET_TRACK_POSITION:
|
2013-08-01 18:13:14 +02:00
|
|
|
emit SeekTo(msg.request_set_track_position().position());
|
|
|
|
break;
|
|
|
|
case pb::remote::INSERT_URLS:
|
|
|
|
InsertUrls(msg);
|
|
|
|
break;
|
|
|
|
case pb::remote::REMOVE_SONGS:
|
|
|
|
RemoveSongs(msg);
|
|
|
|
break;
|
2013-04-20 16:11:57 +02:00
|
|
|
case pb::remote::OPEN_PLAYLIST:
|
2013-08-01 18:13:14 +02:00
|
|
|
OpenPlaylist(msg);
|
|
|
|
break;
|
2013-04-20 16:11:57 +02:00
|
|
|
case pb::remote::CLOSE_PLAYLIST:
|
2013-08-01 18:13:14 +02:00
|
|
|
ClosePlaylist(msg);
|
|
|
|
break;
|
2020-11-27 13:05:53 +01:00
|
|
|
case pb::remote::UPDATE_PLAYLIST:
|
|
|
|
UpdatePlaylist(msg);
|
|
|
|
break;
|
2013-08-01 18:13:14 +02:00
|
|
|
case pb::remote::LOVE:
|
|
|
|
emit Love();
|
|
|
|
break;
|
|
|
|
case pb::remote::BAN:
|
|
|
|
emit Ban();
|
|
|
|
break;
|
|
|
|
case pb::remote::GET_LYRICS:
|
|
|
|
emit GetLyrics();
|
|
|
|
break;
|
2013-07-12 12:31:27 +02:00
|
|
|
case pb::remote::DOWNLOAD_SONGS:
|
2014-11-13 22:31:49 +01:00
|
|
|
client->song_sender()->SendSongs(msg.request_download_songs());
|
2013-08-01 18:13:14 +02:00
|
|
|
break;
|
2013-07-23 16:59:50 +02:00
|
|
|
case pb::remote::SONG_OFFER_RESPONSE:
|
2020-09-18 16:15:19 +02:00
|
|
|
client->song_sender()->ResponseSongOffer(
|
|
|
|
msg.response_song_offer().accepted());
|
2013-08-01 18:13:14 +02:00
|
|
|
break;
|
|
|
|
case pb::remote::GET_LIBRARY:
|
|
|
|
emit SendLibrary(client);
|
|
|
|
break;
|
2013-08-15 20:52:12 +02:00
|
|
|
case pb::remote::RATE_SONG:
|
|
|
|
RateSong(msg);
|
|
|
|
break;
|
2014-10-21 17:59:02 +02:00
|
|
|
case pb::remote::GLOBAL_SEARCH:
|
|
|
|
GlobalSearch(client, msg);
|
|
|
|
break;
|
2020-11-27 13:05:53 +01:00
|
|
|
case pb::remote::REQUEST_FILES:
|
|
|
|
emit SendListFiles(
|
|
|
|
QString::fromStdString(msg.request_list_files().relative_path()),
|
|
|
|
client);
|
|
|
|
break;
|
|
|
|
case pb::remote::APPEND_FILES:
|
|
|
|
AppendFilesToPlaylist(msg);
|
|
|
|
break;
|
|
|
|
case pb::remote::REQUEST_SAVED_RADIOS:
|
|
|
|
emit SendSavedRadios(client);
|
|
|
|
break;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
default:
|
|
|
|
break;
|
2013-01-03 21:40:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-15 13:05:43 +01:00
|
|
|
void IncomingDataParser::GetPlaylistSongs(const pb::remote::Message& msg) {
|
|
|
|
emit SendPlaylistSongs(msg.request_playlist_songs().id());
|
2013-01-03 21:40:47 +01:00
|
|
|
}
|
|
|
|
|
2013-01-15 13:05:43 +01:00
|
|
|
void IncomingDataParser::ChangeSong(const pb::remote::Message& msg) {
|
2013-01-03 21:40:47 +01:00
|
|
|
// Get the first entry and check if there is a song
|
2013-01-15 13:05:43 +01:00
|
|
|
const pb::remote::RequestChangeSong& request = msg.request_change_song();
|
2013-01-03 21:40:47 +01:00
|
|
|
|
|
|
|
// Check if we need to change the playlist
|
2013-01-15 13:05:43 +01:00
|
|
|
if (request.playlist_id() != app_->playlist_manager()->active_id()) {
|
|
|
|
emit SetActivePlaylist(request.playlist_id());
|
2013-01-03 21:40:47 +01:00
|
|
|
}
|
|
|
|
|
2018-06-13 22:37:13 +02:00
|
|
|
switch (doubleclick_playlist_addmode_) {
|
2018-06-13 22:03:23 +02:00
|
|
|
// Play the selected song
|
|
|
|
case MainWindow::PlaylistAddBehaviour_Play:
|
|
|
|
emit PlayAt(request.song_index(), Engine::Manual, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Enque the selected song
|
|
|
|
case MainWindow::PlaylistAddBehaviour_Enqueue:
|
|
|
|
emit Enque(request.playlist_id(), request.song_index());
|
2018-06-13 22:37:13 +02:00
|
|
|
if (app_->player()->GetState() != Engine::Playing) {
|
|
|
|
emit PlayAt(request.song_index(), Engine::Manual, false);
|
2018-06-13 22:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2013-01-03 21:40:47 +01:00
|
|
|
}
|
2013-01-15 14:43:02 +01:00
|
|
|
|
|
|
|
void IncomingDataParser::SetRepeatMode(const pb::remote::Repeat& repeat) {
|
|
|
|
switch (repeat.repeat_mode()) {
|
2013-08-01 18:13:14 +02:00
|
|
|
case pb::remote::Repeat_Off:
|
|
|
|
emit SetRepeatMode(PlaylistSequence::Repeat_Off);
|
|
|
|
break;
|
|
|
|
case pb::remote::Repeat_Track:
|
|
|
|
emit SetRepeatMode(PlaylistSequence::Repeat_Track);
|
|
|
|
break;
|
|
|
|
case pb::remote::Repeat_Album:
|
|
|
|
emit SetRepeatMode(PlaylistSequence::Repeat_Album);
|
|
|
|
break;
|
|
|
|
case pb::remote::Repeat_Playlist:
|
|
|
|
emit SetRepeatMode(PlaylistSequence::Repeat_Playlist);
|
|
|
|
break;
|
2014-02-07 16:34:20 +01:00
|
|
|
default:
|
|
|
|
break;
|
2013-01-15 14:43:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncomingDataParser::SetShuffleMode(const pb::remote::Shuffle& shuffle) {
|
|
|
|
switch (shuffle.shuffle_mode()) {
|
2013-08-01 18:13:14 +02:00
|
|
|
case pb::remote::Shuffle_Off:
|
|
|
|
emit SetShuffleMode(PlaylistSequence::Shuffle_Off);
|
|
|
|
break;
|
|
|
|
case pb::remote::Shuffle_All:
|
|
|
|
emit SetShuffleMode(PlaylistSequence::Shuffle_All);
|
|
|
|
break;
|
|
|
|
case pb::remote::Shuffle_InsideAlbum:
|
|
|
|
emit SetShuffleMode(PlaylistSequence::Shuffle_InsideAlbum);
|
|
|
|
break;
|
|
|
|
case pb::remote::Shuffle_Albums:
|
|
|
|
emit SetShuffleMode(PlaylistSequence::Shuffle_Albums);
|
|
|
|
break;
|
2014-02-07 16:34:20 +01:00
|
|
|
default:
|
|
|
|
break;
|
2013-01-15 14:43:02 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-27 16:54:02 +01:00
|
|
|
|
2013-04-13 11:57:05 +02:00
|
|
|
void IncomingDataParser::InsertUrls(const pb::remote::Message& msg) {
|
|
|
|
const pb::remote::RequestInsertUrls& request = msg.request_insert_urls();
|
2020-11-27 13:05:53 +01:00
|
|
|
int playlist_id = request.playlist_id();
|
2013-04-13 11:57:05 +02:00
|
|
|
|
2015-06-13 16:00:15 +02:00
|
|
|
// Insert plain urls without metadata
|
2019-02-22 18:44:39 +01:00
|
|
|
if (!request.urls().empty()) {
|
2015-06-13 16:00:15 +02:00
|
|
|
QList<QUrl> urls;
|
|
|
|
for (auto it = request.urls().begin(); it != request.urls().end(); ++it) {
|
|
|
|
std::string s = *it;
|
|
|
|
urls << QUrl(QStringFromStdString(s));
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:05:53 +01:00
|
|
|
if (request.has_new_playlist_name())
|
|
|
|
playlist_id =
|
|
|
|
app_->playlist_manager()->New(request.new_playlist_name().c_str());
|
|
|
|
|
2015-06-13 16:00:15 +02:00
|
|
|
// Insert the urls
|
2020-11-27 13:05:53 +01:00
|
|
|
emit InsertUrls(playlist_id, urls, request.position(), request.play_now(),
|
|
|
|
request.enqueue());
|
2013-04-13 11:57:05 +02:00
|
|
|
}
|
|
|
|
|
2015-06-13 16:00:15 +02:00
|
|
|
// Add songs with metadata if present
|
2019-02-22 18:44:39 +01:00
|
|
|
if (!request.songs().empty()) {
|
2015-06-13 16:00:15 +02:00
|
|
|
SongList songs;
|
|
|
|
for (int i = 0; i < request.songs().size(); i++) {
|
|
|
|
songs << CreateSongFromProtobuf(request.songs(i));
|
|
|
|
}
|
2020-11-27 13:05:53 +01:00
|
|
|
|
|
|
|
// create a new playlist if required and not already done above by
|
|
|
|
// InsertUrls
|
|
|
|
if (request.has_new_playlist_name() && playlist_id == request.playlist_id())
|
|
|
|
playlist_id =
|
|
|
|
app_->playlist_manager()->New(request.new_playlist_name().c_str());
|
|
|
|
|
2015-06-13 16:00:15 +02:00
|
|
|
emit InsertSongs(request.playlist_id(), songs, request.position(),
|
|
|
|
request.play_now(), request.enqueue());
|
|
|
|
}
|
2013-04-13 11:57:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IncomingDataParser::RemoveSongs(const pb::remote::Message& msg) {
|
2014-02-07 16:34:20 +01:00
|
|
|
const pb::remote::RequestRemoveSongs& request = msg.request_remove_songs();
|
2013-04-13 11:57:05 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Extract urls
|
|
|
|
QList<int> songs;
|
|
|
|
for (int i = 0; i < request.songs().size(); i++) {
|
|
|
|
songs.append(request.songs(i));
|
|
|
|
}
|
2013-04-13 11:57:05 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Insert the urls
|
|
|
|
emit RemoveSongs(request.playlist_id(), songs);
|
2013-04-13 11:57:05 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
void IncomingDataParser::ClientConnect(const pb::remote::Message& msg,
|
|
|
|
RemoteClient* client) {
|
2013-03-27 16:54:02 +01:00
|
|
|
// Always sned the Clementine infos
|
|
|
|
emit SendClementineInfo();
|
|
|
|
|
|
|
|
// Check if we should send the first data
|
2015-04-24 17:30:21 +02:00
|
|
|
if (!client->isDownloader()) {
|
|
|
|
if (!msg.request_connect().has_send_playlist_songs() // legacy
|
|
|
|
|| msg.request_connect().send_playlist_songs()) {
|
|
|
|
emit SendFirstData(true);
|
|
|
|
} else {
|
|
|
|
emit SendFirstData(false);
|
|
|
|
}
|
2013-03-27 16:54:02 +01:00
|
|
|
}
|
|
|
|
}
|
2013-04-16 13:57:04 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void IncomingDataParser::SendPlaylists(const pb::remote::Message& msg) {
|
|
|
|
if (!msg.has_request_playlists() ||
|
|
|
|
!msg.request_playlists().include_closed()) {
|
2013-04-16 13:57:04 +02:00
|
|
|
emit SendAllActivePlaylists();
|
|
|
|
} else {
|
|
|
|
emit SendAllPlaylists();
|
|
|
|
}
|
|
|
|
}
|
2013-04-20 16:11:57 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void IncomingDataParser::OpenPlaylist(const pb::remote::Message& msg) {
|
2013-04-20 16:11:57 +02:00
|
|
|
emit Open(msg.request_open_playlist().playlist_id());
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void IncomingDataParser::ClosePlaylist(const pb::remote::Message& msg) {
|
2013-04-20 16:11:57 +02:00
|
|
|
emit Close(msg.request_close_playlist().playlist_id());
|
|
|
|
}
|
2013-08-15 20:52:12 +02:00
|
|
|
|
2020-11-27 13:05:53 +01:00
|
|
|
void IncomingDataParser::UpdatePlaylist(const pb::remote::Message& msg) {
|
|
|
|
const pb::remote::RequestUpdatePlaylist& req_update =
|
|
|
|
msg.request_update_playlist();
|
|
|
|
if (req_update.has_create_new_playlist() &&
|
|
|
|
req_update.create_new_playlist()) {
|
|
|
|
emit New(req_update.has_new_playlist_name()
|
|
|
|
? req_update.new_playlist_name().c_str()
|
|
|
|
: "New Playlist");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (req_update.has_clear_playlist() && req_update.clear_playlist()) {
|
|
|
|
emit Clear(req_update.playlist_id());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (req_update.has_new_playlist_name() &&
|
|
|
|
req_update.new_playlist_name().size())
|
|
|
|
emit Rename(req_update.playlist_id(),
|
|
|
|
req_update.new_playlist_name().c_str());
|
|
|
|
if (req_update.has_favorite())
|
|
|
|
emit Favorite(req_update.playlist_id(), req_update.favorite());
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void IncomingDataParser::RateSong(const pb::remote::Message& msg) {
|
|
|
|
double rating = (double)msg.request_rate_song().rating();
|
2013-08-15 20:52:12 +02:00
|
|
|
emit RateCurrentSong(rating);
|
|
|
|
}
|
2014-10-21 17:59:02 +02:00
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
void IncomingDataParser::GlobalSearch(RemoteClient* client,
|
|
|
|
const pb::remote::Message& msg) {
|
2014-10-21 17:59:02 +02:00
|
|
|
emit DoGlobalSearch(QStringFromStdString(msg.request_global_search().query()),
|
|
|
|
client);
|
|
|
|
}
|
2015-06-13 16:00:15 +02:00
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
Song IncomingDataParser::CreateSongFromProtobuf(
|
|
|
|
const pb::remote::SongMetadata& pb) {
|
2015-06-13 16:00:15 +02:00
|
|
|
Song song;
|
2020-09-18 16:15:19 +02:00
|
|
|
song.Init(QStringFromStdString(pb.title()), QStringFromStdString(pb.artist()),
|
|
|
|
QStringFromStdString(pb.album()), pb.length() * kNsecPerSec);
|
2015-06-13 16:00:15 +02:00
|
|
|
|
|
|
|
song.set_albumartist(QStringFromStdString(pb.albumartist()));
|
|
|
|
song.set_genre(QStringFromStdString(pb.genre()));
|
|
|
|
song.set_year(QStringFromStdString(pb.pretty_year()).toInt());
|
|
|
|
song.set_track(pb.track());
|
|
|
|
song.set_disc(pb.disc());
|
|
|
|
song.set_url(QUrl(QStringFromStdString(pb.url())));
|
|
|
|
song.set_filesize(pb.file_size());
|
|
|
|
song.set_rating(pb.rating());
|
|
|
|
song.set_basefilename(QStringFromStdString(pb.filename()));
|
|
|
|
song.set_art_automatic(QStringFromStdString(pb.art_automatic()));
|
|
|
|
song.set_art_manual(QStringFromStdString(pb.art_manual()));
|
|
|
|
song.set_filetype(static_cast<Song::FileType>(pb.type()));
|
|
|
|
|
|
|
|
return song;
|
|
|
|
}
|
2020-11-27 13:05:53 +01:00
|
|
|
|
|
|
|
void IncomingDataParser::AppendFilesToPlaylist(const pb::remote::Message& msg) {
|
|
|
|
if (files_root_folder_.isEmpty()) { // should never happen...
|
|
|
|
qLog(Warning) << "Remote root dir is not set although receiving "
|
|
|
|
"APPEND_FILES request...";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QDir root_dir(files_root_folder_);
|
|
|
|
if (!root_dir.exists()) {
|
|
|
|
qLog(Warning) << "Remote root dir doesn't exist...";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const pb::remote::RequestAppendFiles& req_append = msg.request_append_files();
|
|
|
|
QString relative_path = QString::fromStdString(req_append.relative_path());
|
|
|
|
if (relative_path.startsWith("/")) relative_path.remove(0, 1);
|
|
|
|
|
|
|
|
QFileInfo fi_folder(root_dir, relative_path);
|
2020-12-16 10:39:02 +01:00
|
|
|
if (!fi_folder.exists()) {
|
2020-11-27 13:05:53 +01:00
|
|
|
qLog(Warning) << "Remote relative path " << relative_path
|
|
|
|
<< " doesn't exist...";
|
2020-12-16 10:39:02 +01:00
|
|
|
return;
|
|
|
|
} else if (!fi_folder.isDir()) {
|
2020-11-27 13:05:53 +01:00
|
|
|
qLog(Warning) << "Remote relative path " << relative_path
|
|
|
|
<< " is not a directory...";
|
2020-12-16 10:39:02 +01:00
|
|
|
return;
|
|
|
|
} else if (root_dir.relativeFilePath(fi_folder.absoluteFilePath())
|
|
|
|
.startsWith("../")) {
|
2020-11-27 13:05:53 +01:00
|
|
|
qLog(Warning) << "Remote relative path " << relative_path
|
|
|
|
<< " should not be accessed...";
|
2020-12-16 10:39:02 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QUrl> urls;
|
|
|
|
QDir dir(fi_folder.absoluteFilePath());
|
|
|
|
for (const auto& file : req_append.files()) {
|
|
|
|
QFileInfo fi(dir, file.c_str());
|
|
|
|
if (fi.exists()) urls << QUrl::fromLocalFile(fi.canonicalFilePath());
|
|
|
|
}
|
|
|
|
if (!urls.isEmpty()) {
|
|
|
|
MimeData* data = new MimeData;
|
|
|
|
data->setUrls(urls);
|
|
|
|
if (req_append.has_play_now()) data->play_now_ = req_append.play_now();
|
|
|
|
if (req_append.has_clear_first())
|
|
|
|
data->clear_first_ = req_append.clear_first();
|
|
|
|
if (req_append.has_new_playlist_name()) {
|
|
|
|
QString playlist_name =
|
|
|
|
QString::fromStdString(req_append.new_playlist_name());
|
|
|
|
if (!playlist_name.isEmpty()) {
|
|
|
|
data->open_in_new_playlist_ = true;
|
|
|
|
data->name_for_new_playlist_ = playlist_name;
|
2020-11-27 13:05:53 +01:00
|
|
|
}
|
2020-12-16 10:39:02 +01:00
|
|
|
} else if (req_append.has_playlist_id()) {
|
|
|
|
// if playing we will drop the files in another playlist
|
|
|
|
if (app_->player()->GetState() == Engine::Playing)
|
|
|
|
data->playlist_id = req_append.playlist_id();
|
|
|
|
else
|
|
|
|
// as me may play the song, we change the current playlist
|
|
|
|
emit SetCurrentPlaylist(req_append.playlist_id());
|
2020-11-27 13:05:53 +01:00
|
|
|
}
|
2020-12-16 10:39:02 +01:00
|
|
|
emit AddToPlaylistSignal(data);
|
2020-11-27 13:05:53 +01:00
|
|
|
}
|
|
|
|
}
|