PageRenderTime 60ms CodeModel.GetById 28ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llviewerfoldertype.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 316 lines | 245 code | 35 blank | 36 comment | 29 complexity | a06bb8676d4721028e961c61d13de32d MD5 | raw file
  1/** 
  2 * @file llfoldertype.cpp
  3 * @brief Implementation of LLViewerFolderType functionality.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llviewerfoldertype.h"
 30#include "lldictionary.h"
 31#include "llmemory.h"
 32#include "llvisualparam.h"
 33
 34static const std::string empty_string;
 35
 36struct ViewerFolderEntry : public LLDictionaryEntry
 37{
 38	// Constructor for non-ensembles
 39	ViewerFolderEntry(const std::string &new_category_name, // default name when creating a new category of this type
 40					  const std::string &icon_name_open,	// name of the folder icon
 41					  const std::string &icon_name_closed,
 42					  BOOL is_quiet,						// folder doesn't need a UI update when changed
 43					  bool hide_if_empty,					// folder not shown if empty
 44					  const std::string &dictionary_name = empty_string // no reverse lookup needed on non-ensembles, so in most cases just leave this blank
 45		) 
 46		:
 47		LLDictionaryEntry(dictionary_name),
 48		mNewCategoryName(new_category_name),
 49		mIconNameOpen(icon_name_open),
 50		mIconNameClosed(icon_name_closed),
 51		mIsQuiet(is_quiet),
 52		mHideIfEmpty(hide_if_empty)
 53	{
 54		mAllowedNames.clear();
 55	}
 56
 57	// Constructor for ensembles
 58	ViewerFolderEntry(const std::string &xui_name, 			// name of the xui menu item
 59					  const std::string &new_category_name, // default name when creating a new category of this type
 60					  const std::string &icon_name, 		// name of the folder icon
 61					  const std::string allowed_names 		// allowed item typenames for this folder type
 62		) 
 63		:
 64		LLDictionaryEntry(xui_name),
 65		/* Just use default icons until we actually support ensembles
 66		mIconNameOpen(icon_name),
 67		mIconNameClosed(icon_name),
 68		*/
 69		mIconNameOpen("Inv_FolderOpen"), mIconNameClosed("Inv_FolderClosed"),
 70		mNewCategoryName(new_category_name),
 71		mIsQuiet(FALSE),
 72		mHideIfEmpty(false)
 73	{
 74		const std::string delims (",");
 75		LLStringUtilBase<char>::getTokens(allowed_names, mAllowedNames, delims);
 76	}
 77
 78	bool getIsAllowedName(const std::string &name) const
 79	{
 80		if (mAllowedNames.empty())
 81			return false;
 82		for (name_vec_t::const_iterator iter = mAllowedNames.begin();
 83			 iter != mAllowedNames.end();
 84			 iter++)
 85		{
 86			if (name == (*iter))
 87				return true;
 88		}
 89		return false;
 90	}
 91	const std::string mIconNameOpen;
 92	const std::string mIconNameClosed;
 93	const std::string mNewCategoryName;
 94	typedef std::vector<std::string> name_vec_t;
 95	name_vec_t mAllowedNames;
 96	BOOL mIsQuiet;
 97	bool mHideIfEmpty;
 98};
 99
