diff --git a/src/display/utils.cc b/src/display/utils.cc index 20f8c8ad..1b778bd6 100644 --- a/src/display/utils.cc +++ b/src/display/utils.cc @@ -1,8 +1,10 @@ #include "config.h" +#include #include #include "core/download.h" +#include "utils/timer.h" #include "utils.h" @@ -31,4 +33,20 @@ print_download_status(core::Download* d) { return str.str(); } +std::string +print_hhmmss(utils::Timer t) { + std::tm *u = std::localtime(&t.tval().tv_sec); + + if (u == NULL) + return "inv_time"; + + std::stringstream str; + str.width(2); + str.fill('0'); + + str << u->tm_hour << ':' << u->tm_min << ':' << u->tm_sec; + + return str.str(); +} + } diff --git a/src/display/utils.h b/src/display/utils.h index 6ec3c111..ea1423ea 100644 --- a/src/display/utils.h +++ b/src/display/utils.h @@ -7,10 +7,16 @@ namespace core { class Download; } +namespace utils { + class Timer; +} + namespace display { std::string print_download_status(core::Download* d); +std::string print_hhmmss(utils::Timer t); + } #endif diff --git a/src/display/window_log.cc b/src/display/window_log.cc index 78e9d2c8..a0ed0f6c 100644 --- a/src/display/window_log.cc +++ b/src/display/window_log.cc @@ -3,6 +3,7 @@ #include #include "canvas.h" +#include "utils.h" #include "window_log.h" namespace display { @@ -37,17 +38,10 @@ WindowLog::redraw() { //m_canvas->print(std::max(0, (int)m_canvas->get_width() / 2 - 5), pos++, "*** Log ***"); m_canvas->print(0, 0, "___"); - for (core::Log::iterator itr = m_log->begin(), end = find_older(); itr != end && pos < m_canvas->get_height(); ++itr) { - std::tm *t = std::localtime(&itr->first.tval().tv_sec); - - if (t == NULL) - m_canvas->print(0, pos++, "(time error) %s", - itr->second.c_str()); - else - m_canvas->print(0, pos++, "(%02i:%02i:%02i) %s", - t->tm_hour, t->tm_min, t->tm_sec, - itr->second.c_str()); - } + for (core::Log::iterator itr = m_log->begin(), end = find_older(); itr != end && pos < m_canvas->get_height(); ++itr) + m_canvas->print(0, pos++, "(%s) %s", + print_hhmmss(itr->first).c_str(), + itr->second.c_str()); } void diff --git a/src/display/window_log_complete.cc b/src/display/window_log_complete.cc index 727ae64e..ca5906e7 100644 --- a/src/display/window_log_complete.cc +++ b/src/display/window_log_complete.cc @@ -3,6 +3,7 @@ #include #include "canvas.h" +#include "utils.h" #include "window_log_complete.h" namespace display { @@ -34,17 +35,10 @@ WindowLogComplete::redraw() { m_canvas->print(std::max(0, (int)m_canvas->get_width() / 2 - 5), pos++, "*** Log ***"); - for (core::Log::iterator itr = m_log->begin(), e = m_log->end(); itr != e && pos < m_canvas->get_height(); ++itr) { - std::tm *t = std::localtime(&itr->first.tval().tv_sec); - - if (t == NULL) - m_canvas->print(0, pos++, "(time error) %s", - itr->second.c_str()); - else - m_canvas->print(0, pos++, "(%02i:%02i:%02i) %s", - t->tm_hour, t->tm_min, t->tm_sec, - itr->second.c_str()); - } + for (core::Log::iterator itr = m_log->begin(), e = m_log->end(); itr != e && pos < m_canvas->get_height(); ++itr) + m_canvas->print(0, pos++, "(%s) %s", + print_hhmmss(itr->first).c_str(), + itr->second.c_str()); } void