summaryrefslogtreecommitdiff
path: root/indra/newview/llfavoritesbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llfavoritesbar.cpp')
-rwxr-xr-x[-rw-r--r--]indra/newview/llfavoritesbar.cpp348
1 files changed, 229 insertions, 119 deletions
diff --git a/indra/newview/llfavoritesbar.cpp b/indra/newview/llfavoritesbar.cpp
index e30dd51acb..fc9e85caf8 100644..100755
--- a/indra/newview/llfavoritesbar.cpp
+++ b/indra/newview/llfavoritesbar.cpp
@@ -40,7 +40,6 @@
#include "llagent.h"
#include "llavatarnamecache.h"
#include "llclipboard.h"
-#include "llclipboard.h"
#include "llinventorybridge.h"
#include "llinventoryfunctions.h"
#include "llfloatersidepanelcontainer.h"
@@ -51,7 +50,7 @@
#include "lltoggleablemenu.h"
#include "llviewerinventory.h"
#include "llviewermenu.h"
-#include "llviewermenu.h"
+#include "llviewernetwork.h"
#include "lltooldraganddrop.h"
#include "llsdserialize.h"
@@ -327,6 +326,7 @@ public:
gInventory.updateItem(item);
gInventory.notifyObservers();
+ LLFavoritesOrderStorage::instance().saveOrder();
}
LLView::getWindow()->setCursor(UI_CURSOR_ARROW);
@@ -400,6 +400,8 @@ LLFavoritesBarCtrl::LLFavoritesBarCtrl(const LLFavoritesBarCtrl::Params& p)
mMoreTextBox->setClickedCallback(boost::bind(&LLFavoritesBarCtrl::showDropDownMenu, this));
addChild(mMoreTextBox);
+ mDropDownItemsCount = 0;
+
LLTextBox::Params label_param(p.label);
mBarLabel = LLUICtrlFactory::create<LLTextBox> (label_param);
addChild(mBarLabel);
@@ -478,7 +480,7 @@ BOOL LLFavoritesBarCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
const LLUUID favorites_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_FAVORITE);
if (item->getParentUUID() == favorites_id)
{
- llwarns << "Attemt to copy a favorite item into the same folder." << llendl;
+ LL_WARNS("FavoritesBar") << "Attemt to copy a favorite item into the same folder." << LL_ENDL;
break;
}
@@ -550,6 +552,10 @@ void LLFavoritesBarCtrl::handleNewFavoriteDragAndDrop(LLInventoryItem *item, con
bool insert_before = true;
if (!mItems.empty())
{
+ // [MAINT-2386] When multiple landmarks are selected and dragged onto an empty favorites bar,
+ // the viewer would crash when casting mLastTab below, as mLastTab is still null when the
+ // second landmark is being added.
+ // To ensure mLastTab is valid, we need to call updateButtons() at the end of this function
dest = dynamic_cast<LLFavoriteLandmarkButton*>(mLandingTab);
if (!dest)
{
@@ -621,7 +627,12 @@ void LLFavoritesBarCtrl::handleNewFavoriteDragAndDrop(LLInventoryItem *item, con
cb);
}
- llinfos << "Copied inventory item #" << item->getUUID() << " to favorites." << llendl;
+ // [MAINT-2386] Ensure the favorite button has been created and is valid.
+ // This also ensures that mLastTab will be valid when dropping multiple
+ // landmarks to an empty favorites bar.
+ updateButtons();
+
+ LL_INFOS("FavoritesBar") << "Copied inventory item #" << item->getUUID() << " to favorites." << LL_ENDL;
}
//virtual
@@ -727,7 +738,7 @@ void LLFavoritesBarCtrl::updateButtons()
int first_changed_item_index = 0;
int rightest_point = getRect().mRight - mMoreTextBox->getRect().getWidth();
//lets find first changed button
- while (child_it != childs->end() && first_changed_item_index < mItems.count())
+ while (child_it != childs->end() && first_changed_item_index < mItems.size())
{
LLFavoriteLandmarkButton* button = dynamic_cast<LLFavoriteLandmarkButton*> (*child_it);
if (button)
@@ -749,7 +760,7 @@ void LLFavoritesBarCtrl::updateButtons()
}
// now first_changed_item_index should contains a number of button that need to change
- if (first_changed_item_index <= mItems.count())
+ if (first_changed_item_index <= mItems.size())
{
// Rebuild the buttons only
// child_list_t is a linked list, so safe to erase from the middle if we pre-increment the iterator
@@ -787,7 +798,7 @@ void LLFavoritesBarCtrl::updateButtons()
//last_right_edge is saving coordinates
LLButton* last_new_button = NULL;
int j = first_changed_item_index;
- for (; j < mItems.count(); j++)
+ for (; j < mItems.size(); j++)
{
last_new_button = createButton(mItems[j], button_params, last_right_edge);
if (!last_new_button)
@@ -801,7 +812,7 @@ void LLFavoritesBarCtrl::updateButtons()
}
mFirstDropDownItem = j;
// Chevron button
- if (mFirstDropDownItem < mItems.count())
+ if (mFirstDropDownItem < mItems.size())
{
// if updateButton had been called it means:
//or there are some new favorites, or width had been changed
@@ -820,11 +831,13 @@ void LLFavoritesBarCtrl::updateButtons()
}
// Update overflow menu
LLToggleableMenu* overflow_menu = static_cast <LLToggleableMenu*> (mOverflowMenuHandle.get());
- if (overflow_menu && overflow_menu->getVisible())
+ if (overflow_menu && overflow_menu->getVisible() && (overflow_menu->getItemCount() != mDropDownItemsCount))
{
overflow_menu->setVisible(FALSE);
if (mUpdateDropDownItems)
+ {
showDropDownMenu();
+ }
}
}
else
@@ -858,7 +871,7 @@ LLButton* LLFavoritesBarCtrl::createButton(const LLPointer<LLViewerInventoryItem
fav_btn = LLUICtrlFactory::create<LLFavoriteLandmarkButton>(fav_btn_params);
if (NULL == fav_btn)
{
- llwarns << "Unable to create LLFavoriteLandmarkButton widget: " << item->getName() << llendl;
+ LL_WARNS("FavoritesBar") << "Unable to create LLFavoriteLandmarkButton widget: " << item->getName() << LL_ENDL;
return NULL;
}
@@ -940,6 +953,7 @@ void LLFavoritesBarCtrl::showDropDownMenu()
menu->updateParent(LLMenuGL::sMenuContainer);
menu->setButtonRect(mMoreTextBox->getRect(), this);
positionAndShowMenu(menu);
+ mDropDownItemsCount = menu->getItemCount();
}
}
@@ -963,9 +977,9 @@ void LLFavoritesBarCtrl::updateMenuItems(LLToggleableMenu* menu)
U32 widest_item = 0;
- for (S32 i = mFirstDropDownItem; i < mItems.count(); i++)
+ for (S32 i = mFirstDropDownItem; i < mItems.size(); i++)
{
- LLViewerInventoryItem* item = mItems.get(i);
+ LLViewerInventoryItem* item = mItems.at(i);
const std::string& item_name = item->getName();
LLFavoriteLandmarkMenuItem::Params item_params;
@@ -1146,7 +1160,7 @@ bool LLFavoritesBarCtrl::enableSelected(const LLSD& userdata)
void LLFavoritesBarCtrl::doToSelected(const LLSD& userdata)
{
std::string action = userdata.asString();
- llinfos << "Action = " << action << " Item = " << mSelectedItemID.asString() << llendl;
+ LL_INFOS("FavoritesBar") << "Action = " << action << " Item = " << mSelectedItemID.asString() << LL_ENDL;
LLViewerInventoryItem* item = gInventory.getItem(mSelectedItemID);
if (!item)
@@ -1221,12 +1235,12 @@ BOOL LLFavoritesBarCtrl::isClipboardPasteable() const
return FALSE;
}
- LLDynamicArray<LLUUID> objects;
+ std::vector<LLUUID> objects;
LLClipboard::instance().pasteFromClipboard(objects);
- S32 count = objects.count();
+ S32 count = objects.size();
for(S32 i = 0; i < count; i++)
{
- const LLUUID &item_id = objects.get(i);
+ const LLUUID &item_id = objects.at(i);
// Can't paste folders
const LLInventoryCategory *cat = gInventory.getCategory(item_id);
@@ -1250,13 +1264,13 @@ void LLFavoritesBarCtrl::pasteFromClipboard() const
if(model && isClipboardPasteable())
{
LLInventoryItem* item = NULL;
- LLDynamicArray<LLUUID> objects;
+ std::vector<LLUUID> objects;
LLClipboard::instance().pasteFromClipboard(objects);
- S32 count = objects.count();
+ S32 count = objects.size();
LLUUID parent_id(mFavoriteFolderId);
for(S32 i = 0; i < count; i++)
{
- item = model->getItem(objects.get(i));
+ item = model->getItem(objects.at(i));
if (item)
{
copy_inventory_item(
@@ -1430,14 +1444,44 @@ void LLFavoritesOrderStorage::getSLURL(const LLUUID& asset_id)
boost::bind(&LLFavoritesOrderStorage::onLandmarkLoaded, this, asset_id, _1));
if (lm)
{
+ LL_DEBUGS("FavoritesBar") << "landmark for " << asset_id << " already loaded" << LL_ENDL;
onLandmarkLoaded(asset_id, lm);
}
}
// static
+std::string LLFavoritesOrderStorage::getStoredFavoritesFilename()
+{
+ std::string user_dir = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "");
+
+ return (user_dir.empty() ? ""
+ : gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS,
+ "stored_favorites_"
+ + LLGridManager::getInstance()->getGrid()
+ + ".xml")
+ );
+}
+
+// static
void LLFavoritesOrderStorage::destroyClass()
{
LLFavoritesOrderStorage::instance().cleanup();
+
+
+ std::string old_filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "stored_favorites.xml");
+ llifstream file;
+ file.open(old_filename.c_str());
+ if (file.is_open())
+ {
+ file.close();
+ std::string new_filename = getStoredFavoritesFilename();
+ LL_INFOS("FavoritesBar") << "moving favorites from old name '" << old_filename
+ << "' to new name '" << new_filename << "'"
+ << LL_ENDL;
+ LLFile::copy(old_filename,new_filename);
+ LLFile::remove(old_filename);
+ }
+
if (gSavedPerAccountSettings.getBOOL("ShowFavoritesOnLogin"))
{
LLFavoritesOrderStorage::instance().saveFavoritesSLURLs();
@@ -1448,18 +1492,35 @@ void LLFavoritesOrderStorage::destroyClass()
}
}
+std::string LLFavoritesOrderStorage::getSavedOrderFileName()
+{
+ // If we quit from the login screen we will not have an SL account
+ // name. Don't try to save, otherwise we'll dump a file in
+ // C:\Program Files\SecondLife\ or similar. JC
+ std::string user_dir = gDirUtilp->getLindenUserDir();
+ return (user_dir.empty() ? "" : gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, SORTING_DATA_FILE_NAME));
+}
+
void LLFavoritesOrderStorage::load()
{
// load per-resident sorting information
- std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, SORTING_DATA_FILE_NAME);
+ std::string filename = getSavedOrderFileName();
LLSD settings_llsd;
llifstream file;
- file.open(filename);
+ 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)
@@ -1473,92 +1534,120 @@ void LLFavoritesOrderStorage::saveFavoritesSLURLs()
// Do not change the file if we are not logged in yet.
if (!LLLoginInstance::getInstance()->authSuccess())
{
- llwarns << "Cannot save favorites: not logged in" << llendl;
- return;
- }
-
- std::string user_dir = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "");
- if (user_dir.empty())
- {
- llwarns << "Cannot save favorites: empty user dir name" << llendl;
+ LL_WARNS("FavoritesBar") << "Cannot save favorites: not logged in" << LL_ENDL;
return;
}
- std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "stored_favorites.xml");
- llifstream in_file;
- in_file.open(filename);
- LLSD fav_llsd;
- if (in_file.is_open())
- {
- LLSDSerialize::fromXML(fav_llsd, in_file);
- }
-
- 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())
- {
- lldebugs << "Saving favorite: idx=" << LLFavoritesOrderStorage::instance().getSortIndex((*it)->getUUID()) << ", SLURL=" << slurl_iter->second << ", value=" << value << llendl;
- value["slurl"] = slurl_iter->second;
- user_llsd[LLFavoritesOrderStorage::instance().getSortIndex((*it)->getUUID())] = value;
- }
- else
- {
- llwarns << "Not saving favorite " << value["name"] << ": no matching SLURL" << llendl;
- }
- }
-
- 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.
- lldebugs << "Saved favorites for " << av_name.getUserName() << llendl;
- fav_llsd[av_name.getUserName()] = user_llsd;
-
- llofstream file;
- file.open(filename);
- LLSDSerialize::toPrettyXML(fav_llsd, file);
+ 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 = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "stored_favorites.xml");
- LLSD fav_llsd;
- llifstream file;
- file.open(filename);
- if (!file.is_open()) return;
- LLSDSerialize::fromXML(fav_llsd, file);
-
- LLAvatarName av_name;
- LLAvatarNameCache::get( gAgentID, &av_name );
- // Note : use the "John Doe" and not the "john.doe" version of the name.
- // See saveFavoritesSLURLs() here above for the reason why.
- lldebugs << "Removed favorites for " << av_name.getUserName() << llendl;
- if (fav_llsd.has(av_name.getUserName()))
- {
- fav_llsd.erase(av_name.getUserName());
- }
-
- llofstream out_file;
- out_file.open(filename);
- LLSDSerialize::toPrettyXML(fav_llsd, out_file);
-
+ std::string filename = getStoredFavoritesFilename();
+ if (!filename.empty())
+ {
+ LLSD fav_llsd;
+ llifstream file;
+ file.open(filename.c_str());
+ if (file.is_open())
+ {
+ LLSDSerialize::fromXML(fav_llsd, file);
+ file.close();
+
+ LLAvatarName av_name;
+ LLAvatarNameCache::get( gAgentID, &av_name );
+ // Note : use the "John Doe" and not the "john.doe" version of the name.
+ // 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());
+ }
+
+ llofstream out_file;
+ out_file.open(filename.c_str());
+ if ( out_file.is_open() )
+ {
+ LLSDSerialize::toPrettyXML(fav_llsd, out_file);
+ LL_INFOS("FavoritesBar") << "saved favorites to '" << filename << "' "
+ << LL_ENDL;
+ out_file.close();
+ }
+ }
+ }
}
void LLFavoritesOrderStorage::onLandmarkLoaded(const LLUUID& asset_id, LLLandmark* landmark)
{
- if (!landmark) return;
-
+ if (landmark)
+ {
+ LL_DEBUGS("FavoritesBar") << "landmark for " << asset_id << " loaded" << LL_ENDL;
LLVector3d pos_global;
if (!landmark->getGlobalPos(pos_global))
{
@@ -1569,42 +1658,54 @@ void LLFavoritesOrderStorage::onLandmarkLoaded(const LLUUID& asset_id, LLLandmar
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));
}
+ }
}
void LLFavoritesOrderStorage::storeFavoriteSLURL(const LLUUID& asset_id, std::string& slurl)
{
- lldebugs << "Saving landmark SLURL: " << slurl << llendl;
+ LL_DEBUGS("FavoritesBar") << "Saving landmark SLURL '" << slurl << "' for " << asset_id << LL_ENDL;
mSLURLs[asset_id] = slurl;
}
void LLFavoritesOrderStorage::save()
{
- // nothing to save if clean
- if (!mIsDirty) return;
-
- // If we quit from the login screen we will not have an SL account
- // name. Don't try to save, otherwise we'll dump a file in
- // C:\Program Files\SecondLife\ or similar. JC
- std::string user_dir = gDirUtilp->getLindenUserDir();
- if (!user_dir.empty())
- {
- std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, SORTING_DATA_FILE_NAME);
- 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);
- LLSDSerialize::toPrettyXML(settings_llsd, file);
- }
+ 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
@@ -1627,6 +1728,16 @@ void LLFavoritesOrderStorage::cleanup()
mSortIndexes.swap(aTempMap);
}
+void LLFavoritesOrderStorage::saveOrder()
+{
+ LLInventoryModel::cat_array_t cats;
+ LLInventoryModel::item_array_t items;
+ 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);
+ saveItemsOrder(items);
+}
+
void LLFavoritesOrderStorage::saveItemsOrder( const LLInventoryModel::item_array_t& items )
{
int sortField = 0;
@@ -1649,7 +1760,6 @@ void LLFavoritesOrderStorage::saveItemsOrder( const LLInventoryModel::item_array
gInventory.notifyObservers();
}
-
// See also LLInventorySort where landmarks in the Favorites folder are sorted.
class LLViewerInventoryItemSort
{