diff options
Diffstat (limited to 'indra/newview/llavatariconctrl.cpp')
-rw-r--r-- | indra/newview/llavatariconctrl.cpp | 180 |
1 files changed, 116 insertions, 64 deletions
diff --git a/indra/newview/llavatariconctrl.cpp b/indra/newview/llavatariconctrl.cpp index 1d5fa9ffa7..b56e8d1ec2 100644 --- a/indra/newview/llavatariconctrl.cpp +++ b/indra/newview/llavatariconctrl.cpp @@ -50,7 +50,94 @@ static LLDefaultChildRegistry::Register<LLAvatarIconCtrl> r("avatar_icon"); -LLAvatarIconCtrl::avatar_image_map_t LLAvatarIconCtrl::sImagesCache; +bool LLAvatarIconIDCache::LLAvatarIconIDCacheItem::expired() +{ + const F64 SEC_PER_DAY_PLUS_HOUR = (24.0 + 1.0) * 60.0 * 60.0; + F64 delta = LLDate::now().secondsSinceEpoch() - cached_time.secondsSinceEpoch(); + if (delta > SEC_PER_DAY_PLUS_HOUR) + return true; + return false; +} + +void LLAvatarIconIDCache::load () +{ + llinfos << "Loading avatar icon id cache." << llendl; + + // build filename for each user + std::string resolved_filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, mFilename); + llifstream file(resolved_filename); + + if (!file.is_open()) + return; + + // add each line in the file to the list + int uuid_len = UUID_STR_LENGTH-1; + std::string line; + while (std::getline(file, line)) + { + LLUUID avatar_id; + LLUUID icon_id; + LLDate date; + + std::string avatar_id_str = line.substr(0,uuid_len); + std::string icon_id_str = line.substr(uuid_len,uuid_len); + + std::string date_str = line.substr(uuid_len*2, line.length()-uuid_len*2); + + if(!avatar_id.set(avatar_id_str) || !icon_id.set(icon_id_str) || !date.fromString(date_str)) + continue; + + LLAvatarIconIDCacheItem item = {icon_id,date}; + mCache[avatar_id] = item; + } + + file.close(); + +} + +void LLAvatarIconIDCache::save () +{ + std::string resolved_filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, mFilename); + + // open a file for writing + llofstream file (resolved_filename); + if (!file.is_open()) + { + llwarns << "can't open avatar icons cache file\"" << mFilename << "\" for writing" << llendl; + return; + } + + for(std::map<LLUUID,LLAvatarIconIDCacheItem>::iterator it = mCache.begin();it!=mCache.end();++it) + { + if(!it->second.expired()) + { + file << it->first << it->second.icon_id << it->second.cached_time << std::endl; + } + } + + file.close(); +} + +LLUUID* LLAvatarIconIDCache::get (const LLUUID& avatar_id) +{ + std::map<LLUUID,LLAvatarIconIDCacheItem>::iterator it = mCache.find(avatar_id); + if(it==mCache.end()) + return 0; + if(it->second.expired()) + return 0; + return &it->second.icon_id; +} + +void LLAvatarIconIDCache::add (const LLUUID& avatar_id,const LLUUID& icon_id) +{ + LLAvatarIconIDCacheItem item = {icon_id,LLDate::now()}; + mCache[avatar_id] = item; +} + +void LLAvatarIconIDCache::remove (const LLUUID& avatar_id) +{ + mCache.erase(avatar_id); +} LLAvatarIconCtrl::Params::Params() @@ -65,7 +152,11 @@ LLAvatarIconCtrl::LLAvatarIconCtrl(const LLAvatarIconCtrl::Params& p) : LLIconCtrl(p), mDrawTooltip(p.draw_tooltip) { + mPriority = LLViewerFetchedTexture::BOOST_ICON; + LLRect rect = p.rect; + mDrawWidth = llmax(32, rect.getWidth()) ; + mDrawHeight = llmax(32, rect.getHeight()) ; static LLUICachedControl<S32> llavatariconctrl_symbol_hpad("UIAvatariconctrlSymbolHPad", 2); static LLUICachedControl<S32> llavatariconctrl_symbol_vpad("UIAvatariconctrlSymbolVPad", 2); @@ -94,16 +185,6 @@ LLAvatarIconCtrl::LLAvatarIconCtrl(const LLAvatarIconCtrl::Params& p) rect.setOriginAndSize(left, bottom, llavatariconctrl_symbol_size, llavatariconctrl_symbol_size); - LLIconCtrl::Params icparams; - icparams.name ("Status Symbol"); - icparams.follows.flags (FOLLOWS_RIGHT | FOLLOWS_BOTTOM); - icparams.rect (rect); - mStatusSymbol = LLUICtrlFactory::create<LLIconCtrl> (icparams); - mStatusSymbol->setValue("circle.tga"); - mStatusSymbol->setColor(LLColor4::grey); - - addChild(mStatusSymbol); - if (p.avatar_id.isProvided()) { LLSD value(p.avatar_id); @@ -114,7 +195,6 @@ LLAvatarIconCtrl::LLAvatarIconCtrl(const LLAvatarIconCtrl::Params& p) LLIconCtrl::setValue("default_profile_picture.j2c"); } - LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar; registrar.add("AvatarIcon.Action", boost::bind(&LLAvatarIconCtrl::onAvatarIconContextMenuItemClicked, this, _2)); @@ -152,27 +232,19 @@ void LLAvatarIconCtrl::setValue(const LLSD& value) mAvatarId = value.asUUID(); // *BUG: This will return stale icons if a user changes their - // profile picture. Also, the online/offline tooltips will be - // out of date. However, otherwise we send too many upstream + // profile picture. However, otherwise we send too many upstream // AvatarPropertiesRequest messages. - // - // *TODO: Implement a timeout on the icon cache, perhaps a day?, - // and make the cache update if a user views the full-profile for - // an avatar. + + // to get fresh avatar icon use + // LLAvatarIconIDCache::getInstance()->remove(avatar_id); // Check if cache already contains image_id for that avatar - avatar_image_map_t::iterator it = sImagesCache.find(mAvatarId); - if (it != sImagesCache.end()) + if (!updateFromCache()) { - updateFromCache(it->second); - } - else - { - app->addObserver(value.asUUID(), this); - app->sendAvatarPropertiesRequest(value.asUUID()); + app->addObserver(mAvatarId, this); + app->sendAvatarPropertiesRequest(mAvatarId); } } - } else { @@ -182,48 +254,25 @@ void LLAvatarIconCtrl::setValue(const LLSD& value) gCacheName->get(mAvatarId, FALSE, boost::bind(&LLAvatarIconCtrl::nameUpdatedCallback, this, _1, _2, _3, _4)); } -void LLAvatarIconCtrl::updateFromCache(LLAvatarIconCtrl::LLImagesCacheItem data) +bool LLAvatarIconCtrl::updateFromCache() { + LLUUID* icon_id_ptr = LLAvatarIconIDCache::getInstance()->get(mAvatarId); + if(!icon_id_ptr) + return false; + + const LLUUID& icon_id = *icon_id_ptr; + // Update the avatar - if (data.image_id.notNull()) + if (icon_id.notNull()) { - LLIconCtrl::setValue(data.image_id); + LLIconCtrl::setValue(icon_id); } else { LLIconCtrl::setValue("default_profile_picture.j2c"); } - // Can only see online status of friends - if (LLAvatarTracker::instance().isBuddy(mAvatarId)) - { - if (LLAvatarTracker::instance().isBuddyOnline(mAvatarId)) - { - // Update color of status symbol and tool tip - mStatusSymbol->setColor(LLColor4::green); - if (mDrawTooltip) - { - setToolTip((LLStringExplicit)"Online"); - } - } - else - { - mStatusSymbol->setColor(LLColor4::grey); - if (mDrawTooltip) - { - setToolTip((LLStringExplicit)"Offline"); - } - } - } - else - { - // Not a buddy, no information - mStatusSymbol->setColor(LLColor4::grey); - if (mDrawTooltip) - { - setToolTip((LLStringExplicit)""); - } - } + return true; } //virtual @@ -239,10 +288,8 @@ void LLAvatarIconCtrl::processProperties(void* data, EAvatarProcessorType type) return; } - LLAvatarIconCtrl::LLImagesCacheItem data(avatar_data->image_id, avatar_data->flags); - - updateFromCache(data); - sImagesCache.insert(std::pair<LLUUID, LLAvatarIconCtrl::LLImagesCacheItem>(mAvatarId, data)); + LLAvatarIconIDCache::getInstance()->add(mAvatarId,avatar_data->image_id); + updateFromCache(); } } } @@ -283,6 +330,11 @@ void LLAvatarIconCtrl::nameUpdatedCallback( { mFirstName = first; mLastName = last; + + if (mDrawTooltip) + { + setToolTip(mFirstName + " " + mLastName); + } } } |