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