llviewerinventory.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /**
  2. * @file llviewerinventory.h
  3. * @brief Declaration of the inventory bits that only used on the viewer.
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVIEWERINVENTORY_H
  33. #define LL_LLVIEWERINVENTORY_H
  34. #include "llinitdestroyclass.h" // Also includes "boost/function.hpp"
  35. #include "llinventory.h"
  36. #include "llframetimer.h"
  37. #include "llsettingstype.h"
  38. #include "llwearabletype.h"
  39. class LLInventoryModel;
  40. class LLViewerInventoryCategory;
  41. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  42. // Class LLViewerInventoryItem
  43. //
  44. // An inventory item represents something that the current user has in
  45. // their inventory.
  46. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  47. class LLViewerInventoryItem final : public LLInventoryItem
  48. {
  49. protected:
  50. LOG_CLASS(LLViewerInventoryItem);
  51. public:
  52. typedef std::vector<LLPointer<LLViewerInventoryItem> > item_array_t;
  53. protected:
  54. ~LLViewerInventoryItem() override = default;
  55. public:
  56. // LLInventoryItem / LLInventoryObject overrides
  57. LLAssetType::EType getType() const override;
  58. const LLUUID& getAssetUUID() const override;
  59. const std::string& getName() const override;
  60. const LLPermissions& getPermissions() const override;
  61. const LLUUID& getCreatorUUID() const override;
  62. const std::string& getDescription() const override;
  63. const LLSaleInfo& getSaleInfo() const override;
  64. const LLUUID& getThumbnailUUID() const override;
  65. LLInventoryType::EType getInventoryType() const override;
  66. U32 getFlags() const override;
  67. LL_INLINE LLViewerInventoryItem* asViewerInventoryItem() override
  68. {
  69. return this;
  70. }
  71. LL_INLINE const LLViewerInventoryItem* asViewerInventoryItem() const override
  72. {
  73. return this;
  74. }
  75. // New virtual methods
  76. virtual S32 getSubType() const;
  77. virtual bool isWearableType() const;
  78. virtual LLWearableType::EType getWearableType() const;
  79. virtual bool isSettingsType() const;
  80. virtual LLSettingsType::EType getSettingsType() const;
  81. // Construct a complete viewer inventory item
  82. LLViewerInventoryItem(const LLUUID& item_id, const LLUUID& parent_id,
  83. const LLPermissions& permissions,
  84. const LLUUID& asset_id, LLAssetType::EType type,
  85. LLInventoryType::EType inv_type,
  86. const std::string& name,
  87. const std::string& desc,
  88. const LLSaleInfo& sale_info,
  89. U32 flags, time_t creation_date_utc);
  90. // Construct a viewer inventory item which has the minimal amount of
  91. // information to use in the UI.
  92. LLViewerInventoryItem(const LLUUID& item_id, const LLUUID& parent_id,
  93. const std::string& name,
  94. LLInventoryType::EType inv_type);
  95. // Construct an invalid and incomplete viewer inventory item. Useful for
  96. // unpacking or importing or what have you.
  97. // *NOTE: it is important to call setComplete() if you expect the
  98. // operations to provide all necessary information.
  99. LLViewerInventoryItem();
  100. // Create a copy of an inventory item from a pointer to another item.
  101. // Note: Because InventoryItems are ref counted, reference copy (a = b) is
  102. // prohibited
  103. LLViewerInventoryItem(const LLViewerInventoryItem* other);
  104. LLViewerInventoryItem(const LLInventoryItem* other);
  105. // LLInventoryItem override
  106. void copyItem(const LLInventoryItem* other) override;
  107. // New method
  108. void copyViewerItem(const LLViewerInventoryItem* other);
  109. // Construct a new clone of this item: it creates a new viewer inventory
  110. // item using the copy constructor, and returns it. It is up to the caller
  111. // to delete (unref) the item.
  112. void cloneViewerItem(LLPointer<LLViewerInventoryItem>& newitem) const;
  113. // LLInventoryObject overrides
  114. void updateParentOnServer(bool restamp) const override;
  115. void updateServer(bool is_new) const override;
  116. void fetchFromServer() const;
  117. // LLInventoryItem overrides
  118. void packMessage(LLMessageSystem* msg) const override;
  119. bool unpackMessage(LLMessageSystem* msg, const char* block,
  120. S32 block_num = 0) override;
  121. // New virtual method
  122. virtual bool unpackMessage(LLSD item);
  123. // LLInventoryObject overrides
  124. bool importLegacyStream(std::istream& input_stream) override;
  125. // New methods
  126. LL_INLINE bool isFinished() const { return mIsComplete; }
  127. LL_INLINE void setComplete(bool complete) { mIsComplete = complete; }
  128. virtual void setTransactionID(const LLTransactionID& transaction_id);
  129. struct comparePointers
  130. {
  131. LL_INLINE bool operator()(const LLPointer<LLViewerInventoryItem>& a,
  132. const LLPointer<LLViewerInventoryItem>& b)
  133. {
  134. return a->getName().compare(b->getName()) < 0;
  135. }
  136. };
  137. LL_INLINE LLTransactionID getTransactionID() const
  138. {
  139. return mTransactionID;
  140. }
  141. // true if the baseitem this points to doesn't exist in memory.
  142. bool getIsBrokenLink() const;
  143. LLViewerInventoryItem* getLinkedItem() const;
  144. LLViewerInventoryCategory* getLinkedCategory() const;
  145. protected:
  146. LLTransactionID mTransactionID;
  147. bool mIsComplete;
  148. };
  149. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  150. // Class LLViewerInventoryCategory
  151. //
  152. // An instance of this class represents a category of inventory items. Users
  153. // come with a set of default categories, and can create new ones as needed.
  154. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  155. class LLViewerInventoryCategory final : public LLInventoryCategory
  156. {
  157. protected:
  158. LOG_CLASS(LLViewerInventoryCategory);
  159. public:
  160. typedef std::vector<LLPointer<LLViewerInventoryCategory> > cat_array_t;
  161. protected:
  162. ~LLViewerInventoryCategory() override = default;
  163. public:
  164. LLViewerInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
  165. LLFolderType::EType preferred_type,
  166. const std::string& name,
  167. const LLUUID& owner_id);
  168. LLViewerInventoryCategory(const LLUUID& owner_id);
  169. // Create a copy of an inventory category from a pointer to another category
  170. // Note: Because InventoryCategorys are ref counted, reference copy (a = b)
  171. // is prohibited
  172. LLViewerInventoryCategory(const LLViewerInventoryCategory* other);
  173. void copyViewerCategory(const LLViewerInventoryCategory* other);
  174. LL_INLINE LLViewerInventoryCategory* asViewerInventoryCategory() override
  175. {
  176. return this;
  177. }
  178. LL_INLINE const LLViewerInventoryCategory* asViewerInventoryCategory() const override
  179. {
  180. return this;
  181. }
  182. void updateParentOnServer(bool restamp_children) const override;
  183. void updateServer(bool is_new) const override;
  184. LL_INLINE const LLUUID& getOwnerID() const { return mOwnerID; }
  185. // Version handling
  186. enum { VERSION_UNKNOWN = -1, VERSION_INITIAL = 1 };
  187. LL_INLINE void setVersion(S32 version) { mVersion = version; }
  188. LL_INLINE void setVersionUnknown() { mVersion = VERSION_UNKNOWN; }
  189. LL_INLINE void setVersionInitial() { mVersion = VERSION_INITIAL; }
  190. LL_INLINE S32 getVersion() const { return mVersion; }
  191. LL_INLINE bool isVersionUnknown() const { return mVersion == VERSION_UNKNOWN; }
  192. LL_INLINE bool isVersionInitial() const { return mVersion == VERSION_INITIAL; }
  193. // Returns true if a fetch was issued (but not necessarily in progress).
  194. bool fetch();
  195. typedef enum : U32
  196. {
  197. FETCH_NONE = 0,
  198. FETCH_NORMAL,
  199. FETCH_RECURSIVE,
  200. } EFetchType;
  201. void setFetching(U32 type);
  202. U32 getFetching();
  203. // Returns false when the category is not protected (not at root, or not
  204. // of a protected type, or not bearing the default name of the protected
  205. // type). Returns true for genuinely protected categories.
  206. bool isProtected() const;
  207. // Returns false when the category is not unique (FT_NONE type, or not at
  208. // root, or not bearing the default name of its special type). Returns true
  209. // for genuinely unique categories. Note that for the Cool VL Viewer, a
  210. // unique folder may nonetheless be unprotected (i.e. isProtected() may
  211. // return false while isUnique() returns true), which is the case for all
  212. // v2+ folder types considered as dispensable. HB
  213. bool isUnique() const;
  214. // Used to help make caching more robust. For example, if someone is
  215. // getting 4 packets but logs out after 3, the viewer may never know the
  216. // cache is wrong.
  217. enum { DESCENDENT_COUNT_UNKNOWN = -1 };
  218. LL_INLINE S32 getDescendentCount() const { return mDescendentCount; }
  219. LL_INLINE void setDescendentCount(S32 n) { mDescendentCount = n; }
  220. LL_INLINE bool isDescendentCountUnknown() const
  221. {
  222. return mDescendentCount == DESCENDENT_COUNT_UNKNOWN;
  223. }
  224. // How many descendents do we currently have information for in the
  225. // InventoryModel ?
  226. S32 getViewerDescendentCount() const;
  227. LLSD exportLLSD() const;
  228. bool importLLSD(const LLSD& cat_data);
  229. // Returns true if the category object will accept the incoming item
  230. bool acceptItem(LLInventoryItem* itemp);
  231. // LLInventoryItem overrides
  232. void packMessage(LLMessageSystem* msg) const override;
  233. void unpackMessage(LLMessageSystem* msg, const char* block,
  234. S32 block_num = 0) override;
  235. // New virtual method
  236. virtual bool unpackMessage(const LLSD& category);
  237. protected:
  238. LLUUID mOwnerID;
  239. LLFrameTimer mDescendentsRequested;
  240. S32 mVersion;
  241. S32 mDescendentCount;
  242. U32 mFetching;
  243. };
  244. class LLInventoryCallback : public LLRefCount
  245. {
  246. public:
  247. virtual void fire(const LLUUID& inv_item) = 0;
  248. };
  249. class ActivateGestureCallback final : public LLInventoryCallback
  250. {
  251. public:
  252. void fire(const LLUUID& inv_item) override;
  253. };
  254. void doInventoryCb(LLPointer<LLInventoryCallback> cb, LLUUID id);
  255. typedef boost::function<void(const LLUUID&)> inventory_func_t;
  256. typedef boost::function<void()> nullary_inv_func_t;
  257. void no_inv_op(const LLUUID&); // A do-nothing inventory_func_t
  258. void no_op(); // A do-nothing nullary_inv_func_t.
  259. // Shim between inventory callback and boost function/callable
  260. class LLBoostFuncInventoryCallback : public LLInventoryCallback
  261. {
  262. protected:
  263. LOG_CLASS(LLBoostFuncInventoryCallback);
  264. public:
  265. LLBoostFuncInventoryCallback(inventory_func_t fire_fn = no_inv_op,
  266. nullary_inv_func_t destroy_fn = no_op)
  267. : mFireFunc(fire_fn),
  268. mDestroyFunc(destroy_fn)
  269. {
  270. }
  271. void fire(const LLUUID& item_id) override
  272. {
  273. mFireFunc(item_id);
  274. }
  275. // virtual
  276. ~LLBoostFuncInventoryCallback() override
  277. {
  278. mDestroyFunc();
  279. }
  280. private:
  281. inventory_func_t mFireFunc;
  282. nullary_inv_func_t mDestroyFunc;
  283. };
  284. class LLInventoryCallbackManager final
  285. : public LLDestroyClass<LLInventoryCallbackManager>
  286. {
  287. friend class LLDestroyClass<LLInventoryCallbackManager>;
  288. protected:
  289. LOG_CLASS(LLInventoryCallbackManager);
  290. public:
  291. LLInventoryCallbackManager();
  292. ~LLInventoryCallbackManager();
  293. void fire(U32 callback_id, const LLUUID& item_id);
  294. U32 registerCB(LLPointer<LLInventoryCallback> cb);
  295. private:
  296. static void destroyClass();
  297. private:
  298. typedef std::map<U32, LLPointer<LLInventoryCallback> > callback_map_t;
  299. callback_map_t mMap;
  300. U32 mLastCallback;
  301. static LLInventoryCallbackManager* sInstance;
  302. public:
  303. LL_INLINE static bool instanceExists() { return sInstance != NULL; }
  304. };
  305. extern LLInventoryCallbackManager gInventoryCallbacks;
  306. #define NO_INV_SUBTYPE 0
  307. #define NULL_INV_CB LLPointer<LLInventoryCallback>(NULL)
  308. void update_folder_cb(const LLUUID& folder_id);
  309. // Helper function which creates an item with a good description, updates the
  310. // inventory, updates the server, and pushes the inventory update out to other
  311. // observers.
  312. void create_new_item(const std::string& name, const LLUUID& parent_id,
  313. LLAssetType::EType asset_type,
  314. LLInventoryType::EType inv_type,
  315. U32 next_owner_perm,
  316. std::string desc = LLStringUtil::null);
  317. void create_inventory_item(const LLUUID& parent_id,
  318. const LLTransactionID& transaction_id,
  319. const std::string& name, const std::string& desc,
  320. LLAssetType::EType asset_type,
  321. LLInventoryType::EType inv_type, U8 sub_type,
  322. U32 next_owner_perm,
  323. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  324. // Securely creates a new inventory item by copying from another.
  325. void copy_inventory_item(const LLUUID& current_owner,
  326. const LLUUID& item_id,
  327. const LLUUID& parent_id,
  328. const std::string& new_name = LLStringUtil::null,
  329. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  330. void copy_inventory_category(LLInventoryModel* model,
  331. LLViewerInventoryCategory* cat,
  332. const LLUUID& parent_id,
  333. const LLUUID& root_copy_id = LLUUID::null,
  334. bool move_no_copy_items = false);
  335. void link_inventory_object(const LLUUID& parent_id,
  336. LLPointer<LLInventoryObject> baseobj,
  337. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  338. void link_inventory_object(const LLUUID& parent_id,
  339. const LLUUID& id,
  340. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  341. void link_inventory_array(const LLUUID& parent_id,
  342. LLInventoryObject::object_list_t& baseobj_array,
  343. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  344. // HB: I kept this function (and added AIS3 support to it) because it is
  345. // faster, easier and reliabler to be able to pass at creation time the new
  346. // link item description (containing the layer info) of links created for
  347. // wearables than to change the description of the newly created link (with
  348. // link_inventory_object() the link desc always matches the linked item desc)
  349. // in a callback after it has been created...
  350. void link_inventory_item(const LLUUID& item_id, const LLUUID& parent_id,
  351. const std::string& new_description,
  352. const LLAssetType::EType asset_type,
  353. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  354. void move_inventory_item(const LLUUID& item_id, const LLUUID& parent_id,
  355. const std::string& new_name,
  356. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  357. // Returns true when the UUIDs held in inv_items correspond to inventory items
  358. // or non-protected sub-categories contained inside the same category (parent),
  359. // or false otherwise (including when inv_items is empty). HB
  360. bool movable_objects_with_same_parent(const uuid_vec_t& inv_items);
  361. // Reparents inventory objects (items or categories) which UUIDs are listed in
  362. // inv_items, to the parent_id category. WARNING: no check is done on the
  363. // former parents of the inventory objects. Returns true when some objects have
  364. // actually been moved. HB
  365. bool reparent_to_folder(const LLUUID& parent_id, uuid_vec_t inv_items);
  366. void copy_inventory_from_notecard(const LLUUID& object_id,
  367. const LLUUID& notecard_inv_id,
  368. const LLInventoryItem* srcp,
  369. U32 callback_id = 0);
  370. void update_inventory_item(LLViewerInventoryItem* update_item,
  371. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  372. void update_inventory_item(const LLUUID& item_id, const LLSD& updates,
  373. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  374. void update_inventory_category(const LLUUID& cat_id, const LLSD& updates,
  375. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  376. void remove_inventory_items(LLInventoryObject::object_list_t& items,
  377. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  378. void remove_inventory_item(LLPointer<LLInventoryObject> obj,
  379. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  380. void remove_inventory_item(const LLUUID& item_id,
  381. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  382. void remove_inventory_category(const LLUUID& cat_id,
  383. LLPointer<LLInventoryCallback> cb = NULL_INV_CB,
  384. bool check_protected = true);
  385. void remove_inventory_object(const LLUUID& object_id,
  386. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  387. void remove_folder_contents(const LLUUID& category,
  388. LLPointer<LLInventoryCallback> cb);
  389. void slam_inventory_folder(const LLUUID& folder_id, const LLSD& contents,
  390. LLPointer<LLInventoryCallback> cb);
  391. void purge_descendents_of(const LLUUID& cat_id,
  392. LLPointer<LLInventoryCallback> cb = NULL_INV_CB);
  393. void rename_category(LLInventoryModel* modelp, const LLUUID& cat_id,
  394. const std::string& new_name);
  395. bool get_is_category_renameable(const LLInventoryModel* modelp,
  396. const LLUUID& id);
  397. bool get_is_item_worn(const LLUUID& id, bool include_gestures = true);
  398. S32 get_folder_levels(LLInventoryCategory* catp);
  399. S32 get_folder_path_length(const LLUUID& ancestor_id,
  400. const LLUUID& descendant_id);
  401. S32 count_descendants_items(const LLUUID& cat_id);
  402. // Returns the Id of the associated resident for a calling card: this is non-
  403. // trivial since while calling cards used to always be identified as created
  404. // by the associated resident (including for the cards automatically given by
  405. // the server when befriending someone), LL decided in v2 viewers to recreate
  406. // "missing" calling cards in inventory (meaning their creator is the resident
  407. // running the viewer) and to instead store the Id of the resident they are
  408. // associated with in the description... When passed true for 'allow_self',
  409. // this function returns the agent Id for their own calling cards, else a null
  410. // UUID is returned for the agent calling cards. HB
  411. LLUUID get_calling_card_buddy_id(LLViewerInventoryItem* itemp,
  412. bool allow_self = false);
  413. void move_or_copy_item_from_object(const LLUUID& dest_cat_id,
  414. const LLUUID& object_id,
  415. const LLUUID& item_id,
  416. LLPointer<LLInventoryCallback> cb =
  417. NULL_INV_CB);
  418. #undef NULL_INV_CB
  419. #endif // LL_LLVIEWERINVENTORY_H