put mpd connection related things into namespace

This commit is contained in:
Andrzej Rybczak
2008-12-09 10:16:38 +01:00
parent 1d27b8629d
commit 5c0af01cca
13 changed files with 297 additions and 278 deletions

View File

@@ -29,7 +29,9 @@
# include "tag_editor.h" # include "tag_editor.h"
#endif // HAVE_TAGLIB_H #endif // HAVE_TAGLIB_H
extern MPDConnection *Mpd; using namespace MPD;
extern Connection *Mpd;
extern ncmpcpp_config Config; extern ncmpcpp_config Config;

View File

@@ -24,9 +24,9 @@
#include "mpdpp.h" #include "mpdpp.h"
#include "ncmpcpp.h" #include "ncmpcpp.h"
void UpdateItemList(Menu<Item> *); void UpdateItemList(Menu<MPD::Item> *);
string DisplayItem(const Item &, void *, const Menu<Item> *); string DisplayItem(const MPD::Item &, void *, const Menu<MPD::Item> *);
void GetDirectory(string, string = "/"); void GetDirectory(string, string = "/");

View File

@@ -23,7 +23,7 @@
#include "help.h" #include "help.h"
#include "settings.h" #include "settings.h"
extern MPDConnection *Mpd; extern MPD::Connection *Mpd;
extern ncmpcpp_keys Key; extern ncmpcpp_keys Key;

View File

@@ -24,12 +24,14 @@
#include "helpers.h" #include "helpers.h"
#include "tag_editor.h" #include "tag_editor.h"
extern MPDConnection *Mpd; using namespace MPD;
extern Connection *Mpd;
extern ncmpcpp_config Config; extern ncmpcpp_config Config;
extern Menu<Song> *mPlaylist; extern Menu<Song> *mPlaylist;
extern Menu<Item> *mBrowser; extern Menu<MPD::Item> *mBrowser;
extern Window *wFooter; extern Window *wFooter;
extern NcmpcppScreen current_screen; extern NcmpcppScreen current_screen;

View File

@@ -38,7 +38,7 @@ class CaseInsensitiveSorting
public: public:
bool operator()(string, string); bool operator()(string, string);
bool operator()(Song *, Song *); bool operator()(Song *, Song *);
bool operator()(const Item &, const Item &); bool operator()(const MPD::Item &, const MPD::Item &);
}; };
bool SortSongsByTrack(Song *, Song *); bool SortSongsByTrack(Song *, Song *);

View File

