do not store commands list in MPD::Connection
it should have sent commandlist begin and end commands from the beginning, having separated functions just to handle queueing commands was plainly ugly.
This commit is contained in:
@@ -133,9 +133,14 @@ void Browser::EnterPressed()
|
|||||||
{
|
{
|
||||||
SongList list;
|
SongList list;
|
||||||
Mpd->GetPlaylistContent(locale_to_utf_cpy(item.name), list);
|
Mpd->GetPlaylistContent(locale_to_utf_cpy(item.name), list);
|
||||||
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
Mpd->StartCommandsList();
|
||||||
Mpd->QueueAddSong(**it);
|
SongList::const_iterator it = list.begin();
|
||||||
if (Mpd->CommitQueue())
|
for (; it != list.end(); it++)
|
||||||
|
if (Mpd->AddSong(**it) < 0)
|
||||||
|
break;
|
||||||
|
Mpd->CommitCommandsList();
|
||||||
|
|
||||||
|
if (it != list.begin())
|
||||||
{
|
{
|
||||||
ShowMessage("Loading and playing playlist %s...", item.name.c_str());
|
ShowMessage("Loading and playing playlist %s...", item.name.c_str());
|
||||||
Song *s = &myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
|
Song *s = &myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
|
||||||
@@ -179,9 +184,14 @@ void Browser::SpacePressed()
|
|||||||
SongList list;
|
SongList list;
|
||||||
Mpd->GetDirectoryRecursive(locale_to_utf_cpy(item.name), list);
|
Mpd->GetDirectoryRecursive(locale_to_utf_cpy(item.name), list);
|
||||||
|
|
||||||
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
Mpd->StartCommandsList();
|
||||||
Mpd->QueueAddSong(**it);
|
SongList::const_iterator it = list.begin();
|
||||||
if (Mpd->CommitQueue())
|
for (; it != list.end(); it++)
|
||||||
|
if (Mpd->AddSong(**it) < 0)
|
||||||
|
break;
|
||||||
|
Mpd->CommitCommandsList();
|
||||||
|
|
||||||
|
if (it != list.begin())
|
||||||
{
|
{
|
||||||
ShowMessage("Added folder: %s", item.name.c_str());
|
ShowMessage("Added folder: %s", item.name.c_str());
|
||||||
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
|
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
|
||||||
@@ -198,16 +208,17 @@ void Browser::SpacePressed()
|
|||||||
{
|
{
|
||||||
Playlist::BlockUpdate = 1;
|
Playlist::BlockUpdate = 1;
|
||||||
long long hash = w->Current().song->GetHash();
|
long long hash = w->Current().song->GetHash();
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
|
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
|
||||||
{
|
{
|
||||||
if (myPlaylist->Main()->at(i).GetHash() == hash)
|
if (myPlaylist->Main()->at(i).GetHash() == hash)
|
||||||
{
|
{
|
||||||
Mpd->QueueDeleteSong(i);
|
Mpd->Delete(i);
|
||||||
myPlaylist->Main()->DeleteOption(i);
|
myPlaylist->Main()->DeleteOption(i);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
w->BoldOption(w->Choice(), 0);
|
w->BoldOption(w->Choice(), 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -225,9 +236,14 @@ void Browser::SpacePressed()
|
|||||||
{
|
{
|
||||||
SongList list;
|
SongList list;
|
||||||
Mpd->GetPlaylistContent(locale_to_utf_cpy(item.name), list);
|
Mpd->GetPlaylistContent(locale_to_utf_cpy(item.name), list);
|
||||||
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
Mpd->StartCommandsList();
|
||||||
Mpd->QueueAddSong(**it);
|
SongList::const_iterator it = list.begin();
|
||||||
if (Mpd->CommitQueue())
|
for (; it != list.end(); it++)
|
||||||
|
if (Mpd->AddSong(**it) < 0)
|
||||||
|
break;
|
||||||
|
Mpd->CommitCommandsList();
|
||||||
|
|
||||||
|
if (it != list.begin())
|
||||||
{
|
{
|
||||||
ShowMessage("Loading playlist %s...", item.name.c_str());
|
ShowMessage("Loading playlist %s...", item.name.c_str());
|
||||||
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
|
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
|
||||||
|
|||||||
@@ -2066,7 +2066,7 @@ void mpd_sendPlaylistMoveCommand(mpd_Connection *connection,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mpd_sendPlaylistDeleteCommand(mpd_Connection *connection,
|
void mpd_sendPlaylistDeleteCommand(mpd_Connection *connection,
|
||||||
char *playlist, int pos)
|
const char *playlist, int pos)
|
||||||
{
|
{
|
||||||
char *sPlaylist = mpd_sanitizeArg(playlist);
|
char *sPlaylist = mpd_sanitizeArg(playlist);
|
||||||
int len = strlen("playlistdelete")+2+strlen(sPlaylist)+3+INTLEN+3;
|
int len = strlen("playlistdelete")+2+strlen(sPlaylist)+3+INTLEN+3;
|
||||||
|
|||||||
@@ -673,7 +673,7 @@ void mpd_sendPlaylistMoveCommand(mpd_Connection *connection,
|
|||||||
char *playlist, int from, int to);
|
char *playlist, int from, int to);
|
||||||
|
|
||||||
void mpd_sendPlaylistDeleteCommand(mpd_Connection *connection,
|
void mpd_sendPlaylistDeleteCommand(mpd_Connection *connection,
|
||||||
char *playlist, int pos);
|
const char *playlist, int pos);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -336,9 +336,14 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
|
|||||||
Mpd->StartSearch(1);
|
Mpd->StartSearch(1);
|
||||||
Mpd->AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->Current()));
|
Mpd->AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->Current()));
|
||||||
Mpd->CommitSearch(list);
|
Mpd->CommitSearch(list);
|
||||||
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
Mpd->StartCommandsList();
|
||||||
Mpd->QueueAddSong(**it);
|
SongList::const_iterator it = list.begin();
|
||||||
if (Mpd->CommitQueue())
|
for (; it != list.end(); it++)
|
||||||
|
if (Mpd->AddSong(**it) < 0)
|
||||||
|
break;
|
||||||
|
Mpd->CommitCommandsList();
|
||||||
|
|
||||||
|
if (it != list.begin())
|
||||||
{
|
{
|
||||||
string tag_type = IntoStr(Config.media_lib_primary_tag);
|
string tag_type = IntoStr(Config.media_lib_primary_tag);
|
||||||
ToLower(tag_type);
|
ToLower(tag_type);
|
||||||
@@ -355,9 +360,14 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
|
|||||||
}
|
}
|
||||||
else if (w == Albums)
|
else if (w == Albums)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < Songs->Size(); i++)
|
Mpd->StartCommandsList();
|
||||||
Mpd->QueueAddSong(Songs->at(i));
|
size_t i = 0;
|
||||||
if (Mpd->CommitQueue())
|
for (; i < Songs->Size(); i++)
|
||||||
|
if (Mpd->AddSong(Songs->at(i)) < 0)
|
||||||
|
break;
|
||||||
|
Mpd->CommitCommandsList();
|
||||||
|
|
||||||
|
if (i)
|
||||||
{
|
{
|
||||||
ShowMessage("Adding songs from album \"%s\"", Albums->Current().second.Album.c_str());
|
ShowMessage("Adding songs from album \"%s\"", Albums->Current().second.Album.c_str());
|
||||||
Song *s = &myPlaylist->Main()->at(myPlaylist->Main()->Size()-Songs->Size());
|
Song *s = &myPlaylist->Main()->at(myPlaylist->Main()->Size()-Songs->Size());
|
||||||
@@ -392,16 +402,17 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Playlist::BlockUpdate = 1;
|
Playlist::BlockUpdate = 1;
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
|
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
|
||||||
{
|
{
|
||||||
if (myPlaylist->Main()->at(i).GetHash() == hash)
|
if (myPlaylist->Main()->at(i).GetHash() == hash)
|
||||||
{
|
{
|
||||||
Mpd->QueueDeleteSong(i);
|
Mpd->Delete(i);
|
||||||
myPlaylist->Main()->DeleteOption(i);
|
myPlaylist->Main()->DeleteOption(i);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
Songs->BoldOption(Songs->Choice(), 0);
|
Songs->BoldOption(Songs->Choice(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
166
src/mpdpp.cpp
166
src/mpdpp.cpp
@@ -30,6 +30,7 @@ const char *MPD::Message::FullPlaylist = "Playlist is full!";
|
|||||||
const char *MPD::Message::FunctionDisabledFilteringEnabled = "Function disabled due to enabled filtering in playlist";
|
const char *MPD::Message::FunctionDisabledFilteringEnabled = "Function disabled due to enabled filtering in playlist";
|
||||||
|
|
||||||
Connection::Connection() : isConnected(0),
|
Connection::Connection() : isConnected(0),
|
||||||
|
isCommandsListEnabled(0),
|
||||||
itsErrorCode(0),
|
itsErrorCode(0),
|
||||||
itsMaxPlaylistLength(-1),
|
itsMaxPlaylistLength(-1),
|
||||||
itsHost("localhost"),
|
itsHost("localhost"),
|
||||||
@@ -57,7 +58,6 @@ Connection::~Connection()
|
|||||||
mpd_freeStatus(itsOldStatus);
|
mpd_freeStatus(itsOldStatus);
|
||||||
if (itsCurrentStatus)
|
if (itsCurrentStatus)
|
||||||
mpd_freeStatus(itsCurrentStatus);
|
mpd_freeStatus(itsCurrentStatus);
|
||||||
ClearQueue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Connection::Connect()
|
bool Connection::Connect()
|
||||||
@@ -99,8 +99,8 @@ void Connection::Disconnect()
|
|||||||
itsCurrentStatus = 0;
|
itsCurrentStatus = 0;
|
||||||
itsOldStatus = 0;
|
itsOldStatus = 0;
|
||||||
isConnected = 0;
|
isConnected = 0;
|
||||||
|
isCommandsListEnabled = 0;
|
||||||
itsMaxPlaylistLength = -1;
|
itsMaxPlaylistLength = -1;
|
||||||
ClearQueue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Connection::Version() const
|
float Connection::Version() const
|
||||||
@@ -217,6 +217,7 @@ void Connection::Execute(const string &command) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_executeCommand(itsConnection, command.c_str());
|
mpd_executeCommand(itsConnection, command.c_str());
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -232,6 +233,7 @@ void Connection::Play(int pos) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendPlayCommand(itsConnection, pos);
|
mpd_sendPlayCommand(itsConnection, pos);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,6 +243,7 @@ void Connection::PlayID(int id) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendPlayIdCommand(itsConnection, id);
|
mpd_sendPlayIdCommand(itsConnection, id);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,6 +253,7 @@ void Connection::Pause() const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendPauseCommand(itsConnection, itsCurrentStatus->state != psPause);
|
mpd_sendPauseCommand(itsConnection, itsCurrentStatus->state != psPause);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,6 +263,7 @@ void Connection::Stop() const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendStopCommand(itsConnection);
|
mpd_sendStopCommand(itsConnection);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -268,6 +273,7 @@ void Connection::Next() const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendNextCommand(itsConnection);
|
mpd_sendNextCommand(itsConnection);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -277,6 +283,7 @@ void Connection::Prev() const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendPrevCommand(itsConnection);
|
mpd_sendPrevCommand(itsConnection);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,6 +293,7 @@ void Connection::Move(int from, int to) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendMoveCommand(itsConnection, from, to);
|
mpd_sendMoveCommand(itsConnection, from, to);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,6 +303,7 @@ void Connection::Swap(int from, int to) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendSwapCommand(itsConnection, from, to);
|
mpd_sendSwapCommand(itsConnection, from, to);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,6 +313,7 @@ void Connection::Seek(int where) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendSeekCommand(itsConnection, itsCurrentStatus->song, where);
|
mpd_sendSeekCommand(itsConnection, itsCurrentStatus->song, where);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -313,6 +323,7 @@ void Connection::Shuffle() const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendShuffleCommand(itsConnection);
|
mpd_sendShuffleCommand(itsConnection);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,6 +333,7 @@ void Connection::ClearPlaylist() const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendClearCommand(itsConnection);
|
mpd_sendClearCommand(itsConnection);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -337,6 +349,7 @@ void Connection::AddToPlaylist(const string &path, const string &file) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendPlaylistAddCommand(itsConnection, (char *) path.c_str(), (char *) file.c_str());
|
mpd_sendPlaylistAddCommand(itsConnection, (char *) path.c_str(), (char *) file.c_str());
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -346,6 +359,7 @@ void Connection::Move(const string &path, int from, int to) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendPlaylistMoveCommand(itsConnection, (char *) path.c_str(), from, to);
|
mpd_sendPlaylistMoveCommand(itsConnection, (char *) path.c_str(), from, to);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,6 +369,7 @@ void Connection::Rename(const string &from, const string &to) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendRenameCommand(itsConnection, from.c_str(), to.c_str());
|
mpd_sendRenameCommand(itsConnection, from.c_str(), to.c_str());
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -453,6 +468,7 @@ void Connection::SetRepeat(bool mode) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendRepeatCommand(itsConnection, mode);
|
mpd_sendRepeatCommand(itsConnection, mode);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -462,6 +478,7 @@ void Connection::SetRandom(bool mode) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendRandomCommand(itsConnection, mode);
|
mpd_sendRandomCommand(itsConnection, mode);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -471,6 +488,7 @@ void Connection::SetVolume(int vol) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendSetvolCommand(itsConnection, vol);
|
mpd_sendSetvolCommand(itsConnection, vol);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -480,6 +498,7 @@ void Connection::SetCrossfade(int crossfade) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendCrossfadeCommand(itsConnection, crossfade);
|
mpd_sendCrossfadeCommand(itsConnection, crossfade);
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -492,11 +511,15 @@ int Connection::AddSong(const string &path)
|
|||||||
if (GetPlaylistLength() < itsMaxPlaylistLength)
|
if (GetPlaylistLength() < itsMaxPlaylistLength)
|
||||||
{
|
{
|
||||||
id = mpd_sendAddIdCommand(itsConnection, path.c_str());
|
id = mpd_sendAddIdCommand(itsConnection, path.c_str());
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
|
{
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (itsErrorHandler)
|
id = 0;
|
||||||
|
}
|
||||||
|
else if (itsErrorHandler)
|
||||||
itsErrorHandler(this, MPD_ACK_ERROR_PLAYLIST_MAX, Message::FullPlaylist, NULL);
|
itsErrorHandler(this, MPD_ACK_ERROR_PLAYLIST_MAX, Message::FullPlaylist, NULL);
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
@@ -507,142 +530,57 @@ int Connection::AddSong(const Song &s)
|
|||||||
return !s.Empty() ? (AddSong((!s.IsFromDB() ? "file://" : "") + (s.Localized() ? locale_to_utf_cpy(s.GetFile()) : s.GetFile()))) : -1;
|
return !s.Empty() ? (AddSong((!s.IsFromDB() ? "file://" : "") + (s.Localized() ? locale_to_utf_cpy(s.GetFile()) : s.GetFile()))) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::QueueAddSong(const string &path)
|
void Connection::Delete(int pos) const
|
||||||
{
|
|
||||||
if (isConnected && GetPlaylistLength() < itsMaxPlaylistLength)
|
|
||||||
{
|
|
||||||
QueueCommand *q = new QueueCommand;
|
|
||||||
q->type = qctAdd;
|
|
||||||
q->item_path = path;
|
|
||||||
itsQueue.push_back(q);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::QueueAddSong(const Song &s)
|
|
||||||
{
|
|
||||||
if (!s.Empty())
|
|
||||||
QueueAddSong((!s.IsFromDB() ? "file://" : "") + (s.Localized() ? locale_to_utf_cpy(s.GetFile()) : s.GetFile()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::QueueAddToPlaylist(const string &playlist, const string &path)
|
|
||||||
{
|
{
|
||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
QueueCommand *q = new QueueCommand;
|
mpd_sendDeleteCommand(itsConnection, pos);
|
||||||
q->type = qctAddToPlaylist;
|
if (!isCommandsListEnabled)
|
||||||
q->playlist_path = playlist;
|
mpd_finishCommand(itsConnection);
|
||||||
q->item_path = path;
|
|
||||||
itsQueue.push_back(q);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::QueueAddToPlaylist(const string &playlist, const Song &s)
|
void Connection::DeleteID(int id) const
|
||||||
{
|
|
||||||
if (!s.Empty())
|
|
||||||
QueueAddToPlaylist(playlist, s.Localized() ? locale_to_utf_cpy(s.GetFile()) : s.GetFile());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::QueueDeleteSong(int id)
|
|
||||||
{
|
{
|
||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
QueueCommand *q = new QueueCommand;
|
mpd_sendDeleteIdCommand(itsConnection, id);
|
||||||
q->type = qctDelete;
|
if (!isCommandsListEnabled)
|
||||||
q->id = id;
|
mpd_finishCommand(itsConnection);
|
||||||
itsQueue.push_back(q);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::QueueDeleteSongId(int id)
|
void Connection::Delete(const string &playlist, int pos) const
|
||||||
{
|
{
|
||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
QueueCommand *q = new QueueCommand;
|
mpd_sendPlaylistDeleteCommand(itsConnection, playlist.c_str(), pos);
|
||||||
q->type = qctDeleteID;
|
if (!isCommandsListEnabled)
|
||||||
q->id = id;
|
mpd_finishCommand(itsConnection);
|
||||||
itsQueue.push_back(q);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::QueueMove(int from, int to)
|
void Connection::StartCommandsList()
|
||||||
{
|
{
|
||||||
if (isConnected)
|
|
||||||
{
|
|
||||||
QueueCommand *q = new QueueCommand;
|
|
||||||
q->type = qctMove;
|
|
||||||
q->id = from;
|
|
||||||
q->id2 = to;
|
|
||||||
itsQueue.push_back(q);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::QueueMove(const string &playlist, int from, int to)
|
|
||||||
{
|
|
||||||
if (isConnected)
|
|
||||||
{
|
|
||||||
QueueCommand *q = new QueueCommand;
|
|
||||||
q->type = qctPlaylistMove;
|
|
||||||
q->playlist_path = playlist;
|
|
||||||
q->id = from;
|
|
||||||
q->id2 = to;
|
|
||||||
itsQueue.push_back(q);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::QueueDeleteFromPlaylist(const string &playlist, int pos)
|
|
||||||
{
|
|
||||||
if (isConnected)
|
|
||||||
{
|
|
||||||
QueueCommand *q = new QueueCommand;
|
|
||||||
q->type = qctDeleteFromPlaylist;
|
|
||||||
q->playlist_path = playlist;
|
|
||||||
q->id = pos;
|
|
||||||
itsQueue.push_back(q);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Connection::CommitQueue()
|
|
||||||
{
|
|
||||||
bool retval = false;
|
|
||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendCommandListBegin(itsConnection);
|
mpd_sendCommandListBegin(itsConnection);
|
||||||
for (std::vector<QueueCommand *>::const_iterator it = itsQueue.begin(); it != itsQueue.end(); it++)
|
isCommandsListEnabled = 1;
|
||||||
{
|
|
||||||
switch ((*it)->type)
|
|
||||||
{
|
|
||||||
case qctAdd:
|
|
||||||
mpd_sendAddCommand(itsConnection, (*it)->item_path.c_str());
|
|
||||||
break;
|
|
||||||
case qctAddToPlaylist:
|
|
||||||
mpd_sendPlaylistAddCommand(itsConnection, (char *) (*it)->playlist_path.c_str(), (char *) (*it)->item_path.c_str());
|
|
||||||
break;
|
|
||||||
case qctDelete:
|
|
||||||
mpd_sendDeleteCommand(itsConnection, (*it)->id);
|
|
||||||
break;
|
|
||||||
case qctDeleteID:
|
|
||||||
mpd_sendDeleteIdCommand(itsConnection, (*it)->id);
|
|
||||||
break;
|
|
||||||
case qctMove:
|
|
||||||
mpd_sendMoveCommand(itsConnection, (*it)->id, (*it)->id2);
|
|
||||||
break;
|
|
||||||
case qctPlaylistMove:
|
|
||||||
mpd_sendPlaylistMoveCommand(itsConnection, (char *) (*it)->playlist_path.c_str(), (*it)->id, (*it)->id2);
|
|
||||||
break;
|
|
||||||
case qctDeleteFromPlaylist:
|
|
||||||
mpd_sendPlaylistDeleteCommand(itsConnection, (char *) (*it)->playlist_path.c_str(), (*it)->id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Connection::CommitCommandsList()
|
||||||
|
{
|
||||||
|
if (isConnected)
|
||||||
|
{
|
||||||
mpd_sendCommandListEnd(itsConnection);
|
mpd_sendCommandListEnd(itsConnection);
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
if (GetPlaylistLength() == itsMaxPlaylistLength && itsErrorHandler)
|
if (GetPlaylistLength() == itsMaxPlaylistLength && itsErrorHandler)
|
||||||
itsErrorHandler(this, MPD_ACK_ERROR_PLAYLIST_MAX, Message::FullPlaylist, NULL);
|
itsErrorHandler(this, MPD_ACK_ERROR_PLAYLIST_MAX, Message::FullPlaylist, NULL);
|
||||||
retval = !itsQueue.empty();
|
isCommandsListEnabled = 0;
|
||||||
}
|
}
|
||||||
ClearQueue();
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::DeletePlaylist(const string &name) const
|
void Connection::DeletePlaylist(const string &name) const
|
||||||
@@ -650,6 +588,7 @@ void Connection::DeletePlaylist(const string &name) const
|
|||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
mpd_sendRmCommand(itsConnection, name.c_str());
|
mpd_sendRmCommand(itsConnection, name.c_str());
|
||||||
|
if (!isCommandsListEnabled)
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -888,13 +827,6 @@ int Connection::CheckForErrors()
|
|||||||
return itsErrorCode;
|
return itsErrorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::ClearQueue()
|
|
||||||
{
|
|
||||||
for (std::vector<QueueCommand *>::iterator it = itsQueue.begin(); it != itsQueue.end(); it++)
|
|
||||||
delete *it;
|
|
||||||
itsQueue.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MPD::FreeSongList(SongList &l)
|
void MPD::FreeSongList(SongList &l)
|
||||||
{
|
{
|
||||||
for (SongList::iterator i = l.begin(); i != l.end(); i++)
|
for (SongList::iterator i = l.begin(); i != l.end(); i++)
|
||||||
|
|||||||
29
src/mpdpp.h
29
src/mpdpp.h
@@ -35,7 +35,6 @@ namespace MPD
|
|||||||
extern const char *FunctionDisabledFilteringEnabled;
|
extern const char *FunctionDisabledFilteringEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum QueueCommandType { qctAdd, qctAddToPlaylist, qctDelete, qctDeleteID, qctMove, qctPlaylistMove, qctDeleteFromPlaylist };
|
|
||||||
enum ItemType { itDirectory, itSong, itPlaylist };
|
enum ItemType { itDirectory, itSong, itPlaylist };
|
||||||
enum PlayerState { psUnknown, psStop, psPlay, psPause };
|
enum PlayerState { psUnknown, psStop, psPlay, psPause };
|
||||||
|
|
||||||
@@ -72,16 +71,6 @@ namespace MPD
|
|||||||
|
|
||||||
class Connection
|
class Connection
|
||||||
{
|
{
|
||||||
struct QueueCommand
|
|
||||||
{
|
|
||||||
QueueCommand() : id(0), id2(0) { }
|
|
||||||
QueueCommandType type;
|
|
||||||
std::string playlist_path;
|
|
||||||
std::string item_path;
|
|
||||||
int id;
|
|
||||||
int id2;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef void (*StatusUpdater) (Connection *, StatusChanges, void *);
|
typedef void (*StatusUpdater) (Connection *, StatusChanges, void *);
|
||||||
typedef void (*ErrorHandler) (Connection *, int, const char *, void *);
|
typedef void (*ErrorHandler) (Connection *, int, const char *, void *);
|
||||||
|
|
||||||
@@ -153,16 +142,11 @@ namespace MPD
|
|||||||
|
|
||||||
int AddSong(const std::string &); // returns id of added song
|
int AddSong(const std::string &); // returns id of added song
|
||||||
int AddSong(const Song &); // returns id of added song
|
int AddSong(const Song &); // returns id of added song
|
||||||
void QueueAddSong(const std::string &);
|
void Delete(int) const;
|
||||||
void QueueAddSong(const Song &);
|
void DeleteID(int) const;
|
||||||
void QueueAddToPlaylist(const std::string &, const std::string &);
|
void Delete(const std::string &, int) const;
|
||||||
void QueueAddToPlaylist(const std::string &, const Song &);
|
void StartCommandsList();
|
||||||
void QueueDeleteSong(int);
|
void CommitCommandsList();
|
||||||
void QueueDeleteSongId(int);
|
|
||||||
void QueueMove(int, int);
|
|
||||||
void QueueMove(const std::string &, int, int);
|
|
||||||
void QueueDeleteFromPlaylist(const std::string &, int);
|
|
||||||
bool CommitQueue();
|
|
||||||
|
|
||||||
void DeletePlaylist(const std::string &) const;
|
void DeletePlaylist(const std::string &) const;
|
||||||
bool SavePlaylist(const std::string &) const;
|
bool SavePlaylist(const std::string &) const;
|
||||||
@@ -187,11 +171,11 @@ namespace MPD
|
|||||||
void GetDirectories(const std::string &, TagList &) const;
|
void GetDirectories(const std::string &, TagList &) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ClearQueue();
|
|
||||||
int CheckForErrors();
|
int CheckForErrors();
|
||||||
|
|
||||||
mpd_Connection *itsConnection;
|
mpd_Connection *itsConnection;
|
||||||
bool isConnected;
|
bool isConnected;
|
||||||
|
bool isCommandsListEnabled;
|
||||||
|
|
||||||
std::string itsErrorMessage;
|
std::string itsErrorMessage;
|
||||||
int itsErrorCode;
|
int itsErrorCode;
|
||||||
@@ -215,7 +199,6 @@ namespace MPD
|
|||||||
void *itsErrorHandlerUserdata;
|
void *itsErrorHandlerUserdata;
|
||||||
|
|
||||||
mpd_TagItems itsSearchedField;
|
mpd_TagItems itsSearchedField;
|
||||||
std::vector<QueueCommand *> itsQueue;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -442,11 +442,13 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
vector<size_t> list;
|
vector<size_t> list;
|
||||||
myPlaylist->Main()->GetSelected(list);
|
myPlaylist->Main()->GetSelected(list);
|
||||||
for (vector<size_t>::const_reverse_iterator it = list.rbegin(); it != ((const vector<size_t> &)list).rend(); it++)
|
Mpd->StartCommandsList();
|
||||||
|
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
|
||||||
{
|
{
|
||||||
Mpd->QueueDeleteSongId((*myPlaylist->Main())[*it].GetID());
|
Mpd->DeleteID((*myPlaylist->Main())[*it].GetID());
|
||||||
myPlaylist->Main()->DeleteOption(*it);
|
myPlaylist->Main()->DeleteOption(*it);
|
||||||
}
|
}
|
||||||
|
Mpd->CommitCommandsList();
|
||||||
myPlaylist->FixPositions(list.front());
|
myPlaylist->FixPositions(list.front());
|
||||||
ShowMessage("Selected items deleted!");
|
ShowMessage("Selected items deleted!");
|
||||||
}
|
}
|
||||||
@@ -461,7 +463,7 @@ int main(int argc, char *argv[])
|
|||||||
time(&Timer);
|
time(&Timer);
|
||||||
if (myPlaylist->NowPlaying > myPlaylist->CurrentSong()->GetPosition()) // needed for keeping proper
|
if (myPlaylist->NowPlaying > myPlaylist->CurrentSong()->GetPosition()) // needed for keeping proper
|
||||||
myPlaylist->NowPlaying--; // position of now playing song.
|
myPlaylist->NowPlaying--; // position of now playing song.
|
||||||
Mpd->QueueDeleteSongId(myPlaylist->CurrentSong()->GetID());
|
Mpd->DeleteID(myPlaylist->CurrentSong()->GetID());
|
||||||
myPlaylist->Main()->DeleteOption(id);
|
myPlaylist->Main()->DeleteOption(id);
|
||||||
myPlaylist->Main()->Refresh();
|
myPlaylist->Main()->Refresh();
|
||||||
myPlaylist->Main()->ReadKey(input);
|
myPlaylist->Main()->ReadKey(input);
|
||||||
@@ -470,7 +472,6 @@ int main(int argc, char *argv[])
|
|||||||
myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout);
|
myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout);
|
||||||
Playlist::BlockNowPlayingUpdate = 0;
|
Playlist::BlockNowPlayingUpdate = 0;
|
||||||
}
|
}
|
||||||
Mpd->CommitQueue();
|
|
||||||
}
|
}
|
||||||
else if (myScreen == myBrowser || myScreen->Cmp() == myPlaylistEditor->Playlists)
|
else if (myScreen == myBrowser || myScreen->Cmp() == myPlaylistEditor->Playlists)
|
||||||
{
|
{
|
||||||
@@ -508,11 +509,13 @@ int main(int argc, char *argv[])
|
|||||||
vector<size_t> list;
|
vector<size_t> list;
|
||||||
myPlaylistEditor->Content->GetSelected(list);
|
myPlaylistEditor->Content->GetSelected(list);
|
||||||
locale_to_utf(myPlaylistEditor->Playlists->Current());
|
locale_to_utf(myPlaylistEditor->Playlists->Current());
|
||||||
for (vector<size_t>::const_reverse_iterator it = list.rbegin(); it != ((const vector<size_t> &)list).rend(); it++)
|
Mpd->StartCommandsList();
|
||||||
|
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
|
||||||
{
|
{
|
||||||
Mpd->QueueDeleteFromPlaylist(myPlaylistEditor->Playlists->Current(), *it);
|
Mpd->Delete(myPlaylistEditor->Playlists->Current(), *it);
|
||||||
myPlaylistEditor->Content->DeleteOption(*it);
|
myPlaylistEditor->Content->DeleteOption(*it);
|
||||||
}
|
}
|
||||||
|
Mpd->CommitCommandsList();
|
||||||
utf_to_locale(myPlaylistEditor->Playlists->Current());
|
utf_to_locale(myPlaylistEditor->Playlists->Current());
|
||||||
ShowMessage("Selected items deleted from playlist '%s'!", myPlaylistEditor->Playlists->Current().c_str());
|
ShowMessage("Selected items deleted from playlist '%s'!", myPlaylistEditor->Playlists->Current().c_str());
|
||||||
}
|
}
|
||||||
@@ -524,7 +527,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
TraceMpdStatus();
|
TraceMpdStatus();
|
||||||
time(&Timer);
|
time(&Timer);
|
||||||
Mpd->QueueDeleteFromPlaylist(myPlaylistEditor->Playlists->Current(), myPlaylistEditor->Content->Choice());
|
Mpd->Delete(myPlaylistEditor->Playlists->Current(), myPlaylistEditor->Content->Choice());
|
||||||
myPlaylistEditor->Content->DeleteOption(myPlaylistEditor->Content->Choice());
|
myPlaylistEditor->Content->DeleteOption(myPlaylistEditor->Content->Choice());
|
||||||
myPlaylistEditor->Content->Refresh();
|
myPlaylistEditor->Content->Refresh();
|
||||||
myPlaylistEditor->Content->ReadKey(input);
|
myPlaylistEditor->Content->ReadKey(input);
|
||||||
@@ -532,7 +535,6 @@ int main(int argc, char *argv[])
|
|||||||
utf_to_locale(myPlaylistEditor->Playlists->Current());
|
utf_to_locale(myPlaylistEditor->Playlists->Current());
|
||||||
myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout);
|
myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout);
|
||||||
}
|
}
|
||||||
Mpd->CommitQueue();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Keypressed(input, Key.Prev))
|
else if (Keypressed(input, Key.Prev))
|
||||||
@@ -639,9 +641,10 @@ int main(int argc, char *argv[])
|
|||||||
myPlaylist->Main()->Refresh();
|
myPlaylist->Main()->Refresh();
|
||||||
myPlaylist->Main()->ReadKey(input);
|
myPlaylist->Main()->ReadKey(input);
|
||||||
}
|
}
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (size_t i = 0; i < list.size(); i++)
|
for (size_t i = 0; i < list.size(); i++)
|
||||||
Mpd->QueueMove(origs[i], list[i]);
|
Mpd->Move(origs[i], list[i]);
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -689,10 +692,11 @@ int main(int argc, char *argv[])
|
|||||||
myPlaylistEditor->Content->Refresh();
|
myPlaylistEditor->Content->Refresh();
|
||||||
myPlaylistEditor->Content->ReadKey(input);
|
myPlaylistEditor->Content->ReadKey(input);
|
||||||
}
|
}
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (size_t i = 0; i < list.size(); i++)
|
for (size_t i = 0; i < list.size(); i++)
|
||||||
if (origs[i] != list[i])
|
if (origs[i] != list[i])
|
||||||
Mpd->QueueMove(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
|
Mpd->Move(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -752,9 +756,10 @@ int main(int argc, char *argv[])
|
|||||||
myPlaylist->Main()->Refresh();
|
myPlaylist->Main()->Refresh();
|
||||||
myPlaylist->Main()->ReadKey(input);
|
myPlaylist->Main()->ReadKey(input);
|
||||||
}
|
}
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (int i = list.size()-1; i >= 0; i--)
|
for (int i = list.size()-1; i >= 0; i--)
|
||||||
Mpd->QueueMove(origs[i], list[i]);
|
Mpd->Move(origs[i], list[i]);
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -803,10 +808,11 @@ int main(int argc, char *argv[])
|
|||||||
myPlaylistEditor->Content->Refresh();
|
myPlaylistEditor->Content->Refresh();
|
||||||
myPlaylistEditor->Content->ReadKey(input);
|
myPlaylistEditor->Content->ReadKey(input);
|
||||||
}
|
}
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (int i = list.size()-1; i >= 0; i--)
|
for (int i = list.size()-1; i >= 0; i--)
|
||||||
if (origs[i] != list[i])
|
if (origs[i] != list[i])
|
||||||
Mpd->QueueMove(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
|
Mpd->Move(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -850,13 +856,14 @@ int main(int argc, char *argv[])
|
|||||||
if (pos >= list.front() && pos <= list.back())
|
if (pos >= list.front() && pos <= list.back())
|
||||||
continue;
|
continue;
|
||||||
int diff = pos-list.front();
|
int diff = pos-list.front();
|
||||||
|
Mpd->StartCommandsList();
|
||||||
if (diff > 0)
|
if (diff > 0)
|
||||||
{
|
{
|
||||||
pos -= list.size();
|
pos -= list.size();
|
||||||
size_t i = list.size()-1;
|
size_t i = list.size()-1;
|
||||||
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++, i--)
|
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++, i--)
|
||||||
{
|
{
|
||||||
Mpd->QueueMove(*it, pos+i);
|
Mpd->Move(*it, pos+i);
|
||||||
myPlaylist->Main()->Move(*it, pos+i);
|
myPlaylist->Main()->Move(*it, pos+i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -865,11 +872,11 @@ int main(int argc, char *argv[])
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (vector<size_t>::const_iterator it = list.begin(); it != list.end(); it++, i++)
|
for (vector<size_t>::const_iterator it = list.begin(); it != list.end(); it++, i++)
|
||||||
{
|
{
|
||||||
Mpd->QueueMove(*it, pos+i);
|
Mpd->Move(*it, pos+i);
|
||||||
myPlaylist->Main()->Move(*it, pos+i);
|
myPlaylist->Main()->Move(*it, pos+i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
myPlaylist->Main()->Highlight(pos);
|
myPlaylist->Main()->Highlight(pos);
|
||||||
myPlaylist->FixPositions();
|
myPlaylist->FixPositions();
|
||||||
}
|
}
|
||||||
@@ -885,9 +892,14 @@ int main(int argc, char *argv[])
|
|||||||
Mpd->GetDirectoryRecursive(path, list);
|
Mpd->GetDirectoryRecursive(path, list);
|
||||||
if (!list.empty())
|
if (!list.empty())
|
||||||
{
|
{
|
||||||
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
Mpd->StartCommandsList();
|
||||||
Mpd->QueueAddSong(**it);
|
SongList::const_iterator it = list.begin();
|
||||||
if (Mpd->CommitQueue())
|
for (; it != list.end(); it++)
|
||||||
|
if (Mpd->AddSong(**it) < 0)
|
||||||
|
break;
|
||||||
|
Mpd->CommitCommandsList();
|
||||||
|
|
||||||
|
if (it != list.begin())
|
||||||
{
|
{
|
||||||
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
|
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
|
||||||
if (s.GetHash() != list[0]->GetHash())
|
if (s.GetHash() != list[0]->GetHash())
|
||||||
@@ -1388,9 +1400,14 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (id == 0)
|
if (id == 0)
|
||||||
{
|
{
|
||||||
for (SongList::const_iterator it = result.begin(); it != result.end(); it++)
|
Mpd->StartCommandsList();
|
||||||
Mpd->QueueAddSong(**it);
|
SongList::const_iterator it = result.begin();
|
||||||
if (Mpd->CommitQueue())
|
for (; it != result.end(); it++)
|
||||||
|
if (Mpd->AddSong(**it) < 0)
|
||||||
|
break;
|
||||||
|
Mpd->CommitCommandsList();
|
||||||
|
|
||||||
|
if (it != result.begin())
|
||||||
{
|
{
|
||||||
ShowMessage("Selected items added!");
|
ShowMessage("Selected items added!");
|
||||||
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-result.size());
|
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-result.size());
|
||||||
@@ -1408,18 +1425,20 @@ int main(int argc, char *argv[])
|
|||||||
UnlockStatusbar();
|
UnlockStatusbar();
|
||||||
if (!playlist.empty())
|
if (!playlist.empty())
|
||||||
{
|
{
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (SongList::const_iterator it = result.begin(); it != result.end(); it++)
|
for (SongList::const_iterator it = result.begin(); it != result.end(); it++)
|
||||||
Mpd->QueueAddToPlaylist(real_playlist, **it);
|
Mpd->AddToPlaylist(real_playlist, **it);
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
ShowMessage("Selected items added to playlist '%s'!", playlist.c_str());
|
ShowMessage("Selected items added to playlist '%s'!", playlist.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (id > 1 && id < mDialog.Size()-1)
|
else if (id > 1 && id < mDialog.Size()-1)
|
||||||
{
|
{
|
||||||
locale_to_utf(playlists[id-3]);
|
locale_to_utf(playlists[id-3]);
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (SongList::const_iterator it = result.begin(); it != result.end(); it++)
|
for (SongList::const_iterator it = result.begin(); it != result.end(); it++)
|
||||||
Mpd->QueueAddToPlaylist(playlists[id-3], **it);
|
Mpd->AddToPlaylist(playlists[id-3], **it);
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
utf_to_locale(playlists[id-3]);
|
utf_to_locale(playlists[id-3]);
|
||||||
ShowMessage("Selected items added to playlist '%s'!", playlists[id-3].c_str());
|
ShowMessage("Selected items added to playlist '%s'!", playlists[id-3].c_str());
|
||||||
}
|
}
|
||||||
@@ -1443,18 +1462,19 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
if (myPlaylist->Main()->hasSelected())
|
if (myPlaylist->Main()->hasSelected())
|
||||||
{
|
{
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
|
for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (!myPlaylist->Main()->isSelected(i) && i != myPlaylist->NowPlaying)
|
if (!myPlaylist->Main()->isSelected(i) && i != myPlaylist->NowPlaying)
|
||||||
Mpd->QueueDeleteSong(i);
|
Mpd->Delete(i);
|
||||||
}
|
}
|
||||||
// if mpd deletes now playing song deletion will be sluggishly slow
|
// if mpd deletes now playing song deletion will be sluggishly slow
|
||||||
// then so we have to assure it will be deleted at the very end.
|
// then so we have to assure it will be deleted at the very end.
|
||||||
if (myPlaylist->isPlaying() && !myPlaylist->Main()->isSelected(myPlaylist->NowPlaying))
|
if (myPlaylist->isPlaying() && !myPlaylist->Main()->isSelected(myPlaylist->NowPlaying))
|
||||||
Mpd->QueueDeleteSongId(myPlaylist->NowPlayingSong()->GetID());
|
Mpd->DeleteID(myPlaylist->NowPlayingSong()->GetID());
|
||||||
|
|
||||||
ShowMessage("Deleting all items but selected...");
|
ShowMessage("Deleting all items but selected...");
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
ShowMessage("Items deleted!");
|
ShowMessage("Items deleted!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1464,11 +1484,12 @@ int main(int argc, char *argv[])
|
|||||||
ShowMessage("Nothing is playing now!");
|
ShowMessage("Nothing is playing now!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
|
for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
|
||||||
if (i != myPlaylist->NowPlaying)
|
if (i != myPlaylist->NowPlaying)
|
||||||
Mpd->QueueDeleteSong(i);
|
Mpd->Delete(i);
|
||||||
ShowMessage("Deleting all items except now playing one...");
|
ShowMessage("Deleting all items except now playing one...");
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
ShowMessage("Items deleted!");
|
ShowMessage("Items deleted!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1477,9 +1498,10 @@ int main(int argc, char *argv[])
|
|||||||
if (myPlaylist->Main()->isFiltered())
|
if (myPlaylist->Main()->isFiltered())
|
||||||
{
|
{
|
||||||
ShowMessage("Deleting filtered items...");
|
ShowMessage("Deleting filtered items...");
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
|
for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
|
||||||
Mpd->QueueDeleteSong((*myPlaylist->Main())[i].GetPosition());
|
Mpd->Delete((*myPlaylist->Main())[i].GetPosition());
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
ShowMessage("Filtered items deleted!");
|
ShowMessage("Filtered items deleted!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -243,6 +243,7 @@ void Playlist::Sort()
|
|||||||
|
|
||||||
BlockUpdate = 1;
|
BlockUpdate = 1;
|
||||||
ShowMessage("Sorting playlist...");
|
ShowMessage("Sorting playlist...");
|
||||||
|
Mpd->StartCommandsList();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < playlist.size(); i++)
|
for (size_t i = 0; i < playlist.size(); i++)
|
||||||
@@ -257,6 +258,7 @@ void Playlist::Sort()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (playlist != cmp);
|
while (playlist != cmp);
|
||||||
|
Mpd->CommitCommandsList();
|
||||||
ShowMessage("Playlist sorted!");
|
ShowMessage("Playlist sorted!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -192,9 +192,14 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
|
|||||||
if (w == Playlists && !Playlists->Empty())
|
if (w == Playlists && !Playlists->Empty())
|
||||||
{
|
{
|
||||||
Mpd->GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), list);
|
Mpd->GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), list);
|
||||||
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
Mpd->StartCommandsList();
|
||||||
Mpd->QueueAddSong(**it);
|
SongList::const_iterator it = list.begin();
|
||||||
if (Mpd->CommitQueue())
|
for (; it != list.end(); it++)
|
||||||
|
if (Mpd->AddSong(**it) < 0)
|
||||||
|
break;
|
||||||
|
Mpd->CommitCommandsList();
|
||||||
|
|
||||||
|
if (it != list.begin())
|
||||||
{
|
{
|
||||||
ShowMessage("Loading playlist %s...", Playlists->Current().c_str());
|
ShowMessage("Loading playlist %s...", Playlists->Current().c_str());
|
||||||
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
|
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
|
||||||
@@ -229,16 +234,17 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Playlist::BlockUpdate = 1;
|
Playlist::BlockUpdate = 1;
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
|
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
|
||||||
{
|
{
|
||||||
if (myPlaylist->Main()->at(i).GetHash() == hash)
|
if (myPlaylist->Main()->at(i).GetHash() == hash)
|
||||||
{
|
{
|
||||||
Mpd->QueueDeleteSong(i);
|
Mpd->Delete(i);
|
||||||
myPlaylist->Main()->DeleteOption(i);
|
myPlaylist->Main()->DeleteOption(i);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
Content->BoldOption(Content->Choice(), 0);
|
Content->BoldOption(Content->Choice(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,16 +268,17 @@ void SearchEngine::SpacePressed()
|
|||||||
{
|
{
|
||||||
Playlist::BlockUpdate = 1;
|
Playlist::BlockUpdate = 1;
|
||||||
long long hash = w->Current().second->GetHash();
|
long long hash = w->Current().second->GetHash();
|
||||||
|
Mpd->StartCommandsList();
|
||||||
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
|
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
|
||||||
{
|
{
|
||||||
if (myPlaylist->Main()->at(i).GetHash() == hash)
|
if (myPlaylist->Main()->at(i).GetHash() == hash)
|
||||||
{
|
{
|
||||||
Mpd->QueueDeleteSong(i);
|
Mpd->Delete(i);
|
||||||
myPlaylist->Main()->DeleteOption(i);
|
myPlaylist->Main()->DeleteOption(i);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mpd->CommitQueue();
|
Mpd->CommitCommandsList();
|
||||||
w->BoldOption(w->Choice(), 0);
|
w->BoldOption(w->Choice(), 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -902,8 +902,7 @@ bool TagEditor::WriteTags(Song &s)
|
|||||||
// if we rename local file, it won't get updated
|
// if we rename local file, it won't get updated
|
||||||
// so just remove it from playlist and add again
|
// so just remove it from playlist and add again
|
||||||
size_t pos = myPlaylist->Main()->Choice();
|
size_t pos = myPlaylist->Main()->Choice();
|
||||||
Mpd->QueueDeleteSong(pos);
|
Mpd->Delete(pos);
|
||||||
Mpd->CommitQueue();
|
|
||||||
int id = Mpd->AddSong("file://" + new_name);
|
int id = Mpd->AddSong("file://" + new_name);
|
||||||
if (id >= 0)
|
if (id >= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user