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"
#endif // HAVE_TAGLIB_H
extern MPDConnection *Mpd;
using namespace MPD;
extern Connection *Mpd;
extern ncmpcpp_config Config;

View File

@@ -24,9 +24,9 @@
#include "mpdpp.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 = "/");

View File

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

View File

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

View File

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

View File

@@ -20,14 +20,18 @@
#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),
itsMaxPlaylistLength(-1),
MPD_HOST("localhost"),
MPD_PORT(6600),
MPD_TIMEOUT(15),
itsHost("localhost"),
itsPort(6600),
itsTimeout(15),
itsUpdater(0),
itsErrorHandler(0)
{
@@ -38,7 +42,7 @@ MPDConnection::MPDConnection() : isConnected(0),
itsOldStatus = 0;
}
MPDConnection::~MPDConnection()
Connection::~Connection()
{
if (itsConnection)
mpd_closeConnection(itsConnection);
@@ -53,15 +57,15 @@ MPDConnection::~MPDConnection()
ClearQueue();
}
bool MPDConnection::Connect()
bool Connection::Connect()
{
if (!isConnected && !itsConnection)
{
itsConnection = mpd_newConnection(MPD_HOST.c_str(), MPD_PORT, MPD_TIMEOUT);
itsConnection = mpd_newConnection(itsHost.c_str(), itsPort, itsTimeout);
isConnected = 1;
if (CheckForErrors())
return false;
if (!MPD_PASSWORD.empty())
if (!itsPassword.empty())
SendPassword();
return !CheckForErrors();
}
@@ -69,12 +73,12 @@ bool MPDConnection::Connect()
return true;
}
bool MPDConnection::Connected() const
bool Connection::Connected() const
{
return isConnected;
}
void MPDConnection::Disconnect()
void Connection::Disconnect()
{
if (itsConnection)
mpd_closeConnection(itsConnection);
@@ -96,37 +100,37 @@ void MPDConnection::Disconnect()
ClearQueue();
}
void MPDConnection::SetHostname(const string &host)
void Connection::SetHostname(const string &host)
{
size_t at = host.find("@");
if (at != string::npos)
{
MPD_PASSWORD = host.substr(0, at);
MPD_HOST = host.substr(at+1);
itsPassword = host.substr(0, at);
itsHost = host.substr(at+1);
}
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);
}
void MPDConnection::SetStatusUpdater(StatusUpdater updater, void *data)
void Connection::SetStatusUpdater(StatusUpdater updater, void *data)
{
itsUpdater = updater;
itsStatusUpdaterUserdata = data;
}
void MPDConnection::SetErrorHandler(ErrorHandler handler, void *data)
void Connection::SetErrorHandler(ErrorHandler handler, void *data)
{
itsErrorHandler = handler;
itsErrorHandlerUserdata = data;
}
void MPDConnection::UpdateStatus()
void Connection::UpdateStatus()
{
CheckForErrors();
@@ -150,39 +154,37 @@ void MPDConnection::UpdateStatus()
if (itsCurrentStatus && itsCurrentStats && itsUpdater)
{
MPDStatusChanges changes;
if (itsOldStatus == NULL || itsOldStats == NULL)
{
changes.Playlist = 1;
changes.SongID = 1;
changes.Database = 1;
changes.DBUpdating = 1;
changes.Volume = 1;
changes.ElapsedTime = 1;
changes.Crossfade = 1;
changes.Random = 1;
changes.Repeat = 1;
changes.PlayerState = 1;
itsChanges.Playlist = 1;
itsChanges.SongID = 1;
itsChanges.Database = 1;
itsChanges.DBUpdating = 1;
itsChanges.Volume = 1;
itsChanges.ElapsedTime = 1;
itsChanges.Crossfade = 1;
itsChanges.Random = 1;
itsChanges.Repeat = 1;
itsChanges.PlayerState = 1;
}
else
{
changes.Playlist = itsOldStatus->playlist != itsCurrentStatus->playlist;
changes.SongID = itsOldStatus->songid != itsCurrentStatus->songid;
changes.Database = itsOldStats->dbUpdateTime != itsCurrentStats->dbUpdateTime;
changes.DBUpdating = itsOldStatus->updatingDb != itsCurrentStatus->updatingDb;
changes.Volume = itsOldStatus->volume != itsCurrentStatus->volume;
changes.ElapsedTime = itsOldStatus->elapsedTime != itsCurrentStatus->elapsedTime;
changes.Crossfade = itsOldStatus->crossfade != itsCurrentStatus->crossfade;
changes.Random = itsOldStatus->random != itsCurrentStatus->random;
changes.Repeat = itsOldStatus->repeat != itsCurrentStatus->repeat;
changes.PlayerState = itsOldStatus->state != itsCurrentStatus->state;
itsChanges.Playlist = itsOldStatus->playlist != itsCurrentStatus->playlist;
itsChanges.SongID = itsOldStatus->songid != itsCurrentStatus->songid;
itsChanges.Database = itsOldStats->dbUpdateTime != itsCurrentStats->dbUpdateTime;
itsChanges.DBUpdating = itsOldStatus->updatingDb != itsCurrentStatus->updatingDb;
itsChanges.Volume = itsOldStatus->volume != itsCurrentStatus->volume;
itsChanges.ElapsedTime = itsOldStatus->elapsedTime != itsCurrentStatus->elapsedTime;
itsChanges.Crossfade = itsOldStatus->crossfade != itsCurrentStatus->crossfade;
itsChanges.Random = itsOldStatus->random != itsCurrentStatus->random;
itsChanges.Repeat = itsOldStatus->repeat != itsCurrentStatus->repeat;
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)
{
@@ -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)
{
@@ -200,13 +202,13 @@ void MPDConnection::Execute(const string &command) const
}
}
void MPDConnection::Play() const
void Connection::Play() const
{
if (isConnected)
PlayID(-1);
}
void MPDConnection::Play(int pos) const
void Connection::Play(int pos) const
{
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)
{
@@ -224,7 +226,7 @@ void MPDConnection::PlayID(int id) const
}
}
void MPDConnection::Pause() const
void Connection::Pause() const
{
if (isConnected)
{
@@ -233,7 +235,7 @@ void MPDConnection::Pause() const
}
}
void MPDConnection::Stop() const
void Connection::Stop() const
{
if (isConnected)
{
@@ -242,7 +244,7 @@ void MPDConnection::Stop() const
}
}
void MPDConnection::Next() const
void Connection::Next() const
{
if (isConnected)
{
@@ -251,7 +253,7 @@ void MPDConnection::Next() const
}
}
void MPDConnection::Prev() const
void Connection::Prev() const
{
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)
{
@@ -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)
{
@@ -278,7 +280,7 @@ void MPDConnection::Seek(int where) const
}
}
void MPDConnection::Shuffle() const
void Connection::Shuffle() const
{
if (isConnected)
{
@@ -287,7 +289,7 @@ void MPDConnection::Shuffle() const
}
}
void MPDConnection::ClearPlaylist() const
void Connection::ClearPlaylist() const
{
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())
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)
{
@@ -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)
{
@@ -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)
{
@@ -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)
{
@@ -344,7 +346,7 @@ void MPDConnection::GetPlaylistChanges(long long id, SongList &v) const
{
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;
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)
{
@@ -371,12 +373,12 @@ Song MPDConnection::GetSong(const string &path) const
return Song();
}
int MPDConnection::GetCurrentSongPos() const
int Connection::GetCurrentSongPos() const
{
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))
{
@@ -398,7 +400,7 @@ Song MPDConnection::GetCurrentSong() const
return Song();
}
void MPDConnection::GetPlaylistContent(const string &path, SongList &v) const
void Connection::GetPlaylistContent(const string &path, SongList &v) const
{
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)
{
@@ -427,7 +429,7 @@ void MPDConnection::SetRepeat(bool mode) const
}
}
void MPDConnection::SetRandom(bool mode) const
void Connection::SetRandom(bool mode) const
{
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)
{
@@ -445,7 +447,7 @@ void MPDConnection::SetVolume(int vol) const
}
}
void MPDConnection::SetCrossfade(int crossfade) const
void Connection::SetCrossfade(int crossfade) const
{
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;
if (isConnected)
@@ -472,12 +474,12 @@ int MPDConnection::AddSong(const string &path)
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)
{
@@ -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())
QueueAddSong(s.GetFile());
}
void MPDConnection::QueueAddToPlaylist(const string &playlist, const string &path)
void Connection::QueueAddToPlaylist(const string &playlist, const string &path)
{
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())
QueueAddToPlaylist(playlist, s.GetFile());
}
void MPDConnection::QueueDeleteSong(int id)
void Connection::QueueDeleteSong(int id)
{
if (isConnected)
{
@@ -523,7 +525,7 @@ void MPDConnection::QueueDeleteSong(int id)
}
}
void MPDConnection::QueueDeleteSongId(int id)
void Connection::QueueDeleteSongId(int id)
{
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)
{
@@ -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)
{
@@ -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)
{
@@ -571,7 +573,7 @@ void MPDConnection::QueueDeleteFromPlaylist(const string &playlist, int pos)
}
}
bool MPDConnection::CommitQueue()
bool Connection::CommitQueue()
{
bool retval = false;
if (isConnected)
@@ -615,7 +617,7 @@ bool MPDConnection::CommitQueue()
return retval;
}
void MPDConnection::DeletePlaylist(const string &name) const
void Connection::DeletePlaylist(const string &name) const
{
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)
{
@@ -636,7 +638,7 @@ bool MPDConnection::SavePlaylist(const string &name) const
return false;
}
void MPDConnection::GetPlaylists(TagList &v) const
void Connection::GetPlaylists(TagList &v) const
{
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)
{
@@ -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)
{
@@ -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)
{
@@ -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)
mpd_startSearch(itsConnection, exact_match);
}
void MPDConnection::StartFieldSearch(mpd_TagItems item)
void Connection::StartFieldSearch(mpd_TagItems item)
{
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)
mpd_addConstraintSearch(itsConnection, item, str.c_str());
}
void MPDConnection::CommitSearch(SongList &v) const
void Connection::CommitSearch(SongList &v) const
{
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)
{
@@ -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)
{
@@ -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)
{
@@ -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)
{
@@ -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)
{
@@ -842,7 +844,7 @@ void MPDConnection::GetDirectories(const string &path, TagList &v) const
}
}
int MPDConnection::CheckForErrors()
int Connection::CheckForErrors()
{
itsErrorCode = 0;
if (itsConnection->error)
@@ -871,21 +873,21 @@ int MPDConnection::CheckForErrors()
return itsErrorCode;
}
void MPDConnection::ClearQueue()
void Connection::ClearQueue()
{
for (std::vector<QueueCommand *>::iterator it = itsQueue.begin(); it != itsQueue.end(); it++)
delete *it;
itsQueue.clear();
}
void FreeSongList(SongList &l)
void MPD::FreeSongList(SongList &l)
{
for (SongList::iterator i = l.begin(); i != l.end(); i++)
delete *i;
l.clear();
}
void FreeItemList(ItemList &l)
void MPD::FreeItemList(ItemList &l)
{
for (ItemList::iterator i = l.begin(); i != l.end(); i++)
delete i->song;

View File

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

View File

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

View File

@@ -21,7 +21,9 @@
#include "helpers.h"
#include "search_engine.h"
extern MPDConnection *Mpd;
using namespace MPD;
extern Connection *Mpd;
extern Menu<Song> *mPlaylist;
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))
extern MPDConnection *Mpd;
using namespace MPD;
extern Connection *Mpd;
extern ncmpcpp_config Config;
extern Menu<Song> *mPlaylist;
@@ -109,7 +111,7 @@ void TraceMpdStatus()
else
block_progressbar_update = !allow_statusbar_unlock;
MPDStatusChanges changes;
StatusChanges changes;
switch (Mpd->GetState())
{
case psStop:
@@ -126,7 +128,7 @@ void TraceMpdStatus()
//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)
{
@@ -139,10 +141,10 @@ void NcmpcppErrorCallback(MPDConnection *Mpd, int errorid, string msg, void *)
wFooter->SetGetStringHelper(TraceMpdStatus);
}
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;
wFooter->DisableBB();

View File

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

View File

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

View File

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