several code clean-ups and corrections
This commit is contained in:
@@ -136,8 +136,8 @@ bool ParseArgv(vector<string> &v)
|
|||||||
else if (*it == "volume")
|
else if (*it == "volume")
|
||||||
{
|
{
|
||||||
it++;
|
it++;
|
||||||
Mpd->GetStatus();
|
Mpd->UpdateStatus();
|
||||||
if (Mpd->CheckForErrors())
|
if (!Mpd->GetErrorMessage().empty())
|
||||||
{
|
{
|
||||||
cout << "Error: " << Mpd->GetErrorMessage() << endl;
|
cout << "Error: " << Mpd->GetErrorMessage() << endl;
|
||||||
return 1;
|
return 1;
|
||||||
@@ -151,7 +151,7 @@ bool ParseArgv(vector<string> &v)
|
|||||||
cout << "ncmpcpp: invalid option " << *it << endl;
|
cout << "ncmpcpp: invalid option " << *it << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Mpd->CheckForErrors())
|
if (!Mpd->GetErrorMessage().empty())
|
||||||
{
|
{
|
||||||
cout << "Error: " << Mpd->GetErrorMessage() << endl;
|
cout << "Error: " << Mpd->GetErrorMessage() << endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -119,20 +119,15 @@ void MPDConnection::SetErrorHandler(ErrorHandler handler, void *data)
|
|||||||
itsErrorHandlerUserdata = data;
|
itsErrorHandlerUserdata = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPDConnection::GetStatus()
|
void MPDConnection::UpdateStatus()
|
||||||
{
|
{
|
||||||
|
CheckForErrors();
|
||||||
|
|
||||||
if (itsOldStatus)
|
if (itsOldStatus)
|
||||||
mpd_freeStatus(itsOldStatus);
|
mpd_freeStatus(itsOldStatus);
|
||||||
itsOldStatus = itsCurrentStatus;
|
itsOldStatus = itsCurrentStatus;
|
||||||
mpd_sendStatusCommand(itsConnection);
|
mpd_sendStatusCommand(itsConnection);
|
||||||
itsCurrentStatus = mpd_getStatus(itsConnection);
|
itsCurrentStatus = mpd_getStatus(itsConnection);
|
||||||
}
|
|
||||||
|
|
||||||
void MPDConnection::UpdateStatus()
|
|
||||||
{
|
|
||||||
CheckForErrors();
|
|
||||||
|
|
||||||
GetStatus();
|
|
||||||
|
|
||||||
if (!itsMaxPlaylistLength)
|
if (!itsMaxPlaylistLength)
|
||||||
itsMaxPlaylistLength = GetPlaylistLength();
|
itsMaxPlaylistLength = GetPlaylistLength();
|
||||||
@@ -140,14 +135,16 @@ void MPDConnection::UpdateStatus()
|
|||||||
if (CheckForErrors())
|
if (CheckForErrors())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MPDStatusChanges changes;
|
|
||||||
|
|
||||||
if (itsOldStats)
|
if (itsOldStats)
|
||||||
mpd_freeStats(itsOldStats);
|
mpd_freeStats(itsOldStats);
|
||||||
itsOldStats = itsCurrentStats;
|
itsOldStats = itsCurrentStats;
|
||||||
mpd_sendStatsCommand(itsConnection);
|
mpd_sendStatsCommand(itsConnection);
|
||||||
itsCurrentStats = mpd_getStats(itsConnection);
|
itsCurrentStats = mpd_getStats(itsConnection);
|
||||||
|
|
||||||
|
if (itsCurrentStatus && itsUpdater)
|
||||||
|
{
|
||||||
|
MPDStatusChanges changes;
|
||||||
|
|
||||||
if (itsOldStatus == NULL)
|
if (itsOldStatus == NULL)
|
||||||
{
|
{
|
||||||
changes.Playlist = 1;
|
changes.Playlist = 1;
|
||||||
@@ -174,9 +171,9 @@ void MPDConnection::UpdateStatus()
|
|||||||
changes.Repeat = itsOldStatus->repeat != itsCurrentStatus->repeat;
|
changes.Repeat = itsOldStatus->repeat != itsCurrentStatus->repeat;
|
||||||
changes.PlayerState = itsOldStatus->state != itsCurrentStatus->state;
|
changes.PlayerState = itsOldStatus->state != itsCurrentStatus->state;
|
||||||
}
|
}
|
||||||
if (itsUpdater)
|
|
||||||
itsUpdater(this, changes, itsErrorHandlerUserdata);
|
itsUpdater(this, changes, itsErrorHandlerUserdata);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MPDConnection::UpdateDirectory(const string &path) const
|
void MPDConnection::UpdateDirectory(const string &path) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ class MPDConnection
|
|||||||
|
|
||||||
void SetStatusUpdater(StatusUpdater, void *);
|
void SetStatusUpdater(StatusUpdater, void *);
|
||||||
void SetErrorHandler(ErrorHandler, void *);
|
void SetErrorHandler(ErrorHandler, void *);
|
||||||
void GetStatus();
|
|
||||||
void UpdateStatus();
|
void UpdateStatus();
|
||||||
void UpdateDirectory(const string &) const;
|
void UpdateDirectory(const string &) const;
|
||||||
|
|
||||||
@@ -122,7 +121,7 @@ class MPDConnection
|
|||||||
int GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : 0; }
|
int GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : 0; }
|
||||||
void GetPlaylistChanges(long long, SongList &) const;
|
void GetPlaylistChanges(long long, SongList &) const;
|
||||||
|
|
||||||
string GetErrorMessage() const { return itsErrorMessage; }
|
const string & GetErrorMessage() const { return itsErrorMessage; }
|
||||||
int GetErrorCode() const { return itsErrorCode; }
|
int GetErrorCode() const { return itsErrorCode; }
|
||||||
|
|
||||||
Song GetCurrentSong() const;
|
Song GetCurrentSong() const;
|
||||||
@@ -171,10 +170,9 @@ class MPDConnection
|
|||||||
void GetSongs(const string &, SongList &) const;
|
void GetSongs(const string &, SongList &) const;
|
||||||
void GetDirectories(const string &, TagList &) const;
|
void GetDirectories(const string &, TagList &) const;
|
||||||
|
|
||||||
int CheckForErrors();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ClearQueue();
|
void ClearQueue();
|
||||||
|
int CheckForErrors();
|
||||||
|
|
||||||
mpd_Connection *itsConnection;
|
mpd_Connection *itsConnection;
|
||||||
bool isConnected;
|
bool isConnected;
|
||||||
|
|||||||
@@ -319,15 +319,16 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *)
|
|||||||
playing_song_scroll_begin = 0;
|
playing_song_scroll_begin = 0;
|
||||||
|
|
||||||
if (Mpd->GetState() == psPlay)
|
if (Mpd->GetState() == psPlay)
|
||||||
|
{
|
||||||
|
WindowTitle(DisplaySong(Mpd->GetCurrentSong(), &Config.song_window_title_format));
|
||||||
changed.ElapsedTime = 1;
|
changed.ElapsedTime = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (changed.ElapsedTime)
|
if (changed.ElapsedTime)
|
||||||
{
|
{
|
||||||
Song s = Mpd->GetCurrentSong();
|
const Song &s = Mpd->GetCurrentSong();
|
||||||
if (!player_state.empty() && !s.Empty())
|
if (!player_state.empty() && !s.Empty())
|
||||||
{
|
{
|
||||||
WindowTitle(DisplaySong(s, &Config.song_window_title_format));
|
|
||||||
|
|
||||||
int elapsed = Mpd->GetElapsedTime();
|
int elapsed = Mpd->GetElapsedTime();
|
||||||
|
|
||||||
// 'repeat one' mode check - be sure that we deal with item with known length
|
// 'repeat one' mode check - be sure that we deal with item with known length
|
||||||
@@ -391,14 +392,14 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *)
|
|||||||
if (changed.Repeat)
|
if (changed.Repeat)
|
||||||
{
|
{
|
||||||
mpd_repeat = (Mpd->GetRepeat() ? "r" : "");
|
mpd_repeat = (Mpd->GetRepeat() ? "r" : "");
|
||||||
ShowMessage("Repeat is " + (string)(mpd_repeat.empty() ? "off" : "on"));
|
ShowMessage("Repeat is " + string(mpd_repeat.empty() ? "off" : "on"));
|
||||||
header_update_status = 1;
|
header_update_status = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (changed.Random)
|
if (changed.Random)
|
||||||
{
|
{
|
||||||
mpd_random = Mpd->GetRandom() ? "z" : "";
|
mpd_random = Mpd->GetRandom() ? "z" : "";
|
||||||
ShowMessage("Random is " + (string)(mpd_random.empty() ? "off" : "on"));
|
ShowMessage("Random is " + string(mpd_random.empty() ? "off" : "on"));
|
||||||
header_update_status = 1;
|
header_update_status = 1;
|
||||||
}
|
}
|
||||||
if (changed.Crossfade)
|
if (changed.Crossfade)
|
||||||
|
|||||||
Reference in New Issue
Block a user