From 3419ff13a8cc0404293aa7825c37aad17f570bbf Mon Sep 17 00:00:00 2001 From: unK Date: Sat, 13 Sep 2008 17:09:20 +0200 Subject: [PATCH] improve time displaying / allow markers for empty tags without color --- src/misc.cpp | 20 ------------ src/misc.h | 2 -- src/ncmpcpp.cpp | 2 +- src/song.cpp | 71 ++++++++++++++++++++++++++---------------- src/song.h | 11 +++---- src/status_checker.cpp | 4 +-- 6 files changed, 53 insertions(+), 57 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index dd1f6300..17705bb0 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -46,23 +46,3 @@ string IntoStr(double liczba, int precision) return ss.str(); } -string ShowTime(int length) -{ - stringstream ss; - - int minutes = length/60; - length -= minutes*60; - int seconds = length; - - ss << minutes << ":"; - if (seconds == 0) - { ss << "00"; - return ss.str(); - } - if (seconds < 10) - ss << "0" << seconds; - else - ss << seconds; - return ss.str(); -} - diff --git a/src/misc.h b/src/misc.h index 6ca72f1c..ed720fd4 100644 --- a/src/misc.h +++ b/src/misc.h @@ -35,7 +35,5 @@ int StrToInt(string); string IntoStr(int); string IntoStr(double, int); -string ShowTime(int); - #endif diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 327d7dea..5067174f 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -2060,7 +2060,7 @@ int main(int argc, char *argv[]) songpos = 0; wFooter->Bold(1); - string tracklength = "[" + ShowTime(songpos) + "/" + s.GetLength() + "]"; + string tracklength = "[" + Song::ShowTime(songpos) + "/" + s.GetLength() + "]"; wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, tracklength); double progressbar_size = (double)songpos/(s.GetTotalLength()); int howlong = wFooter->GetWidth()*progressbar_size; diff --git a/src/song.cpp b/src/song.cpp index 1b881d6f..8b79de69 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -30,16 +30,25 @@ string UNKNOWN_ALBUM; void DefineEmptyTags() { - const string et_col = IntoStr(Config.empty_tags_color); - EMPTY_TAG = "[." + et_col + "][/" + et_col + "]"; - UNKNOWN_ARTIST = "[." + et_col + "][/" + et_col + "]"; - UNKNOWN_TITLE = "[." + et_col + "][/" + et_col + "]"; - UNKNOWN_ALBUM = "[." + et_col + "][/" + et_col + "]"; + if (Config.empty_tags_color != clDefault) + { + const string et_col = IntoStr(Config.empty_tags_color); + EMPTY_TAG = "[." + et_col + "][/" + et_col + "]"; + UNKNOWN_ARTIST = "[." + et_col + "][/" + et_col + "]"; + UNKNOWN_TITLE = "[." + et_col + "][/" + et_col + "]"; + UNKNOWN_ALBUM = "[." + et_col + "][/" + et_col + "]"; + } + else + { + EMPTY_TAG = ""; + UNKNOWN_ARTIST = ""; + UNKNOWN_TITLE = ""; + UNKNOWN_ALBUM = "time/60), - itsSecondsLength((s->time-itsMinutesLength*60)), + itsLength(s->time), itsPosition(s->pos), itsID(s->id), itsGetEmptyFields(0) @@ -85,22 +94,9 @@ Song::Song(mpd_Song *s) : itsHash(0), string Song::GetLength() const { - std::stringstream ss; - - if (!GetTotalLength()) + if (!itsLength) return "-:--"; - - ss << itsMinutesLength << ":"; - if (!itsSecondsLength) - { - ss << "00"; - return ss.str(); - } - if (itsSecondsLength < 10) - ss << "0" << itsSecondsLength; - else - ss << itsSecondsLength; - return ss.str(); + return ShowTime(itsLength); } void Song::Clear() @@ -119,15 +115,14 @@ void Song::Clear() itsPerformer.clear(); itsDisc.clear(); itsComment.clear(); - itsMinutesLength = 0; - itsSecondsLength = 0; + itsLength = 0; itsPosition = 0; itsID = 0; } bool Song::Empty() const { - return itsFile.empty() && itsShortName.empty() && itsArtist.empty() && itsTitle.empty() && itsAlbum.empty() && itsTrack.empty() && itsYear.empty() && itsGenre.empty(); + return itsFile.empty() && itsShortName.empty() && itsArtist.empty() && itsTitle.empty() && itsAlbum.empty() && itsTrack.empty() && itsYear.empty() && itsGenre.empty() && itsComposer.empty() && itsPerformer.empty() && itsDisc.empty() && itsComment.empty(); } string Song::GetFile() const @@ -197,7 +192,7 @@ string Song::GetComment() const bool Song::operator==(const Song &s) const { - return itsFile == s.itsFile && itsArtist == s.itsArtist && itsTitle == s.itsTitle && itsAlbum == s.itsAlbum && itsTrack == s.itsTrack && itsYear == s.itsYear && itsGenre == s.itsGenre && itsComposer == s.itsComposer && itsPerformer == s.itsPerformer && itsDisc == s.itsDisc && itsComment == s.itsComment && itsHash == s.itsHash && itsMinutesLength && s.itsMinutesLength && itsSecondsLength == s.itsSecondsLength && itsPosition == s.itsPosition && itsID == s.itsID; + return itsFile == s.itsFile && itsArtist == s.itsArtist && itsTitle == s.itsTitle && itsAlbum == s.itsAlbum && itsTrack == s.itsTrack && itsYear == s.itsYear && itsGenre == s.itsGenre && itsComposer == s.itsComposer && itsPerformer == s.itsPerformer && itsDisc == s.itsDisc && itsComment == s.itsComment && itsHash == s.itsHash && itsLength && s.itsLength && itsPosition == s.itsPosition && itsID == s.itsID; } bool Song::operator!=(const Song &s) const @@ -210,3 +205,27 @@ bool Song::operator<(const Song &s) const return itsPosition < s.itsPosition; } +string Song::ShowTime(int length) +{ + std::stringstream ss; + + int hours = length/3600; + length -= hours*3600; + int minutes = length/60; + length -= minutes*60; + int seconds = length; + + if (hours > 0) + { + ss << hours << ":" + << std::setw(2) << std::setfill('0') << minutes << ":" + << std::setw(2) << std::setfill('0') << seconds; + } + else + { + ss << minutes << ":" + << std::setw(2) << std::setfill('0') << seconds; + } + return ss.str(); +} + diff --git a/src/song.h b/src/song.h index 933dcb03..1a35f33c 100644 --- a/src/song.h +++ b/src/song.h @@ -36,7 +36,7 @@ void DefineEmptyTags(); class Song { public: - Song() : itsHash(0), itsMinutesLength(0), itsSecondsLength(0), itsPosition(0), itsID(0), itsGetEmptyFields(0) { } + Song() : itsHash(0), itsLength(0), itsPosition(0), itsID(0), itsGetEmptyFields(0) { } Song(mpd_Song *); ~Song() {}; @@ -56,9 +56,7 @@ class Song string GetComment() const; string GetLength() const; long long GetHash() const { return itsHash; } - int GetTotalLength() const { return itsSecondsLength < 0 ? 0 : itsMinutesLength*60+itsSecondsLength; } - int GetMinutesLength() const { return itsMinutesLength; } - int GetSecondsLength() const { return itsSecondsLength; } + int GetTotalLength() const { return itsLength < 0 ? 0 : itsLength; } int GetPosition() const { return itsPosition; } int GetID() const { return itsID; } @@ -85,6 +83,8 @@ class Song bool operator==(const Song &) const; bool operator!=(const Song &) const; bool operator<(const Song &rhs) const; + + static string ShowTime(int); private: string itsFile; string itsShortName; @@ -102,8 +102,7 @@ class Song string itsDisc; string itsComment; long long itsHash; - int itsMinutesLength; - int itsSecondsLength; + int itsLength; int itsPosition; int itsID; bool itsGetEmptyFields; diff --git a/src/status_checker.cpp b/src/status_checker.cpp index 41c57410..864072df 100644 --- a/src/status_checker.cpp +++ b/src/status_checker.cpp @@ -321,9 +321,9 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *da { string tracklength; if (s.GetTotalLength()) - tracklength = " [" + ShowTime(elapsed) + "/" + s.GetLength() + "]"; + tracklength = " [" + Song::ShowTime(elapsed) + "/" + s.GetLength() + "]"; else - tracklength = " [" + ShowTime(elapsed) + "]"; + tracklength = " [" + Song::ShowTime(elapsed) + "]"; my_string_t playing_song = TO_WSTRING(DisplaySong(s, &Config.song_status_format)); int max_length_without_scroll = wFooter->GetWidth()-player_state.length()-tracklength.length();