throw away isConnected variable and use itsConnection instead

This commit is contained in:
Andrzej Rybczak
2009-10-06 07:18:46 +02:00
parent f61b4716a2
commit d82498ea16
2 changed files with 183 additions and 215 deletions

View File

@@ -33,7 +33,6 @@ 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() : itsConnection(0), Connection::Connection() : itsConnection(0),
isConnected(0),
isCommandsListEnabled(0), isCommandsListEnabled(0),
itsErrorCode(0), itsErrorCode(0),
itsMaxPlaylistLength(-1), itsMaxPlaylistLength(-1),
@@ -59,23 +58,19 @@ Connection::~Connection()
bool Connection::Connect() bool Connection::Connect()
{ {
if (!isConnected && !itsConnection) if (itsConnection)
{ return true;
itsConnection = mpd_connection_new(itsHost.c_str(), itsPort, itsTimeout*1000 /* timeout is in ms now */); itsConnection = mpd_connection_new(itsHost.c_str(), itsPort, itsTimeout*1000 /* timeout is in ms now */);
isConnected = 1;
if (CheckForErrors()) if (CheckForErrors())
return false; return false;
if (!itsPassword.empty()) if (!itsPassword.empty())
SendPassword(); SendPassword();
return !CheckForErrors(); return !CheckForErrors();
}
else
return true;
} }
bool Connection::Connected() const bool Connection::Connected() const
{ {
return isConnected; return itsConnection;
} }
void Connection::Disconnect() void Connection::Disconnect()
@@ -89,14 +84,13 @@ void Connection::Disconnect()
itsConnection = 0; itsConnection = 0;
itsCurrentStatus = 0; itsCurrentStatus = 0;
itsOldStatus = 0; itsOldStatus = 0;
isConnected = 0;
isCommandsListEnabled = 0; isCommandsListEnabled = 0;
itsMaxPlaylistLength = -1; itsMaxPlaylistLength = -1;
} }
float Connection::Version() const float Connection::Version() const
{ {
if (!isConnected) if (!itsConnection)
return 0; return 0;
const unsigned *version = mpd_connection_get_server_version(itsConnection); const unsigned *version = mpd_connection_get_server_version(itsConnection);
return version[1] + version[2]*0.1; return version[1] + version[2]*0.1;
@@ -195,9 +189,8 @@ void Connection::UpdateStatus()
bool Connection::UpdateDirectory(const std::string &path) bool Connection::UpdateDirectory(const std::string &path)
{ {
if (!isConnected) if (!itsConnection)
return false; return false;
if (!mpd_run_update(itsConnection, path.c_str())) if (!mpd_run_update(itsConnection, path.c_str()))
return false; return false;
UpdateStatus(); UpdateStatus();
@@ -206,98 +199,98 @@ bool Connection::UpdateDirectory(const std::string &path)
void Connection::Play() const void Connection::Play() const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_play : mpd_run_play)(itsConnection); (isCommandsListEnabled ? mpd_send_play : mpd_run_play)(itsConnection);
} }
void Connection::Play(int pos) const void Connection::Play(int pos) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_play_pos : mpd_run_play_pos)(itsConnection, pos); (isCommandsListEnabled ? mpd_send_play_pos : mpd_run_play_pos)(itsConnection, pos);
} }
void Connection::PlayID(int id) const void Connection::PlayID(int id) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_play_id : mpd_run_play_id)(itsConnection, id); (isCommandsListEnabled ? mpd_send_play_id : mpd_run_play_id)(itsConnection, id);
} }
void Connection::Pause(bool state) const void Connection::Pause(bool state) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_pause : mpd_run_pause)(itsConnection, state); (isCommandsListEnabled ? mpd_send_pause : mpd_run_pause)(itsConnection, state);
} }
void Connection::Toggle() const void Connection::Toggle() const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_toggle_pause : mpd_run_toggle_pause)(itsConnection); (isCommandsListEnabled ? mpd_send_toggle_pause : mpd_run_toggle_pause)(itsConnection);
} }
void Connection::Stop() const void Connection::Stop() const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_stop : mpd_run_stop)(itsConnection); (isCommandsListEnabled ? mpd_send_stop : mpd_run_stop)(itsConnection);
} }
void Connection::Next() const void Connection::Next() const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_next : mpd_run_next)(itsConnection); (isCommandsListEnabled ? mpd_send_next : mpd_run_next)(itsConnection);
} }
void Connection::Prev() const void Connection::Prev() const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_previous : mpd_run_previous)(itsConnection); (isCommandsListEnabled ? mpd_send_previous : mpd_run_previous)(itsConnection);
} }
void Connection::Move(unsigned from, unsigned to) const void Connection::Move(unsigned from, unsigned to) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_move : mpd_run_move)(itsConnection, from, to); (isCommandsListEnabled ? mpd_send_move : mpd_run_move)(itsConnection, from, to);
} }
void Connection::Swap(unsigned from, unsigned to) const void Connection::Swap(unsigned from, unsigned to) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_swap : mpd_run_swap)(itsConnection, from, to); (isCommandsListEnabled ? mpd_send_swap : mpd_run_swap)(itsConnection, from, to);
} }
void Connection::Seek(unsigned where) const void Connection::Seek(unsigned where) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_seek_pos : mpd_run_seek_pos)(itsConnection, Mpd.GetCurrentSongPos(), where); (isCommandsListEnabled ? mpd_send_seek_pos : mpd_run_seek_pos)(itsConnection, Mpd.GetCurrentSongPos(), where);
} }
void Connection::Shuffle() const void Connection::Shuffle() const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_shuffle : mpd_run_shuffle)(itsConnection); (isCommandsListEnabled ? mpd_send_shuffle : mpd_run_shuffle)(itsConnection);
} }
void Connection::ClearPlaylist() const void Connection::ClearPlaylist() const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_clear : mpd_run_clear)(itsConnection); (isCommandsListEnabled ? mpd_send_clear : mpd_run_clear)(itsConnection);
} }
void Connection::ClearPlaylist(const std::string &playlist) const void Connection::ClearPlaylist(const std::string &playlist) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_playlist_clear : mpd_run_playlist_clear)(itsConnection, playlist.c_str()); (isCommandsListEnabled ? mpd_send_playlist_clear : mpd_run_playlist_clear)(itsConnection, playlist.c_str());
} }
@@ -310,14 +303,14 @@ void Connection::AddToPlaylist(const std::string &path, const Song &s) const
void Connection::AddToPlaylist(const std::string &path, const std::string &file) const void Connection::AddToPlaylist(const std::string &path, const std::string &file) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_playlist_add : mpd_run_playlist_add)(itsConnection, path.c_str(), file.c_str()); (isCommandsListEnabled ? mpd_send_playlist_add : mpd_run_playlist_add)(itsConnection, path.c_str(), file.c_str());
} }
void Connection::Move(const std::string &path, int from, int to) const void Connection::Move(const std::string &path, int from, int to) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
mpd_send_playlist_move(itsConnection, path.c_str(), from, to); mpd_send_playlist_move(itsConnection, path.c_str(), from, to);
if (!isCommandsListEnabled) if (!isCommandsListEnabled)
@@ -326,36 +319,31 @@ void Connection::Move(const std::string &path, int from, int to) const
void Connection::Rename(const std::string &from, const std::string &to) const void Connection::Rename(const std::string &from, const std::string &to) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_rename : mpd_run_rename)(itsConnection, from.c_str(), to.c_str()); (isCommandsListEnabled ? mpd_send_rename : mpd_run_rename)(itsConnection, from.c_str(), to.c_str());
} }
void Connection::GetPlaylistChanges(unsigned version, SongList &v) const void Connection::GetPlaylistChanges(unsigned version, SongList &v) const
{ {
if (isConnected) if (!itsConnection)
{ return;
if (!version) if (!version)
v.reserve(GetPlaylistLength()); v.reserve(GetPlaylistLength());
mpd_send_queue_changes_meta(itsConnection, version); mpd_send_queue_changes_meta(itsConnection, version);
while (mpd_song *s = mpd_recv_song(itsConnection)) while (mpd_song *s = mpd_recv_song(itsConnection))
v.push_back(new Song(s, 1)); v.push_back(new Song(s, 1));
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
}
} }
Song Connection::GetSong(const std::string &path) const Song Connection::GetSong(const std::string &path) const
{ {
if (isConnected) if (!itsConnection)
{ return Song();
mpd_send_list_all_meta(itsConnection, path.c_str()); mpd_send_list_all_meta(itsConnection, path.c_str());
mpd_song *s = mpd_recv_song(itsConnection); mpd_song *s = mpd_recv_song(itsConnection);
Song result(s);
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
return result; return Song(s);
}
else
return Song();
} }
int Connection::GetCurrentSongPos() const int Connection::GetCurrentSongPos() const
@@ -365,69 +353,67 @@ int Connection::GetCurrentSongPos() const
Song Connection::GetCurrentSong() const Song Connection::GetCurrentSong() const
{ {
return Song(isConnected && isPlaying() ? mpd_run_current_song(itsConnection) : 0); return Song(itsConnection && isPlaying() ? mpd_run_current_song(itsConnection) : 0);
} }
void Connection::GetPlaylistContent(const std::string &path, SongList &v) const void Connection::GetPlaylistContent(const std::string &path, SongList &v) const
{ {
if (isConnected) if (!itsConnection)
{ return;
mpd_send_list_playlist_meta(itsConnection, path.c_str()); mpd_send_list_playlist_meta(itsConnection, path.c_str());
while (mpd_song *s = mpd_recv_song(itsConnection)) while (mpd_song *s = mpd_recv_song(itsConnection))
v.push_back(new Song(s)); v.push_back(new Song(s));
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
}
} }
void Connection::SetRepeat(bool mode) const void Connection::SetRepeat(bool mode) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_repeat : mpd_run_repeat)(itsConnection, mode); (isCommandsListEnabled ? mpd_send_repeat : mpd_run_repeat)(itsConnection, mode);
} }
void Connection::SetRandom(bool mode) const void Connection::SetRandom(bool mode) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_random : mpd_run_random)(itsConnection, mode); (isCommandsListEnabled ? mpd_send_random : mpd_run_random)(itsConnection, mode);
} }
void Connection::SetSingle(bool mode) const void Connection::SetSingle(bool mode) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_single : mpd_run_single)(itsConnection, mode); (isCommandsListEnabled ? mpd_send_single : mpd_run_single)(itsConnection, mode);
} }
void Connection::SetConsume(bool mode) const void Connection::SetConsume(bool mode) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_consume : mpd_run_consume)(itsConnection, mode); (isCommandsListEnabled ? mpd_send_consume : mpd_run_consume)(itsConnection, mode);
} }
void Connection::SetVolume(unsigned vol) void Connection::SetVolume(unsigned vol)
{ {
if (isConnected && vol <= 100) if (!itsConnection || vol > 100)
{ return;
if (mpd_run_set_volume(itsConnection, vol) && itsUpdater) if (mpd_run_set_volume(itsConnection, vol) && itsUpdater)
UpdateStatus(); UpdateStatus();
}
} }
void Connection::SetCrossfade(unsigned crossfade) const void Connection::SetCrossfade(unsigned crossfade) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_crossfade : mpd_run_crossfade)(itsConnection, crossfade); (isCommandsListEnabled ? mpd_send_crossfade : mpd_run_crossfade)(itsConnection, crossfade);
} }
int Connection::AddSong(const std::string &path) int Connection::AddSong(const std::string &path)
{ {
if (itsConnection)
return -1;
int id = -1; int id = -1;
if (isConnected)
{
if (GetPlaylistLength() < itsMaxPlaylistLength) if (GetPlaylistLength() < itsMaxPlaylistLength)
{ {
mpd_send_add_id(itsConnection, path.c_str()); mpd_send_add_id(itsConnection, path.c_str());
@@ -442,7 +428,6 @@ int Connection::AddSong(const std::string &path)
} }
else if (itsErrorHandler) else if (itsErrorHandler)
itsErrorHandler(this, MPD_SERVER_ERROR_PLAYLIST_MAX, Message::FullPlaylist, itsErrorHandlerUserdata); itsErrorHandler(this, MPD_SERVER_ERROR_PLAYLIST_MAX, Message::FullPlaylist, itsErrorHandlerUserdata);
}
return id; return id;
} }
@@ -453,7 +438,7 @@ int Connection::AddSong(const Song &s)
void Connection::Add(const std::string &path) const void Connection::Add(const std::string &path) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
mpd_send_add(itsConnection, path.c_str()); mpd_send_add(itsConnection, path.c_str());
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
@@ -461,7 +446,7 @@ void Connection::Add(const std::string &path) const
bool Connection::AddRandomSongs(size_t number) bool Connection::AddRandomSongs(size_t number)
{ {
if (!isConnected && !number) if (!itsConnection && !number)
return false; return false;
TagList files; TagList files;
@@ -495,7 +480,7 @@ bool Connection::AddRandomSongs(size_t number)
void Connection::Delete(unsigned pos) const void Connection::Delete(unsigned pos) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
mpd_send_delete(itsConnection, pos); mpd_send_delete(itsConnection, pos);
if (!isCommandsListEnabled) if (!isCommandsListEnabled)
@@ -504,7 +489,7 @@ void Connection::Delete(unsigned pos) const
void Connection::DeleteID(unsigned id) const void Connection::DeleteID(unsigned id) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
mpd_send_delete_id(itsConnection, id); mpd_send_delete_id(itsConnection, id);
if (!isCommandsListEnabled) if (!isCommandsListEnabled)
@@ -513,73 +498,65 @@ void Connection::DeleteID(unsigned id) const
void Connection::Delete(const std::string &playlist, unsigned pos) const void Connection::Delete(const std::string &playlist, unsigned pos) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_playlist_delete : mpd_run_playlist_delete)(itsConnection, playlist.c_str(), pos); (isCommandsListEnabled ? mpd_send_playlist_delete : mpd_run_playlist_delete)(itsConnection, playlist.c_str(), pos);
} }
void Connection::StartCommandsList() void Connection::StartCommandsList()
{ {
if (isConnected) if (!itsConnection)
{ return;
mpd_command_list_begin(itsConnection, 1); mpd_command_list_begin(itsConnection, 1);
isCommandsListEnabled = 1; isCommandsListEnabled = 1;
}
} }
bool Connection::CommitCommandsList() bool Connection::CommitCommandsList()
{ {
if (isConnected) if (!itsConnection)
{ return false;
mpd_command_list_end(itsConnection); mpd_command_list_end(itsConnection);
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
UpdateStatus(); UpdateStatus();
if (GetPlaylistLength() == itsMaxPlaylistLength && itsErrorHandler) if (GetPlaylistLength() == itsMaxPlaylistLength && itsErrorHandler)
itsErrorHandler(this, MPD_SERVER_ERROR_PLAYLIST_MAX, Message::FullPlaylist, itsErrorHandlerUserdata); itsErrorHandler(this, MPD_SERVER_ERROR_PLAYLIST_MAX, Message::FullPlaylist, itsErrorHandlerUserdata);
isCommandsListEnabled = 0; isCommandsListEnabled = 0;
}
return !CheckForErrors(); return !CheckForErrors();
} }
void Connection::DeletePlaylist(const std::string &name) const void Connection::DeletePlaylist(const std::string &name) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
(isCommandsListEnabled ? mpd_send_rm : mpd_run_rm)(itsConnection, name.c_str()); (isCommandsListEnabled ? mpd_send_rm : mpd_run_rm)(itsConnection, name.c_str());
} }
bool Connection::SavePlaylist(const std::string &name) const bool Connection::SavePlaylist(const std::string &name) const
{ {
if (isConnected) if (!itsConnection)
{ return false;
mpd_send_save(itsConnection, name.c_str()); mpd_send_save(itsConnection, name.c_str());
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
return !(mpd_connection_get_error(itsConnection) == MPD_ERROR_SERVER return !(mpd_connection_get_error(itsConnection) == MPD_ERROR_SERVER
&& mpd_connection_get_server_error(itsConnection) == MPD_SERVER_ERROR_EXIST); && mpd_connection_get_server_error(itsConnection) == MPD_SERVER_ERROR_EXIST);
}
else
return false;
} }
void Connection::GetPlaylists(TagList &v) const void Connection::GetPlaylists(TagList &v) const
{ {
if (isConnected) if (!itsConnection)
{ return;
ItemList list; ItemList list;
GetDirectory("/", list); GetDirectory("/", list);
for (ItemList::const_iterator it = list.begin(); it != list.end(); ++it) for (ItemList::const_iterator it = list.begin(); it != list.end(); ++it)
if (it->type == itPlaylist) if (it->type == itPlaylist)
v.push_back(it->name); v.push_back(it->name);
FreeItemList(list); FreeItemList(list);
}
} }
void Connection::GetList(TagList &v, mpd_tag_type type) const void Connection::GetList(TagList &v, mpd_tag_type type) const
{ {
if (isConnected) if (!itsConnection)
{ return;
mpd_search_db_tags(itsConnection, type); mpd_search_db_tags(itsConnection, type);
mpd_search_commit(itsConnection); mpd_search_commit(itsConnection);
while (mpd_pair *item = mpd_recv_pair_tag(itsConnection, type)) while (mpd_pair *item = mpd_recv_pair_tag(itsConnection, type))
@@ -589,13 +566,12 @@ void Connection::GetList(TagList &v, mpd_tag_type type) const
mpd_return_pair(itsConnection, item); mpd_return_pair(itsConnection, item);
} }
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
}
} }
void Connection::GetAlbums(const std::string &artist, TagList &v) const void Connection::GetAlbums(const std::string &artist, TagList &v) const
{ {
if (isConnected) if (!itsConnection)
{ return;
mpd_search_db_tags(itsConnection, MPD_TAG_ALBUM); mpd_search_db_tags(itsConnection, MPD_TAG_ALBUM);
if (!artist.empty()) if (!artist.empty())
mpd_search_add_tag_constraint(itsConnection, MPD_OPERATOR_DEFAULT, MPD_TAG_ARTIST, artist.c_str()); mpd_search_add_tag_constraint(itsConnection, MPD_OPERATOR_DEFAULT, MPD_TAG_ARTIST, artist.c_str());
@@ -607,18 +583,17 @@ void Connection::GetAlbums(const std::string &artist, TagList &v) const
mpd_return_pair(itsConnection, item); mpd_return_pair(itsConnection, item);
} }
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
}
} }
void Connection::StartSearch(bool exact_match) const void Connection::StartSearch(bool exact_match) const
{ {
if (isConnected) if (itsConnection)
mpd_search_db_songs(itsConnection, exact_match); mpd_search_db_songs(itsConnection, exact_match);
} }
void Connection::StartFieldSearch(mpd_tag_type item) void Connection::StartFieldSearch(mpd_tag_type item)
{ {
if (isConnected) if (itsConnection)
{ {
itsSearchedField = item; itsSearchedField = item;
mpd_search_db_tags(itsConnection, item); mpd_search_db_tags(itsConnection, item);
@@ -630,25 +605,24 @@ void Connection::AddSearch(mpd_tag_type item, const std::string &str) const
// mpd version < 0.14.* doesn't support empty search constraints // mpd version < 0.14.* doesn't support empty search constraints
if (Version() < 14 && str.empty()) if (Version() < 14 && str.empty())
return; return;
if (isConnected) if (itsConnection)
mpd_search_add_tag_constraint(itsConnection, MPD_OPERATOR_DEFAULT, item, str.c_str()); mpd_search_add_tag_constraint(itsConnection, MPD_OPERATOR_DEFAULT, item, str.c_str());
} }
void Connection::CommitSearch(SongList &v) const void Connection::CommitSearch(SongList &v) const
{ {
if (isConnected) if (!itsConnection)
{ return;
mpd_search_commit(itsConnection); mpd_search_commit(itsConnection);
while (mpd_song *s = mpd_recv_song(itsConnection)) while (mpd_song *s = mpd_recv_song(itsConnection))
v.push_back(new Song(s)); v.push_back(new Song(s));
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
}
} }
void Connection::CommitSearch(TagList &v) const void Connection::CommitSearch(TagList &v) const
{ {
if (isConnected) if (!itsConnection)
{ return;
mpd_search_commit(itsConnection); mpd_search_commit(itsConnection);
while (mpd_pair *tag = mpd_recv_pair_tag(itsConnection, itsSearchedField)) while (mpd_pair *tag = mpd_recv_pair_tag(itsConnection, itsSearchedField))
{ {
@@ -657,33 +631,32 @@ void Connection::CommitSearch(TagList &v) const
mpd_return_pair(itsConnection, tag); mpd_return_pair(itsConnection, tag);
} }
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
}
} }
void Connection::GetDirectory(const std::string &path, ItemList &v) const void Connection::GetDirectory(const std::string &path, ItemList &v) const
{ {
if (isConnected) if (!itsConnection)
{ return;
mpd_send_list_meta(itsConnection, path.c_str()); mpd_send_list_meta(itsConnection, path.c_str());
while (mpd_entity *item = mpd_recv_entity(itsConnection)) while (mpd_entity *item = mpd_recv_entity(itsConnection))
{ {
Item i; Item it;
switch (mpd_entity_get_type(item)) switch (mpd_entity_get_type(item))
{ {
case MPD_ENTITY_TYPE_DIRECTORY: case MPD_ENTITY_TYPE_DIRECTORY:
i.name = mpd_directory_get_path(mpd_entity_get_directory(item)); it.name = mpd_directory_get_path(mpd_entity_get_directory(item));
i.type = itDirectory; it.type = itDirectory;
goto WRITE; goto WRITE;
case MPD_ENTITY_TYPE_SONG: case MPD_ENTITY_TYPE_SONG:
i.song = new Song(mpd_song_dup(mpd_entity_get_song(item))); it.song = new Song(mpd_song_dup(mpd_entity_get_song(item)));
i.type = itSong; it.type = itSong;
goto WRITE; goto WRITE;
case MPD_ENTITY_TYPE_PLAYLIST: case MPD_ENTITY_TYPE_PLAYLIST:
i.name = mpd_playlist_get_path(mpd_entity_get_playlist(item)); it.name = mpd_playlist_get_path(mpd_entity_get_playlist(item));
i.type = itPlaylist; it.type = itPlaylist;
goto WRITE; goto WRITE;
WRITE: WRITE:
v.push_back(i); v.push_back(it);
break; break;
default: default:
break; break;
@@ -691,35 +664,32 @@ void Connection::GetDirectory(const std::string &path, ItemList &v) const
mpd_entity_free(item); mpd_entity_free(item);
} }
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
}
} }
void Connection::GetDirectoryRecursive(const std::string &path, SongList &v) const void Connection::GetDirectoryRecursive(const std::string &path, SongList &v) const
{ {
if (isConnected) if (!itsConnection)
{ return;
mpd_send_list_all_meta(itsConnection, path.c_str()); mpd_send_list_all_meta(itsConnection, path.c_str());
while (mpd_song *s = mpd_recv_song(itsConnection)) while (mpd_song *s = mpd_recv_song(itsConnection))
v.push_back(new Song(s)); v.push_back(new Song(s));
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
}
} }
void Connection::GetSongs(const std::string &path, SongList &v) const void Connection::GetSongs(const std::string &path, SongList &v) const
{ {
if (isConnected) if (!itsConnection)
{ return;
mpd_send_list_meta(itsConnection, path.c_str()); mpd_send_list_meta(itsConnection, path.c_str());
while (mpd_song *s = mpd_recv_song(itsConnection)) while (mpd_song *s = mpd_recv_song(itsConnection))
v.push_back(new Song(s)); v.push_back(new Song(s));
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
}
} }
void Connection::GetDirectories(const std::string &path, TagList &v) const void Connection::GetDirectories(const std::string &path, TagList &v) const
{ {
if (isConnected) if (!itsConnection)
{ return;
mpd_send_list_meta(itsConnection, path.c_str()); mpd_send_list_meta(itsConnection, path.c_str());
while (mpd_directory *dir = mpd_recv_directory(itsConnection)) while (mpd_directory *dir = mpd_recv_directory(itsConnection))
{ {
@@ -727,12 +697,11 @@ void Connection::GetDirectories(const std::string &path, TagList &v) const
mpd_directory_free(dir); mpd_directory_free(dir);
} }
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
}
} }
void Connection::GetOutputs(OutputList &v) const void Connection::GetOutputs(OutputList &v) const
{ {
if (!isConnected) if (!itsConnection)
return; return;
mpd_send_outputs(itsConnection); mpd_send_outputs(itsConnection);
while (mpd_output *output = mpd_recv_output(itsConnection)) while (mpd_output *output = mpd_recv_output(itsConnection))
@@ -745,14 +714,14 @@ void Connection::GetOutputs(OutputList &v) const
bool Connection::EnableOutput(int id) bool Connection::EnableOutput(int id)
{ {
if (!isConnected) if (!itsConnection)
return false; return false;
return mpd_run_enable_output(itsConnection, id); return mpd_run_enable_output(itsConnection, id);
} }
bool Connection::DisableOutput(int id) bool Connection::DisableOutput(int id)
{ {
if (!isConnected) if (!itsConnection)
return false; return false;
return mpd_run_disable_output(itsConnection, id); return mpd_run_disable_output(itsConnection, id);
} }

View File

@@ -192,7 +192,6 @@ namespace MPD
int CheckForErrors(); int CheckForErrors();
mpd_connection *itsConnection; mpd_connection *itsConnection;
bool isConnected;
bool isCommandsListEnabled; bool isCommandsListEnabled;
std::string itsErrorMessage; std::string itsErrorMessage;