@@ -20,14 +20,18 @@
#include "mpdpp.h" #include "mpdpp.h"
const string playlist_max_message = "playlist is at the max size"; using namespace MPD;
MPDConnection::MPDConnection() : isConnected(0), using std::string;
const char *playlist_max_message = "playlist is at the max size";
Connection::Connection() : isConnected(0),
itsErrorCode(0), itsErrorCode(0),
itsMaxPlaylistLength(-1), itsMaxPlaylistLength(-1),
MPD_HOST("localhost"), itsHost("localhost"),
MPD_PORT(6600), itsPort(6600),
MPD_TIMEOUT(15), itsTimeout(15),
itsUpdater(0), itsUpdater(0),
itsErrorHandler(0) itsErrorHandler(0)
{ {
@@ -38,7 +42,7 @@ MPDConnection::MPDConnection() : isConnected(0),
itsOldStatus = 0; itsOldStatus = 0;
} }
MPDConnection::~MPDConnection() Connection::~Connection()
{ {
if (itsConnection) if (itsConnection)
mpd_closeConnection(itsConnection); mpd_closeConnection(itsConnection);
@@ -53,15 +57,15 @@ MPDConnection::~MPDConnection()
ClearQueue(); ClearQueue();
} }
bool MPDConnection::Connect() bool Connection::Connect()
{ {
if (!isConnected && !itsConnection) if (!isConnected && !itsConnection)
{ {
itsConnection = mpd_newConnection(MPD_HOST.c_str(), MPD_PORT, MPD_TIMEOUT); itsConnection = mpd_newConnection(itsHost.c_str(), itsPort, itsTimeout);
isConnected = 1; isConnected = 1;
if (CheckForErrors()) if (CheckForErrors())
return false; return false;
if (!MPD_PASSWORD.empty()) if (!itsPassword.empty())
SendPassword(); SendPassword();
return !CheckForErrors(); return !CheckForErrors();
} }
@@ -69,12 +73,12 @@ bool MPDConnection::Connect()
return true; return true;
} }
bool MPDConnection::Connected() const bool Connection::Connected() const
{ {
return isConnected; return isConnected;
} }
void MPDConnection::Disconnect() void Connection::Disconnect()
{ {
if (itsConnection) if (itsConnection)
mpd_closeConnection(itsConnection); mpd_closeConnection(itsConnection);
@@ -96,37 +100,37 @@ void MPDConnection::Disconnect()
ClearQueue(); ClearQueue();
} }
void MPDConnection::SetHostname(const string &host) void Connection::SetHostname(const string &host)
{ {
size_t at = host.find("@"); size_t at = host.find("@");
if (at != string::npos) if (at != string::npos)
{ {
MPD_PASSWORD = host.substr(0, at); itsPassword = host.substr(0, at);
MPD_HOST = host.substr(at+1); itsHost = host.substr(at+1);
} }
else else
MPD_HOST = host; itsHost = host;
} }
void MPDConnection::SendPassword() const void Connection::SendPassword() const
{ {
mpd_sendPasswordCommand(itsConnection, MPD_PASSWORD.c_str()); mpd_sendPasswordCommand(itsConnection, itsPassword.c_str());
mpd_finishCommand(itsConnection); mpd_finishCommand(itsConnection);
} }
void MPDConnection::SetStatusUpdater(StatusUpdater updater, void *data) void Connection::SetStatusUpdater(StatusUpdater updater, void *data)
{ {
itsUpdater = updater; itsUpdater = updater;
itsStatusUpdaterUserdata = data; itsStatusUpdaterUserdata = data;
} }
void MPDConnection::SetErrorHandler(ErrorHandler handler, void *data) void Connection::SetErrorHandler(ErrorHandler handler, void *data)
{ {
itsErrorHandler = handler; itsErrorHandler = handler;
itsErrorHandlerUserdata = data; itsErrorHandlerUserdata = data;
} }
void MPDConnection::UpdateStatus() void Connection::UpdateStatus()
{ {
CheckForErrors(); CheckForErrors();
@@ -150,39 +154,37 @@ void MPDConnection::UpdateStatus()
if (itsCurrentStatus && itsCurrentStats && itsUpdater) if (itsCurrentStatus && itsCurrentStats && itsUpdater)
{ {
MPDStatusChanges changes;
if (itsOldStatus == NULL || itsOldStats == NULL) if (itsOldStatus == NULL || itsOldStats == NULL)
{ {
changes.Playlist = 1; itsChanges.Playlist = 1;
changes.SongID = 1; itsChanges.SongID = 1;
changes.Database = 1; itsChanges.Database = 1;
changes.DBUpdating = 1; itsChanges.DBUpdating = 1;
changes.Volume = 1; itsChanges.Volume = 1;
changes.ElapsedTime = 1; itsChanges.ElapsedTime = 1;
changes.Crossfade = 1; itsChanges.Crossfade = 1;
changes.Random = 1; itsChanges.Random = 1;
changes.Repeat = 1; itsChanges.Repeat = 1;
changes.PlayerState = 1; itsChanges.PlayerState = 1;
} }
else else
{ {
changes.Playlist = itsOldStatus->playlist != itsCurrentStatus->playlist; itsChanges.Playlist = itsOldStatus->playlist != itsCurrentStatus->playlist;
changes.SongID = itsOldStatus->songid != itsCurrentStatus->songid; itsChanges.SongID = itsOldStatus->songid != itsCurrentStatus->songid;
changes.Database = itsOldStats->dbUpdateTime != itsCurrentStats->dbUpdateTime; itsChanges.Database = itsOldStats->dbUpdateTime != itsCurrentStats->dbUpdateTime;
changes.DBUpdating = itsOldStatus->updatingDb != itsCurrentStatus->updatingDb; itsChanges.DBUpdating = itsOldStatus->updatingDb != itsCurrentStatus->updatingDb;
changes.Volume = itsOldStatus->volume != itsCurrentStatus->volume; itsChanges.Volume = itsOldStatus->volume != itsCurrentStatus->volume;
changes.ElapsedTime = itsOldStatus->elapsedTime != itsCurrentStatus->elapsedTime; itsChanges.ElapsedTime = itsOldStatus->elapsedTime != itsCurrentStatus->elapsedTime;
changes.Crossfade = itsOldStatus->crossfade != itsCurrentStatus->crossfade; itsChanges.Crossfade = itsOldStatus->crossfade != itsCurrentStatus->crossfade;
changes.Random = itsOldStatus->random != itsCurrentStatus->random; itsChanges.Random = itsOldStatus->random != itsCurrentStatus->random;
changes.Repeat = itsOldStatus->repeat != itsCurrentStatus->repeat; itsChanges.Repeat = itsOldStatus->repeat != itsCurrentStatus->repeat;
changes.PlayerState = itsOldStatus->state != itsCurrentStatus->state; itsChanges.PlayerState = itsOldStatus->state != itsCurrentStatus->state;
} }
itsUpdater(this, changes, itsErrorHandlerUserdata); itsUpdater(this, itsChanges, itsErrorHandlerUserdata);
} }
} }
void MPDConnection::UpdateDirectory(const string &path) const void Connection::UpdateDirectory(const string &path) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -191,7 +193,7 @@ void MPDConnection::UpdateDirectory(const string &path) const
} }
} }
void MPDConnection::Execute(const string &command) const void Connection::Execute(const string &command) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -200,13 +202,13 @@ void MPDConnection::Execute(const string &command) const
} }
} }
void MPDConnection::Play() const void Connection::Play() const
{ {
if (isConnected) if (isConnected)
PlayID(-1); PlayID(-1);
} }
void MPDConnection::Play(int pos) const void Connection::Play(int pos) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -215,7 +217,7 @@ void MPDConnection::Play(int pos) const
} }
} }
void MPDConnection::PlayID(int id) const void Connection::PlayID(int id) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -224,7 +226,7 @@ void MPDConnection::PlayID(int id) const
} }
} }
void MPDConnection::Pause() const void Connection::Pause() const
{ {
if (isConnected) if (isConnected)
{ {
@@ -233,7 +235,7 @@ void MPDConnection::Pause() const
} }
} }
void MPDConnection::Stop() const void Connection::Stop() const
{ {
if (isConnected) if (isConnected)
{ {
@@ -242,7 +244,7 @@ void MPDConnection::Stop() const
} }
} }
void MPDConnection::Next() const void Connection::Next() const
{ {
if (isConnected) if (isConnected)
{ {
@@ -251,7 +253,7 @@ void MPDConnection::Next() const
} }
} }
void MPDConnection::Prev() const void Connection::Prev() const
{ {
if (isConnected) if (isConnected)
{ {
@@ -260,7 +262,7 @@ void MPDConnection::Prev() const
} }
} }
void MPDConnection::Move(int from, int to) const void Connection::Move(int from, int to) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -269,7 +271,7 @@ void MPDConnection::Move(int from, int to) const
} }
} }
void MPDConnection::Seek(int where) const void Connection::Seek(int where) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -278,7 +280,7 @@ void MPDConnection::Seek(int where) const
} }
} }
void MPDConnection::Shuffle() const void Connection::Shuffle() const
{ {
if (isConnected) if (isConnected)
{ {
@@ -287,7 +289,7 @@ void MPDConnection::Shuffle() const
} }
} }
void MPDConnection::ClearPlaylist() const void Connection::ClearPlaylist() const
{ {
if (isConnected) if (isConnected)
{ {
@@ -296,13 +298,13 @@ void MPDConnection::ClearPlaylist() const
} }
} }
void MPDConnection::AddToPlaylist(const string &path, const Song &s) const void Connection::AddToPlaylist(const string &path, const Song &s) const
{ {
if (!s.Empty()) if (!s.Empty())
AddToPlaylist(path, s.GetFile()); AddToPlaylist(path, s.GetFile());
} }
void MPDConnection::AddToPlaylist(const string &path, const string &file) const void Connection::AddToPlaylist(const string &path, const string &file) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -311,7 +313,7 @@ void MPDConnection::AddToPlaylist(const string &path, const string &file) const
} }
} }
void MPDConnection::Move(const string &path, int from, int to) const void Connection::Move(const string &path, int from, int to) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -320,7 +322,7 @@ void MPDConnection::Move(const string &path, int from, int to) const
} }
} }
void MPDConnection::Rename(const string &from, const string &to) const void Connection::Rename(const string &from, const string &to) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -329,7 +331,7 @@ void MPDConnection::Rename(const string &from, const string &to) const
} }
} }
void MPDConnection::GetPlaylistChanges(long long id, SongList &v) const void Connection::GetPlaylistChanges(long long id, SongList &v) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -344,7 +346,7 @@ void MPDConnection::GetPlaylistChanges(long long id, SongList &v) const
{ {
if (item->type == MPD_INFO_ENTITY_TYPE_SONG) if (item->type == MPD_INFO_ENTITY_TYPE_SONG)
{ {
Song *s = new Song(item->info.song, 1); Song *s = new Song(item->info.song);
item->info.song = 0; item->info.song = 0;
v.push_back(s); v.push_back(s);
} }
@@ -354,7 +356,7 @@ void MPDConnection::GetPlaylistChanges(long long id, SongList &v) const
} }
} }
Song MPDConnection::GetSong(const string &path) const Song Connection::GetSong(const string &path) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -371,12 +373,12 @@ Song MPDConnection::GetSong(const string &path) const
return Song(); return Song();
} }
int MPDConnection::GetCurrentSongPos() const int Connection::GetCurrentSongPos() const
{ {
return isConnected && itsCurrentStatus ? (itsCurrentStatus->state == psPlay || itsCurrentStatus->state == psPause ? itsCurrentStatus->song : -1) : -1; return isConnected && itsCurrentStatus ? (itsCurrentStatus->state == psPlay || itsCurrentStatus->state == psPause ? itsCurrentStatus->song : -1) : -1;
} }
Song MPDConnection::GetCurrentSong() const Song Connection::GetCurrentSong() const
{ {
if (isConnected && (GetState() == psPlay || GetState() == psPause)) if (isConnected && (GetState() == psPlay || GetState() == psPause))
{ {
@@ -398,7 +400,7 @@ Song MPDConnection::GetCurrentSong() const
return Song(); return Song();
} }
void MPDConnection::GetPlaylistContent(const string &path, SongList &v) const void Connection::GetPlaylistContent(const string &path, SongList &v) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -418,7 +420,7 @@ void MPDConnection::GetPlaylistContent(const string &path, SongList &v) const
} }
} }
void MPDConnection::SetRepeat(bool mode) const void Connection::SetRepeat(bool mode) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -427,7 +429,7 @@ void MPDConnection::SetRepeat(bool mode) const
} }
} }
void MPDConnection::SetRandom(bool mode) const void Connection::SetRandom(bool mode) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -436,7 +438,7 @@ void MPDConnection::SetRandom(bool mode) const
} }
} }
void MPDConnection::SetVolume(int vol) const void Connection::SetVolume(int vol) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -445,7 +447,7 @@ void MPDConnection::SetVolume(int vol) const
} }
} }
void MPDConnection::SetCrossfade(int crossfade) const void Connection::SetCrossfade(int crossfade) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -454,7 +456,7 @@ void MPDConnection::SetCrossfade(int crossfade) const
} }
} }
int MPDConnection::AddSong(const string &path) int Connection::AddSong(const string &path)
{ {
int id = -1; int id = -1;
if (isConnected) if (isConnected)
@@ -472,12 +474,12 @@ int MPDConnection::AddSong(const string &path)
return id; return id;
} }
int MPDConnection::AddSong(const Song &s) int Connection::AddSong(const Song &s)
{ {
return !s.Empty() ? (s.IsFromDB() ? AddSong(s.GetFile()) : AddSong("file://" + s.GetFile())) : -1; return !s.Empty() ? (s.IsFromDB() ? AddSong(s.GetFile()) : AddSong("file://" + string(s.GetFile()))) : -1;
} }
void MPDConnection::QueueAddSong(const string &path) void Connection::QueueAddSong(const string &path)
{ {
if (isConnected && GetPlaylistLength() < itsMaxPlaylistLength) if (isConnected && GetPlaylistLength() < itsMaxPlaylistLength)
{ {
@@ -488,13 +490,13 @@ void MPDConnection::QueueAddSong(const string &path)
} }
} }
void MPDConnection::QueueAddSong(const Song &s) void Connection::QueueAddSong(const Song &s)
{ {
if (!s.Empty()) if (!s.Empty())
QueueAddSong(s.GetFile()); QueueAddSong(s.GetFile());
} }
void MPDConnection::QueueAddToPlaylist(const string &playlist, const string &path) void Connection::QueueAddToPlaylist(const string &playlist, const string &path)
{ {
if (isConnected) if (isConnected)
{ {
@@ -506,13 +508,13 @@ void MPDConnection::QueueAddToPlaylist(const string &playlist, const string &pat
} }
} }
void MPDConnection::QueueAddToPlaylist(const string &playlist, const Song &s) void Connection::QueueAddToPlaylist(const string &playlist, const Song &s)
{ {
if (!s.Empty()) if (!s.Empty())
QueueAddToPlaylist(playlist, s.GetFile()); QueueAddToPlaylist(playlist, s.GetFile());
} }
void MPDConnection::QueueDeleteSong(int id) void Connection::QueueDeleteSong(int id)
{ {
if (isConnected) if (isConnected)
{ {
@@ -523,7 +525,7 @@ void MPDConnection::QueueDeleteSong(int id)
} }
} }
void MPDConnection::QueueDeleteSongId(int id) void Connection::QueueDeleteSongId(int id)
{ {
if (isConnected) if (isConnected)
{ {
@@ -534,7 +536,7 @@ void MPDConnection::QueueDeleteSongId(int id)
} }
} }
void MPDConnection::QueueMove(int from, int to) void Connection::QueueMove(int from, int to)
{ {
if (isConnected) if (isConnected)
{ {
@@ -546,7 +548,7 @@ void MPDConnection::QueueMove(int from, int to)
} }
} }
void MPDConnection::QueueMove(const string &playlist, int from, int to) void Connection::QueueMove(const string &playlist, int from, int to)
{ {
if (isConnected) if (isConnected)
{ {
@@ -559,7 +561,7 @@ void MPDConnection::QueueMove(const string &playlist, int from, int to)
} }
} }
void MPDConnection::QueueDeleteFromPlaylist(const string &playlist, int pos) void Connection::QueueDeleteFromPlaylist(const string &playlist, int pos)
{ {
if (isConnected) if (isConnected)
{ {
@@ -571,7 +573,7 @@ void MPDConnection::QueueDeleteFromPlaylist(const string &playlist, int pos)
} }
} }
bool MPDConnection::CommitQueue() bool Connection::CommitQueue()
{ {
bool retval = false; bool retval = false;
if (isConnected) if (isConnected)
@@ -615,7 +617,7 @@ bool MPDConnection::CommitQueue()
return retval; return retval;
} }
void MPDConnection::DeletePlaylist(const string &name) const void Connection::DeletePlaylist(const string &name) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -624,7 +626,7 @@ void MPDConnection::DeletePlaylist(const string &name) const
} }
} }
bool MPDConnection::SavePlaylist(const string &name) const bool Connection::SavePlaylist(const string &name) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -636,7 +638,7 @@ bool MPDConnection::SavePlaylist(const string &name) const
return false; return false;
} }
void MPDConnection::GetPlaylists(TagList &v) const void Connection::GetPlaylists(TagList &v) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -651,7 +653,7 @@ void MPDConnection::GetPlaylists(TagList &v) const
} }
} }
void MPDConnection::GetList(TagList &v, mpd_TagItems type) const void Connection::GetList(TagList &v, mpd_TagItems type) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -666,7 +668,7 @@ void MPDConnection::GetList(TagList &v, mpd_TagItems type) const
} }
} }
void MPDConnection::GetArtists(TagList &v) const void Connection::GetArtists(TagList &v) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -681,7 +683,7 @@ void MPDConnection::GetArtists(TagList &v) const
} }
} }
void MPDConnection::GetAlbums(string artist, TagList &v) const void Connection::GetAlbums(string artist, TagList &v) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -696,13 +698,13 @@ void MPDConnection::GetAlbums(string artist, TagList &v) const
} }
} }
void MPDConnection::StartSearch(bool exact_match) const void Connection::StartSearch(bool exact_match) const
{ {
if (isConnected) if (isConnected)
mpd_startSearch(itsConnection, exact_match); mpd_startSearch(itsConnection, exact_match);
} }
void MPDConnection::StartFieldSearch(mpd_TagItems item) void Connection::StartFieldSearch(mpd_TagItems item)
{ {
if (isConnected) if (isConnected)
{ {
@@ -711,13 +713,13 @@ void MPDConnection::StartFieldSearch(mpd_TagItems item)
} }
} }
void MPDConnection::AddSearch(mpd_TagItems item, const string &str) const void Connection::AddSearch(mpd_TagItems item, const string &str) const
{ {
if (isConnected) if (isConnected)
mpd_addConstraintSearch(itsConnection, item, str.c_str()); mpd_addConstraintSearch(itsConnection, item, str.c_str());
} }
void MPDConnection::CommitSearch(SongList &v) const void Connection::CommitSearch(SongList &v) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -737,7 +739,7 @@ void MPDConnection::CommitSearch(SongList &v) const
} }
} }
void MPDConnection::CommitSearch(TagList &v) const void Connection::CommitSearch(TagList &v) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -754,7 +756,7 @@ void MPDConnection::CommitSearch(TagList &v) const
} }
} }
void MPDConnection::GetDirectory(const string &path, ItemList &v) const void Connection::GetDirectory(const string &path, ItemList &v) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -786,7 +788,7 @@ void MPDConnection::GetDirectory(const string &path, ItemList &v) const
} }
} }
void MPDConnection::GetDirectoryRecursive(const string &path, SongList &v) const void Connection::GetDirectoryRecursive(const string &path, SongList &v) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -806,7 +808,7 @@ void MPDConnection::GetDirectoryRecursive(const string &path, SongList &v) const
} }
} }
void MPDConnection::GetSongs(const string &path, SongList &v) const void Connection::GetSongs(const string &path, SongList &v) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -826,7 +828,7 @@ void MPDConnection::GetSongs(const string &path, SongList &v) const
} }
} }
void MPDConnection::GetDirectories(const string &path, TagList &v) const void Connection::GetDirectories(const string &path, TagList &v) const
{ {
if (isConnected) if (isConnected)
{ {
@@ -842,7 +844,7 @@ void MPDConnection::GetDirectories(const string &path, TagList &v) const
} }
} }
int MPDConnection::CheckForErrors() int Connection::CheckForErrors()
{ {
itsErrorCode = 0; itsErrorCode = 0;
if (itsConnection->error) if (itsConnection->error)
@@ -871,21 +873,21 @@ int MPDConnection::CheckForErrors()
return itsErrorCode; return itsErrorCode;
} }
void MPDConnection::ClearQueue() void Connection::ClearQueue()
{ {
for (std::vector<QueueCommand *>::iterator it = itsQueue.begin(); it != itsQueue.end(); it++) for (std::vector<QueueCommand *>::iterator it = itsQueue.begin(); it != itsQueue.end(); it++)
delete *it; delete *it;
itsQueue.clear(); itsQueue.clear();
} }
void FreeSongList(SongList &l) void MPD::FreeSongList(SongList &l)
{ {
for (SongList::iterator i = l.begin(); i != l.end(); i++) for (SongList::iterator i = l.begin(); i != l.end(); i++)
delete *i; delete *i;
l.clear(); l.clear();
} }
void FreeItemList(ItemList &l) void MPD::FreeItemList(ItemList &l)
{ {
for (ItemList::iterator i = l.begin(); i != l.end(); i++) for (ItemList::iterator i = l.begin(); i != l.end(); i++)
delete i->song; delete i->song;

View File

@@ -18,190 +18,195 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef HAVE_MPDPP_H #ifndef _MPDPP_H
#define HAVE_MPDPP_H #define _MPDPP_H
#include <vector>
#include "libmpdclient.h" #include "libmpdclient.h"
#include "ncmpcpp.h"
#include "song.h" #include "song.h"
enum QueueCommandType { qctAdd, qctAddToPlaylist, qctDelete, qctDeleteID, qctMove, qctPlaylistMove, qctDeleteFromPlaylist }; namespace MPD
enum ItemType { itDirectory, itSong, itPlaylist };
enum PlayerState { psUnknown, psStop, psPlay, psPause };
struct MPDStatusChanges
{ {
MPDStatusChanges() : Playlist(0), SongID(0), Database(0), DBUpdating(0), Volume(0), ElapsedTime(0), Crossfade(0), Random(0), Repeat(0), PlayerState(0) { } enum QueueCommandType { qctAdd, qctAddToPlaylist, qctDelete, qctDeleteID, qctMove, qctPlaylistMove, qctDeleteFromPlaylist };
bool Playlist; enum ItemType { itDirectory, itSong, itPlaylist };
bool SongID; enum PlayerState { psUnknown, psStop, psPlay, psPause };
bool Database;
bool DBUpdating;
bool Volume;
bool ElapsedTime;
bool Crossfade;
bool Random;
bool Repeat;
bool PlayerState;
};
struct QueueCommand struct Item
{ {
QueueCommand() : id(0), id2(0) { } Item() : song(0) { }
QueueCommandType type; Song *song;
string playlist_path; ItemType type;
string item_path; std::string name;
int id; };
int id2;
};
struct Item struct StatusChanges
{ {
Item() : song(0) { } bool Playlist:1;
Song *song; bool SongID:1;
ItemType type; bool Database:1;
string name; bool DBUpdating:1;
}; bool Volume:1;
bool ElapsedTime:1;
bool Crossfade:1;
bool Random:1;
bool Repeat:1;
bool PlayerState:1;
};
typedef std::vector<Item> ItemList; typedef std::vector<Item> ItemList;
typedef std::vector<Song *> SongList; typedef std::vector<Song *> SongList;
typedef std::vector<string> TagList; typedef std::vector<std::string> TagList;
void FreeSongList(SongList &); void FreeSongList(SongList &);
void FreeItemList(ItemList &); void FreeItemList(ItemList &);
class MPDConnection class Connection
{ {
typedef void (*StatusUpdater) (MPDConnection *, MPDStatusChanges, void *); struct QueueCommand
typedef void (*ErrorHandler) (MPDConnection *, int, string, void *); {
QueueCommand() : id(0), id2(0) { }
QueueCommandType type;
std::string playlist_path;
std::string item_path;
int id;
int id2;
};
public: typedef void (*StatusUpdater) (Connection *, StatusChanges, void *);
MPDConnection(); typedef void (*ErrorHandler) (Connection *, int, const char *, void *);
~MPDConnection();
bool Connect(); public:
bool Connected() const; Connection();
void Disconnect(); ~Connection();
const string & GetHostname() { return MPD_HOST; } bool Connect();
int GetPort() { return MPD_PORT; } bool Connected() const;
void Disconnect();
void SetHostname(const string &); const std::string & GetHostname() { return itsHost; }
void SetPort(int port) { MPD_PORT = port; } int GetPort() { return itsPort; }
void SetTimeout(int timeout) { MPD_TIMEOUT = timeout; }
void SetPassword(const string &password) { MPD_PASSWORD = password; }
void SendPassword() const;
void SetStatusUpdater(StatusUpdater, void *); void SetHostname(const std::string &);
void SetErrorHandler(ErrorHandler, void *); void SetPort(int port) { itsPort = port; }
void UpdateStatus(); void SetTimeout(int timeout) { itsTimeout = timeout; }
void UpdateDirectory(const string &) const; void SetPassword(const std::string &password) { itsPassword = password; }
void SendPassword() const;
void Execute(const string &) const; void SetStatusUpdater(StatusUpdater, void *);
void SetErrorHandler(ErrorHandler, void *);
void UpdateStatus();
void UpdateDirectory(const std::string &) const;
void Play() const; void Execute(const std::string &) const;
void Play(int) const;
void PlayID(int) const;
void Pause() const;
void Stop() const;
void Next() const;
void Prev() const;
void Move(int, int) const;
void Seek(int) const;
void Shuffle() const;
void ClearPlaylist() const;
PlayerState GetState() const { return isConnected && itsCurrentStatus ? (PlayerState)itsCurrentStatus->state : psUnknown; } void Play() const;
bool GetRepeat() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->repeat : 0; } void Play(int) const;
bool GetRandom() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->random : 0; } void PlayID(int) const;
bool GetDBIsUpdating() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->updatingDb : 0; } void Pause() const;
int GetVolume() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->volume : -1; } void Stop() const;
int GetCrossfade() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->crossfade : -1; } void Next() const;
long long GetPlaylistID() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlist : -1; } void Prev() const;
long long GetOldPlaylistID() const { return isConnected && itsOldStatus ? itsOldStatus->playlist : -1; } void Move(int, int) const;
int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; } void Seek(int) const;
void Shuffle() const;
void ClearPlaylist() const;
unsigned int GetMaxPlaylistLength() const { return itsMaxPlaylistLength; } PlayerState GetState() const { return isConnected && itsCurrentStatus ? (PlayerState)itsCurrentStatus->state : psUnknown; }
int GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : 0; } bool GetRepeat() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->repeat : 0; }
void GetPlaylistChanges(long long, SongList &) const; bool GetRandom() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->random : 0; }
bool GetDBIsUpdating() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->updatingDb : 0; }
int GetVolume() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->volume : -1; }
int GetCrossfade() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->crossfade : -1; }
long long GetPlaylistID() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlist : -1; }
long long GetOldPlaylistID() const { return isConnected && itsOldStatus ? itsOldStatus->playlist : -1; }
int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; }
const string & GetErrorMessage() const { return itsErrorMessage; } unsigned int GetMaxPlaylistLength() const { return itsMaxPlaylistLength; }
int GetErrorCode() const { return itsErrorCode; } int GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : 0; }
void GetPlaylistChanges(long long, SongList &) const;
Song GetCurrentSong() const; const std::string & GetErrorMessage() const { return itsErrorMessage; }
int GetCurrentSongPos() const; int GetErrorCode() const { return itsErrorCode; }
Song GetSong(const string &) const;
void GetPlaylistContent(const string &, SongList &) const;
void SetRepeat(bool) const; Song GetCurrentSong() const;
void SetRandom(bool) const; int GetCurrentSongPos() const;
void SetVolume(int) const; Song GetSong(const std::string &) const;
void SetCrossfade(int) const; void GetPlaylistContent(const std::string &, SongList &) const;
int AddSong(const string &); // returns id of added song void SetRepeat(bool) const;
int AddSong(const Song &); // returns id of added song void SetRandom(bool) const;
void QueueAddSong(const string &); void SetVolume(int) const;
void QueueAddSong(const Song &); void SetCrossfade(int) const;
void QueueAddToPlaylist(const string &, const string &);
void QueueAddToPlaylist(const string &, const Song &);
void QueueDeleteSong(int);
void QueueDeleteSongId(int);
void QueueMove(int, int);
void QueueMove(const string &, int, int);
void QueueDeleteFromPlaylist(const string &, int);
bool CommitQueue();
void DeletePlaylist(const string &) const; int AddSong(const std::string &); // returns id of added song
bool SavePlaylist(const string &) const; int AddSong(const Song &); // returns id of added song
void ClearPlaylist(const string &) const; void QueueAddSong(const std::string &);
void AddToPlaylist(const string &, const Song &) const; void QueueAddSong(const Song &);
void AddToPlaylist(const string &, const string &) const; void QueueAddToPlaylist(const std::string &, const std::string &);
void Move(const string &, int, int) const; void QueueAddToPlaylist(const std::string &, const Song &);
void Rename(const string &, const string &) const; void QueueDeleteSong(int);
void QueueDeleteSongId(int);
void QueueMove(int, int);
void QueueMove(const std::string &, int, int);
void QueueDeleteFromPlaylist(const std::string &, int);
bool CommitQueue();
void StartSearch(bool) const; void DeletePlaylist(const std::string &) const;
void StartFieldSearch(mpd_TagItems); bool SavePlaylist(const std::string &) const;
void AddSearch(mpd_TagItems, const string &) const; void ClearPlaylist(const std::string &) const;
void CommitSearch(SongList &) const; void AddToPlaylist(const std::string &, const Song &) const;
void CommitSearch(TagList &) const; void AddToPlaylist(const std::string &, const std::string &) const;
void Move(const std::string &, int, int) const;
void Rename(const std::string &, const std::string &) const;
void GetPlaylists(TagList &) const; void StartSearch(bool) const;
void GetList(TagList &, mpd_TagItems) const; void StartFieldSearch(mpd_TagItems);
void GetArtists(TagList &) const; void AddSearch(mpd_TagItems, const std::string &) const;
void GetAlbums(string, TagList &) const; void CommitSearch(SongList &) const;
void GetDirectory(const string &, ItemList &) const; void CommitSearch(TagList &) const;
void GetDirectoryRecursive(const string &, SongList &) const;
void GetSongs(const string &, SongList &) const;
void GetDirectories(const string &, TagList &) const;
private: void GetPlaylists(TagList &) const;
void ClearQueue(); void GetList(TagList &, mpd_TagItems) const;
int CheckForErrors(); void GetArtists(TagList &) const;
void GetAlbums(std::string, TagList &) const;
void GetDirectory(const std::string &, ItemList &) const;
void GetDirectoryRecursive(const std::string &, SongList &) const;
void GetSongs(const std::string &, SongList &) const;
void GetDirectories(const std::string &, TagList &) const;
mpd_Connection *itsConnection; private:
bool isConnected; void ClearQueue();
int CheckForErrors();
string itsErrorMessage; mpd_Connection *itsConnection;
int itsErrorCode; bool isConnected;
unsigned int itsMaxPlaylistLength;
string MPD_HOST; std::string itsErrorMessage;
int MPD_PORT; int itsErrorCode;
int MPD_TIMEOUT; unsigned int itsMaxPlaylistLength;
string MPD_PASSWORD;
mpd_Stats *itsOldStats; std::string itsHost;
mpd_Stats *itsCurrentStats; int itsPort;
mpd_Status *itsCurrentStatus; int itsTimeout;
mpd_Status *itsOldStatus; std::string itsPassword;
StatusUpdater itsUpdater; mpd_Stats *itsOldStats;
void *itsStatusUpdaterUserdata; mpd_Stats *itsCurrentStats;
ErrorHandler itsErrorHandler; mpd_Status *itsCurrentStatus;
void *itsErrorHandlerUserdata; mpd_Status *itsOldStatus;
mpd_TagItems itsSearchedField; StatusChanges itsChanges;
std::vector<QueueCommand *> itsQueue;
}; StatusUpdater itsUpdater;
void *itsStatusUpdaterUserdata;
ErrorHandler itsErrorHandler;
void *itsErrorHandlerUserdata;
mpd_TagItems itsSearchedField;
std::vector<QueueCommand *> itsQueue;
};
}
#endif #endif

