PageRenderTime 70ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llviewerinventory.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 380 lines | 237 code | 67 blank | 76 comment | 1 complexity | cc9428a05aa24e79a985179ba8ff4bf6 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewerinventory.h
  3. * @brief Declaration of the inventory bits that only used on the viewer.
  4. *
  5. * $LicenseInfo:firstyear=2002&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. #ifndef LL_LLVIEWERINVENTORY_H
  27. #define LL_LLVIEWERINVENTORY_H
  28. #include "llinventory.h"
  29. #include "llframetimer.h"
  30. #include "llwearable.h"
  31. #include "llui.h" //for LLDestroyClass
  32. #include <boost/signals2.hpp> // boost::signals2::trackable
  33. class LLFolderView;
  34. class LLFolderBridge;
  35. class LLViewerInventoryCategory;
  36. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. // Class LLViewerInventoryItem
  38. //
  39. // An inventory item represents something that the current user has in
  40. // their inventory.
  41. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  42. class LLViewerInventoryItem : public LLInventoryItem, public boost::signals2::trackable
  43. {
  44. public:
  45. typedef LLDynamicArray<LLPointer<LLViewerInventoryItem> > item_array_t;
  46. protected:
  47. ~LLViewerInventoryItem( void ); // ref counted
  48. BOOL extractSortFieldAndDisplayName(S32* sortField, std::string* displayName) const { return extractSortFieldAndDisplayName(mName, sortField, displayName); }
  49. mutable std::string mDisplayName;
  50. public:
  51. virtual LLAssetType::EType getType() const;
  52. virtual const LLUUID& getAssetUUID() const;
  53. virtual const LLUUID& getProtectedAssetUUID() const; // returns LLUUID::null if current agent does not have permission to expose this asset's UUID to the user
  54. virtual const std::string& getName() const;
  55. virtual S32 getSortField() const;
  56. virtual void setSortField(S32 sortField);
  57. virtual void getSLURL(); //Caches SLURL for landmark. //*TODO: Find a better way to do it and remove this method from here.
  58. virtual const LLPermissions& getPermissions() const;
  59. virtual const bool getIsFullPerm() const; // 'fullperm' in the popular sense: modify-ok & copy-ok & transfer-ok, no special god rules applied
  60. virtual const LLUUID& getCreatorUUID() const;
  61. virtual const std::string& getDescription() const;
  62. virtual const LLSaleInfo& getSaleInfo() const;
  63. virtual LLInventoryType::EType getInventoryType() const;
  64. virtual bool isWearableType() const;
  65. virtual LLWearableType::EType getWearableType() const;
  66. virtual U32 getFlags() const;
  67. virtual time_t getCreationDate() const;
  68. virtual U32 getCRC32() const; // really more of a checksum.
  69. static BOOL extractSortFieldAndDisplayName(const std::string& name, S32* sortField, std::string* displayName);
  70. // construct a complete viewer inventory item
  71. LLViewerInventoryItem(const LLUUID& uuid, const LLUUID& parent_uuid,
  72. const LLPermissions& permissions,
  73. const LLUUID& asset_uuid,
  74. LLAssetType::EType type,
  75. LLInventoryType::EType inv_type,
  76. const std::string& name,
  77. const std::string& desc,
  78. const LLSaleInfo& sale_info,
  79. U32 flags,
  80. time_t creation_date_utc);
  81. // construct a viewer inventory item which has the minimal amount
  82. // of information to use in the UI.
  83. LLViewerInventoryItem(
  84. const LLUUID& item_id,
  85. const LLUUID& parent_id,
  86. const std::string& name,
  87. LLInventoryType::EType inv_type);
  88. // construct an invalid and incomplete viewer inventory item.
  89. // usually useful for unpacking or importing or what have you.
  90. // *NOTE: it is important to call setComplete() if you expect the
  91. // operations to provide all necessary information.
  92. LLViewerInventoryItem();
  93. // Create a copy of an inventory item from a pointer to another item
  94. // Note: Because InventoryItems are ref counted,
  95. // reference copy (a = b) is prohibited
  96. LLViewerInventoryItem(const LLViewerInventoryItem* other);
  97. LLViewerInventoryItem(const LLInventoryItem* other);
  98. void copyViewerItem(const LLViewerInventoryItem* other);
  99. /*virtual*/ void copyItem(const LLInventoryItem* other);
  100. // construct a new clone of this item - it creates a new viewer
  101. // inventory item using the copy constructor, and returns it.
  102. // It is up to the caller to delete (unref) the item.
  103. void cloneViewerItem(LLPointer<LLViewerInventoryItem>& newitem) const;
  104. // virtual methods
  105. virtual void removeFromServer( void );
  106. virtual void updateParentOnServer(BOOL restamp) const;
  107. virtual void updateServer(BOOL is_new) const;
  108. void fetchFromServer(void) const;
  109. //virtual void packMessage(LLMessageSystem* msg) const;
  110. virtual BOOL unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
  111. virtual BOOL unpackMessage(LLSD item);
  112. virtual BOOL importFile(LLFILE* fp);
  113. virtual BOOL importLegacyStream(std::istream& input_stream);
  114. // file handling on the viewer. These are not meant for anything
  115. // other than cacheing.
  116. bool exportFileLocal(LLFILE* fp) const;
  117. bool importFileLocal(LLFILE* fp);
  118. // new methods
  119. BOOL isFinished() const { return mIsComplete; }
  120. void setComplete(BOOL complete) { mIsComplete = complete; }
  121. //void updateAssetOnServer() const;
  122. virtual void packMessage(LLMessageSystem* msg) const;
  123. virtual void setTransactionID(const LLTransactionID& transaction_id);
  124. struct comparePointers
  125. {
  126. bool operator()(const LLPointer<LLViewerInventoryItem>& a, const LLPointer<LLViewerInventoryItem>& b)
  127. {
  128. return a->getName().compare(b->getName()) < 0;
  129. }
  130. };
  131. LLTransactionID getTransactionID() const { return mTransactionID; }
  132. bool getIsBrokenLink() const; // true if the baseitem this points to doesn't exist in memory.
  133. LLViewerInventoryItem *getLinkedItem() const;
  134. LLViewerInventoryCategory *getLinkedCategory() const;
  135. // Checks the items permissions (for owner, group, or everyone) and returns true if all mask bits are set.
  136. bool checkPermissionsSet(PermissionMask mask) const;
  137. PermissionMask getPermissionMask() const;
  138. // callback
  139. void onCallingCardNameLookup(const LLUUID& id, const std::string& name, bool is_group);
  140. // If this is a broken link, try to fix it and any other identical link.
  141. BOOL regenerateLink();
  142. public:
  143. BOOL mIsComplete;
  144. LLTransactionID mTransactionID;
  145. };
  146. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  147. // Class LLViewerInventoryCategory
  148. //
  149. // An instance of this class represents a category of inventory
  150. // items. Users come with a set of default categories, and can create
  151. // new ones as needed.
  152. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  153. class LLViewerInventoryCategory : public LLInventoryCategory
  154. {
  155. public:
  156. typedef LLDynamicArray<LLPointer<LLViewerInventoryCategory> > cat_array_t;
  157. protected:
  158. ~LLViewerInventoryCategory();
  159. public:
  160. LLViewerInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
  161. LLFolderType::EType preferred_type,
  162. const std::string& name,
  163. const LLUUID& owner_id);
  164. LLViewerInventoryCategory(const LLUUID& owner_id);
  165. // Create a copy of an inventory category from a pointer to another category
  166. // Note: Because InventoryCategorys are ref counted, reference copy (a = b)
  167. // is prohibited
  168. LLViewerInventoryCategory(const LLViewerInventoryCategory* other);
  169. void copyViewerCategory(const LLViewerInventoryCategory* other);
  170. virtual void removeFromServer();
  171. virtual void updateParentOnServer(BOOL restamp_children) const;
  172. virtual void updateServer(BOOL is_new) const;
  173. const LLUUID& getOwnerID() const { return mOwnerID; }
  174. // Version handling
  175. enum { VERSION_UNKNOWN = -1, VERSION_INITIAL = 1 };
  176. S32 getVersion() const { return mVersion; }
  177. void setVersion(S32 version) { mVersion = version; }
  178. // Returns true if a fetch was issued.
  179. bool fetch();
  180. // used to help make cacheing more robust - for example, if
  181. // someone is getting 4 packets but logs out after 3. the viewer
  182. // may never know the cache is wrong.
  183. enum { DESCENDENT_COUNT_UNKNOWN = -1 };
  184. S32 getDescendentCount() const { return mDescendentCount; }
  185. void setDescendentCount(S32 descendents) { mDescendentCount = descendents; }
  186. // file handling on the viewer. These are not meant for anything
  187. // other than cacheing.
  188. bool exportFileLocal(LLFILE* fp) const;
  189. bool importFileLocal(LLFILE* fp);
  190. void determineFolderType();
  191. void changeType(LLFolderType::EType new_folder_type);
  192. private:
  193. friend class LLInventoryModel;
  194. void localizeName(); // intended to be called from the LLInventoryModel
  195. protected:
  196. LLUUID mOwnerID;
  197. S32 mVersion;
  198. S32 mDescendentCount;
  199. LLFrameTimer mDescendentsRequested;
  200. };
  201. class LLInventoryCallback : public LLRefCount
  202. {
  203. public:
  204. virtual void fire(const LLUUID& inv_item) = 0;
  205. };
  206. class WearOnAvatarCallback : public LLInventoryCallback
  207. {
  208. public:
  209. WearOnAvatarCallback(bool do_replace = false) : mReplace(do_replace) {}
  210. void fire(const LLUUID& inv_item);
  211. protected:
  212. bool mReplace;
  213. };
  214. class ModifiedCOFCallback : public LLInventoryCallback
  215. {
  216. void fire(const LLUUID& inv_item);
  217. };
  218. class LLViewerJointAttachment;
  219. class RezAttachmentCallback : public LLInventoryCallback
  220. {
  221. public:
  222. RezAttachmentCallback(LLViewerJointAttachment *attachmentp);
  223. void fire(const LLUUID& inv_item);
  224. protected:
  225. ~RezAttachmentCallback();
  226. private:
  227. LLViewerJointAttachment* mAttach;
  228. };
  229. class ActivateGestureCallback : public LLInventoryCallback
  230. {
  231. public:
  232. void fire(const LLUUID& inv_item);
  233. };
  234. class CreateGestureCallback : public LLInventoryCallback
  235. {
  236. public:
  237. void fire(const LLUUID& inv_item);
  238. };
  239. class AddFavoriteLandmarkCallback : public LLInventoryCallback
  240. {
  241. public:
  242. AddFavoriteLandmarkCallback() : mTargetLandmarkId(LLUUID::null) {}
  243. void setTargetLandmarkId(const LLUUID& target_uuid) { mTargetLandmarkId = target_uuid; }
  244. private:
  245. void fire(const LLUUID& inv_item);
  246. LLUUID mTargetLandmarkId;
  247. };
  248. // misc functions
  249. //void inventory_reliable_callback(void**, S32 status);
  250. class LLInventoryCallbackManager : public LLDestroyClass<LLInventoryCallbackManager>
  251. {
  252. friend class LLDestroyClass<LLInventoryCallbackManager>;
  253. public:
  254. LLInventoryCallbackManager();
  255. ~LLInventoryCallbackManager();
  256. void fire(U32 callback_id, const LLUUID& item_id);
  257. U32 registerCB(LLPointer<LLInventoryCallback> cb);
  258. private:
  259. typedef std::map<U32, LLPointer<LLInventoryCallback> > callback_map_t;
  260. callback_map_t mMap;
  261. U32 mLastCallback;
  262. static LLInventoryCallbackManager *sInstance;
  263. static void destroyClass();
  264. public:
  265. static bool is_instantiated() { return sInstance != NULL; }
  266. };
  267. extern LLInventoryCallbackManager gInventoryCallbacks;
  268. #define NOT_WEARABLE (LLWearableType::EType)0
  269. // *TODO: Find a home for these
  270. void create_inventory_item(const LLUUID& agent_id, const LLUUID& session_id,
  271. const LLUUID& parent, const LLTransactionID& transaction_id,
  272. const std::string& name,
  273. const std::string& desc, LLAssetType::EType asset_type,
  274. LLInventoryType::EType inv_type, LLWearableType::EType wtype,
  275. U32 next_owner_perm,
  276. LLPointer<LLInventoryCallback> cb);
  277. void create_inventory_callingcard(const LLUUID& avatar_id, const LLUUID& parent = LLUUID::null, LLPointer<LLInventoryCallback> cb=NULL);
  278. /**
  279. * @brief Securely create a new inventory item by copying from another.
  280. */
  281. void copy_inventory_item(
  282. const LLUUID& agent_id,
  283. const LLUUID& current_owner,
  284. const LLUUID& item_id,
  285. const LLUUID& parent_id,
  286. const std::string& new_name,
  287. LLPointer<LLInventoryCallback> cb);
  288. void link_inventory_item(
  289. const LLUUID& agent_id,
  290. const LLUUID& item_id,
  291. const LLUUID& parent_id,
  292. const std::string& new_name,
  293. const std::string& new_description,
  294. const LLAssetType::EType asset_type,
  295. LLPointer<LLInventoryCallback> cb);
  296. void move_inventory_item(
  297. const LLUUID& agent_id,
  298. const LLUUID& session_id,
  299. const LLUUID& item_id,
  300. const LLUUID& parent_id,
  301. const std::string& new_name,
  302. LLPointer<LLInventoryCallback> cb);
  303. const LLUUID get_folder_by_itemtype(const LLInventoryItem *src);
  304. void copy_inventory_from_notecard(const LLUUID& destination_id,
  305. const LLUUID& object_id,
  306. const LLUUID& notecard_inv_id,
  307. const LLInventoryItem *src,
  308. U32 callback_id = 0);
  309. void menu_create_inventory_item(LLFolderView* root,
  310. LLFolderBridge* bridge,
  311. const LLSD& userdata,
  312. const LLUUID& default_parent_uuid = LLUUID::null);
  313. #endif // LL_LLVIEWERINVENTORY_H