diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2009-10-11 17:03:00 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2009-10-11 17:03:00 +0200 |
commit | 03f6fd904f639fb7210d995759caadf6a83a3859 (patch) | |
tree | 51ca65e5a77490cbe2c20f3c5b70705179887b21 /src/helpers.h | |
parent | aebc5db0e1634b7dade9c2b31ef4ffb70829e694 (diff) |
new screen: mpd server info
Diffstat (limited to 'src/helpers.h')
-rw-r--r-- | src/helpers.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/helpers.h b/src/helpers.h index e44e375c..7dee4110 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -162,6 +162,49 @@ template <typename C> void String2Buffer(const std::basic_string<C> &s, basic_bu } } +template <typename T> void ShowTime(T &buf, size_t length, bool short_names) +{ + const unsigned MINUTE = 60; + const unsigned HOUR = 60*MINUTE; + const unsigned DAY = 24*HOUR; + const unsigned YEAR = 365*DAY; + + unsigned years = length/YEAR; + if (years) + { + buf << years << (short_names ? "y" : (years == 1 ? " year" : " years")); + length -= years*YEAR; + if (length) + buf << ", "; + } + unsigned days = length/DAY; + if (days) + { + buf << days << (short_names ? "d" : (days == 1 ? " day" : " days")); + length -= days*DAY; + if (length) + buf << ", "; + } + unsigned hours = length/HOUR; + if (hours) + { + buf << hours << (short_names ? "h" : (hours == 1 ? " hour" : " hours")); + length -= hours*HOUR; + if (length) + buf << ", "; + } + unsigned minutes = length/MINUTE; + if (minutes) + { + buf << minutes << (short_names ? "m" : (minutes == 1 ? " minute" : " minutes")); + length -= minutes*MINUTE; + if (length) + buf << ", "; + } + if (length) + buf << length << (short_names ? "s" : (length == 1 ? " second" : " seconds")); +} + template <typename T> void ShowTag(T &buf, const std::string &tag) { if (tag.empty()) @@ -175,6 +218,8 @@ inline bool Keypressed(int in, const int *key) return in == key[0] || in == key[1]; } +std::string Timestamp(time_t t); + void UpdateSongList(Menu<MPD::Song> *); #ifdef HAVE_TAGLIB_H |