summaryrefslogtreecommitdiff
path: root/indra/newview/llfavoritesbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llfavoritesbar.cpp')
-rwxr-xr-xindra/newview/llfavoritesbar.cpp407
1 files changed, 245 insertions, 162 deletions
diff --git a/indra/newview/llfavoritesbar.cpp b/indra/newview/llfavoritesbar.cpp
index fc9e85caf8..8f3eaaa207 100755
--- a/indra/newview/llfavoritesbar.cpp
+++ b/indra/newview/llfavoritesbar.cpp
@@ -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"))
- {
- LLFavoritesOrderStorage::instance().saveFavoritesSLURLs();
- }
- else
+ std::string filename = getSavedOrderFileName();
+ file.open(filename.c_str());
+ if (file.is_open())
{
- LLFavoritesOrderStorage::instance().removeFavoritesRecordOfUser();
+ file.close();
+ LLFile::remove(filename);
+ if(mSaveOnExit)
+ {
+ LLFavoritesOrderStorage::instance().saveFavoritesRecord(true);
+ }
}
}
@@ -1503,108 +1543,57 @@ 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;
- }
-
- 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()));
+ 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)
+ {
+ mSortIndexes.insert(std::make_pair(LLUUID(iter->first), (S32)iter->second.asInteger()));
+ }
}
-}
-
-void LLFavoritesOrderStorage::saveFavoritesSLURLs()
-{
- // Do not change the file if we are not logged in yet.
- if (!LLLoginInstance::getInstance()->authSuccess())
+ else
{
- LL_WARNS("FavoritesBar") << "Cannot save favorites: not logged in" << LL_ENDL;
- return;
+ 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;
+ }
+ }
}
-
- 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()
@@ -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);
@@ -1728,6 +1704,17 @@ void LLFavoritesOrderStorage::cleanup()
mSortIndexes.swap(aTempMap);
}
+// See also LLInventorySort where landmarks in the Favorites folder are sorted.
+class LLViewerInventoryItemSort
+{
+public:
+ bool operator()(const LLPointer<LLViewerInventoryItem>& a, const LLPointer<LLViewerInventoryItem>& b)
+ {
+ return LLFavoritesOrderStorage::instance().getSortIndex(a->getUUID())
+ < LLFavoritesOrderStorage::instance().getSortIndex(b->getUUID());
+ }
+};
+
void LLFavoritesOrderStorage::saveOrder()
{
LLInventoryModel::cat_array_t cats;
@@ -1735,13 +1722,14 @@ void LLFavoritesOrderStorage::saveOrder()
LLIsType is_type(LLAssetType::AT_LANDMARK);
LLUUID favorites_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_FAVORITE);
gInventory.collectDescendentsIf(favorites_id, cats, items, LLInventoryModel::EXCLUDE_TRASH, is_type);
+ std::sort(items.begin(), items.end(), LLViewerInventoryItemSort());
saveItemsOrder(items);
}
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)
{
@@ -1760,16 +1748,7 @@ void LLFavoritesOrderStorage::saveItemsOrder( const LLInventoryModel::item_array
gInventory.notifyObservers();
}
-// See also LLInventorySort where landmarks in the Favorites folder are sorted.
-class LLViewerInventoryItemSort
-{
-public:
- bool operator()(const LLPointer<LLViewerInventoryItem>& a, const LLPointer<LLViewerInventoryItem>& b)
- {
- return LLFavoritesOrderStorage::instance().getSortIndex(a->getUUID())
- < LLFavoritesOrderStorage::instance().getSortIndex(b->getUUID());
- }
-};
+
// * @param source_item_id - LLUUID of the source item to be moved into new position
// * @param target_item_id - LLUUID of the target item before which source item should be placed.
@@ -1790,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;