View File

@@ -80,6 +80,8 @@
vFoundPositions.clear(); \ vFoundPositions.clear(); \
} while (0) } while (0)
using namespace MPD;
ncmpcpp_config Config; ncmpcpp_config Config;
ncmpcpp_keys Key; ncmpcpp_keys Key;
@@ -117,7 +119,7 @@ Scrollpad *sInfo;
Window *wHeader; Window *wHeader;
Window *wFooter; Window *wFooter;
MPDConnection *Mpd; Connection *Mpd;
int now_playing = -1; int now_playing = -1;
int lock_statusbar_delay = -1; int lock_statusbar_delay = -1;
@@ -174,7 +176,7 @@ int main(int argc, char *argv[])
ReadKeys(Key); ReadKeys(Key);
DefineEmptyTags(); DefineEmptyTags();
Mpd = new MPDConnection; Mpd = new Connection;
if (getenv("MPD_HOST")) if (getenv("MPD_HOST"))
Mpd->SetHostname(getenv("MPD_HOST")); Mpd->SetHostname(getenv("MPD_HOST"));
@@ -932,7 +934,7 @@ int main(int argc, char *argv[])
} }
header_update_status = 1; header_update_status = 1;
PlayerState mpd_state = Mpd->GetState(); PlayerState mpd_state = Mpd->GetState();
MPDStatusChanges changes; StatusChanges changes;
if (mpd_state == psPlay || mpd_state == psPause) if (mpd_state == psPlay || mpd_state == psPause)
changes.ElapsedTime = 1; // restore status changes.ElapsedTime = 1; // restore status
else else

