PageRenderTime 41ms CodeModel.GetById 14ms app.highlight 22ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llcommon/llfoldertype.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 168 lines | 111 code | 18 blank | 39 comment | 7 complexity | 751df2013b02193977ad2a80e2a4456d MD5 | raw file
  1/** 
  2 * @file llfoldertype.cpp
  3 * @brief Implementatino of LLFolderType 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 "linden_common.h"
 28
 29#include "llfoldertype.h"
 30#include "lldictionary.h"
 31#include "llmemory.h"
 32#include "llsingleton.h"
 33
 34///----------------------------------------------------------------------------
 35/// Class LLFolderType
 36///----------------------------------------------------------------------------
 37struct FolderEntry : public LLDictionaryEntry
 38{
 39	FolderEntry(const std::string &type_name, // 8 character limit!
 40				bool is_protected) // can the viewer change categories of this type?
 41		:
 42	LLDictionaryEntry(type_name),
 43	mIsProtected(is_protected)
 44	{
 45		llassert(type_name.length() <= 8);
 46	}
 47
 48	const bool mIsProtected;
 49};
 50
 51class LLFolderDictionary : public LLSingleton<LLFolderDictionary>,
 52						   public LLDictionary<LLFolderType::EType, FolderEntry>
 53{
 54public:
 55	LLFolderDictionary();
 56protected:
 57	virtual LLFolderType::EType notFound() const
 58	{
 59		return LLFolderType::FT_NONE;
 60	}
 61};
 62
 63LLFolderDictionary::LLFolderDictionary()
 64{
 65	//       													    TYPE NAME	PROTECTED
 66	//      													   |-----------|---------|
 67	addEntry(LLFolderType::FT_TEXTURE, 				new FolderEntry("texture",	TRUE));
 68	addEntry(LLFolderType::FT_SOUND, 				new FolderEntry("sound",	TRUE));
 69	addEntry(LLFolderType::FT_CALLINGCARD, 			new FolderEntry("callcard",	TRUE));
 70	addEntry(LLFolderType::FT_LANDMARK, 			new FolderEntry("landmark",	TRUE));
 71	addEntry(LLFolderType::FT_CLOTHING, 			new FolderEntry("clothing",	TRUE));
 72	addEntry(LLFolderType::FT_OBJECT, 				new FolderEntry("object",	TRUE));
 73	addEntry(LLFolderType::FT_NOTECARD, 			new FolderEntry("notecard",	TRUE));
 74	addEntry(LLFolderType::FT_ROOT_INVENTORY, 		new FolderEntry("root_inv",	TRUE));
 75	addEntry(LLFolderType::FT_LSL_TEXT, 			new FolderEntry("lsltext",	TRUE));
 76	addEntry(LLFolderType::FT_BODYPART, 			new FolderEntry("bodypart",	TRUE));
 77	addEntry(LLFolderType::FT_TRASH, 				new FolderEntry("trash",	TRUE));
 78	addEntry(LLFolderType::FT_SNAPSHOT_CATEGORY, 	new FolderEntry("snapshot", TRUE));
 79	addEntry(LLFolderType::FT_LOST_AND_FOUND, 		new FolderEntry("lstndfnd",	TRUE));
 80	addEntry(LLFolderType::FT_ANIMATION, 			new FolderEntry("animatn",	TRUE));
 81	addEntry(LLFolderType::FT_GESTURE, 				new FolderEntry("gesture",	TRUE));
 82	addEntry(LLFolderType::FT_FAVORITE, 			new FolderEntry("favorite",	TRUE));
 83	
 84	for (S32 ensemble_num = S32(LLFolderType::FT_ENSEMBLE_START); ensemble_num <= S32(LLFolderType::FT_ENSEMBLE_END); ensemble_num++)
 85	{
 86		addEntry(LLFolderType::EType(ensemble_num), new FolderEntry("ensemble", FALSE)); 
 87	}
 88
 89	addEntry(LLFolderType::FT_CURRENT_OUTFIT, 		new FolderEntry("current",	TRUE));
 90	addEntry(LLFolderType::FT_OUTFIT, 				new FolderEntry("outfit",	FALSE));
 91	addEntry(LLFolderType::FT_MY_OUTFITS, 			new FolderEntry("my_otfts",	TRUE));
 92
 93	addEntry(LLFolderType::FT_MESH, 				new FolderEntry("mesh",	TRUE));
 94
 95	addEntry(LLFolderType::FT_INBOX, 				new FolderEntry("inbox",	TRUE));
 96	addEntry(LLFolderType::FT_OUTBOX, 				new FolderEntry("outbox",	TRUE));
 97	addEntry(LLFolderType::FT_BASIC_ROOT,			new FolderEntry("basic_rt", TRUE));
 98		 
 99	addEntry(LLFolderType::FT_NONE, 				new FolderEntry("-1",		FALSE));
100};
101
102// static
103LLFolderType::EType LLFolderType::lookup(const std::string& name)
104{
105	return LLFolderDictionary::getInstance()->lookup(name);
106}
107
108// static
109const std::string &LLFolderType::lookup(LLFolderType::EType folder_type)
110{
111	const FolderEntry *entry = LLFolderDictionary::getInstance()->lookup(folder_type);
112	if (entry)
113	{
114		return entry->mName;
115	}
116	else
117	{
118		return badLookup();
119	}
120}
121
122// static
123// Only ensembles and plain folders aren't protected.  "Protected" means
124// you can't change certain properties such as their type.
125bool LLFolderType::lookupIsProtectedType(EType folder_type)
126{
127	const LLFolderDictionary *dict = LLFolderDictionary::getInstance();
128	const FolderEntry *entry = dict->lookup(folder_type);
129	if (entry)
130	{
131		return entry->mIsProtected;
132	}
133	return true;
134}
135
136// static
137bool LLFolderType::lookupIsEnsembleType(EType folder_type)
138{
139	return (folder_type >= FT_ENSEMBLE_START &&
140			folder_type <= FT_ENSEMBLE_END);
141}
142
143// static
144LLAssetType::EType LLFolderType::folderTypeToAssetType(LLFolderType::EType folder_type)
145{
146	if (LLAssetType::lookup(LLAssetType::EType(folder_type)) == LLAssetType::badLookup())
147	{
148		llwarns << "Converting to unknown asset type " << folder_type << llendl;
149	}
150	return (LLAssetType::EType)folder_type;
151}
152
153// static
154LLFolderType::EType LLFolderType::assetTypeToFolderType(LLAssetType::EType asset_type)
155{
156	if (LLFolderType::lookup(LLFolderType::EType(asset_type)) == LLFolderType::badLookup())
157	{
158		llwarns << "Converting to unknown folder type " << asset_type << llendl;
159	}
160	return (LLFolderType::EType)asset_type;
161}
162
163// static
164const std::string &LLFolderType::badLookup()
165{
166	static const std::string sBadLookup = "llfoldertype_bad_lookup";
167	return sBadLookup;
168}