From 13118c1148ddae3828305b92895dc8b11ad29f46 Mon Sep 17 00:00:00 2001 From: martii Date: Fri, 10 Jan 2014 20:02:16 +0100 Subject: [PATCH] gui/components/cc_frm_clock: simplify; setClockFormat/setClockBlink has now impact on running thread Conflicts: src/gui/components/cc_frm_clock.cpp src/gui/timeosd.cpp --- src/gui/components/cc_frm_clock.cpp | 19 +++++-------------- src/gui/components/cc_frm_clock.h | 8 +++++--- src/gui/timeosd.cpp | 4 ++-- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/gui/components/cc_frm_clock.cpp b/src/gui/components/cc_frm_clock.cpp index c538faf5a..5f06b78b4 100644 --- a/src/gui/components/cc_frm_clock.cpp +++ b/src/gui/components/cc_frm_clock.cpp @@ -72,7 +72,8 @@ CComponentsFrmClock::CComponentsFrmClock( const int& x_pos, const int& y_pos, c cl_thread = 0; cl_interval = 1; - cl_blink_str = ""; + activeClock = true; + cl_blink_str = format_str; paintClock = false; activeClock = activ; @@ -89,12 +90,13 @@ CComponentsFrmClock::~CComponentsFrmClock() stopThread(); } + void CComponentsFrmClock::initTimeString() { struct tm t; time_t ltime; - ltime=time(<ime); - strftime((char*) &cl_timestr, sizeof(cl_timestr), cl_format_str.c_str(), localtime_r(<ime, &t)); + ltime=time(NULL); + strftime((char*) &cl_timestr, sizeof(cl_timestr), getTimeFormat(ltime), localtime_r(<ime, &t)); } // How does it works? @@ -261,20 +263,9 @@ void* CComponentsFrmClock::initClockThread(void *arg) #if 0 time_t count = time(0); #endif - std::string format_str_save = clock->cl_format_str; // FIXME. This will cause setClockFormat() to be ignored. --martii //start loop for paint while(clock != NULL) { if (clock->paintClock) { - // Blinking depending on the blink format string - if (!clock->cl_blink_str.empty() && (clock->cl_format_str.length() == clock->cl_blink_str.length())) { - if (clock->cl_format_str == clock->cl_blink_str.c_str()) - clock->cl_format_str = format_str_save; - else { - format_str_save = clock->cl_format_str; - clock->cl_format_str = clock->cl_blink_str; - } - } - //paint segements, but wihtout saved backgrounds clock->paint(CC_SAVE_SCREEN_NO); #if 0 count = time(0); diff --git a/src/gui/components/cc_frm_clock.h b/src/gui/components/cc_frm_clock.h index f8725cd4a..ede5d9002 100644 --- a/src/gui/components/cc_frm_clock.h +++ b/src/gui/components/cc_frm_clock.h @@ -71,10 +71,10 @@ class CComponentsFrmClock : public CComponentsForm ///text color int cl_col_text; ///time format - std::string cl_format_str; + const char *cl_format_str; ///time format for blink - std::string cl_blink_str; - ///time string align, default allign is ver and hor centered + const char *cl_blink_str; + ///time string align, default align is ver and hor centered int cl_align; ///initialize clock contents @@ -83,6 +83,8 @@ class CComponentsFrmClock : public CComponentsForm virtual void initTimeString(); ///initialize of general alignment of timestring segments within form area void initSegmentAlign(int* segment_width, int* segment_height); + //return current time string format + const char *getTimeFormat(time_t when) { return (when & 1) ? cl_format_str : cl_blink_str; } ///return pointer of font object inline Font** getClockFont(); diff --git a/src/gui/timeosd.cpp b/src/gui/timeosd.cpp index 199a0b7c5..8912373e8 100644 --- a/src/gui/timeosd.cpp +++ b/src/gui/timeosd.cpp @@ -87,11 +87,11 @@ void CTimeOSD::initTimeString() struct tm t; if (m_mode == MODE_DESC) { char tt[20]; - strftime(tt, sizeof(tt), cl_format_str.c_str(), gmtime_r(&m_time_show, &t)); + strftime(tt, sizeof(tt), cl_format_str, gmtime_r(&m_time_show, &t)); snprintf(cl_timestr, sizeof(cl_timestr), "-%s", tt); } else - strftime(cl_timestr, sizeof(cl_timestr), cl_format_str.c_str(), gmtime_r(&m_time_show, &t)); + strftime(cl_timestr, sizeof(cl_timestr), cl_format_str, gmtime_r(&m_time_show, &t)); } void CTimeOSD::show(time_t time_show, bool force)