View File

@@ -21,7 +21,9 @@
#include "helpers.h" #include "helpers.h"
#include "search_engine.h" #include "search_engine.h"
extern MPDConnection *Mpd; using namespace MPD;
extern Connection *Mpd;
extern Menu<Song> *mPlaylist; extern Menu<Song> *mPlaylist;
extern Menu< std::pair<string, Song> > *mSearcher; extern Menu< std::pair<string, Song> > *mSearcher;

View File

@@ -26,7 +26,9 @@
#define UPDATE_WINDOW_TITLE WindowTitle(DisplaySong(Mpd->GetCurrentSong(), &Config.song_window_title_format)) #define UPDATE_WINDOW_TITLE WindowTitle(DisplaySong(Mpd->GetCurrentSong(), &Config.song_window_title_format))
extern MPDConnection *Mpd; using namespace MPD;
extern Connection *Mpd;
extern ncmpcpp_config Config; extern ncmpcpp_config Config;
extern Menu<Song> *mPlaylist; extern Menu<Song> *mPlaylist;
@@ -109,7 +111,7 @@ void TraceMpdStatus()
else else
block_progressbar_update = !allow_statusbar_unlock; block_progressbar_update = !allow_statusbar_unlock;
MPDStatusChanges changes; StatusChanges changes;
switch (Mpd->GetState()) switch (Mpd->GetState())
{ {
case psStop: case psStop:
@@ -126,7 +128,7 @@ void TraceMpdStatus()
//wHeader->WriteXY(0,1, IntoStr(now_playing), 1); //wHeader->WriteXY(0,1, IntoStr(now_playing), 1);
} }
void NcmpcppErrorCallback(MPDConnection *Mpd, int errorid, string msg, void *) void NcmpcppErrorCallback(Connection *Mpd, int errorid, const char *msg, void *)
{ {
if (errorid == MPD_ACK_ERROR_PERMISSION) if (errorid == MPD_ACK_ERROR_PERMISSION)
{ {
@@ -139,10 +141,10 @@ void NcmpcppErrorCallback(MPDConnection *Mpd, int errorid, string msg, void *)
wFooter->SetGetStringHelper(TraceMpdStatus); wFooter->SetGetStringHelper(TraceMpdStatus);
} }
else else
ShowMessage("%s", msg.c_str()); ShowMessage("%s", msg);
} }
void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *) void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
{ {
int sx, sy; int sx, sy;
wFooter->DisableBB(); wFooter->DisableBB();

View File

@@ -25,8 +25,8 @@
#include "ncmpcpp.h" #include "ncmpcpp.h"
void TraceMpdStatus(); void TraceMpdStatus();
void NcmpcppStatusChanged(MPDConnection *, MPDStatusChanges, void *); void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges, void *);
void NcmpcppErrorCallback(MPDConnection *, int, string, void *); void NcmpcppErrorCallback(MPD::Connection *, int, const char *, void *);
#endif #endif

View File

@@ -31,10 +31,12 @@
#include "helpers.h" #include "helpers.h"
#include "status_checker.h" #include "status_checker.h"
using namespace MPD;
extern ncmpcpp_config Config; extern ncmpcpp_config Config;
extern ncmpcpp_keys Key; extern ncmpcpp_keys Key;
extern MPDConnection *Mpd; extern Connection *Mpd;
extern Menu<Song> *mPlaylist; extern Menu<Song> *mPlaylist;
extern Menu<string> *mTagEditor; extern Menu<string> *mTagEditor;

View File

@@ -35,7 +35,7 @@
typedef void (Song::*SongSetFunction)(const string &); typedef void (Song::*SongSetFunction)(const string &);
string FindSharedDir(Menu<Song> *); string FindSharedDir(Menu<Song> *);
string FindSharedDir(const SongList &); string FindSharedDir(const MPD::SongList &);
string DisplayTag(const Song &, void *, const Menu<Song> *); string DisplayTag(const Song &, void *, const Menu<Song> *);
SongSetFunction IntoSetFunction(mpd_TagItems); SongSetFunction IntoSetFunction(mpd_TagItems);
@@ -44,7 +44,7 @@ void ReadTagsFromFile(mpd_Song *);
bool GetSongTags(Song &); bool GetSongTags(Song &);
bool WriteTags(Song &); bool WriteTags(Song &);
void __deal_with_filenames(SongList &); void __deal_with_filenames(MPD::SongList &);
#endif #endif