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
meow-7.2.2
Vadim Savchuk 2009-11-24 22:59:00 +02:00
parent 11a9fe3e7c
commit a7d2130464
4 changed files with 66 additions and 35 deletions

View File

@ -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<LLAvatarListItem*>(*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);
}
}

View File

@ -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);
}

View File

@ -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;

View File

@ -7,6 +7,18 @@
name="avatar_list_item"
top="0"
width="320">
<!--
Strings used to localize last interaction time.
See last_interaction textbox below.
-->
<string name="FormatSeconds">[COUNT]s</string>
<string name="FormatMinutes">[COUNT]m</string>
<string name="FormatHours">[COUNT]h</string>
<string name="FormatDays">[COUNT]d</string>
<string name="FormatWeeks">[COUNT]w</string>
<string name="FormatMonths">[COUNT]mon</string>
<string name="FormatYears">[COUNT]y</string>
<icon
follows="top|right|left"
height="24"