diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2008-12-11 16:12:39 +0100 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2008-12-11 16:12:39 +0100 |
commit | cfa8268f2dc6a14ea3a2700fd556fdb1e294e9ce (patch) | |
tree | 4634744df099ead699797ae537ee2c5e49b700ee | |
parent | 563c4530aae3aa310d0c3686edb1381ce5353ba1 (diff) |
improve handling playlist stats (btw several other improvements)
-rw-r--r-- | src/helpers.cpp | 78 | ||||
-rw-r--r-- | src/helpers.h | 2 | ||||
-rw-r--r-- | src/ncmpcpp.cpp | 7 | ||||
-rw-r--r-- | src/song.cpp | 7 | ||||
-rw-r--r-- | src/song.h | 2 | ||||
-rw-r--r-- | src/status_checker.cpp | 23 |
6 files changed, 60 insertions, 59 deletions
diff --git a/src/helpers.cpp b/src/helpers.cpp index 0596f28a..f4f19a17 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -358,57 +358,59 @@ string FindSharedDir(const string &one, const string &two) return i != string::npos ? result.substr(0, i) : "/"; } -string TotalPlaylistLength() +void DisplayTotalPlaylistLength(Window &w) { const int MINUTE = 60; const int HOUR = 60*MINUTE; const int DAY = 24*HOUR; const int YEAR = 365*DAY; - string result; int length = 0; + for (size_t i = 0; i < mPlaylist->Size(); i++) length += mPlaylist->at(i).GetTotalLength(); - if (!length) - return result; - - result += ", length: "; + w << '(' << mPlaylist->Size() << (mPlaylist->Size() == 1 ? " item" : " items"); - int years = length/YEAR; - if (years) - { - result += IntoStr(years) + (years == 1 ? " year" : " years"); - length -= years*YEAR; - if (length) - result += ", "; - } - int days = length/DAY; - if (days) - { - result += IntoStr(days) + (days == 1 ? " day" : " days"); - length -= days*DAY; - if (length) - result += ", "; - } - int hours = length/HOUR; - if (hours) - { - result += IntoStr(hours) + (hours == 1 ? " hour" : " hours"); - length -= hours*HOUR; - if (length) - result += ", "; - } - int minutes = length/MINUTE; - if (minutes) + if (length) { - result += IntoStr(minutes) + (minutes == 1 ? " minute" : " minutes"); - length -= minutes*MINUTE; + w << ", length: "; + int years = length/YEAR; + if (years) + { + w << years << (years == 1 ? " year" : " years"); + length -= years*YEAR; + if (length) + w << ", "; + } + int days = length/DAY; + if (days) + { + w << days << (days == 1 ? " day" : " days"); + length -= days*DAY; + if (length) + w << ", "; + } + int hours = length/HOUR; + if (hours) + { + w << hours << (hours == 1 ? " hour" : " hours"); + length -= hours*HOUR; + if (length) + w << ", "; + } + int minutes = length/MINUTE; + if (minutes) + { + w << minutes << (minutes == 1 ? " minute" : " minutes"); + length -= minutes*MINUTE; + if (length) + w << ", "; + } if (length) - result += ", "; + w << length << (length == 1 ? " second" : " seconds"); } - if (length) - result += IntoStr(length) + (length == 1 ? " second" : " seconds"); - return result; + w << ')'; + w.Refresh(); } void DisplayStringPair(const StringPair &pair, void *, Menu<StringPair> *menu) diff --git a/src/helpers.h b/src/helpers.h index 2052539a..a5b219e4 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -57,7 +57,7 @@ Window &operator<<(Window &, mpd_TagItems); string IntoStr(mpd_TagItems); string FindSharedDir(const string &, const string &); -string TotalPlaylistLength(); +void DisplayTotalPlaylistLength(Window &); void DisplayStringPair(const StringPair &, void *, Menu<StringPair> *); string DisplayColumns(string); void DisplaySongInColumns(const Song &, void *, Menu<Song> *); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 56e0fb47..e8e114bd 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -173,7 +173,6 @@ int main(int argc, char *argv[]) DefaultKeys(Key); ReadConfiguration(Config); ReadKeys(Key); - DefineEmptyTags(); Mpd = new Connection; @@ -181,8 +180,6 @@ int main(int argc, char *argv[]) Mpd->SetHostname(getenv("MPD_HOST")); if (getenv("MPD_PORT")) Mpd->SetPort(atoi(getenv("MPD_PORT"))); - if (getenv("MPD_PASSWORD")) - Mpd->SetPassword(getenv("MPD_PASSWORD")); if (Config.mpd_host != "localhost") Mpd->SetHostname(Config.mpd_host); @@ -425,8 +422,8 @@ int main(int argc, char *argv[]) wHeader->WriteXY(0, 0, 1, "%s", title.c_str()); wHeader->Bold(0); - if (current_screen == csPlaylist && !playlist_stats.empty()) - wHeader->WriteXY(title.length(), 0, 0, "%s", playlist_stats.c_str()); + if (current_screen == csPlaylist) + DisplayTotalPlaylistLength(*wHeader); else if (current_screen == csBrowser) { size_t max_length_without_scroll = wHeader->GetWidth()-volume_state.length()-title.length(); diff --git a/src/song.cpp b/src/song.cpp index bb419102..5c62b3cb 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -23,12 +23,7 @@ extern ncmpcpp_config Config; -string EMPTY_TAG; - -void DefineEmptyTags() -{ - EMPTY_TAG = "<empty>"; -} +string EMPTY_TAG = "<empty>"; Song::Song(mpd_Song *s, bool copy_ptr) : itsSong(s), itsSlash(string::npos), @@ -31,8 +31,6 @@ using std::string; -void DefineEmptyTags(); - class Song { public: diff --git a/src/status_checker.cpp b/src/status_checker.cpp index cf5156e7..6f63fb02 100644 --- a/src/status_checker.cpp +++ b/src/status_checker.cpp @@ -67,7 +67,7 @@ int old_playing; time_t time_of_statusbar_lock; -string playlist_stats; +//string playlist_stats; string volume_state; string switch_state; @@ -208,12 +208,9 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *) if (mPlaylist->Empty()) { - playlist_stats.clear(); mPlaylist->Reset(); ShowMessage("Cleared playlist!"); } - else - playlist_stats = "(" + IntoStr(mPlaylist->Size()) + (mPlaylist->Size() == 1 ? " item" : " items") + TotalPlaylistLength() + ")"; if (!block_item_list_update) { @@ -332,9 +329,19 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *) { string tracklength; if (s.GetTotalLength()) - tracklength = " [" + Song::ShowTime(elapsed) + "/" + s.GetLength() + "]"; + { + tracklength = " ["; + tracklength += Song::ShowTime(elapsed); + tracklength += "/"; + tracklength += s.GetLength(); + tracklength += "]"; + } else - tracklength = " [" + Song::ShowTime(elapsed) + "]"; + { + tracklength = " ["; + tracklength += Song::ShowTime(elapsed); + tracklength += "]"; + } my_string_t playing_song = TO_WSTRING(s.toString(Config.song_status_format)); const size_t max_length_without_scroll = wFooter->GetWidth()-player_state.length()-tracklength.length(); @@ -444,7 +451,9 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *) if ((changed.Volume) && Config.header_visibility) { int vol = Mpd->GetVolume(); - volume_state = " Volume: " + IntoStr(vol) + "%"; + volume_state = " Volume: "; + volume_state += IntoStr(vol); + volume_state += "%"; wHeader->SetColor(Config.volume_color); wHeader->WriteXY(wHeader->GetWidth()-volume_state.length(), 0, 1, "%s", volume_state.c_str()); wHeader->SetColor(Config.header_color); |