MAINT-5001 FIXED Logging in and then quickly logging out removes stored favorite login locations

master
Mnikolenko ProductEngine 2015-06-23 12:47:54 +03:00
parent e998f1427f
commit 3e0f31f406
7 changed files with 279 additions and 166 deletions

View File

@ -31,3 +31,4 @@
LLUUID gAgentID;
LLUUID gAgentSessionID;
std::string gAgentUsername;

View File

@ -30,5 +30,6 @@
extern LLUUID gAgentID;
extern LLUUID gAgentSessionID;
extern std::string gAgentUsername;
#endif

View File

@ -380,9 +380,11 @@ LLFavoritesBarCtrl::LLFavoritesBarCtrl(const LLFavoritesBarCtrl::Params& p)
mShowDragMarker(FALSE),
mLandingTab(NULL),
mLastTab(NULL),
mTabsHighlightEnabled(TRUE)
, mUpdateDropDownItems(true)
, mRestoreOverflowMenu(false)
mTabsHighlightEnabled(TRUE),
mUpdateDropDownItems(true),
mRestoreOverflowMenu(false),
mGetPrevItems(true),
mItemsChangedTimer()
{
// Register callback for menus with current registrar (will be parent panel's registrar)
LLUICtrl::CommitCallbackRegistry::currentRegistrar().add("Favorites.DoToSelected",
@ -659,6 +661,15 @@ void LLFavoritesBarCtrl::changed(U32 mask)
LLFavoritesOrderStorage::instance().getSLURL((*i)->getAssetUUID());
}
updateButtons();
if (!mItemsChangedTimer.getStarted())
{
mItemsChangedTimer.start();
}
else
{
mItemsChangedTimer.reset();
}
}
}
@ -693,6 +704,21 @@ void LLFavoritesBarCtrl::draw()
// Once drawn, mark this false so we won't draw it again (unless we hit the favorite bar again)
mShowDragMarker = FALSE;
}
if (mItemsChangedTimer.getStarted())
{
if (mItemsChangedTimer.getElapsedTimeF32() > 1.f)
{
LLFavoritesOrderStorage::instance().saveFavoritesRecord();
mItemsChangedTimer.stop();
}
}
if(!mItemsChangedTimer.getStarted() && LLFavoritesOrderStorage::instance().mUpdateRequired)
{
LLFavoritesOrderStorage::instance().mUpdateRequired = false;
mItemsChangedTimer.start();
}
}
const LLButton::Params& LLFavoritesBarCtrl::getButtonParams()
@ -723,6 +749,12 @@ void LLFavoritesBarCtrl::updateButtons()
return;
}
if(mGetPrevItems)
{
LLFavoritesOrderStorage::instance().mPrevFavorites = mItems;
mGetPrevItems = false;
}
const LLButton::Params& button_params = getButtonParams();
if(mItems.empty())
@ -844,6 +876,7 @@ void LLFavoritesBarCtrl::updateButtons()
{
mUpdateDropDownItems = false;
}
}
LLButton* LLFavoritesBarCtrl::createButton(const LLPointer<LLViewerInventoryItem> item, const LLButton::Params& button_params, S32 x_offset)
@ -912,9 +945,11 @@ BOOL LLFavoritesBarCtrl::postBuild()
BOOL LLFavoritesBarCtrl::collectFavoriteItems(LLInventoryModel::item_array_t &items)
{
if (mFavoriteFolderId.isNull())
return FALSE;
LLInventoryModel::cat_array_t cats;
LLIsType is_type(LLAssetType::AT_LANDMARK);
@ -1411,6 +1446,7 @@ void LLFavoritesBarCtrl::insertItem(LLInventoryModel::item_array_t& items, const
const std::string LLFavoritesOrderStorage::SORTING_DATA_FILE_NAME = "landmarks_sorting.xml";
const S32 LLFavoritesOrderStorage::NO_INDEX = -1;
bool LLFavoritesOrderStorage::mSaveOnExit = false;
void LLFavoritesOrderStorage::setSortIndex(const LLViewerInventoryItem* inv_item, S32 sort_index)
{
@ -1447,6 +1483,7 @@ void LLFavoritesOrderStorage::getSLURL(const LLUUID& asset_id)
LL_DEBUGS("FavoritesBar") << "landmark for " << asset_id << " already loaded" << LL_ENDL;
onLandmarkLoaded(asset_id, lm);
}
return;
}
// static
@ -1482,13 +1519,16 @@ void LLFavoritesOrderStorage::destroyClass()
LLFile::remove(old_filename);
}
if (gSavedPerAccountSettings.getBOOL("ShowFavoritesOnLogin"))
std::string filename = getSavedOrderFileName();
file.open(filename.c_str());
if (file.is_open())
{
LLFavoritesOrderStorage::instance().saveFavoritesSLURLs();
}
else
{
LLFavoritesOrderStorage::instance().removeFavoritesRecordOfUser();
file.close();
LLFile::remove(filename);
if(mSaveOnExit)
{
LLFavoritesOrderStorage::instance().saveFavoritesRecord(true);
}
}
}
@ -1503,110 +1543,59 @@ std::string LLFavoritesOrderStorage::getSavedOrderFileName()
void LLFavoritesOrderStorage::load()
{
// load per-resident sorting information
std::string filename = getSavedOrderFileName();
LLSD settings_llsd;
llifstream file;
file.open(filename.c_str());
if (file.is_open())
{
LLSDSerialize::fromXML(settings_llsd, file);
LL_INFOS("FavoritesBar") << "loaded favorites order from '" << filename << "' "
<< (settings_llsd.isMap() ? "" : "un") << "successfully"
<< LL_ENDL;
file.close();
}
else
{
LL_WARNS("FavoritesBar") << "unable to open favorites order file at '" << filename << "'" << LL_ENDL;
}
LL_INFOS("FavoritesBar") << "loaded favorites order from '" << filename << "' "
<< (settings_llsd.isMap() ? "" : "un") << "successfully"
<< LL_ENDL;
file.close();
mSaveOnExit = true;
for (LLSD::map_const_iterator iter = settings_llsd.beginMap();
iter != settings_llsd.endMap(); ++iter)
for (LLSD::map_const_iterator iter = settings_llsd.beginMap();
iter != settings_llsd.endMap(); ++iter)
{
mSortIndexes.insert(std::make_pair(LLUUID(iter->first), (S32)iter->second.asInteger()));
}
}
else
{
mSortIndexes.insert(std::make_pair(LLUUID(iter->first), (S32)iter->second.asInteger()));
filename = getStoredFavoritesFilename();
if (!filename.empty())
{
llifstream in_file;
in_file.open(filename.c_str());
LLSD fav_llsd;
LLSD user_llsd;
if (in_file.is_open())
{
LLSDSerialize::fromXML(fav_llsd, in_file);
LL_INFOS("FavoritesBar") << "loaded favorites from '" << filename << "' "
<< (fav_llsd.isMap() ? "" : "un") << "successfully"
<< LL_ENDL;
in_file.close();
user_llsd = fav_llsd[gAgentUsername];
S32 index = 0;
for (LLSD::array_iterator iter = user_llsd.beginArray();
iter != user_llsd.endArray(); ++iter)
{
mSortIndexes.insert(std::make_pair(iter->get("id").asUUID(), index));
index++;
}
}
else
{
LL_WARNS("FavoritesBar") << "unable to open favorites from '" << filename << "'" << LL_ENDL;
}
}
}
}
void LLFavoritesOrderStorage::saveFavoritesSLURLs()
{
// Do not change the file if we are not logged in yet.
if (!LLLoginInstance::getInstance()->authSuccess())
{
LL_WARNS("FavoritesBar") << "Cannot save favorites: not logged in" << LL_ENDL;
return;
}
std::string filename = getStoredFavoritesFilename();
if (!filename.empty())
{
llifstream in_file;
in_file.open(filename.c_str());
LLSD fav_llsd;
if (in_file.is_open())
{
LLSDSerialize::fromXML(fav_llsd, in_file);
LL_INFOS("FavoritesBar") << "loaded favorites from '" << filename << "' "
<< (fav_llsd.isMap() ? "" : "un") << "successfully"
<< LL_ENDL;
in_file.close();
}
else
{
LL_WARNS("FavoritesBar") << "unable to open favorites from '" << filename << "'" << LL_ENDL;
}
const LLUUID fav_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_FAVORITE);
LLInventoryModel::cat_array_t cats;
LLInventoryModel::item_array_t items;
gInventory.collectDescendents(fav_id, cats, items, LLInventoryModel::EXCLUDE_TRASH);
LLSD user_llsd;
for (LLInventoryModel::item_array_t::iterator it = items.begin(); it != items.end(); it++)
{
LLSD value;
value["name"] = (*it)->getName();
value["asset_id"] = (*it)->getAssetUUID();
slurls_map_t::iterator slurl_iter = mSLURLs.find(value["asset_id"]);
if (slurl_iter != mSLURLs.end())
{
LL_DEBUGS("FavoritesBar") << "Saving favorite: idx=" << LLFavoritesOrderStorage::instance().getSortIndex((*it)->getUUID()) << ", SLURL=" << slurl_iter->second << ", value=" << value << LL_ENDL;
value["slurl"] = slurl_iter->second;
user_llsd[LLFavoritesOrderStorage::instance().getSortIndex((*it)->getUUID())] = value;
}
else
{
LL_WARNS("FavoritesBar") << "Not saving favorite " << value["name"] << ": no matching SLURL" << LL_ENDL;
}
}
LLAvatarName av_name;
LLAvatarNameCache::get( gAgentID, &av_name );
// Note : use the "John Doe" and not the "john.doe" version of the name
// as we'll compare it with the stored credentials in the login panel.
fav_llsd[av_name.getUserName()] = user_llsd;
llofstream file;
file.open(filename.c_str());
if ( file.is_open() )
{
LLSDSerialize::toPrettyXML(fav_llsd, file);
LL_INFOS("FavoritesBar") << "saved favorites for '" << av_name.getUserName()
<< "' to '" << filename << "' "
<< LL_ENDL;
file.close();
}
else
{
LL_WARNS("FavoritesBar") << "unable to open favorites storage for '" << av_name.getUserName()
<< "' at '" << filename << "' "
<< LL_ENDL;
}
}
}
void LLFavoritesOrderStorage::removeFavoritesRecordOfUser()
{
std::string filename = getStoredFavoritesFilename();
@ -1626,8 +1615,30 @@ void LLFavoritesOrderStorage::removeFavoritesRecordOfUser()
// See saveFavoritesSLURLs() here above for the reason why.
if (fav_llsd.has(av_name.getUserName()))
{
LL_INFOS("FavoritesBar") << "Removed favorites for " << av_name.getUserName() << LL_ENDL;
fav_llsd.erase(av_name.getUserName());
LLSD user_llsd = fav_llsd[av_name.getUserName()];
if (user_llsd.beginArray()->has("id"))
{
for (LLSD::array_iterator iter = user_llsd.beginArray();iter != user_llsd.endArray(); ++iter)
{
LLSD value;
value["id"]= iter->get("id").asUUID();
iter->assign(value);
}
fav_llsd[av_name.getUserName()] = user_llsd;
llofstream file;
file.open(filename.c_str());
if ( file.is_open() )
{
LLSDSerialize::toPrettyXML(fav_llsd, file);
file.close();
}
}
else
{
LL_INFOS("FavoritesBar") << "Removed favorites for " << av_name.getUserName() << LL_ENDL;
fav_llsd.erase(av_name.getUserName());
}
}
llofstream out_file;
@ -1648,20 +1659,20 @@ void LLFavoritesOrderStorage::onLandmarkLoaded(const LLUUID& asset_id, LLLandmar
if (landmark)
{
LL_DEBUGS("FavoritesBar") << "landmark for " << asset_id << " loaded" << LL_ENDL;
LLVector3d pos_global;
if (!landmark->getGlobalPos(pos_global))
{
// If global position was unknown on first getGlobalPos() call
// it should be set for the subsequent calls.
landmark->getGlobalPos(pos_global);
}
LLVector3d pos_global;
if (!landmark->getGlobalPos(pos_global))
{
// If global position was unknown on first getGlobalPos() call
// it should be set for the subsequent calls.
landmark->getGlobalPos(pos_global);
}
if (!pos_global.isExactlyZero())
{
LL_DEBUGS("FavoritesBar") << "requesting slurl for landmark " << asset_id << LL_ENDL;
LLLandmarkActions::getSLURLfromPosGlobal(pos_global,
if (!pos_global.isExactlyZero())
{
LL_DEBUGS("FavoritesBar") << "requesting slurl for landmark " << asset_id << LL_ENDL;
LLLandmarkActions::getSLURLfromPosGlobal(pos_global,
boost::bind(&LLFavoritesOrderStorage::storeFavoriteSLURL, this, asset_id, _1));
}
}
}
}
@ -1671,41 +1682,6 @@ void LLFavoritesOrderStorage::storeFavoriteSLURL(const LLUUID& asset_id, std::st
mSLURLs[asset_id] = slurl;
}
void LLFavoritesOrderStorage::save()
{
if (mIsDirty)
{
// something changed, so save it
std::string filename = LLFavoritesOrderStorage::getInstance()->getSavedOrderFileName();
if (!filename.empty())
{
LLSD settings_llsd;
for(sort_index_map_t::const_iterator iter = mSortIndexes.begin(); iter != mSortIndexes.end(); ++iter)
{
settings_llsd[iter->first.asString()] = iter->second;
}
llofstream file;
file.open(filename.c_str());
if ( file.is_open() )
{
LLSDSerialize::toPrettyXML(settings_llsd, file);
LL_INFOS("FavoritesBar") << "saved favorites order to '" << filename << "' " << LL_ENDL;
}
else
{
LL_WARNS("FavoritesBar") << "failed to open favorites order file '" << filename << "' " << LL_ENDL;
}
}
else
{
LL_DEBUGS("FavoritesBar") << "no user directory available to store favorites order file" << LL_ENDL;
}
}
}
void LLFavoritesOrderStorage::cleanup()
{
// nothing to clean
@ -1720,7 +1696,7 @@ void LLFavoritesOrderStorage::cleanup()
sort_index_map_t aTempMap;
//copy unremoved values from mSortIndexes to aTempMap
std::remove_copy_if(mSortIndexes.begin(), mSortIndexes.end(),
std::remove_copy_if(mSortIndexes.begin(), mSortIndexes.end(),
inserter(aTempMap, aTempMap.begin()),
is_not_in_fav);
@ -1752,8 +1728,8 @@ void LLFavoritesOrderStorage::saveOrder()
void LLFavoritesOrderStorage::saveItemsOrder( const LLInventoryModel::item_array_t& items )
{
int sortField = 0;
int sortField = 0;
// current order is saved by setting incremental values (1, 2, 3, ...) for the sort field
for (LLInventoryModel::item_array_t::const_iterator i = items.begin(); i != items.end(); ++i)
{
@ -1793,6 +1769,110 @@ void LLFavoritesOrderStorage::rearrangeFavoriteLandmarks(const LLUUID& source_it
saveItemsOrder(items);
}
BOOL LLFavoritesOrderStorage::saveFavoritesRecord(bool pref_changed)
{
LLUUID favorite_folder= gInventory.findCategoryUUIDForType(LLFolderType::FT_FAVORITE);
if (favorite_folder.isNull())
return FALSE;
LLInventoryModel::item_array_t items;
LLInventoryModel::cat_array_t cats;
LLIsType is_type(LLAssetType::AT_LANDMARK);
gInventory.collectDescendentsIf(favorite_folder, cats, items, LLInventoryModel::EXCLUDE_TRASH, is_type);
std::sort(items.begin(), items.end(), LLFavoritesSort());
if((items != mPrevFavorites) || pref_changed)
{
std::string filename = getStoredFavoritesFilename();
if (!filename.empty())
{
llifstream in_file;
in_file.open(filename.c_str());
LLSD fav_llsd;
if (in_file.is_open())
{
LLSDSerialize::fromXML(fav_llsd, in_file);
in_file.close();
}
else
{
LL_WARNS("FavoritesBar") << "unable to open favorites from '" << filename << "'" << LL_ENDL;
}
LLSD user_llsd;
S32 fav_iter = 0;
for (LLInventoryModel::item_array_t::iterator it = items.begin(); it != items.end(); it++)
{
LLSD value;
if (gSavedPerAccountSettings.getBOOL("ShowFavoritesOnLogin"))
{
value["name"] = (*it)->getName();
value["asset_id"] = (*it)->getAssetUUID();
value["id"] = (*it)->getUUID();
slurls_map_t::iterator slurl_iter = mSLURLs.find(value["asset_id"]);
if (slurl_iter != mSLURLs.end())
{
value["slurl"] = slurl_iter->second;
user_llsd[fav_iter] = value;
}
else
{
getSLURL((*it)->getAssetUUID());
mUpdateRequired = true;
return FALSE;
}
}
else
{
value["id"] = (*it)->getUUID();
user_llsd[fav_iter] = value;
}
fav_iter ++;
}
LLAvatarName av_name;
LLAvatarNameCache::get( gAgentID, &av_name );
// Note : use the "John Doe" and not the "john.doe" version of the name
// as we'll compare it with the stored credentials in the login panel.
fav_llsd[av_name.getUserName()] = user_llsd;
llofstream file;
file.open(filename.c_str());
if ( file.is_open() )
{
LLSDSerialize::toPrettyXML(fav_llsd, file);
file.close();
mSaveOnExit = false;
}
else
{
LL_WARNS("FavoritesBar") << "unable to open favorites storage for '" << av_name.getUserName()
<< "' at '" << filename << "' " << LL_ENDL;
}
}
mPrevFavorites = items;
}
return TRUE;
}
void LLFavoritesOrderStorage::showFavoritesOnLoginChanged(BOOL show)
{
if (show)
{
saveFavoritesRecord(true);
}
else
{
removeFavoritesRecordOfUser();
}
}
void AddFavoriteLandmarkCallback::fire(const LLUUID& inv_item_id)
{
if (mTargetLandmarkId.isNull()) return;

View File

@ -105,8 +105,10 @@ protected:
bool mUpdateDropDownItems;
bool mRestoreOverflowMenu;
LLUUID mSelectedItemID;
bool mGetPrevItems;
LLUUID mSelectedItemID;
LLFrameTimer mItemsChangedTimer;
LLUIImage* mImageDragIndication;
private:
@ -204,12 +206,23 @@ public:
* @see cleanup()
*/
static void destroyClass();
static std::string getStoredFavoritesFilename();
static std::string getSavedOrderFileName();
BOOL saveFavoritesRecord(bool pref_changed = false);
void showFavoritesOnLoginChanged(BOOL show);
LLInventoryModel::item_array_t mPrevFavorites;
const static S32 NO_INDEX;
static bool mSaveOnExit;
bool mUpdateRequired;
private:
friend class LLSingleton<LLFavoritesOrderStorage>;
LLFavoritesOrderStorage() : mIsDirty(false) { load(); }
~LLFavoritesOrderStorage() { save(); }
LLFavoritesOrderStorage() : mIsDirty(false), mUpdateRequired(false){ load(); }
~LLFavoritesOrderStorage() {}
/**
* Removes sort indexes for items which are not in Favorites bar for now.
@ -217,13 +230,8 @@ private:
void cleanup();
const static std::string SORTING_DATA_FILE_NAME;
std::string getSavedOrderFileName();
static std::string getStoredFavoritesFilename();
void load();
void save();
void saveFavoritesSLURLs();
void load();
// Remove record of current user's favorites from file on disk.
void removeFavoritesRecordOfUser();

View File

@ -49,6 +49,7 @@
//#include "llfirstuse.h"
#include "llfloaterreg.h"
#include "llfloaterabout.h"
#include "llfavoritesbar.h"
#include "llfloaterhardwaresettings.h"
#include "llfloatersidepanelcontainer.h"
#include "llfloaterimsession.h"
@ -1919,7 +1920,7 @@ BOOL LLPanelPreference::postBuild()
}
if (hasChild("favorites_on_login_check", TRUE))
{
getChild<LLCheckBoxCtrl>("favorites_on_login_check")->setCommitCallback(boost::bind(&showFavoritesOnLoginWarning, _1, _2));
getChild<LLCheckBoxCtrl>("favorites_on_login_check")->setCommitCallback(boost::bind(&handleFavoritesOnLoginChanged, _1, _2));
bool show_favorites_at_login = LLPanelLogin::getShowFavorites();
getChild<LLCheckBoxCtrl>("favorites_on_login_check")->setValue(show_favorites_at_login);
}
@ -2004,11 +2005,15 @@ void LLPanelPreference::showFriendsOnlyWarning(LLUICtrl* checkbox, const LLSD& v
}
}
void LLPanelPreference::showFavoritesOnLoginWarning(LLUICtrl* checkbox, const LLSD& value)
void LLPanelPreference::handleFavoritesOnLoginChanged(LLUICtrl* checkbox, const LLSD& value)
{
if (checkbox && checkbox->getValue())
if (checkbox)
{
LLNotificationsUtil::add("FavoritesOnLogin");
LLFavoritesOrderStorage::instance().showFavoritesOnLoginChanged(checkbox->getValue().asBoolean());
if(checkbox->getValue())
{
LLNotificationsUtil::add("FavoritesOnLogin");
}
}
}

View File

@ -229,7 +229,7 @@ private:
//for "Only friends and groups can call or IM me"
static void showFriendsOnlyWarning(LLUICtrl*, const LLSD&);
//for "Show my Favorite Landmarks at Login"
static void showFavoritesOnLoginWarning(LLUICtrl* checkbox, const LLSD& value);
static void handleFavoritesOnLoginChanged(LLUICtrl* checkbox, const LLSD& value);
typedef std::map<std::string, LLColor4> string_color_map_t;
string_color_map_t mSavedColors;

View File

@ -3218,6 +3218,23 @@ bool process_login_success_response()
LLStringUtil::trim(gDisplayName);
}
}
std::string first_name;
if(response.has("first_name"))
{
first_name = response["first_name"].asString();
LLStringUtil::replaceChar(first_name, '"', ' ');
LLStringUtil::trim(first_name);
gAgentUsername = first_name;
}
if(response.has("last_name") && !gAgentUsername.empty() && (gAgentUsername != "Resident"))
{
std::string last_name = response["last_name"].asString();
LLStringUtil::replaceChar(last_name, '"', ' ');
LLStringUtil::trim(last_name);
gAgentUsername = gAgentUsername + " " + last_name;
}
if(gDisplayName.empty())
{
if(response.has("first_name"))
@ -3238,6 +3255,7 @@ bool process_login_success_response()
gDisplayName += text;
}
}
if(gDisplayName.empty())
{
gDisplayName.assign(gUserCredential->asString());