hbinventoryclipboard.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /**
  2. * @file hbinventoryclipboard.cpp
  3. * @brief HBInventoryClipboard class implementation
  4. * This is a full rewrite/expansion of LL's original LLInventoryClipboard class
  5. *
  6. * $LicenseInfo:firstyear=2012&license=viewergpl$
  7. *
  8. * Copyright (c) 2012-2023, Henri Beauchamp.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #include "llviewerprecompiledheaders.h"
  34. #include "hbinventoryclipboard.h"
  35. #include "llinventorymodel.h"
  36. #include "llwindow.h" // For gWindowp
  37. uuid_vec_t HBInventoryClipboard::sObjects;
  38. uuid_vec_t HBInventoryClipboard::sCutObjects;
  39. HBInventoryClipboard::assets_map_t HBInventoryClipboard::sAssets;
  40. ///////////////////////////////////////////////////////////////////////////////
  41. // Inventory objects management
  42. //static
  43. void HBInventoryClipboard::store(const uuid_vec_t& inv_objects)
  44. {
  45. reset();
  46. for (S32 i = 0, count = inv_objects.size(); i < count; ++i)
  47. {
  48. sObjects.emplace_back(inv_objects[i]);
  49. }
  50. }
  51. //static
  52. void HBInventoryClipboard::retrieve(uuid_vec_t& inv_objects)
  53. {
  54. inv_objects.clear();
  55. LLUUID object_id;
  56. for (S32 i = 0, count = sObjects.size(); i < count; ++i)
  57. {
  58. object_id = sObjects[i];
  59. // Only add objects that have not since been purged...
  60. if (gInventory.getItem(object_id) ||
  61. gInventory.getCategory(object_id))
  62. {
  63. inv_objects.emplace_back(object_id);
  64. }
  65. }
  66. }
  67. //static
  68. void HBInventoryClipboard::retrieveCuts(uuid_vec_t& inv_objects)
  69. {
  70. inv_objects.clear();
  71. LLUUID object_id;
  72. for (S32 i = 0, count = sCutObjects.size(); i < count; ++i)
  73. {
  74. object_id = sCutObjects[i];
  75. // Only add objects that have not since been purged...
  76. if (gInventory.getItem(object_id) ||
  77. gInventory.getCategory(object_id))
  78. {
  79. inv_objects.emplace_back(object_id);
  80. }
  81. }
  82. }
  83. //static
  84. bool HBInventoryClipboard::isCopied(const LLUUID& object_id)
  85. {
  86. uuid_vec_t::iterator end = sObjects.end();
  87. return std::find(sObjects.begin(), end, object_id) != end;
  88. }
  89. //static
  90. bool HBInventoryClipboard::isCut(const LLUUID& object_id)
  91. {
  92. uuid_vec_t::iterator end = sCutObjects.end();
  93. return std::find(sCutObjects.begin(), end, object_id) != end;
  94. }
  95. ///////////////////////////////////////////////////////////////////////////////
  96. // Inventory assets management
  97. // Helper function.
  98. static void copy_to_text_clipboard(const LLUUID& asset_id)
  99. {
  100. if (!gWindowp) return; // Paranoia
  101. gWindowp->copyTextToClipboard(utf8str_to_wstring(asset_id.asString()));
  102. }
  103. //static
  104. void HBInventoryClipboard::addAsset(const LLUUID& asset_id,
  105. LLInventoryType::EType type,
  106. bool copy_id_to_text_clipboard)
  107. {
  108. // Snapshot and textures are share same type of asset...
  109. if (type == LLInventoryType::IT_SNAPSHOT)
  110. {
  111. type = LLInventoryType::IT_TEXTURE;
  112. }
  113. if (asset_id.notNull())
  114. {
  115. sAssets.emplace(asset_id, type);
  116. if (copy_id_to_text_clipboard)
  117. {
  118. copy_to_text_clipboard(asset_id);
  119. }
  120. }
  121. }
  122. //static
  123. void HBInventoryClipboard::storeAsset(const LLUUID& asset_id,
  124. LLInventoryType::EType type,
  125. bool copy_id_to_text_clipboard)
  126. {
  127. resetAssets();
  128. // Snapshot and textures are share same type of asset...
  129. if (type == LLInventoryType::IT_SNAPSHOT)
  130. {
  131. type = LLInventoryType::IT_TEXTURE;
  132. }
  133. if (asset_id.notNull())
  134. {
  135. sAssets.emplace(asset_id, type);
  136. if (copy_id_to_text_clipboard)
  137. {
  138. copy_to_text_clipboard(asset_id);
  139. }
  140. }
  141. }
  142. //static
  143. void HBInventoryClipboard::storeAsset(const LLInventoryItem* itemp,
  144. bool copy_id_to_text_clipboard)
  145. {
  146. if (itemp)
  147. {
  148. resetAssets();
  149. LLInventoryType::EType type = itemp->getInventoryType();
  150. // Snapshot and textures are share same type of asset...
  151. if (type == LLInventoryType::IT_SNAPSHOT)
  152. {
  153. type = LLInventoryType::IT_TEXTURE;
  154. }
  155. const LLUUID& asset_id = itemp->getAssetUUID();
  156. if (asset_id.notNull())
  157. {
  158. sAssets.emplace(asset_id, type);
  159. if (copy_id_to_text_clipboard)
  160. {
  161. copy_to_text_clipboard(asset_id);
  162. }
  163. }
  164. }
  165. }
  166. //static
  167. void HBInventoryClipboard::retrieveAssets(uuid_vec_t& inv_assets,
  168. LLInventoryType::EType type)
  169. {
  170. // Snapshot and textures are share same type of asset...
  171. if (type == LLInventoryType::IT_SNAPSHOT)
  172. {
  173. type = LLInventoryType::IT_TEXTURE;
  174. }
  175. inv_assets.clear();
  176. for (assets_map_t::const_iterator it = sAssets.begin(),
  177. end = sAssets.end();
  178. it != end; ++it)
  179. {
  180. if (it->second == type)
  181. {
  182. inv_assets.emplace_back(it->first);
  183. }
  184. }
  185. }
  186. //static
  187. bool HBInventoryClipboard::hasAssets(LLInventoryType::EType type)
  188. {
  189. // Snapshot and textures are share same type of asset...
  190. if (type == LLInventoryType::IT_SNAPSHOT)
  191. {
  192. type = LLInventoryType::IT_TEXTURE;
  193. }
  194. for (assets_map_t::const_iterator it = sAssets.begin(),
  195. end = sAssets.end();
  196. it != end; ++it)
  197. {
  198. if (it->second == type)
  199. {
  200. return true;
  201. }
  202. }
  203. return false;
  204. }