define MPD::Connection handler as an object, not pointer

This commit is contained in:
Andrzej Rybczak
2009-07-04 06:07:00 +02:00
parent 979a9e7670
commit 2eb913fe22
14 changed files with 287 additions and 290 deletions

View File

@@ -117,7 +117,7 @@ void Browser::EnterPressed()
{ {
if (myPlaylist->Main()->at(i).GetHash() == hash) if (myPlaylist->Main()->at(i).GetHash() == hash)
{ {
Mpd->Play(i); Mpd.Play(i);
found = 1; found = 1;
break; break;
} }
@@ -126,10 +126,10 @@ void Browser::EnterPressed()
break; break;
} }
Song &s = *item.song; Song &s = *item.song;
int id = Mpd->AddSong(s); int id = Mpd.AddSong(s);
if (id >= 0) if (id >= 0)
{ {
Mpd->PlayID(id); Mpd.PlayID(id);
ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str()); ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str());
w->BoldOption(w->Choice(), 1); w->BoldOption(w->Choice(), 1);
} }
@@ -138,20 +138,20 @@ void Browser::EnterPressed()
case itPlaylist: case itPlaylist:
{ {
SongList list; SongList list;
Mpd->GetPlaylistContent(locale_to_utf_cpy(item.name), list); Mpd.GetPlaylistContent(locale_to_utf_cpy(item.name), list);
Mpd->StartCommandsList(); Mpd.StartCommandsList();
SongList::const_iterator it = list.begin(); SongList::const_iterator it = list.begin();
for (; it != list.end(); it++) for (; it != list.end(); it++)
if (Mpd->AddSong(**it) < 0) if (Mpd.AddSong(**it) < 0)
break; break;
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
if (it != list.begin()) 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());
if (s->GetHash() == list[0]->GetHash()) if (s->GetHash() == list[0]->GetHash())
Mpd->PlayID(s->GetID()); Mpd.PlayID(s->GetID());
else else
ShowMessage("%s", MPD::Message::PartOfSongsAdded); ShowMessage("%s", MPD::Message::PartOfSongsAdded);
} }
@@ -189,29 +189,29 @@ void Browser::SpacePressed()
ShowMessage("Scanning \"%s\"...", item.name.c_str()); ShowMessage("Scanning \"%s\"...", item.name.c_str());
myBrowser->GetLocalDirectory(list, item.name, 1); myBrowser->GetLocalDirectory(list, item.name, 1);
Mpd->StartCommandsList(); Mpd.StartCommandsList();
for (ItemList::const_iterator it = list.begin(); it != list.end(); ++it) for (ItemList::const_iterator it = list.begin(); it != list.end(); ++it)
{ {
if (everything_was_added && Mpd->AddSong(*it->song) < 0) if (everything_was_added && Mpd.AddSong(*it->song) < 0)
everything_was_added = 0; everything_was_added = 0;
delete it->song; delete it->song;
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
} }
else else
{ {
SongList list; SongList list;
Mpd->GetDirectoryRecursive(locale_to_utf_cpy(item.name), list); Mpd.GetDirectoryRecursive(locale_to_utf_cpy(item.name), list);
Mpd->StartCommandsList(); Mpd.StartCommandsList();
for (SongList::const_iterator it = list.begin(); it != list.end(); it++) for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
{ {
if (Mpd->AddSong(**it) < 0) if (Mpd.AddSong(**it) < 0)
{ {
everything_was_added = 0; everything_was_added = 0;
break; break;
} }
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
FreeSongList(list); FreeSongList(list);
} }
@@ -227,24 +227,24 @@ 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(); 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->Delete(i); Mpd.Delete(i);
myPlaylist->Main()->DeleteOption(i); myPlaylist->Main()->DeleteOption(i);
i--; i--;
} }
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
w->BoldOption(w->Choice(), 0); w->BoldOption(w->Choice(), 0);
Playlist::BlockUpdate = 0; Playlist::BlockUpdate = 0;
} }
else else
{ {
Song &s = *item.song; Song &s = *item.song;
if (Mpd->AddSong(s) != -1) if (Mpd.AddSong(s) != -1)
{ {
ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str()); ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str());
w->BoldOption(w->Choice(), 1); w->BoldOption(w->Choice(), 1);
@@ -255,13 +255,13 @@ void Browser::SpacePressed()
case itPlaylist: case itPlaylist:
{ {
SongList list; SongList list;
Mpd->GetPlaylistContent(locale_to_utf_cpy(item.name), list); Mpd.GetPlaylistContent(locale_to_utf_cpy(item.name), list);
Mpd->StartCommandsList(); Mpd.StartCommandsList();
SongList::const_iterator it = list.begin(); SongList::const_iterator it = list.begin();
for (; it != list.end(); it++) for (; it != list.end(); it++)
if (Mpd->AddSong(**it) < 0) if (Mpd.AddSong(**it) < 0)
break; break;
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
if (it != list.begin()) if (it != list.begin())
{ {
@@ -347,7 +347,7 @@ void Browser::GetSelectedSongs(MPD::SongList &v)
{ {
case itDirectory: case itDirectory:
{ {
Mpd->GetDirectoryRecursive(locale_to_utf_cpy(item.name), v); Mpd.GetDirectoryRecursive(locale_to_utf_cpy(item.name), v);
break; break;
} }
case itSong: case itSong:
@@ -357,7 +357,7 @@ void Browser::GetSelectedSongs(MPD::SongList &v)
} }
case itPlaylist: case itPlaylist:
{ {
Mpd->GetPlaylistContent(locale_to_utf_cpy(item.name), v); Mpd.GetPlaylistContent(locale_to_utf_cpy(item.name), v);
break; break;
} }
} }
@@ -498,7 +498,7 @@ void Browser::GetDirectory(string dir, string subdir)
} }
ItemList list; ItemList list;
Config.local_browser ? GetLocalDirectory(list) : Mpd->GetDirectory(dir, list); Config.local_browser ? GetLocalDirectory(list) : Mpd.GetDirectory(dir, list);
sort(list.begin(), list.end(), CaseInsensitiveSorting()); sort(list.begin(), list.end(), CaseInsensitiveSorting());
for (ItemList::iterator it = list.begin(); it != list.end(); it++) for (ItemList::iterator it = list.begin(); it != list.end(); it++)
@@ -579,7 +579,7 @@ void Browser::ClearDirectory(const std::string &path) const
void Browser::ChangeBrowseMode() void Browser::ChangeBrowseMode()
{ {
if (Mpd->GetHostname()[0] != '/') if (Mpd.GetHostname()[0] != '/')
return; return;
Config.local_browser = !Config.local_browser; Config.local_browser = !Config.local_browser;

View File

@@ -33,8 +33,6 @@ namespace Global
extern Window *wHeader; extern Window *wHeader;
extern Window *wFooter; extern Window *wFooter;
extern MPD::Connection *Mpd;
extern size_t MainStartY; extern size_t MainStartY;
extern size_t MainHeight; extern size_t MainHeight;

View File

@@ -224,7 +224,7 @@ void Help::GetKeybindings()
# else # else
*w << DisplayKeys(Key.EditTags) << "Rename playlist/directory\n"; *w << DisplayKeys(Key.EditTags) << "Rename playlist/directory\n";
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
if (Mpd->GetHostname()[0] == '/') // are we connected to unix socket? if (Mpd.GetHostname()[0] == '/') // are we connected to unix socket?
*w << DisplayKeys(Key.SwitchTagTypeList)<< "Browse MPD database/local filesystem\n"; *w << DisplayKeys(Key.SwitchTagTypeList)<< "Browse MPD database/local filesystem\n";
*w << DisplayKeys(Key.GoToNowPlaying) << "Locate currently playing song\n"; *w << DisplayKeys(Key.GoToNowPlaying) << "Locate currently playing song\n";
*w << DisplayKeys(Key.GoToParentDir) << "Go to parent directory\n"; *w << DisplayKeys(Key.GoToParentDir) << "Go to parent directory\n";

View File

@@ -30,15 +30,14 @@
#include "tag_editor.h" #include "tag_editor.h"
using namespace MPD; using namespace MPD;
using Global::Mpd;
using Global::wFooter; using Global::wFooter;
using std::string; using std::string;
bool ConnectToMPD() bool ConnectToMPD()
{ {
if (!Mpd->Connect()) if (!Mpd.Connect())
{ {
std::cout << "Cannot connect to mpd: " << Mpd->GetErrorMessage() << std::endl; std::cout << "Cannot connect to mpd: " << Mpd.GetErrorMessage() << std::endl;
return false; return false;
} }
return true; return true;
@@ -57,14 +56,14 @@ void ParseArgv(int argc, char **argv)
{ {
if (++i >= argc) if (++i >= argc)
exit(0); exit(0);
Mpd->SetHostname(argv[i]); Mpd.SetHostname(argv[i]);
continue; continue;
} }
if (strcmp(argv[i], "-p") == 0) if (strcmp(argv[i], "-p") == 0)
{ {
if (++i >= argc) if (++i >= argc)
exit(0); exit(0);
Mpd->SetPort(atoi(argv[i])); Mpd.SetPort(atoi(argv[i]));
continue; continue;
} }
else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
@@ -107,25 +106,25 @@ void ParseArgv(int argc, char **argv)
if (strcmp(argv[i], "play") == 0) if (strcmp(argv[i], "play") == 0)
{ {
Mpd->Play(); Mpd.Play();
quit = 1; quit = 1;
} }
else if (strcmp(argv[i], "pause") == 0) else if (strcmp(argv[i], "pause") == 0)
{ {
Mpd->Execute("pause \"1\"\n"); Mpd.Execute("pause \"1\"\n");
quit = 1; quit = 1;
} }
else if (strcmp(argv[i], "toggle") == 0) else if (strcmp(argv[i], "toggle") == 0)
{ {
Mpd->UpdateStatus(); Mpd.UpdateStatus();
switch (Mpd->GetState()) switch (Mpd.GetState())
{ {
case psPause: case psPause:
case psPlay: case psPlay:
Mpd->Pause(); Mpd.Pause();
break; break;
case psStop: case psStop:
Mpd->Play(); Mpd.Play();
break; break;
default: default:
break; break;
@@ -134,30 +133,30 @@ void ParseArgv(int argc, char **argv)
} }
else if (strcmp(argv[i], "stop") == 0) else if (strcmp(argv[i], "stop") == 0)
{ {
Mpd->Stop(); Mpd.Stop();
quit = 1; quit = 1;
} }
else if (strcmp(argv[i], "next") == 0) else if (strcmp(argv[i], "next") == 0)
{ {
Mpd->Next(); Mpd.Next();
quit = 1; quit = 1;
} }
else if (strcmp(argv[i], "prev") == 0) else if (strcmp(argv[i], "prev") == 0)
{ {
Mpd->Prev(); Mpd.Prev();
quit = 1; quit = 1;
} }
else if (strcmp(argv[i], "volume") == 0) else if (strcmp(argv[i], "volume") == 0)
{ {
i++; i++;
Mpd->UpdateStatus(); Mpd.UpdateStatus();
if (!Mpd->GetErrorMessage().empty()) if (!Mpd.GetErrorMessage().empty())
{ {
cout << "Error: " << Mpd->GetErrorMessage() << endl; cout << "Error: " << Mpd.GetErrorMessage() << endl;
exit(0); exit(0);
} }
if (i != argc) if (i != argc)
Mpd->SetVolume(Mpd->GetVolume()+atoi(argv[i])); Mpd.SetVolume(Mpd.GetVolume()+atoi(argv[i]));
quit = 1; quit = 1;
} }
else else
@@ -165,9 +164,9 @@ void ParseArgv(int argc, char **argv)
cout << "ncmpcpp: invalid option: " << argv[i] << endl; cout << "ncmpcpp: invalid option: " << argv[i] << endl;
exit(0); exit(0);
} }
if (!Mpd->GetErrorMessage().empty()) if (!Mpd.GetErrorMessage().empty())
{ {
cout << "Error: " << Mpd->GetErrorMessage() << endl; cout << "Error: " << Mpd.GetErrorMessage() << endl;
exit(0); exit(0);
} }
} }

View File

@@ -166,7 +166,7 @@ void MediaLibrary::Update()
TagList list; TagList list;
Albums->Clear(0); Albums->Clear(0);
Songs->Clear(0); Songs->Clear(0);
Mpd->GetList(list, Config.media_lib_primary_tag); Mpd.GetList(list, Config.media_lib_primary_tag);
sort(list.begin(), list.end(), CaseInsensitiveSorting()); sort(list.begin(), list.end(), CaseInsensitiveSorting());
for (TagList::iterator it = list.begin(); it != list.end(); it++) for (TagList::iterator it = list.begin(); it != list.end(); it++)
{ {
@@ -186,22 +186,22 @@ void MediaLibrary::Update()
TagList list; TagList list;
locale_to_utf(Artists->Current()); locale_to_utf(Artists->Current());
if (Config.media_lib_primary_tag == MPD_TAG_ITEM_ARTIST) if (Config.media_lib_primary_tag == MPD_TAG_ITEM_ARTIST)
Mpd->GetAlbums(Artists->Current(), list); Mpd.GetAlbums(Artists->Current(), list);
else else
{ {
Mpd->StartFieldSearch(MPD_TAG_ITEM_ALBUM); Mpd.StartFieldSearch(MPD_TAG_ITEM_ALBUM);
Mpd->AddSearch(Config.media_lib_primary_tag, Artists->Current()); Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
Mpd->CommitSearch(list); Mpd.CommitSearch(list);
} }
// <mpd-0.14 doesn't support searching for empty tag // <mpd-0.14 doesn't support searching for empty tag
if (Mpd->Version() > 13) if (Mpd.Version() > 13)
{ {
TagList noalbum_list; TagList noalbum_list;
Mpd->StartFieldSearch(MPD_TAG_ITEM_FILENAME); Mpd.StartFieldSearch(MPD_TAG_ITEM_FILENAME);
Mpd->AddSearch(Config.media_lib_primary_tag, Artists->Current()); Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, ""); Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, "");
Mpd->CommitSearch(noalbum_list); Mpd.CommitSearch(noalbum_list);
if (!noalbum_list.empty()) if (!noalbum_list.empty())
Albums->AddOption(std::make_pair("<no album>", SearchConstraints("", ""))); Albums->AddOption(std::make_pair("<no album>", SearchConstraints("", "")));
} }
@@ -209,10 +209,10 @@ void MediaLibrary::Update()
for (TagList::const_iterator it = list.begin(); it != list.end(); it++) for (TagList::const_iterator it = list.begin(); it != list.end(); it++)
{ {
TagList l; TagList l;
Mpd->StartFieldSearch(MPD_TAG_ITEM_DATE); Mpd.StartFieldSearch(MPD_TAG_ITEM_DATE);
Mpd->AddSearch(Config.media_lib_primary_tag, Artists->Current()); Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, *it); Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, *it);
Mpd->CommitSearch(l); Mpd.CommitSearch(l);
if (l.empty()) if (l.empty())
{ {
Albums->AddOption(std::make_pair(*it, SearchConstraints(*it, ""))); Albums->AddOption(std::make_pair(*it, SearchConstraints(*it, "")));
@@ -233,22 +233,22 @@ void MediaLibrary::Update()
TagList artists; TagList artists;
*Albums << XY(0, 0) << "Fetching albums..."; *Albums << XY(0, 0) << "Fetching albums...";
Albums->Window::Refresh(); Albums->Window::Refresh();
Mpd->GetList(artists, Config.media_lib_primary_tag); Mpd.GetList(artists, Config.media_lib_primary_tag);
for (TagList::const_iterator i = artists.begin(); i != artists.end(); i++) for (TagList::const_iterator i = artists.begin(); i != artists.end(); i++)
{ {
TagList albums; TagList albums;
Mpd->StartFieldSearch(MPD_TAG_ITEM_ALBUM); Mpd.StartFieldSearch(MPD_TAG_ITEM_ALBUM);
Mpd->AddSearch(Config.media_lib_primary_tag, *i); Mpd.AddSearch(Config.media_lib_primary_tag, *i);
Mpd->CommitSearch(albums); Mpd.CommitSearch(albums);
for (TagList::const_iterator j = albums.begin(); j != albums.end(); j++) for (TagList::const_iterator j = albums.begin(); j != albums.end(); j++)
{ {
if (Config.media_lib_primary_tag != MPD_TAG_ITEM_DATE) if (Config.media_lib_primary_tag != MPD_TAG_ITEM_DATE)
{ {
TagList years; TagList years;
Mpd->StartFieldSearch(MPD_TAG_ITEM_DATE); Mpd.StartFieldSearch(MPD_TAG_ITEM_DATE);
Mpd->AddSearch(Config.media_lib_primary_tag, *i); Mpd.AddSearch(Config.media_lib_primary_tag, *i);
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, *j); Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, *j);
Mpd->CommitSearch(years); Mpd.CommitSearch(years);
if (!years.empty()) if (!years.empty())
{ {
for (TagList::const_iterator k = years.begin(); k != years.end(); k++) for (TagList::const_iterator k = years.begin(); k != years.end(); k++)
@@ -283,8 +283,8 @@ void MediaLibrary::Update()
SongList list; SongList list;
Songs->Clear(0); Songs->Clear(0);
Mpd->StartSearch(1); Mpd.StartSearch(1);
Mpd->AddSearch(Config.media_lib_primary_tag, hasTwoColumns ? Albums->Current().second.Artist : locale_to_utf_cpy(Artists->Current())); Mpd.AddSearch(Config.media_lib_primary_tag, hasTwoColumns ? Albums->Current().second.Artist : locale_to_utf_cpy(Artists->Current()));
if (Albums->Empty()) // left for compatibility with <mpd-0.14 if (Albums->Empty()) // left for compatibility with <mpd-0.14
{ {
*Albums << XY(0, 0) << "No albums found."; *Albums << XY(0, 0) << "No albums found.";
@@ -292,11 +292,11 @@ void MediaLibrary::Update()
} }
else else
{ {
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, Albums->Current().second.Album); Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, Albums->Current().second.Album);
if (!Albums->Current().second.Album.empty()) // for <no album> if (!Albums->Current().second.Album.empty()) // for <no album>
Mpd->AddSearch(MPD_TAG_ITEM_DATE, Albums->Current().second.Year); Mpd.AddSearch(MPD_TAG_ITEM_DATE, Albums->Current().second.Year);
} }
Mpd->CommitSearch(list); Mpd.CommitSearch(list);
sort(list.begin(), list.end(), SortSongsByTrack); sort(list.begin(), list.end(), SortSongsByTrack);
bool bold = 0; bool bold = 0;
@@ -470,15 +470,15 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
if (!Artists->Empty() && w == Artists) if (!Artists->Empty() && w == Artists)
{ {
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);
Mpd->StartCommandsList(); Mpd.StartCommandsList();
SongList::const_iterator it = list.begin(); SongList::const_iterator it = list.begin();
for (; it != list.end(); it++) for (; it != list.end(); it++)
if (Mpd->AddSong(**it) < 0) if (Mpd.AddSong(**it) < 0)
break; break;
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
if (it != list.begin()) if (it != list.begin())
{ {
@@ -489,7 +489,7 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
if (s->GetHash() == list[0]->GetHash()) if (s->GetHash() == list[0]->GetHash())
{ {
if (add_n_play) if (add_n_play)
Mpd->PlayID(s->GetID()); Mpd.PlayID(s->GetID());
} }
else else
ShowMessage("%s", MPD::Message::PartOfSongsAdded); ShowMessage("%s", MPD::Message::PartOfSongsAdded);
@@ -497,12 +497,12 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
} }
else if (w == Albums) else if (w == Albums)
{ {
Mpd->StartCommandsList(); Mpd.StartCommandsList();
size_t i = 0; size_t i = 0;
for (; i < Songs->Size(); i++) for (; i < Songs->Size(); i++)
if (Mpd->AddSong(Songs->at(i)) < 0) if (Mpd.AddSong(Songs->at(i)) < 0)
break; break;
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
if (i) if (i)
{ {
@@ -511,7 +511,7 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
if (s->GetHash() == Songs->at(0).GetHash()) if (s->GetHash() == Songs->at(0).GetHash())
{ {
if (add_n_play) if (add_n_play)
Mpd->PlayID(s->GetID()); Mpd.PlayID(s->GetID());
} }
else else
ShowMessage("%s", MPD::Message::PartOfSongsAdded); ShowMessage("%s", MPD::Message::PartOfSongsAdded);
@@ -531,7 +531,7 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
{ {
if (myPlaylist->Main()->at(i).GetHash() == hash) if (myPlaylist->Main()->at(i).GetHash() == hash)
{ {
Mpd->Play(i); Mpd.Play(i);
break; break;
} }
} }
@@ -539,17 +539,17 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
else else
{ {
Playlist::BlockUpdate = 1; Playlist::BlockUpdate = 1;
Mpd->StartCommandsList(); 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->Delete(i); Mpd.Delete(i);
myPlaylist->Main()->DeleteOption(i); myPlaylist->Main()->DeleteOption(i);
i--; i--;
} }
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
Songs->BoldOption(Songs->Choice(), 0); Songs->BoldOption(Songs->Choice(), 0);
Playlist::BlockUpdate = 0; Playlist::BlockUpdate = 0;
} }
@@ -557,12 +557,12 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
else else
{ {
Song &s = Songs->Current(); Song &s = Songs->Current();
int id = Mpd->AddSong(s); int id = Mpd.AddSong(s);
if (id >= 0) if (id >= 0)
{ {
ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str()); ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str());
if (add_n_play) if (add_n_play)
Mpd->PlayID(id); Mpd.PlayID(id);
Songs->BoldOption(Songs->Choice(), 1); Songs->BoldOption(Songs->Choice(), 1);
} }
} }

View File

@@ -28,6 +28,8 @@ using namespace MPD;
using std::string; using std::string;
MPD::Connection Mpd;
const char *MPD::Message::PartOfSongsAdded = "Only part of requested songs' list added to playlist!"; const char *MPD::Message::PartOfSongsAdded = "Only part of requested songs' list added to playlist!";
const char *MPD::Message::FullPlaylist = "Playlist is full!"; 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";

View File

@@ -214,5 +214,7 @@ namespace MPD
}; };
} }
extern MPD::Connection Mpd;
#endif #endif

View File

@@ -75,8 +75,6 @@ BasicScreen *Global::myOldScreen;
Window *Global::wHeader; Window *Global::wHeader;
Window *Global::wFooter; Window *Global::wFooter;
Connection *Global::Mpd;
size_t Global::MainStartY; size_t Global::MainStartY;
size_t Global::MainHeight; size_t Global::MainHeight;
@@ -93,19 +91,17 @@ int main(int argc, char *argv[])
ReadConfiguration(Config); ReadConfiguration(Config);
ReadKeys(Key); ReadKeys(Key);
Mpd = new Connection;
if (getenv("MPD_HOST")) if (getenv("MPD_HOST"))
Mpd->SetHostname(getenv("MPD_HOST")); Mpd.SetHostname(getenv("MPD_HOST"));
if (getenv("MPD_PORT")) if (getenv("MPD_PORT"))
Mpd->SetPort(atoi(getenv("MPD_PORT"))); Mpd.SetPort(atoi(getenv("MPD_PORT")));
if (Config.mpd_host != "localhost") if (Config.mpd_host != "localhost")
Mpd->SetHostname(Config.mpd_host); Mpd.SetHostname(Config.mpd_host);
if (Config.mpd_port != 6600) if (Config.mpd_port != 6600)
Mpd->SetPort(Config.mpd_port); Mpd.SetPort(Config.mpd_port);
Mpd->SetTimeout(Config.mpd_connection_timeout); Mpd.SetTimeout(Config.mpd_connection_timeout);
if (argc > 1) if (argc > 1)
{ {
@@ -151,8 +147,8 @@ int main(int argc, char *argv[])
myPlaylist->SwitchTo(); myPlaylist->SwitchTo();
myPlaylist->UpdateTimer(); myPlaylist->UpdateTimer();
Mpd->SetStatusUpdater(NcmpcppStatusChanged, NULL); Mpd.SetStatusUpdater(NcmpcppStatusChanged, NULL);
Mpd->SetErrorHandler(NcmpcppErrorCallback, NULL); Mpd.SetErrorHandler(NcmpcppErrorCallback, NULL);
// local variables // local variables
int input; int input;
@@ -178,12 +174,12 @@ int main(int argc, char *argv[])
while (!main_exit) while (!main_exit)
{ {
if (!Mpd->Connected()) if (!Mpd.Connected())
{ {
ShowMessage("Attempting to reconnect..."); ShowMessage("Attempting to reconnect...");
if (Mpd->Connect()) if (Mpd.Connect())
{ {
ShowMessage("Connected to %s!", Mpd->GetHostname().c_str()); ShowMessage("Connected to %s!", Mpd.GetHostname().c_str());
MessagesAllowed = 0; MessagesAllowed = 0;
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
# ifdef ENABLE_OUTPUTS # ifdef ENABLE_OUTPUTS
@@ -332,16 +328,16 @@ int main(int argc, char *argv[])
const Song *s = myPlaylist->NowPlayingSong(); const Song *s = myPlaylist->NowPlayingSong();
if (!s) if (!s)
continue; continue;
Mpd->Seek(s->GetTotalLength()*mouse_event.x/double(COLS)); Mpd.Seek(s->GetTotalLength()*mouse_event.x/double(COLS));
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if (mouse_event.bstate & BUTTON1_PRESSED else if (mouse_event.bstate & BUTTON1_PRESSED
&& Config.statusbar_visibility && Config.statusbar_visibility
&& Mpd->GetState() > psStop && Mpd.GetState() > psStop
&& mouse_event.y == LINES-1 && mouse_event.x < 9 && mouse_event.y == LINES-1 && mouse_event.x < 9
) // playing/paused ) // playing/paused
{ {
Mpd->Pause(); Mpd.Pause();
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if ((mouse_event.bstate & BUTTON2_PRESSED || mouse_event.bstate & BUTTON4_PRESSED) else if ((mouse_event.bstate & BUTTON2_PRESSED || mouse_event.bstate & BUTTON4_PRESSED)
@@ -350,9 +346,9 @@ int main(int argc, char *argv[])
) // volume ) // volume
{ {
if (mouse_event.bstate & BUTTON2_PRESSED) if (mouse_event.bstate & BUTTON2_PRESSED)
Mpd->SetVolume(Mpd->GetVolume()-2); Mpd.SetVolume(Mpd.GetVolume()-2);
else else
Mpd->SetVolume(Mpd->GetVolume()+2); Mpd.SetVolume(Mpd.GetVolume()+2);
} }
else else
myScreen->MouseButtonPressed(mouse_event); myScreen->MouseButtonPressed(mouse_event);
@@ -409,10 +405,10 @@ int main(int argc, char *argv[])
myScreen->Refresh(); myScreen->Refresh();
RedrawStatusbar = 1; RedrawStatusbar = 1;
StatusChanges changes; StatusChanges changes;
if (Mpd->GetState() < psPlay) if (Mpd.GetState() < psPlay)
changes.PlayerState = 1; changes.PlayerState = 1;
changes.StatusFlags = 1; // force status update changes.StatusFlags = 1; // force status update
NcmpcppStatusChanged(Mpd, changes, NULL); NcmpcppStatusChanged(&Mpd, changes, NULL);
} }
else if (Keypressed(input, Key.GoToParentDir)) else if (Keypressed(input, Key.GoToParentDir))
{ {
@@ -447,7 +443,7 @@ int main(int argc, char *argv[])
} }
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
else else
Mpd->SetVolume(Mpd->GetVolume()+1); Mpd.SetVolume(Mpd.GetVolume()+1);
} }
else if (Keypressed(input, Key.VolumeDown)) else if (Keypressed(input, Key.VolumeDown))
{ {
@@ -466,7 +462,7 @@ int main(int argc, char *argv[])
} }
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
else else
Mpd->SetVolume(Mpd->GetVolume()-1); Mpd.SetVolume(Mpd.GetVolume()-1);
} }
else if (Keypressed(input, Key.Delete)) else if (Keypressed(input, Key.Delete))
{ {
@@ -477,13 +473,13 @@ int main(int argc, char *argv[])
{ {
vector<size_t> list; vector<size_t> list;
myPlaylist->Main()->GetSelected(list); myPlaylist->Main()->GetSelected(list);
Mpd->StartCommandsList(); Mpd.StartCommandsList();
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++) for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
{ {
Mpd->DeleteID((*myPlaylist->Main())[*it].GetID()); Mpd.DeleteID((*myPlaylist->Main())[*it].GetID());
myPlaylist->Main()->DeleteOption(*it); myPlaylist->Main()->DeleteOption(*it);
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
myPlaylist->FixPositions(list.front()); myPlaylist->FixPositions(list.front());
ShowMessage("Selected items deleted!"); ShowMessage("Selected items deleted!");
} }
@@ -501,7 +497,7 @@ int main(int argc, char *argv[])
// needed for keeping proper position of now playing song. // needed for keeping proper position of now playing song.
if (myPlaylist->NowPlaying > myPlaylist->CurrentSong()->GetPosition()-del_counter) if (myPlaylist->NowPlaying > myPlaylist->CurrentSong()->GetPosition()-del_counter)
myPlaylist->NowPlaying--; myPlaylist->NowPlaying--;
Mpd->DeleteID(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);
@@ -530,7 +526,7 @@ int main(int argc, char *argv[])
while (in != 'y' && in != 'n'); while (in != 'y' && in != 'n');
if (in == 'y') if (in == 'y')
{ {
Mpd->DeletePlaylist(locale_to_utf_cpy(name)); Mpd.DeletePlaylist(locale_to_utf_cpy(name));
ShowMessage("Playlist \"%s\" deleted!", name.c_str()); ShowMessage("Playlist \"%s\" deleted!", name.c_str());
if (!Config.local_browser && myBrowser->Main()) if (!Config.local_browser && myBrowser->Main())
myBrowser->GetDirectory("/"); myBrowser->GetDirectory("/");
@@ -587,7 +583,7 @@ int main(int argc, char *argv[])
{ {
ShowMessage("\"%s\" has been successfuly deleted!", name.c_str()); ShowMessage("\"%s\" has been successfuly deleted!", name.c_str());
if (!Config.local_browser) if (!Config.local_browser)
Mpd->UpdateDirectory(myBrowser->CurrentDir()); Mpd.UpdateDirectory(myBrowser->CurrentDir());
else else
myBrowser->GetDirectory(myBrowser->CurrentDir()); myBrowser->GetDirectory(myBrowser->CurrentDir());
} }
@@ -607,13 +603,13 @@ int main(int argc, char *argv[])
myPlaylistEditor->Content->GetSelected(list); myPlaylistEditor->Content->GetSelected(list);
string playlist = locale_to_utf_cpy(myPlaylistEditor->Playlists->Current()); string playlist = locale_to_utf_cpy(myPlaylistEditor->Playlists->Current());
ShowMessage("Deleting selected items..."); ShowMessage("Deleting selected items...");
Mpd->StartCommandsList(); Mpd.StartCommandsList();
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++) for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
{ {
Mpd->Delete(playlist, *it); Mpd.Delete(playlist, *it);
myPlaylistEditor->Content->DeleteOption(*it); myPlaylistEditor->Content->DeleteOption(*it);
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
ShowMessage("Selected items deleted from playlist \"%s\"!", myPlaylistEditor->Playlists->Current().c_str()); ShowMessage("Selected items deleted from playlist \"%s\"!", myPlaylistEditor->Playlists->Current().c_str());
} }
else else
@@ -624,7 +620,7 @@ int main(int argc, char *argv[])
{ {
TraceMpdStatus(); TraceMpdStatus();
myPlaylist->UpdateTimer(); myPlaylist->UpdateTimer();
Mpd->Delete(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);
@@ -636,17 +632,17 @@ int main(int argc, char *argv[])
} }
else if (Keypressed(input, Key.Prev)) else if (Keypressed(input, Key.Prev))
{ {
Mpd->Prev(); Mpd.Prev();
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if (Keypressed(input, Key.Next)) else if (Keypressed(input, Key.Next))
{ {
Mpd->Next(); Mpd.Next();
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if (Keypressed(input, Key.Pause)) else if (Keypressed(input, Key.Pause))
{ {
Mpd->Pause(); Mpd.Pause();
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if (Keypressed(input, Key.SavePlaylist)) else if (Keypressed(input, Key.SavePlaylist))
@@ -664,7 +660,7 @@ int main(int argc, char *argv[])
} }
if (!playlist_name.empty()) if (!playlist_name.empty())
{ {
if (Mpd->SavePlaylist(real_playlist_name)) if (Mpd.SavePlaylist(real_playlist_name))
{ {
ShowMessage("Playlist saved as: %s", playlist_name.c_str()); ShowMessage("Playlist saved as: %s", playlist_name.c_str());
if (myPlaylistEditor->Main()) // check if initialized if (myPlaylistEditor->Main()) // check if initialized
@@ -686,8 +682,8 @@ int main(int argc, char *argv[])
if (in == 'y') if (in == 'y')
{ {
Mpd->DeletePlaylist(real_playlist_name); Mpd.DeletePlaylist(real_playlist_name);
if (Mpd->SavePlaylist(real_playlist_name)) if (Mpd.SavePlaylist(real_playlist_name))
ShowMessage("Playlist overwritten!"); ShowMessage("Playlist overwritten!");
} }
else else
@@ -708,7 +704,7 @@ int main(int argc, char *argv[])
} }
else if (Keypressed(input, Key.Stop)) else if (Keypressed(input, Key.Stop))
{ {
Mpd->Stop(); Mpd.Stop();
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if (Keypressed(input, Key.MvSongUp)) else if (Keypressed(input, Key.MvSongUp))
@@ -744,10 +740,10 @@ int main(int argc, char *argv[])
myPlaylist->Main()->Refresh(); myPlaylist->Main()->Refresh();
myPlaylist->Main()->ReadKey(input); myPlaylist->Main()->ReadKey(input);
} }
Mpd->StartCommandsList(); Mpd.StartCommandsList();
for (size_t i = 0; i < list.size(); i++) for (size_t i = 0; i < list.size(); i++)
Mpd->Move(origs[i], list[i]); Mpd.Move(origs[i], list[i]);
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
} }
else else
{ {
@@ -769,7 +765,7 @@ int main(int argc, char *argv[])
myPlaylist->Main()->Refresh(); myPlaylist->Main()->Refresh();
myPlaylist->Main()->ReadKey(input); myPlaylist->Main()->ReadKey(input);
} }
Mpd->Move(from, to); Mpd.Move(from, to);
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout); myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout);
@@ -797,11 +793,11 @@ int main(int argc, char *argv[])
myPlaylistEditor->Content->Refresh(); myPlaylistEditor->Content->Refresh();
myPlaylistEditor->Content->ReadKey(input); myPlaylistEditor->Content->ReadKey(input);
} }
Mpd->StartCommandsList(); 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->Move(myPlaylistEditor->Playlists->Current(), origs[i], list[i]); Mpd.Move(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
} }
else else
{ {
@@ -818,7 +814,7 @@ int main(int argc, char *argv[])
myPlaylistEditor->Content->ReadKey(input); myPlaylistEditor->Content->ReadKey(input);
} }
if (from != to) if (from != to)
Mpd->Move(myPlaylistEditor->Playlists->Current(), from, to); Mpd.Move(myPlaylistEditor->Playlists->Current(), from, to);
} }
myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout); myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout);
} }
@@ -856,10 +852,10 @@ int main(int argc, char *argv[])
myPlaylist->Main()->Refresh(); myPlaylist->Main()->Refresh();
myPlaylist->Main()->ReadKey(input); myPlaylist->Main()->ReadKey(input);
} }
Mpd->StartCommandsList(); Mpd.StartCommandsList();
for (int i = list.size()-1; i >= 0; i--) for (int i = list.size()-1; i >= 0; i--)
Mpd->Move(origs[i], list[i]); Mpd.Move(origs[i], list[i]);
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
} }
else else
{ {
@@ -881,7 +877,7 @@ int main(int argc, char *argv[])
myPlaylist->Main()->Refresh(); myPlaylist->Main()->Refresh();
myPlaylist->Main()->ReadKey(input); myPlaylist->Main()->ReadKey(input);
} }
Mpd->Move(from, to); Mpd.Move(from, to);
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout); myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout);
@@ -910,11 +906,11 @@ int main(int argc, char *argv[])
myPlaylistEditor->Content->Refresh(); myPlaylistEditor->Content->Refresh();
myPlaylistEditor->Content->ReadKey(input); myPlaylistEditor->Content->ReadKey(input);
} }
Mpd->StartCommandsList(); 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->Move(myPlaylistEditor->Playlists->Current(), origs[i], list[i]); Mpd.Move(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
} }
else else
{ {
@@ -931,7 +927,7 @@ int main(int argc, char *argv[])
myPlaylistEditor->Content->ReadKey(input); myPlaylistEditor->Content->ReadKey(input);
} }
if (from != to) if (from != to)
Mpd->Move(myPlaylistEditor->Playlists->Current(), from, to); Mpd.Move(myPlaylistEditor->Playlists->Current(), from, to);
} }
myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout); myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout);
} }
@@ -954,14 +950,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(); 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->Move(*it, pos+i); Mpd.Move(*it, pos+i);
myPlaylist->Main()->Move(*it, pos+i); myPlaylist->Main()->Move(*it, pos+i);
} }
} }
@@ -970,11 +966,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->Move(*it, pos+i); Mpd.Move(*it, pos+i);
myPlaylist->Main()->Move(*it, pos+i); myPlaylist->Main()->Move(*it, pos+i);
} }
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
myPlaylist->Main()->Highlight(pos); myPlaylist->Main()->Highlight(pos);
myPlaylist->FixPositions(); myPlaylist->FixPositions();
} }
@@ -989,23 +985,23 @@ int main(int argc, char *argv[])
if (!path.empty()) if (!path.empty())
{ {
SongList list; SongList list;
Mpd->GetDirectoryRecursive(path, list); Mpd.GetDirectoryRecursive(path, list);
if (!list.empty()) if (!list.empty())
{ {
Mpd->StartCommandsList(); Mpd.StartCommandsList();
SongList::const_iterator it = list.begin(); SongList::const_iterator it = list.begin();
if (myScreen == myPlaylistEditor) if (myScreen == myPlaylistEditor)
{ {
for (; it != list.end(); it++) for (; it != list.end(); it++)
Mpd->AddToPlaylist(myPlaylistEditor->Playlists->Current(), **it); Mpd.AddToPlaylist(myPlaylistEditor->Playlists->Current(), **it);
} }
else else
{ {
for (; it != list.end(); it++) for (; it != list.end(); it++)
if (Mpd->AddSong(**it) < 0) if (Mpd.AddSong(**it) < 0)
break; break;
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
if (it != list.begin() && myScreen != myPlaylistEditor) if (it != list.begin() && myScreen != myPlaylistEditor)
{ {
@@ -1018,11 +1014,11 @@ int main(int argc, char *argv[])
{ {
if (myScreen == myPlaylistEditor) if (myScreen == myPlaylistEditor)
{ {
Mpd->AddToPlaylist(myPlaylistEditor->Playlists->Current(), path); Mpd.AddToPlaylist(myPlaylistEditor->Playlists->Current(), path);
} }
else else
{ {
Mpd->AddSong(path); Mpd.AddSong(path);
} }
} }
if (myScreen == myPlaylistEditor) if (myScreen == myPlaylistEditor)
@@ -1048,7 +1044,7 @@ int main(int argc, char *argv[])
int songpos; int songpos;
time_t t = time(NULL); time_t t = time(NULL);
songpos = Mpd->GetElapsedTime(); songpos = Mpd.GetElapsedTime();
while (Keypressed(input, Key.SeekForward) || Keypressed(input, Key.SeekBackward)) while (Keypressed(input, Key.SeekForward) || Keypressed(input, Key.SeekBackward))
{ {
@@ -1083,7 +1079,7 @@ int main(int argc, char *argv[])
wFooter->Bold(0); wFooter->Bold(0);
wFooter->Refresh(); wFooter->Refresh();
} }
Mpd->Seek(songpos); Mpd.Seek(songpos);
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
UnlockProgressbar(); UnlockProgressbar();
@@ -1149,13 +1145,13 @@ int main(int argc, char *argv[])
else if (Keypressed(input, Key.UpdateDB)) else if (Keypressed(input, Key.UpdateDB))
{ {
if (myScreen == myBrowser) if (myScreen == myBrowser)
Mpd->UpdateDirectory(locale_to_utf_cpy(myBrowser->CurrentDir())); Mpd.UpdateDirectory(locale_to_utf_cpy(myBrowser->CurrentDir()));
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
else if (myScreen == myTagEditor && !Config.albums_in_tag_editor) else if (myScreen == myTagEditor && !Config.albums_in_tag_editor)
Mpd->UpdateDirectory(myTagEditor->CurrentDir()); Mpd.UpdateDirectory(myTagEditor->CurrentDir());
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
else else
Mpd->UpdateDirectory("/"); Mpd.UpdateDirectory("/");
} }
else if (Keypressed(input, Key.GoToNowPlaying)) else if (Keypressed(input, Key.GoToNowPlaying))
{ {
@@ -1173,17 +1169,17 @@ int main(int argc, char *argv[])
} }
else if (Keypressed(input, Key.ToggleRepeat)) else if (Keypressed(input, Key.ToggleRepeat))
{ {
Mpd->SetRepeat(!Mpd->GetRepeat()); Mpd.SetRepeat(!Mpd.GetRepeat());
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if (Keypressed(input, Key.Shuffle)) else if (Keypressed(input, Key.Shuffle))
{ {
Mpd->Shuffle(); Mpd.Shuffle();
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if (Keypressed(input, Key.ToggleRandom)) else if (Keypressed(input, Key.ToggleRandom))
{ {
Mpd->SetRandom(!Mpd->GetRandom()); Mpd.SetRandom(!Mpd.GetRandom());
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if (Keypressed(input, Key.ToggleSingle)) else if (Keypressed(input, Key.ToggleSingle))
@@ -1198,18 +1194,18 @@ int main(int argc, char *argv[])
} }
else else
{ {
Mpd->SetSingle(!Mpd->GetSingle()); Mpd.SetSingle(!Mpd.GetSingle());
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
} }
else if (Keypressed(input, Key.ToggleConsume)) else if (Keypressed(input, Key.ToggleConsume))
{ {
Mpd->SetConsume(!Mpd->GetConsume()); Mpd.SetConsume(!Mpd.GetConsume());
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if (Keypressed(input, Key.ToggleCrossfade)) else if (Keypressed(input, Key.ToggleCrossfade))
{ {
Mpd->SetCrossfade(Mpd->GetCrossfade() ? 0 : Config.crossfade_time); Mpd.SetCrossfade(Mpd.GetCrossfade() ? 0 : Config.crossfade_time);
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if (Keypressed(input, Key.SetCrossfade)) else if (Keypressed(input, Key.SetCrossfade))
@@ -1222,7 +1218,7 @@ int main(int argc, char *argv[])
if (cf > 0) if (cf > 0)
{ {
Config.crossfade_time = cf; Config.crossfade_time = cf;
Mpd->SetCrossfade(cf); Mpd.SetCrossfade(cf);
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
} }
@@ -1246,9 +1242,9 @@ int main(int argc, char *argv[])
bool success = 1; bool success = 1;
SongList list; SongList list;
ShowMessage("Updating tags..."); ShowMessage("Updating tags...");
Mpd->StartSearch(1); Mpd.StartSearch(1);
Mpd->AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(myLibrary->Artists->Current())); Mpd.AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(myLibrary->Artists->Current()));
Mpd->CommitSearch(list); Mpd.CommitSearch(list);
Song::SetFunction set = IntoSetFunction(Config.media_lib_primary_tag); Song::SetFunction set = IntoSetFunction(Config.media_lib_primary_tag);
if (!set) if (!set)
continue; continue;
@@ -1267,7 +1263,7 @@ int main(int argc, char *argv[])
} }
if (success) if (success)
{ {
Mpd->UpdateDirectory(locale_to_utf_cpy(FindSharedDir(list))); Mpd.UpdateDirectory(locale_to_utf_cpy(FindSharedDir(list)));
ShowMessage("Tags updated succesfully!"); ShowMessage("Tags updated succesfully!");
} }
FreeSongList(list); FreeSongList(list);
@@ -1305,7 +1301,7 @@ int main(int argc, char *argv[])
} }
if (success) if (success)
{ {
Mpd->UpdateDirectory(locale_to_utf_cpy(FindSharedDir(myLibrary->Songs))); Mpd.UpdateDirectory(locale_to_utf_cpy(FindSharedDir(myLibrary->Songs)));
ShowMessage("Tags updated succesfully!"); ShowMessage("Tags updated succesfully!");
} }
} }
@@ -1323,7 +1319,7 @@ int main(int argc, char *argv[])
string full_new_dir = Config.mpd_music_dir + myTagEditor->CurrentDir() + "/" + locale_to_utf_cpy(new_dir); string full_new_dir = Config.mpd_music_dir + myTagEditor->CurrentDir() + "/" + locale_to_utf_cpy(new_dir);
if (rename(full_old_dir.c_str(), full_new_dir.c_str()) == 0) if (rename(full_old_dir.c_str(), full_new_dir.c_str()) == 0)
{ {
Mpd->UpdateDirectory(myTagEditor->CurrentDir()); Mpd.UpdateDirectory(myTagEditor->CurrentDir());
} }
else else
{ {
@@ -1359,7 +1355,7 @@ int main(int argc, char *argv[])
{ {
ShowMessage("\"%s\" renamed to \"%s\"", old_dir.c_str(), new_dir.c_str()); ShowMessage("\"%s\" renamed to \"%s\"", old_dir.c_str(), new_dir.c_str());
if (!Config.local_browser) if (!Config.local_browser)
Mpd->UpdateDirectory(locale_to_utf_cpy(FindSharedDir(old_dir, new_dir))); Mpd.UpdateDirectory(locale_to_utf_cpy(FindSharedDir(old_dir, new_dir)));
myBrowser->GetDirectory(myBrowser->CurrentDir()); myBrowser->GetDirectory(myBrowser->CurrentDir());
} }
else else
@@ -1375,7 +1371,7 @@ int main(int argc, char *argv[])
UnlockStatusbar(); UnlockStatusbar();
if (!new_name.empty() && new_name != old_name) if (!new_name.empty() && new_name != old_name)
{ {
Mpd->Rename(locale_to_utf_cpy(old_name), locale_to_utf_cpy(new_name)); Mpd.Rename(locale_to_utf_cpy(old_name), locale_to_utf_cpy(new_name));
ShowMessage("Playlist \"%s\" renamed to \"%s\"", old_name.c_str(), new_name.c_str()); ShowMessage("Playlist \"%s\" renamed to \"%s\"", old_name.c_str(), new_name.c_str());
if (!Config.local_browser) if (!Config.local_browser)
myBrowser->GetDirectory("/"); myBrowser->GetDirectory("/");
@@ -1418,7 +1414,7 @@ int main(int argc, char *argv[])
} }
catch (std::out_of_range) { } catch (std::out_of_range) { }
if (newpos > 0 && newpos < s->GetTotalLength()) if (newpos > 0 && newpos < s->GetTotalLength())
Mpd->Seek(newpos); Mpd.Seek(newpos);
else else
ShowMessage("Out of bounds, 0:00-%s possible for mm:ss, %d given.", s->GetLength().c_str(), newpos); ShowMessage("Out of bounds, 0:00-%s possible for mm:ss, %d given.", s->GetLength().c_str(), newpos);
} }
@@ -1426,7 +1422,7 @@ int main(int argc, char *argv[])
{ {
newpos = StrToInt(position); newpos = StrToInt(position);
if (newpos > 0 && newpos < s->GetTotalLength()) if (newpos > 0 && newpos < s->GetTotalLength())
Mpd->Seek(newpos); Mpd.Seek(newpos);
else else
ShowMessage("Out of bounds, 1-%d possible for seconds, %d given.", s->GetTotalLength(), newpos); ShowMessage("Out of bounds, 1-%d possible for seconds, %d given.", s->GetTotalLength(), newpos);
} }
@@ -1434,7 +1430,7 @@ int main(int argc, char *argv[])
{ {
newpos = StrToInt(position); newpos = StrToInt(position);
if (newpos > 0 && newpos < 100) if (newpos > 0 && newpos < 100)
Mpd->Seek(s->GetTotalLength()*newpos/100.0); Mpd.Seek(s->GetTotalLength()*newpos/100.0);
else else
ShowMessage("Out of bounds, 1-99 possible for %%, %d given.", newpos); ShowMessage("Out of bounds, 1-99 possible for %%, %d given.", newpos);
} }
@@ -1491,7 +1487,7 @@ int main(int argc, char *argv[])
mDialog.AddOption("Create new playlist", 0, playlists_not_active); mDialog.AddOption("Create new playlist", 0, playlists_not_active);
mDialog.AddSeparator(); mDialog.AddSeparator();
TagList playlists; TagList playlists;
Mpd->GetPlaylists(playlists); Mpd.GetPlaylists(playlists);
for (TagList::iterator it = playlists.begin(); it != playlists.end(); it++) for (TagList::iterator it = playlists.begin(); it != playlists.end(); it++)
{ {
utf_to_locale(*it); utf_to_locale(*it);
@@ -1530,12 +1526,12 @@ int main(int argc, char *argv[])
if (id == 0) if (id == 0)
{ {
Mpd->StartCommandsList(); Mpd.StartCommandsList();
SongList::const_iterator it = result.begin(); SongList::const_iterator it = result.begin();
for (; it != result.end(); it++) for (; it != result.end(); it++)
if (Mpd->AddSong(**it) < 0) if (Mpd.AddSong(**it) < 0)
break; break;
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
if (it != result.begin()) if (it != result.begin())
{ {
@@ -1555,20 +1551,20 @@ int main(int argc, char *argv[])
UnlockStatusbar(); UnlockStatusbar();
if (!playlist.empty()) if (!playlist.empty())
{ {
Mpd->StartCommandsList(); 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->AddToPlaylist(real_playlist, **it); Mpd.AddToPlaylist(real_playlist, **it);
Mpd->CommitCommandsList(); 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)
{ {
string playlist = locale_to_utf_cpy(mDialog.Current()); string playlist = locale_to_utf_cpy(mDialog.Current());
Mpd->StartCommandsList(); 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->AddToPlaylist(playlist, **it); Mpd.AddToPlaylist(playlist, **it);
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
ShowMessage("Selected items added to playlist \"%s\"!", mDialog.Current().c_str()); ShowMessage("Selected items added to playlist \"%s\"!", mDialog.Current().c_str());
} }
@@ -1588,19 +1584,19 @@ int main(int argc, char *argv[])
CHECK_PLAYLIST_FOR_FILTERING; CHECK_PLAYLIST_FOR_FILTERING;
if (myPlaylist->Main()->hasSelected()) if (myPlaylist->Main()->hasSelected())
{ {
Mpd->StartCommandsList(); 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->Delete(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->DeleteID(myPlaylist->NowPlayingSong()->GetID()); Mpd.DeleteID(myPlaylist->NowPlayingSong()->GetID());
ShowMessage("Deleting all items but selected..."); ShowMessage("Deleting all items but selected...");
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
ShowMessage("Items deleted!"); ShowMessage("Items deleted!");
} }
else else
@@ -1610,12 +1606,12 @@ int main(int argc, char *argv[])
ShowMessage("Nothing is playing now!"); ShowMessage("Nothing is playing now!");
continue; continue;
} }
Mpd->StartCommandsList(); 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->Delete(i); Mpd.Delete(i);
ShowMessage("Deleting all items except now playing one..."); ShowMessage("Deleting all items except now playing one...");
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
ShowMessage("Items deleted!"); ShowMessage("Items deleted!");
} }
} }
@@ -1624,10 +1620,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(); Mpd.StartCommandsList();
for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--) for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
Mpd->Delete((*myPlaylist->Main())[i].GetPosition()); Mpd.Delete((*myPlaylist->Main())[i].GetPosition());
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
ShowMessage("Filtered items deleted!"); ShowMessage("Filtered items deleted!");
} }
else else
@@ -1651,7 +1647,7 @@ int main(int argc, char *argv[])
if (in == 'y') if (in == 'y')
{ {
Mpd->ClearPlaylist(locale_to_utf_cpy(myPlaylistEditor->Playlists->Current())); Mpd.ClearPlaylist(locale_to_utf_cpy(myPlaylistEditor->Playlists->Current()));
myPlaylistEditor->Content->Clear(0); myPlaylistEditor->Content->Clear(0);
} }
else else
@@ -1660,7 +1656,7 @@ int main(int argc, char *argv[])
else else
{ {
ShowMessage("Clearing playlist..."); ShowMessage("Clearing playlist...");
Mpd->ClearPlaylist(); Mpd.ClearPlaylist();
} }
if (myScreen != myPlaylistEditor || in == 'y') if (myScreen != myPlaylistEditor || in == 'y')
ShowMessage("Playlist cleared!"); ShowMessage("Playlist cleared!");
@@ -1788,7 +1784,7 @@ int main(int argc, char *argv[])
Statusbar() << "Number of random songs: "; Statusbar() << "Number of random songs: ";
size_t number = StrToLong(wFooter->GetString()); size_t number = StrToLong(wFooter->GetString());
UnlockStatusbar(); UnlockStatusbar();
if (number && Mpd->AddRandomSongs(number)) if (number && Mpd.AddRandomSongs(number))
ShowMessage(SIZE_T_FORMAT " random song%s added to playlist!", number, number == 1 ? "" : "s"); ShowMessage(SIZE_T_FORMAT " random song%s added to playlist!", number, number == 1 ? "" : "s");
} }
else if (myScreen == myBrowser) else if (myScreen == myBrowser)
@@ -1914,7 +1910,7 @@ int main(int argc, char *argv[])
// restore old cerr buffer // restore old cerr buffer
std::cerr.rdbuf(cerr_buffer); std::cerr.rdbuf(cerr_buffer);
errorlog.close(); errorlog.close();
Mpd->Disconnect(); Mpd.Disconnect();
DestroyScreen(); DestroyScreen();
WindowTitle(""); WindowTitle("");
return 0; return 0;

View File

@@ -73,7 +73,7 @@ void Outputs::EnterPressed()
{ {
if (w->Current().second) if (w->Current().second)
{ {
if (Mpd->DisableOutput(w->Choice())) if (Mpd.DisableOutput(w->Choice()))
{ {
ShowMessage("Output \"%s\" disabled", w->Current().first.c_str()); ShowMessage("Output \"%s\" disabled", w->Current().first.c_str());
w->Current().second = 0; w->Current().second = 0;
@@ -82,7 +82,7 @@ void Outputs::EnterPressed()
} }
else else
{ {
if (Mpd->EnableOutput(w->Choice())) if (Mpd.EnableOutput(w->Choice()))
{ {
ShowMessage("Output \"%s\" enabled", w->Current().first.c_str()); ShowMessage("Output \"%s\" enabled", w->Current().first.c_str());
w->Current().second = 1; w->Current().second = 1;
@@ -109,7 +109,7 @@ void Outputs::MouseButtonPressed(MEVENT me)
void Outputs::FetchList() void Outputs::FetchList()
{ {
MPD::OutputList ol; MPD::OutputList ol;
Mpd->GetOutputs(ol); Mpd.GetOutputs(ol);
w->Clear(); w->Clear();
for (MPD::OutputList::const_iterator it = ol.begin(); it != ol.end(); it++) for (MPD::OutputList::const_iterator it = ol.begin(); it != ol.end(); it++)
w->AddOption(*it, it->second); w->AddOption(*it, it->second);

View File

@@ -127,7 +127,7 @@ void Playlist::EnterPressed()
{ {
if (!w->Empty()) if (!w->Empty())
{ {
Mpd->PlayID(w->Current().GetID()); Mpd.PlayID(w->Current().GetID());
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
} }
@@ -147,7 +147,7 @@ void Playlist::MouseButtonPressed(MEVENT me)
w->Goto(me.y); w->Goto(me.y);
if (me.bstate & BUTTON3_PRESSED) if (me.bstate & BUTTON3_PRESSED)
{ {
Mpd->Play(w->Current().GetPosition()); Mpd.Play(w->Current().GetPosition());
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
} }
@@ -249,13 +249,13 @@ void Playlist::Sort()
{ {
BlockUpdate = 1; BlockUpdate = 1;
ShowMessage("Reversing playlist order..."); ShowMessage("Reversing playlist order...");
Mpd->StartCommandsList(); Mpd.StartCommandsList();
for (size_t i = 0, j = w->Size()-1; i < w->Size()/2; i++, j--) for (size_t i = 0, j = w->Size()-1; i < w->Size()/2; i++, j--)
{ {
Mpd->Swap(i, j); Mpd.Swap(i, j);
w->Swap(i, j); w->Swap(i, j);
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
ShowMessage("Playlist reversed!"); ShowMessage("Playlist reversed!");
return; return;
} }
@@ -290,14 +290,14 @@ void Playlist::Sort()
BlockUpdate = 1; BlockUpdate = 1;
ShowMessage("Sorting playlist..."); ShowMessage("Sorting playlist...");
Mpd->StartCommandsList(); Mpd.StartCommandsList();
do do
{ {
for (size_t i = 0; i < playlist.size(); i++) for (size_t i = 0; i < playlist.size(); i++)
{ {
if (playlist[i]->GetPosition() > int(i)) if (playlist[i]->GetPosition() > int(i))
{ {
Mpd->Swap(playlist[i]->GetPosition(), i); Mpd.Swap(playlist[i]->GetPosition(), i);
std::swap(cmp[playlist[i]->GetPosition()], cmp[i]); std::swap(cmp[playlist[i]->GetPosition()], cmp[i]);
w->Swap(playlist[i]->GetPosition(), i); w->Swap(playlist[i]->GetPosition(), i);
} }
@@ -305,7 +305,7 @@ void Playlist::Sort()
} }
} }
while (playlist != cmp); while (playlist != cmp);
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
ShowMessage("Playlist sorted!"); ShowMessage("Playlist sorted!");
} }
@@ -374,7 +374,7 @@ std::string Playlist::TotalLength()
size_t real_size = w->Size(); size_t real_size = w->Size();
w->ShowFiltered(); w->ShowFiltered();
if (w->Size() != real_size) if (w->Size() != real_size)
result << " (out of " << Mpd->GetPlaylistLength() << ")"; result << " (out of " << Mpd.GetPlaylistLength() << ")";
} }
if (itsTotalLength) if (itsTotalLength)

View File

@@ -116,7 +116,7 @@ void PlaylistEditor::Update()
{ {
Content->Clear(0); Content->Clear(0);
TagList list; TagList list;
Mpd->GetPlaylists(list); Mpd.GetPlaylists(list);
sort(list.begin(), list.end(), CaseInsensitiveSorting()); sort(list.begin(), list.end(), CaseInsensitiveSorting());
for (TagList::iterator it = list.begin(); it != list.end(); it++) for (TagList::iterator it = list.begin(); it != list.end(); it++)
{ {
@@ -131,7 +131,7 @@ void PlaylistEditor::Update()
{ {
Content->Reset(); Content->Reset();
SongList list; SongList list;
Mpd->GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), list); Mpd.GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), list);
if (!list.empty()) if (!list.empty())
Content->SetTitle("Playlist's content (" + IntoStr(list.size()) + " item" + (list.size() == 1 ? ")" : "s)")); Content->SetTitle("Playlist's content (" + IntoStr(list.size()) + " item" + (list.size() == 1 ? ")" : "s)"));
else else
@@ -197,13 +197,13 @@ 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);
Mpd->StartCommandsList(); Mpd.StartCommandsList();
SongList::const_iterator it = list.begin(); SongList::const_iterator it = list.begin();
for (; it != list.end(); it++) for (; it != list.end(); it++)
if (Mpd->AddSong(**it) < 0) if (Mpd.AddSong(**it) < 0)
break; break;
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
if (it != list.begin()) if (it != list.begin())
{ {
@@ -212,7 +212,7 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
if (s.GetHash() == list[0]->GetHash()) if (s.GetHash() == list[0]->GetHash())
{ {
if (add_n_play) if (add_n_play)
Mpd->PlayID(s.GetID()); Mpd.PlayID(s.GetID());
} }
else else
ShowMessage("%s", MPD::Message::PartOfSongsAdded); ShowMessage("%s", MPD::Message::PartOfSongsAdded);
@@ -232,7 +232,7 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
{ {
if (myPlaylist->Main()->at(i).GetHash() == hash) if (myPlaylist->Main()->at(i).GetHash() == hash)
{ {
Mpd->Play(i); Mpd.Play(i);
break; break;
} }
} }
@@ -240,17 +240,17 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
else else
{ {
Playlist::BlockUpdate = 1; Playlist::BlockUpdate = 1;
Mpd->StartCommandsList(); 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->Delete(i); Mpd.Delete(i);
myPlaylist->Main()->DeleteOption(i); myPlaylist->Main()->DeleteOption(i);
i--; i--;
} }
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
Content->BoldOption(Content->Choice(), 0); Content->BoldOption(Content->Choice(), 0);
Playlist::BlockUpdate = 0; Playlist::BlockUpdate = 0;
} }
@@ -258,12 +258,12 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
else else
{ {
const Song &s = Content->Current(); const Song &s = Content->Current();
int id = Mpd->AddSong(s); int id = Mpd.AddSong(s);
if (id >= 0) if (id >= 0)
{ {
ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str()); ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str());
if (add_n_play) if (add_n_play)
Mpd->PlayID(id); Mpd.PlayID(id);
Content->BoldOption(Content->Choice(), 1); Content->BoldOption(Content->Choice(), 1);
} }
} }

View File

@@ -234,7 +234,7 @@ void SearchEngine::EnterPressed()
{ {
if (myPlaylist->Main()->at(i).GetHash() == hash) if (myPlaylist->Main()->at(i).GetHash() == hash)
{ {
Mpd->Play(i); Mpd.Play(i);
break; break;
} }
} }
@@ -242,10 +242,10 @@ void SearchEngine::EnterPressed()
else else
{ {
const Song &s = *w->Current().second; const Song &s = *w->Current().second;
int id = Mpd->AddSong(s); int id = Mpd.AddSong(s);
if (id >= 0) if (id >= 0)
{ {
Mpd->PlayID(id); Mpd.PlayID(id);
ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str()); ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str());
w->BoldOption(w->Choice(), 1); w->BoldOption(w->Choice(), 1);
} }
@@ -273,24 +273,24 @@ 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(); 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->Delete(i); Mpd.Delete(i);
myPlaylist->Main()->DeleteOption(i); myPlaylist->Main()->DeleteOption(i);
i--; i--;
} }
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
w->BoldOption(w->Choice(), 0); w->BoldOption(w->Choice(), 0);
Playlist::BlockUpdate = 0; Playlist::BlockUpdate = 0;
} }
else else
{ {
const Song &s = *w->Current().second; const Song &s = *w->Current().second;
if (Mpd->AddSong(s) != -1) if (Mpd.AddSong(s) != -1)
{ {
ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str()); ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str());
w->BoldOption(w->Choice(), 1); w->BoldOption(w->Choice(), 1);
@@ -421,7 +421,7 @@ void SearchEngine::Search()
SongList list; SongList list;
if (Config.search_in_db) if (Config.search_in_db)
Mpd->GetDirectoryRecursive("/", list); Mpd.GetDirectoryRecursive("/", list);
else else
{ {
list.reserve(myPlaylist->Main()->Size()); list.reserve(myPlaylist->Main()->Size());

View File

@@ -109,7 +109,7 @@ void UnlockStatusbar()
else else
block_progressbar_update = 0; block_progressbar_update = 0;
} }
if (Mpd->GetState() < psPlay) if (Mpd.GetState() < psPlay)
Statusbar() << wclrtoeol; Statusbar() << wclrtoeol;
} }
@@ -118,12 +118,12 @@ void TraceMpdStatus()
static timeval past, now; static timeval past, now;
gettimeofday(&now, 0); gettimeofday(&now, 0);
if ((Mpd->Connected() if ((Mpd.Connected()
&& (/*(now.tv_sec == past.tv_sec && now.tv_usec >= past.tv_usec+500000) || */now.tv_sec > past.tv_sec)) && (/*(now.tv_sec == past.tv_sec && now.tv_usec >= past.tv_usec+500000) || */now.tv_sec > past.tv_sec))
|| UpdateStatusImmediately || UpdateStatusImmediately
) )
{ {
Mpd->UpdateStatus(); Mpd.UpdateStatus();
BlockItemListUpdate = 0; BlockItemListUpdate = 0;
Playlist::BlockUpdate = 0; Playlist::BlockUpdate = 0;
UpdateStatusImmediately = 0; UpdateStatusImmediately = 0;
@@ -145,29 +145,29 @@ void TraceMpdStatus()
else else
block_progressbar_update = !allow_statusbar_unlock; block_progressbar_update = !allow_statusbar_unlock;
if (Mpd->GetState() < psPlay && !block_statusbar_update) if (Mpd.GetState() < psPlay && !block_statusbar_update)
Statusbar() << wclrtoeol; Statusbar() << wclrtoeol;
} }
} }
} }
void NcmpcppErrorCallback(Connection *Mpd, int errorid, const char *msg, void *) void NcmpcppErrorCallback(Connection *, int errorid, const char *msg, void *)
{ {
if (errorid == MPD_ACK_ERROR_PERMISSION) if (errorid == MPD_ACK_ERROR_PERMISSION)
{ {
wFooter->SetGetStringHelper(NULL); wFooter->SetGetStringHelper(NULL);
Statusbar() << "Password: "; Statusbar() << "Password: ";
string password = wFooter->GetString(-1, 0, 1); string password = wFooter->GetString(-1, 0, 1);
Mpd->SetPassword(password); Mpd.SetPassword(password);
Mpd->SendPassword(); Mpd.SendPassword();
Mpd->UpdateStatus(); Mpd.UpdateStatus();
wFooter->SetGetStringHelper(StatusbarGetStringHelper); wFooter->SetGetStringHelper(StatusbarGetStringHelper);
} }
else else
ShowMessage("%s", msg); ShowMessage("%s", msg);
} }
void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *) void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
{ {
static size_t playing_song_scroll_begin = 0; static size_t playing_song_scroll_begin = 0;
static string player_state; static string player_state;
@@ -178,10 +178,10 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
wFooter->Bold(1); wFooter->Bold(1);
wFooter->GetXY(sx, sy); wFooter->GetXY(sx, sy);
if ((myPlaylist->NowPlaying != Mpd->GetCurrentSongPos() || changed.SongID) && !Playlist::BlockNowPlayingUpdate) if ((myPlaylist->NowPlaying != Mpd.GetCurrentSongPos() || changed.SongID) && !Playlist::BlockNowPlayingUpdate)
{ {
myPlaylist->OldPlaying = myPlaylist->NowPlaying; myPlaylist->OldPlaying = myPlaylist->NowPlaying;
myPlaylist->NowPlaying = Mpd->GetCurrentSongPos(); myPlaylist->NowPlaying = Mpd.GetCurrentSongPos();
bool was_filtered = myPlaylist->Main()->isFiltered(); bool was_filtered = myPlaylist->Main()->isFiltered();
myPlaylist->Main()->ShowAll(); myPlaylist->Main()->ShowAll();
try try
@@ -202,19 +202,19 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
{ {
if (!Playlist::BlockUpdate) if (!Playlist::BlockUpdate)
{ {
np = Mpd->GetCurrentSong(); np = Mpd.GetCurrentSong();
if (Mpd->GetState() > psStop) if (Mpd.GetState() > psStop)
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
bool was_filtered = myPlaylist->Main()->isFiltered(); bool was_filtered = myPlaylist->Main()->isFiltered();
myPlaylist->Main()->ShowAll(); myPlaylist->Main()->ShowAll();
SongList list; SongList list;
size_t playlist_length = Mpd->GetPlaylistLength(); size_t playlist_length = Mpd.GetPlaylistLength();
if (playlist_length < myPlaylist->Main()->Size()) if (playlist_length < myPlaylist->Main()->Size())
myPlaylist->Main()->ResizeList(playlist_length); myPlaylist->Main()->ResizeList(playlist_length);
Mpd->GetPlaylistChanges(Mpd->GetOldPlaylistID(), list); Mpd.GetPlaylistChanges(Mpd.GetOldPlaylistID(), list);
myPlaylist->Main()->Reserve(playlist_length); myPlaylist->Main()->Reserve(playlist_length);
for (SongList::const_iterator it = list.begin(); it != list.end(); it++) for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
{ {
@@ -306,7 +306,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
} }
if (changed.PlayerState) if (changed.PlayerState)
{ {
PlayerState mpd_state = Mpd->GetState(); PlayerState mpd_state = Mpd.GetState();
switch (mpd_state) switch (mpd_state)
{ {
case psUnknown: case psUnknown:
@@ -352,45 +352,45 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
{ {
if (myPlaylist->isPlaying()) if (myPlaylist->isPlaying())
{ {
np = Mpd->GetCurrentSong(); np = Mpd.GetCurrentSong();
if (!Config.execute_on_song_change.empty()) if (!Config.execute_on_song_change.empty())
system(np.toString(Config.execute_on_song_change).c_str()); system(np.toString(Config.execute_on_song_change).c_str());
if (Mpd->GetState() > psStop) if (Mpd.GetState() > psStop)
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
if (Config.autocenter_mode && !myPlaylist->Main()->isFiltered()) if (Config.autocenter_mode && !myPlaylist->Main()->isFiltered())
myPlaylist->Main()->Highlight(myPlaylist->NowPlaying); myPlaylist->Main()->Highlight(myPlaylist->NowPlaying);
if (!Mpd->GetElapsedTime()) if (!Mpd.GetElapsedTime())
mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth()); mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth());
if (Config.now_playing_lyrics && !Mpd->GetSingle() && myScreen == myLyrics && myOldScreen == myPlaylist) if (Config.now_playing_lyrics && !Mpd.GetSingle() && myScreen == myLyrics && myOldScreen == myPlaylist)
Lyrics::Reload = 1; Lyrics::Reload = 1;
} }
Playlist::ReloadRemaining = 1; Playlist::ReloadRemaining = 1;
playing_song_scroll_begin = 0; playing_song_scroll_begin = 0;
if (Mpd->GetState() == psPlay) if (Mpd.GetState() == psPlay)
{ {
changed.ElapsedTime = 1; changed.ElapsedTime = 1;
} }
} }
static time_t now, past = 0; static time_t now, past = 0;
time(&now); time(&now);
if (((now > past || changed.SongID) && Mpd->GetState() > psStop) || RedrawStatusbar) if (((now > past || changed.SongID) && Mpd.GetState() > psStop) || RedrawStatusbar)
{ {
time(&past); time(&past);
if (np.Empty()) if (np.Empty())
{ {
np = Mpd->GetCurrentSong(); np = Mpd.GetCurrentSong();
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
} }
if (!np.Empty() && !player_state.empty()) if (!np.Empty() && !player_state.empty())
{ {
int mpd_elapsed = Mpd->GetElapsedTime(); int mpd_elapsed = Mpd.GetElapsedTime();
if (elapsed < mpd_elapsed-2 || elapsed+1 > mpd_elapsed) if (elapsed < mpd_elapsed-2 || elapsed+1 > mpd_elapsed)
elapsed = mpd_elapsed; elapsed = mpd_elapsed;
else if (Mpd->GetState() == psPlay && !RedrawStatusbar) else if (Mpd.GetState() == psPlay && !RedrawStatusbar)
elapsed++; elapsed++;
if (!block_statusbar_update && Config.statusbar_visibility) if (!block_statusbar_update && Config.statusbar_visibility)
@@ -447,33 +447,33 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
if (changed.Repeat) if (changed.Repeat)
{ {
mpd_repeat = Mpd->GetRepeat() ? 'r' : 0; mpd_repeat = Mpd.GetRepeat() ? 'r' : 0;
ShowMessage("Repeat mode is %s", !mpd_repeat ? "off" : "on"); ShowMessage("Repeat mode is %s", !mpd_repeat ? "off" : "on");
} }
if (changed.Random) if (changed.Random)
{ {
mpd_random = Mpd->GetRandom() ? 'z' : 0; mpd_random = Mpd.GetRandom() ? 'z' : 0;
ShowMessage("Random mode is %s", !mpd_random ? "off" : "on"); ShowMessage("Random mode is %s", !mpd_random ? "off" : "on");
} }
if (changed.Single) if (changed.Single)
{ {
mpd_single = Mpd->GetSingle() ? 's' : 0; mpd_single = Mpd.GetSingle() ? 's' : 0;
ShowMessage("Single mode is %s", !mpd_single ? "off" : "on"); ShowMessage("Single mode is %s", !mpd_single ? "off" : "on");
} }
if (changed.Consume) if (changed.Consume)
{ {
mpd_consume = Mpd->GetConsume() ? 'c' : 0; mpd_consume = Mpd.GetConsume() ? 'c' : 0;
ShowMessage("Consume mode is %s", !mpd_consume ? "off" : "on"); ShowMessage("Consume mode is %s", !mpd_consume ? "off" : "on");
} }
if (changed.Crossfade) if (changed.Crossfade)
{ {
int crossfade = Mpd->GetCrossfade(); int crossfade = Mpd.GetCrossfade();
mpd_crossfade = crossfade ? 'x' : 0; mpd_crossfade = crossfade ? 'x' : 0;
ShowMessage("Crossfade set to %d seconds", crossfade); ShowMessage("Crossfade set to %d seconds", crossfade);
} }
if (changed.DBUpdating) if (changed.DBUpdating)
{ {
mpd_db_updating = Mpd->GetDBIsUpdating() ? 'U' : 0; mpd_db_updating = Mpd.GetDBIsUpdating() ? 'U' : 0;
ShowMessage(!mpd_db_updating ? "Database update finished!" : "Database update started!"); ShowMessage(!mpd_db_updating ? "Database update finished!" : "Database update started!");
} }
if (changed.StatusFlags && Config.header_visibility) if (changed.StatusFlags && Config.header_visibility)
@@ -512,7 +512,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
if (changed.Volume && Config.header_visibility) if (changed.Volume && Config.header_visibility)
{ {
VolumeState = " Volume: "; VolumeState = " Volume: ";
int volume = Mpd->GetVolume(); int volume = Mpd.GetVolume();
if (volume < 0) if (volume < 0)
VolumeState += "n/a"; VolumeState += "n/a";
else else

View File

@@ -193,7 +193,7 @@ void TinyTagEditor::EnterPressed()
ShowMessage("Tags updated!"); ShowMessage("Tags updated!");
if (s.IsFromDB()) if (s.IsFromDB())
{ {
Mpd->UpdateDirectory(locale_to_utf_cpy(s.GetDirectory())); Mpd.UpdateDirectory(locale_to_utf_cpy(s.GetDirectory()));
if (myOldScreen == mySearcher) if (myOldScreen == mySearcher)
*mySearcher->Main()->Current().second = s; *mySearcher->Main()->Current().second = s;
} }
@@ -443,14 +443,14 @@ void TagEditor::Update()
{ {
*Albums << XY(0, 0) << "Fetching albums..."; *Albums << XY(0, 0) << "Fetching albums...";
Albums->Window::Refresh(); Albums->Window::Refresh();
Mpd->GetAlbums("", list); Mpd.GetAlbums("", list);
for (TagList::const_iterator it = list.begin(); it != list.end(); it++) for (TagList::const_iterator it = list.begin(); it != list.end(); it++)
{ {
SongList l; SongList l;
Mpd->StartSearch(1); Mpd.StartSearch(1);
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, *it); Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, *it);
Mpd->CommitSearch(l); Mpd.CommitSearch(l);
if (!l.empty()) if (!l.empty())
{ {
l[0]->Localize(); l[0]->Localize();
@@ -463,7 +463,7 @@ void TagEditor::Update()
else else
{ {
int highlightme = -1; int highlightme = -1;
Mpd->GetDirectories(itsBrowsedDir, list); Mpd.GetDirectories(itsBrowsedDir, list);
sort(list.begin(), list.end(), CaseInsensitiveSorting()); sort(list.begin(), list.end(), CaseInsensitiveSorting());
if (itsBrowsedDir != "/") if (itsBrowsedDir != "/")
{ {
@@ -497,9 +497,9 @@ void TagEditor::Update()
SongList list; SongList list;
if (Config.albums_in_tag_editor) if (Config.albums_in_tag_editor)
{ {
Mpd->StartSearch(1); Mpd.StartSearch(1);
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, Albums->Current().second); Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, Albums->Current().second);
Mpd->CommitSearch(list); Mpd.CommitSearch(list);
sort(list.begin(), list.end(), CaseInsensitiveSorting()); sort(list.begin(), list.end(), CaseInsensitiveSorting());
for (SongList::iterator it = list.begin(); it != list.end(); it++) for (SongList::iterator it = list.begin(); it != list.end(); it++)
{ {
@@ -509,7 +509,7 @@ void TagEditor::Update()
} }
else else
{ {
Mpd->GetSongs(Dirs->Current().second, list); Mpd.GetSongs(Dirs->Current().second, list);
sort(list.begin(), list.end(), CaseInsensitiveSorting()); sort(list.begin(), list.end(), CaseInsensitiveSorting());
for (SongList::const_iterator it = list.begin(); it != list.end(); it++) for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
{ {
@@ -535,7 +535,7 @@ void TagEditor::EnterPressed()
if (w == Dirs) if (w == Dirs)
{ {
TagList test; TagList test;
Mpd->GetDirectories(LeftColumn->Current().second, test); Mpd.GetDirectories(LeftColumn->Current().second, test);
if (!test.empty()) if (!test.empty())
{ {
itsHighlightedDir = itsBrowsedDir; itsHighlightedDir = itsBrowsedDir;
@@ -686,7 +686,7 @@ void TagEditor::EnterPressed()
w->Refresh(); w->Refresh();
w = LeftColumn; w = LeftColumn;
LeftColumn->HighlightColor(Config.active_column_color); LeftColumn->HighlightColor(Config.active_column_color);
Mpd->UpdateDirectory(locale_to_utf_cpy(FindSharedDir(Tags))); Mpd.UpdateDirectory(locale_to_utf_cpy(FindSharedDir(Tags)));
} }
else else
Tags->Clear(0); Tags->Clear(0);
@@ -986,15 +986,15 @@ 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->StartCommandsList(); Mpd.StartCommandsList();
Mpd->Delete(pos); Mpd.Delete(pos);
int id = Mpd->AddSong("file://" + new_name); int id = Mpd.AddSong("file://" + new_name);
if (id >= 0) if (id >= 0)
{ {
s = myPlaylist->Main()->Back(); s = myPlaylist->Main()->Back();
Mpd->Move(s.GetPosition(), pos); Mpd.Move(s.GetPosition(), pos);
} }
Mpd->CommitCommandsList(); Mpd.CommitCommandsList();
} }
else // only myBrowser->Main() else // only myBrowser->Main()
s.SetFile(new_name); s.SetFile(new_name);