100class LLViewerFolderDictionary : public LLSingleton<LLViewerFolderDictionary>,
101								 public LLDictionary<LLFolderType::EType, ViewerFolderEntry>
102{
103public:
104	LLViewerFolderDictionary();
105protected:
106	bool initEnsemblesFromFile(); // Reads in ensemble information from foldertypes.xml
107};
108
109LLViewerFolderDictionary::LLViewerFolderDictionary()
110{
111	//       													    	  NEW CATEGORY NAME         FOLDER OPEN             FOLDER CLOSED          QUIET?      HIDE IF EMPTY?
112	//      												  		     |-------------------------|-----------------------|----------------------|-----------|--------------|
113	addEntry(LLFolderType::FT_TEXTURE, 				new ViewerFolderEntry("Textures",				"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
114	addEntry(LLFolderType::FT_SOUND, 				new ViewerFolderEntry("Sounds",					"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
115	addEntry(LLFolderType::FT_CALLINGCARD, 			new ViewerFolderEntry("Calling Cards",			"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
116	addEntry(LLFolderType::FT_LANDMARK, 			new ViewerFolderEntry("Landmarks",				"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
117	addEntry(LLFolderType::FT_CLOTHING, 			new ViewerFolderEntry("Clothing",				"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
118	addEntry(LLFolderType::FT_OBJECT, 				new ViewerFolderEntry("Objects",				"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
119	addEntry(LLFolderType::FT_NOTECARD, 			new ViewerFolderEntry("Notecards",				"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
120	addEntry(LLFolderType::FT_ROOT_INVENTORY, 		new ViewerFolderEntry("My Inventory",			"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     false));
121	addEntry(LLFolderType::FT_LSL_TEXT, 			new ViewerFolderEntry("Scripts",				"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
122	addEntry(LLFolderType::FT_BODYPART, 			new ViewerFolderEntry("Body Parts",				"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
123	addEntry(LLFolderType::FT_TRASH, 				new ViewerFolderEntry("Trash",					"Inv_TrashOpen",		"Inv_TrashClosed",		TRUE,      false));
124	addEntry(LLFolderType::FT_SNAPSHOT_CATEGORY, 	new ViewerFolderEntry("Photo Album",			"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
125	addEntry(LLFolderType::FT_LOST_AND_FOUND, 		new ViewerFolderEntry("Lost And Found",	   		"Inv_LostOpen",			"Inv_LostClosed",		TRUE,      true));
126	addEntry(LLFolderType::FT_ANIMATION, 			new ViewerFolderEntry("Animations",				"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
127	addEntry(LLFolderType::FT_GESTURE, 				new ViewerFolderEntry("Gestures",				"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
128	addEntry(LLFolderType::FT_FAVORITE, 			new ViewerFolderEntry("Favorites",				"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
129
130	addEntry(LLFolderType::FT_CURRENT_OUTFIT, 		new ViewerFolderEntry("Current Outfit",			"Inv_SysOpen",			"Inv_SysClosed",		TRUE,      false));
131	addEntry(LLFolderType::FT_OUTFIT, 				new ViewerFolderEntry("New Outfit",				"Inv_LookFolderOpen",	"Inv_LookFolderClosed",	TRUE,      true));
132	addEntry(LLFolderType::FT_MY_OUTFITS, 			new ViewerFolderEntry("My Outfits",				"Inv_SysOpen",			"Inv_SysClosed",		TRUE,      true));
133	addEntry(LLFolderType::FT_MESH, 				new ViewerFolderEntry("Meshes",					"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
134	
135	addEntry(LLFolderType::FT_INBOX, 				new ViewerFolderEntry("Inbox",					"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
136	addEntry(LLFolderType::FT_OUTBOX, 				new ViewerFolderEntry("Outbox",					"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
137
138	addEntry(LLFolderType::FT_BASIC_ROOT, 			new ViewerFolderEntry("Basic Root",				"Inv_SysOpen",			"Inv_SysClosed",		FALSE,     true));
139		 
140	addEntry(LLFolderType::FT_NONE, 				new ViewerFolderEntry("New Folder",				"Inv_FolderOpen",		"Inv_FolderClosed",		FALSE,     false, "default"));
141
142#if SUPPORT_ENSEMBLES
143	initEnsemblesFromFile();
144#else
145	for (U32 type = (U32)LLFolderType::FT_ENSEMBLE_START; type <= (U32)LLFolderType::FT_ENSEMBLE_END; ++type)
146	{
147		addEntry((LLFolderType::EType)type, 		new ViewerFolderEntry("New Folder",				"Inv_FolderOpen",		"Inv_FolderClosed",		FALSE,     false));
148	}	
149#endif
150}
151
152bool LLViewerFolderDictionary::initEnsemblesFromFile()
153{
154	std::string xml_filename = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"foldertypes.xml");
155	LLXmlTree folder_def;
156	if (!folder_def.parseFile(xml_filename))
157	{
158		llerrs << "Failed to parse folders file " << xml_filename << llendl;
159		return false;
160	}
161
162	LLXmlTreeNode* rootp = folder_def.getRoot();
163	for (LLXmlTreeNode* ensemble = rootp->getFirstChild();
164		 ensemble;
165		 ensemble = rootp->getNextChild())
166	{
167		if (!ensemble->hasName("ensemble"))
168		{
169			llwarns << "Invalid ensemble definition node " << ensemble->getName() << llendl;
170			continue;
171		}
172
173		S32 ensemble_type;
174		static LLStdStringHandle ensemble_num_string = LLXmlTree::addAttributeString("foldertype_num");
175		if (!ensemble->getFastAttributeS32(ensemble_num_string, ensemble_type))
176		{
177			llwarns << "No ensemble type defined" << llendl;
178			continue;
179		}
180
181
182		if (ensemble_type < S32(LLFolderType::FT_ENSEMBLE_START) || ensemble_type > S32(LLFolderType::FT_ENSEMBLE_END))
183		{
184			llwarns << "Exceeded maximum ensemble index" << LLFolderType::FT_ENSEMBLE_END << llendl;
185			break;
186		}
187
188		std::string xui_name;
189		static LLStdStringHandle xui_name_string = LLXmlTree::addAttributeString("xui_name");
190		if (!ensemble->getFastAttributeString(xui_name_string, xui_name))
191		{
192			llwarns << "No xui name defined" << llendl;
193			continue;
194		}
195
196		std::string icon_name;
197		static LLStdStringHandle icon_name_string = LLXmlTree::addAttributeString("icon_name");
198		if (!ensemble->getFastAttributeString(icon_name_string, icon_name))
199		{
200			llwarns << "No ensemble icon name defined" << llendl;
201			continue;
202		}
203
204		std::string allowed_names;
205		static LLStdStringHandle allowed_names_string = LLXmlTree::addAttributeString("allowed");
206		if (!ensemble->getFastAttributeString(allowed_names_string, allowed_names))
207		{
208		}
209
210		// Add the entry and increment the asset number.
211		const static std::string new_ensemble_name = "New Ensemble";
212		addEntry(LLFolderType::EType(ensemble_type), new ViewerFolderEntry(xui_name, new_ensemble_name, icon_name, allowed_names));
213	}
214
215	return true;
216}
217
218
219const std::string &LLViewerFolderType::lookupXUIName(LLFolderType::EType folder_type)
220{
221	const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
222	if (entry)
223	{
224		return entry->mName;
225	}
226	return badLookup();
227}
228
229LLFolderType::EType LLViewerFolderType::lookupTypeFromXUIName(const std::string &name)
230{
231	return LLViewerFolderDictionary::getInstance()->lookup(name);
232}
233
234const std::string &LLViewerFolderType::lookupIconName(LLFolderType::EType folder_type, BOOL is_open)
235{
236	const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
237	if (entry)
238	{
239		if (is_open)
240			return entry->mIconNameOpen;
241		else
242			return entry->mIconNameClosed;
243	}
244	
245	// Error condition.  Return something so that we don't show a grey box in inventory view.
246	const ViewerFolderEntry *default_entry = LLViewerFolderDictionary::getInstance()->lookup(LLFolderType::FT_NONE);
247	if (default_entry)
248	{
249		return default_entry->mIconNameClosed;
250	}
251	
252	// Should not get here unless there's something corrupted with the FT_NONE entry.
253	return badLookup();
254}
255
256BOOL LLViewerFolderType::lookupIsQuietType(LLFolderType::EType folder_type)
257{
258	const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
259	if (entry)
260	{
261		return entry->mIsQuiet;
262	}
263	return FALSE;
264}
265
266bool LLViewerFolderType::lookupIsHiddenIfEmpty(LLFolderType::EType folder_type)
267{
268	const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
269	if (entry)
270	{
271		return entry->mHideIfEmpty;
272	}
273	return false;
274}
275
276const std::string &LLViewerFolderType::lookupNewCategoryName(LLFolderType::EType folder_type)
277{
278	const ViewerFolderEntry *entry = LLViewerFolderDictionary::getInstance()->lookup(folder_type);
279	if (entry)
280	{
281		return entry->mNewCategoryName;
282	}
283	return badLookup();
284}
285
286LLFolderType::EType LLViewerFolderType::lookupTypeFromNewCategoryName(const std::string& name)
287{
288	for (LLViewerFolderDictionary::const_iterator iter = LLViewerFolderDictionary::getInstance()->begin();
289		 iter != LLViewerFolderDictionary::getInstance()->end();
290		 iter++)
291	{
292		const ViewerFolderEntry *entry = iter->second;
293		if (entry->mNewCategoryName == name)
294		{
295			return iter->first;
296		}
297	}
298	return FT_NONE;
299}
300
301
302U64 LLViewerFolderType::lookupValidFolderTypes(const std::string& item_name)
303{
304	U64 matching_folders = 0;
305	for (LLViewerFolderDictionary::const_iterator iter = LLViewerFolderDictionary::getInstance()->begin();
306		 iter != LLViewerFolderDictionary::getInstance()->end();
307		 iter++)
308	{
309		const ViewerFolderEntry *entry = iter->second;
310		if (entry->getIsAllowedName(item_name))
311		{
312			matching_folders |= 1LL << iter->first;
313		}
314	}
315	return matching_folders;
316}