From 64fcedda00205f0c0b9464967f06322d4c7afa91 Mon Sep 17 00:00:00 2001 From: simonb Date: Fri, 5 Jan 2007 16:10:56 +0000 Subject: use LC_TIME for interpreting clock locale. Fix something likely to break locales on BSDs and things without nl_langinfo --- ChangeLog | 3 +++ src/ClockTool.cc | 20 ++++++++++++++++---- src/ClockTool.hh | 2 ++ src/FbTk/FbString.cc | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index deb2a32..e7ea179 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ (Format: Year/Month/Day) Changes for 1.0rc3: *07/01/05: + * Fix locale being applied to the clock. (Simon) + - Also fixed a likely locale-killer for BSDs (without nl_langinfo) + ClockTool.hh/cc FbTk/FbString.cc * Fix nls digit strings to prefix with zero "%4d" => "%04d" for proper spacing (Simon) Screen.cc nls/fluxbox-nls.hh nls/*/*.m diff --git a/src/ClockTool.cc b/src/ClockTool.cc index 7385a98..6e06ed6 100644 --- a/src/ClockTool.cc +++ b/src/ClockTool.cc @@ -143,11 +143,19 @@ ClockTool::ClockTool(const FbTk::FbWindow &parent, m_screen(screen), m_pixmap(0), m_timeformat(screen.resourceManager(), std::string("%k:%M"), - screen.name() + ".strftimeFormat", screen.altName() + ".StrftimeFormat") { + screen.name() + ".strftimeFormat", screen.altName() + ".StrftimeFormat"), + m_stringconvertor(FbTk::StringConvertor::ToFbString) { // attach signals theme.reconfigSig().attach(this); - _FB_USES_NLS; + std::string time_locale = setlocale(LC_TIME, NULL); + size_t pos = time_locale.find('.'); + if (pos != std::string::npos) + time_locale = time_locale.substr(pos+1); + if (!time_locale.empty()) + m_stringconvertor.setSource(time_locale); + + _FB_USES_NLS; // setup timer to check the clock every 0.01 second // if nothing has changed, it wont update the graphics @@ -256,9 +264,13 @@ void ClockTool::updateTime() { #ifdef HAVE_STRFTIME time_string_len = strftime(time_string, 255, m_timeformat->c_str(), time_type); - if( time_string_len == 0 || m_button.text() == time_string) + if( time_string_len == 0) + return; + std::string text = m_stringconvertor.recode(time_string); + if (m_button.text() == text) return; - m_button.setText(time_string); + + m_button.setText(text); unsigned int new_width = m_theme.font().textWidth(time_string, time_string_len) + 2; if (new_width > m_button.width()) { diff --git a/src/ClockTool.hh b/src/ClockTool.hh index d55bf5f..7e29bd5 100644 --- a/src/ClockTool.hh +++ b/src/ClockTool.hh @@ -32,6 +32,7 @@ #include "FbTk/Observer.hh" #include "FbTk/Resource.hh" #include "FbTk/Timer.hh" +#include "FbTk/FbString.hh" #include @@ -83,6 +84,7 @@ private: FbTk::Resource m_timeformat; + FbTk::StringConvertor m_stringconvertor; }; #endif // CLOCKTOOL_HH diff --git a/src/FbTk/FbString.cc b/src/FbTk/FbString.cc index c767a30..6614ec4 100644 --- a/src/FbTk/FbString.cc +++ b/src/FbTk/FbString.cc @@ -79,7 +79,7 @@ void init() { string locale = setlocale(LC_CTYPE, NULL); size_t pos = locale.find('.'); if (pos != string::npos) - locale_codeset = locale.substr(pos); + locale_codeset = locale.substr(pos+1); #endif // CODESET #ifdef DEBUG -- cgit v0.11.2