From a7d2130464fa5e73ba7faf8b697b98443e80257a Mon Sep 17 00:00:00 2001 From: Vadim Savchuk Date: Tue, 24 Nov 2009 22:59:00 +0200 Subject: Fixed major bug EXT-2701 (Recent People > last_interaction value is not internationalized). Made the avatar last interaction time localizeable. This also fixes task EXT-1096 (Implement Recent time in Recent People list for Avatar items). --HG-- branch : product-engine --- indra/newview/llavatarlist.cpp | 33 +------------- indra/newview/llavatarlistitem.cpp | 52 +++++++++++++++++++++- indra/newview/llavatarlistitem.h | 4 +- .../default/xui/en/panel_avatar_list_item.xml | 12 +++++ 4 files changed, 66 insertions(+), 35 deletions(-) diff --git a/indra/newview/llavatarlist.cpp b/indra/newview/llavatarlist.cpp index bb03f47f46..7f3f869e5d 100644 --- a/indra/newview/llavatarlist.cpp +++ b/indra/newview/llavatarlist.cpp @@ -363,37 +363,6 @@ void LLAvatarList::computeDifference( vadded.erase(it, vadded.end()); } -static std::string format_secs(S32 secs) -{ - // *TODO: reinventing the wheel? - // *TODO: i18n - static const int LL_AL_MIN = 60; - static const int LL_AL_HOUR = LL_AL_MIN * 60; - static const int LL_AL_DAY = LL_AL_HOUR * 24; - static const int LL_AL_WEEK = LL_AL_DAY * 7; - static const int LL_AL_MONTH = LL_AL_DAY * 31; - static const int LL_AL_YEAR = LL_AL_DAY * 365; - - std::string s; - - if (secs >= LL_AL_YEAR) - s = llformat("%dy", secs / LL_AL_YEAR); - else if (secs >= LL_AL_MONTH) - s = llformat("%dmon", secs / LL_AL_MONTH); - else if (secs >= LL_AL_WEEK) - s = llformat("%dw", secs / LL_AL_WEEK); - else if (secs >= LL_AL_DAY) - s = llformat("%dd", secs / LL_AL_DAY); - else if (secs >= LL_AL_HOUR) - s = llformat("%dh", secs / LL_AL_HOUR); - else if (secs >= LL_AL_MIN) - s = llformat("%dm", secs / LL_AL_MIN); - else - s = llformat("%ds", secs); - - return s; -} - // Refresh shown time of our last interaction with all listed avatars. void LLAvatarList::updateLastInteractionTimes() { @@ -407,7 +376,7 @@ void LLAvatarList::updateLastInteractionTimes() LLAvatarListItem* item = static_cast(*it); S32 secs_since = now - (S32) LLRecentPeople::instance().getDate(item->getAvatarId()).secondsSinceEpoch(); if (secs_since >= 0) - item->setLastInteractionTime(format_secs(secs_since)); + item->setLastInteractionTime(secs_since); } } diff --git a/indra/newview/llavatarlistitem.cpp b/indra/newview/llavatarlistitem.cpp index c670a65bcc..efc9538fa6 100644 --- a/indra/newview/llavatarlistitem.cpp +++ b/indra/newview/llavatarlistitem.cpp @@ -198,9 +198,9 @@ void LLAvatarListItem::showLastInteractionTime(bool show) mAvatarName->setRect(name_rect); } -void LLAvatarListItem::setLastInteractionTime(const std::string& val) +void LLAvatarListItem::setLastInteractionTime(U32 secs_since) { - mLastInteractionTime->setValue(val); + mLastInteractionTime->setValue(formatSeconds(secs_since)); } void LLAvatarListItem::setShowInfoBtn(bool show) @@ -326,3 +326,51 @@ void LLAvatarListItem::reshapeAvatarName() mAvatarName->reshape(width, height); } + +// Convert given number of seconds to a string like "23 minutes", "15 hours" or "3 years", +// taking i18n into account. The format string to use is taken from the panel XML. +std::string LLAvatarListItem::formatSeconds(U32 secs) +{ + static const U32 LL_ALI_MIN = 60; + static const U32 LL_ALI_HOUR = LL_ALI_MIN * 60; + static const U32 LL_ALI_DAY = LL_ALI_HOUR * 24; + static const U32 LL_ALI_WEEK = LL_ALI_DAY * 7; + static const U32 LL_ALI_MONTH = LL_ALI_DAY * 30; + static const U32 LL_ALI_YEAR = LL_ALI_DAY * 365; + + std::string fmt; + U32 count = 0; + + if (secs >= LL_ALI_YEAR) + { + fmt = "FormatYears"; count = secs / LL_ALI_YEAR; + } + else if (secs >= LL_ALI_MONTH) + { + fmt = "FormatMonths"; count = secs / LL_ALI_MONTH; + } + else if (secs >= LL_ALI_WEEK) + { + fmt = "FormatWeeks"; count = secs / LL_ALI_WEEK; + } + else if (secs >= LL_ALI_DAY) + { + fmt = "FormatDays"; count = secs / LL_ALI_DAY; + } + else if (secs >= LL_ALI_HOUR) + { + fmt = "FormatHours"; count = secs / LL_ALI_HOUR; + } + else if (secs >= LL_ALI_MIN) + { + fmt = "FormatMinutes"; count = secs / LL_ALI_MIN; + } + else + { + fmt = "FormatSeconds"; count = secs; + } + + LLStringUtil::format_map_t args; + args["[COUNT]"] = llformat("%u", count); + return getString(fmt, args); +} diff --git a/indra/newview/llavatarlistitem.h b/indra/newview/llavatarlistitem.h index 9d48101a44..341f5a6bcf 100644 --- a/indra/newview/llavatarlistitem.h +++ b/indra/newview/llavatarlistitem.h @@ -63,7 +63,7 @@ public: void setOnline(bool online); void setName(const std::string& name); void setAvatarId(const LLUUID& id, bool ignore_status_changes = false); - void setLastInteractionTime(const std::string& val); + void setLastInteractionTime(U32 secs_since); //Show/hide profile/info btn, translating speaker indicator and avatar name coordinates accordingly void setShowProfileBtn(bool show); void setShowInfoBtn(bool show); @@ -94,6 +94,8 @@ private: void onNameCache(const std::string& first_name, const std::string& last_name); + std::string formatSeconds(U32 secs); + LLAvatarIconCtrl* mAvatarIcon; LLTextBox* mAvatarName; LLTextBox* mLastInteractionTime; diff --git a/indra/newview/skins/default/xui/en/panel_avatar_list_item.xml b/indra/newview/skins/default/xui/en/panel_avatar_list_item.xml index 2eaa3a94ee..45f9d9c7b6 100644 --- a/indra/newview/skins/default/xui/en/panel_avatar_list_item.xml +++ b/indra/newview/skins/default/xui/en/panel_avatar_list_item.xml @@ -7,6 +7,18 @@ name="avatar_list_item" top="0" width="320"> + + [COUNT]s + [COUNT]m + [COUNT]h + [COUNT]d + [COUNT]w + [COUNT]mon + [COUNT]y +