diff options
Diffstat (limited to 'indra/newview/llviewerinventory.cpp')
-rw-r--r-- | indra/newview/llviewerinventory.cpp | 241 |
1 files changed, 187 insertions, 54 deletions
diff --git a/indra/newview/llviewerinventory.cpp b/indra/newview/llviewerinventory.cpp index 31dc83e75a..b69eaa4853 100644 --- a/indra/newview/llviewerinventory.cpp +++ b/indra/newview/llviewerinventory.cpp @@ -34,6 +34,7 @@ #include "llviewerinventory.h" #include "llnotificationsutil.h" +#include "llsdserialize.h" #include "message.h" #include "indra_constants.h" @@ -44,6 +45,7 @@ #include "llconsole.h" #include "llinventorymodel.h" #include "llgesturemgr.h" +#include "llsidetray.h" #include "llinventorybridge.h" #include "llfloaterinventory.h" @@ -72,7 +74,23 @@ public: bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web) { - if (params.size() < 2) return false; + if (params.size() < 1) + { + return false; + } + + // support secondlife:///app/inventory/show + if (params[0].asString() == "show") + { + LLSideTray::getInstance()->showPanel("sidepanel_inventory", LLSD()); + return true; + } + + // otherwise, we need a UUID and a verb... + if (params.size() < 2) + { + return false; + } LLUUID inventory_id; if (!inventory_id.set(params[0], FALSE)) { @@ -631,6 +649,8 @@ bool LLViewerInventoryCategory::exportFileLocal(LLFILE* fp) const void LLViewerInventoryCategory::determineFolderType() { + /* Do NOT uncomment this code. This is for future 2.1 support of ensembles. + llassert(FALSE); LLFolderType::EType original_type = getPreferredType(); if (LLFolderType::lookupIsProtectedType(original_type)) return; @@ -674,6 +694,8 @@ void LLViewerInventoryCategory::determineFolderType() { changeType(LLFolderType::FT_NONE); } + llassert(FALSE); + */ } void LLViewerInventoryCategory::changeType(LLFolderType::EType new_folder_type) @@ -1154,81 +1176,196 @@ const std::string& LLViewerInventoryItem::getName() const return linked_category->getName(); } - return getDisplayName(); + return LLInventoryItem::getName(); } -const std::string& LLViewerInventoryItem::getDisplayName() const +/** + * Class to store sorting order of favorites landmarks in a local file. EXT-3985. + * It replaced previously implemented solution to store sort index in landmark's name as a "<N>@" prefix. + * Data are stored in user home directory. + */ +class LLFavoritesOrderStorage : public LLSingleton<LLFavoritesOrderStorage> + , public LLDestroyClass<LLFavoritesOrderStorage> { - std::string result; - BOOL hasSortField = extractSortFieldAndDisplayName(0, &result); +public: + /** + * Sets sort index for specified with LLUUID favorite landmark + */ + void setSortIndex(const LLUUID& inv_item_id, S32 sort_index); + + /** + * Gets sort index for specified with LLUUID favorite landmark + */ + S32 getSortIndex(const LLUUID& inv_item_id); + void removeSortIndex(const LLUUID& inv_item_id); + + /** + * Implementation of LLDestroyClass. Calls cleanup() instance method. + * + * It is important this callback is called before gInventory is cleaned. + * For now it is called from LLAppViewer::cleanup() -> LLAppViewer::disconnectViewer(), + * Inventory is cleaned later from LLAppViewer::cleanup() after LLAppViewer::disconnectViewer() is called. + * @see cleanup() + */ + static void destroyClass(); + + const static S32 NO_INDEX; +private: + friend class LLSingleton<LLFavoritesOrderStorage>; + LLFavoritesOrderStorage() : mIsDirty(false) { load(); } + ~LLFavoritesOrderStorage() { save(); } + + /** + * Removes sort indexes for items which are not in Favorites bar for now. + */ + void cleanup(); + + const static std::string SORTING_DATA_FILE_NAME; + + void load(); + void save(); + + typedef std::map<LLUUID, S32> sort_index_map_t; + sort_index_map_t mSortIndexes; + + bool mIsDirty; + + struct IsNotInFavorites + { + IsNotInFavorites(const LLInventoryModel::item_array_t& items) + : mFavoriteItems(items) + { - return mDisplayName = hasSortField ? result : LLInventoryItem::getName(); -} + } -// static -std::string LLViewerInventoryItem::getDisplayName(const std::string& name) -{ - std::string result; - BOOL hasSortField = extractSortFieldAndDisplayName(name, 0, &result); + /** + * Returns true if specified item is not found among inventory items + */ + bool operator()(const sort_index_map_t::value_type& id_index_pair) const + { + LLPointer<LLViewerInventoryItem> item = gInventory.getItem(id_index_pair.first); + if (item.isNull()) return true; - return hasSortField ? result : name; -} + LLInventoryModel::item_array_t::const_iterator found_it = + std::find(mFavoriteItems.begin(), mFavoriteItems.end(), item); -S32 LLViewerInventoryItem::getSortField() const -{ - S32 result; - BOOL hasSortField = extractSortFieldAndDisplayName(&result, 0); + return found_it == mFavoriteItems.end(); + } + private: + LLInventoryModel::item_array_t mFavoriteItems; + }; - return hasSortField ? result : -1; +}; + +const std::string LLFavoritesOrderStorage::SORTING_DATA_FILE_NAME = "landmarks_sorting.xml"; +const S32 LLFavoritesOrderStorage::NO_INDEX = -1; + +void LLFavoritesOrderStorage::setSortIndex(const LLUUID& inv_item_id, S32 sort_index) +{ + mSortIndexes[inv_item_id] = sort_index; + mIsDirty = true; } -void LLViewerInventoryItem::setSortField(S32 sortField) +S32 LLFavoritesOrderStorage::getSortIndex(const LLUUID& inv_item_id) { - using std::string; + sort_index_map_t::const_iterator it = mSortIndexes.find(inv_item_id); + if (it != mSortIndexes.end()) + { + return it->second; + } + return NO_INDEX; +} - std::stringstream ss; - ss << sortField; +void LLFavoritesOrderStorage::removeSortIndex(const LLUUID& inv_item_id) +{ + mSortIndexes.erase(inv_item_id); + mIsDirty = true; +} - string newSortField = ss.str(); +// static +void LLFavoritesOrderStorage::destroyClass() +{ + LLFavoritesOrderStorage::instance().cleanup(); +} - const char separator = getSeparator(); - const string::size_type separatorPos = mName.find(separator, 0); +void LLFavoritesOrderStorage::load() +{ + // load per-resident sorting information + std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, SORTING_DATA_FILE_NAME); - if (separatorPos < string::npos) + LLSD settings_llsd; + llifstream file; + file.open(filename); + if (file.is_open()) { - // the name of the LLViewerInventoryItem already consists of sort field and display name. - mName = newSortField + separator + mName.substr(separatorPos + 1, string::npos); + LLSDSerialize::fromXML(settings_llsd, file); } - else + + for (LLSD::map_const_iterator iter = settings_llsd.beginMap(); + iter != settings_llsd.endMap(); ++iter) { - // there is no sort field in the name of LLViewerInventoryItem, we should add it - mName = newSortField + separator + mName; + mSortIndexes.insert(std::make_pair(LLUUID(iter->first), (S32)iter->second.asInteger())); } } -void LLViewerInventoryItem::rename(const std::string& n) +void LLFavoritesOrderStorage::save() { - using std::string; + // nothing to save if clean + if (!mIsDirty) return; - string new_name(n); - LLStringUtil::replaceNonstandardASCII(new_name, ' '); - LLStringUtil::replaceChar(new_name, '|', ' '); - LLStringUtil::trim(new_name); - LLStringUtil::truncate(new_name, DB_INV_ITEM_NAME_STR_LEN); + // 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; - const char separator = getSeparator(); - const string::size_type separatorPos = mName.find(separator, 0); + for(sort_index_map_t::const_iterator iter = mSortIndexes.begin(); iter != mSortIndexes.end(); ++iter) + { + settings_llsd[iter->first.asString()] = iter->second; + } - if (separatorPos < string::npos) - { - mName.replace(separatorPos + 1, string::npos, new_name); - } - else - { - mName = new_name; + llofstream file; + file.open(filename); + LLSDSerialize::toPrettyXML(settings_llsd, file); } } +void LLFavoritesOrderStorage::cleanup() +{ + // nothing to clean + if (!mIsDirty) return; + + 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); + + IsNotInFavorites is_not_in_fav(items); + + sort_index_map_t aTempMap; + //copy unremoved values from mSortIndexes to aTempMap + std::remove_copy_if(mSortIndexes.begin(), mSortIndexes.end(), + inserter(aTempMap, aTempMap.begin()), + is_not_in_fav); + + //Swap the contents of mSortIndexes and aTempMap + mSortIndexes.swap(aTempMap); +} + + +S32 LLViewerInventoryItem::getSortField() const +{ + return LLFavoritesOrderStorage::instance().getSortIndex(mUUID); +} + +void LLViewerInventoryItem::setSortField(S32 sortField) +{ + LLFavoritesOrderStorage::instance().setSortIndex(mUUID, sortField); +} + const LLPermissions& LLViewerInventoryItem::getPermissions() const { // Use the actual permissions of the symlink, not its parent. @@ -1317,6 +1454,8 @@ U32 LLViewerInventoryItem::getCRC32() const return LLInventoryItem::getCRC32(); } +// *TODO: mantipov: should be removed with LMSortPrefix patch in llinventorymodel.cpp, EXT-3985 +static char getSeparator() { return '@'; } BOOL LLViewerInventoryItem::extractSortFieldAndDisplayName(const std::string& name, S32* sortField, std::string* displayName) { using std::string; @@ -1352,12 +1491,6 @@ BOOL LLViewerInventoryItem::extractSortFieldAndDisplayName(const std::string& na return result; } -void LLViewerInventoryItem::insertDefaultSortField(std::string& name) -{ - name.insert(0, std::string("1") + getSeparator()); -} - - // This returns true if the item that this item points to // doesn't exist in memory (i.e. LLInventoryModel). The baseitem // might still be in the database but just not loaded yet. |