PageRenderTime 31ms CodeModel.GetById 21ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llviewerassettype.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 111 lines | 71 code | 12 blank | 28 comment | 1 complexity | 11dce91dc3e6833c957d8a426cc318ad MD5 | raw file
  1/** 
  2 * @file llassettype.cpp
  3 * @brief Implementatino of LLViewerAssetType 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 "llviewerassettype.h"
 30#include "lldictionary.h"
 31#include "llmemory.h"
 32#include "llsingleton.h"
 33
 34static const std::string empty_string;
 35
 36struct ViewerAssetEntry : public LLDictionaryEntry
 37{
 38	ViewerAssetEntry(EDragAndDropType dad_type // drag and drop type
 39		)
 40		:
 41		LLDictionaryEntry(empty_string), // no reverse lookup needed for now, so just leave this blank
 42		mDadType(dad_type)
 43	{
 44	}
 45	EDragAndDropType mDadType;
 46};
 47
 48class LLViewerAssetDictionary : public LLSingleton<LLViewerAssetDictionary>,
 49						  public LLDictionary<LLViewerAssetType::EType, ViewerAssetEntry>
 50{
 51public:
 52	LLViewerAssetDictionary();
 53};
 54
 55LLViewerAssetDictionary::LLViewerAssetDictionary()
 56{
 57	//       												      	   	   	 DRAG&DROP TYPE		    
 58	//   	   	   	   	   	   	   	   	   	   	   	   	   	   	   	   	   	|--------------------|
 59	addEntry(LLViewerAssetType::AT_TEXTURE, 			new ViewerAssetEntry(DAD_TEXTURE));
 60	addEntry(LLViewerAssetType::AT_SOUND, 				new ViewerAssetEntry(DAD_SOUND));
 61	addEntry(LLViewerAssetType::AT_CALLINGCARD, 		new ViewerAssetEntry(DAD_CALLINGCARD));
 62	addEntry(LLViewerAssetType::AT_LANDMARK, 			new ViewerAssetEntry(DAD_LANDMARK));
 63	addEntry(LLViewerAssetType::AT_SCRIPT, 				new ViewerAssetEntry(DAD_NONE));
 64	addEntry(LLViewerAssetType::AT_CLOTHING, 			new ViewerAssetEntry(DAD_CLOTHING));
 65	addEntry(LLViewerAssetType::AT_OBJECT, 				new ViewerAssetEntry(DAD_OBJECT));
 66	addEntry(LLViewerAssetType::AT_NOTECARD, 			new ViewerAssetEntry(DAD_NOTECARD));
 67	addEntry(LLViewerAssetType::AT_CATEGORY, 			new ViewerAssetEntry(DAD_CATEGORY));
 68	addEntry(LLViewerAssetType::AT_LSL_TEXT, 			new ViewerAssetEntry(DAD_SCRIPT));
 69	addEntry(LLViewerAssetType::AT_LSL_BYTECODE, 		new ViewerAssetEntry(DAD_NONE));
 70	addEntry(LLViewerAssetType::AT_TEXTURE_TGA, 		new ViewerAssetEntry(DAD_NONE));
 71	addEntry(LLViewerAssetType::AT_BODYPART, 			new ViewerAssetEntry(DAD_BODYPART));
 72	addEntry(LLViewerAssetType::AT_SOUND_WAV, 			new ViewerAssetEntry(DAD_NONE));
 73	addEntry(LLViewerAssetType::AT_IMAGE_TGA, 			new ViewerAssetEntry(DAD_NONE));
 74	addEntry(LLViewerAssetType::AT_IMAGE_JPEG, 			new ViewerAssetEntry(DAD_NONE));
 75	addEntry(LLViewerAssetType::AT_ANIMATION, 			new ViewerAssetEntry(DAD_ANIMATION));
 76	addEntry(LLViewerAssetType::AT_GESTURE, 			new ViewerAssetEntry(DAD_GESTURE));
 77	addEntry(LLViewerAssetType::AT_SIMSTATE, 			new ViewerAssetEntry(DAD_NONE));
 78
 79	addEntry(LLViewerAssetType::AT_LINK, 				new ViewerAssetEntry(DAD_LINK));
 80	addEntry(LLViewerAssetType::AT_LINK_FOLDER, 		new ViewerAssetEntry(DAD_LINK));
 81
 82	addEntry(LLViewerAssetType::AT_MESH, 				new ViewerAssetEntry(DAD_MESH));
 83	
 84	addEntry(LLViewerAssetType::AT_WIDGET, 				new ViewerAssetEntry(DAD_WIDGET));
 85	
 86	addEntry(LLViewerAssetType::AT_NONE, 				new ViewerAssetEntry(DAD_NONE));
 87};
 88
 89EDragAndDropType LLViewerAssetType::lookupDragAndDropType(EType asset_type)
 90{
 91	const LLViewerAssetDictionary *dict = LLViewerAssetDictionary::getInstance();
 92	const ViewerAssetEntry *entry = dict->lookup(asset_type);
 93	if (entry)
 94		return entry->mDadType;
 95	else
 96		return DAD_NONE;
 97}
 98
 99// Generate a good default description
100void LLViewerAssetType::generateDescriptionFor(LLViewerAssetType::EType asset_type,
101											   std::string& description)
102{
103	const S32 BUF_SIZE = 30;
104	char time_str[BUF_SIZE];	/* Flawfinder: ignore */
105	time_t now;
106	time(&now);
107	memset(time_str, '\0', BUF_SIZE);
108	strftime(time_str, BUF_SIZE - 1, "%Y-%m-%d %H:%M:%S ", localtime(&now));
109	description.assign(time_str);
110	description.append(LLAssetType::lookupHumanReadable(asset_type));
111}