summaryrefslogtreecommitdiff
path: root/indra/llinventory/llinventory.h
blob: 0e77d49d734615068dc15175adbc2e6e89acc3fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/**
 * @file llinventory.h
 * @brief LLInventoryItem and LLInventoryCategory class declaration.
 *
 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#ifndef LL_LLINVENTORY_H
#define LL_LLINVENTORY_H

#include "llfoldertype.h"
#include "llinventorytype.h"
#include "llpermissions.h"
#include "llrefcount.h"
#include "llsaleinfo.h"
#include "llsd.h"
#include "lluuid.h"
#include "lltrace.h"

class LLMessageSystem;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLInventoryObject
//
//   Base class for anything in the user's inventory.   Handles the common code
//   between items and categories.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLInventoryObject : public LLRefCount
{
public:
    typedef std::list<LLPointer<LLInventoryObject> > object_list_t;
    typedef std::list<LLConstPointer<LLInventoryObject> > const_object_list_t;

    //--------------------------------------------------------------------
    // Initialization
    //--------------------------------------------------------------------
public:
    LLInventoryObject();
    LLInventoryObject(const LLUUID& uuid,
                      const LLUUID& parent_uuid,
                      LLAssetType::EType type,
                      const std::string& name);
    void copyObject(const LLInventoryObject* other); // LLRefCount requires custom copy
protected:
    virtual ~LLInventoryObject();

    //--------------------------------------------------------------------
    // Accessors
    //--------------------------------------------------------------------
public:
    virtual const LLUUID& getUUID() const; // inventoryID that this item points to
    virtual const LLUUID& getLinkedUUID() const; // inventoryID that this item points to, else this item's inventoryID
    const LLUUID& getParentUUID() const;
    virtual const LLUUID& getThumbnailUUID() const;
    virtual bool getIsFavorite() const;
    virtual const std::string& getName() const;
    virtual LLAssetType::EType getType() const;
    LLAssetType::EType getActualType() const; // bypasses indirection for linked items
    BOOL getIsLinkType() const;
    virtual time_t getCreationDate() const;

    //--------------------------------------------------------------------
    // Mutators
    //   Will not call updateServer
    //--------------------------------------------------------------------
public:
    void setUUID(const LLUUID& new_uuid);
    virtual void rename(const std::string& new_name);
    void setParent(const LLUUID& new_parent);
    virtual void setThumbnailUUID(const LLUUID& thumbnail_uuid);
    virtual void setFavorite(bool favorite);
    void setType(LLAssetType::EType type);
    virtual void setCreationDate(time_t creation_date_utc); // only stored for items

    // in place correction for inventory name string
    static void correctInventoryName(std::string& name);

    //--------------------------------------------------------------------
    // File Support
    //   Implemented here so that a minimal information set can be transmitted
    //   between simulator and viewer.
    //--------------------------------------------------------------------

    virtual BOOL importLegacyStream(std::istream& input_stream);
    virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;

    virtual void updateParentOnServer(BOOL) const;
    virtual void updateServer(BOOL) const;

    //--------------------------------------------------------------------
    // Member Variables
    //--------------------------------------------------------------------
protected:
    LLUUID mUUID;
    LLUUID mParentUUID; // Parent category.  Root categories have LLUUID::NULL.
    LLUUID mThumbnailUUID;
    bool mFavorite;
    LLAssetType::EType mType;
    std::string mName;
    time_t mCreationDate; // seconds from 1/1/1970, UTC
};

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLInventoryItem
//
//   An item in the current user's inventory.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLInventoryItem : public LLInventoryObject
{
public:
    typedef std::vector<LLPointer<LLInventoryItem> > item_array_t;

    //--------------------------------------------------------------------
    // Initialization
    //--------------------------------------------------------------------
public:
    LLInventoryItem(const LLUUID& uuid,
                    const LLUUID& parent_uuid,
                    const LLPermissions& permissions,
                    const LLUUID& asset_uuid,
                    LLAssetType::EType type,
                    LLInventoryType::EType inv_type,
                    const std::string& name,
                    const std::string& desc,
                    const LLSaleInfo& sale_info,
                    U32 flags,
                    S32 creation_date_utc);
    LLInventoryItem();
    // Create a copy of an inventory item from a pointer to another item
    // Note: Because InventoryItems are ref counted, reference copy (a = b)
    // is prohibited
    LLInventoryItem(const LLInventoryItem* other);
    virtual void copyItem(const LLInventoryItem* other); // LLRefCount requires custom copy
    void generateUUID() { mUUID.generate(); }
protected:
    ~LLInventoryItem(); // ref counted

    //--------------------------------------------------------------------
    // Accessors
    //--------------------------------------------------------------------
public:
    virtual const LLUUID& getLinkedUUID() const;
    virtual const LLPermissions& getPermissions() const;
    virtual const LLUUID& getCreatorUUID() const;
    virtual const LLUUID& getAssetUUID() const;
    virtual const std::string& getDescription() const;
    virtual const std::string& getActualDescription() const; // Does not follow links
    virtual const LLSaleInfo& getSaleInfo() const;
    virtual LLInventoryType::EType getInventoryType() const;
    virtual U32 getFlags() const;
    virtual time_t getCreationDate() const;
    virtual U32 getCRC32() const; // really more of a checksum.

    //--------------------------------------------------------------------
    // Mutators
    //   Will not call updateServer and will never fail
    //   (though it may correct to sane values)
    //--------------------------------------------------------------------
public:
    void setAssetUUID(const LLUUID& asset_id);
    static void correctInventoryDescription(std::string& name);
    void setDescription(const std::string& new_desc);
    void setSaleInfo(const LLSaleInfo& sale_info);
    void setPermissions(const LLPermissions& perm);
    void setInventoryType(LLInventoryType::EType inv_type);
    void setFlags(U32 flags);
    void setCreator(const LLUUID& creator); // only used for calling cards

    // Check for changes in permissions masks and sale info
    // and set the corresponding bits in mFlags.
    void accumulatePermissionSlamBits(const LLInventoryItem& old_item);

    // Put this inventory item onto the current outgoing mesage.
    // Assumes you have already called nextBlock().
    virtual void packMessage(LLMessageSystem* msg) const;

    // Returns TRUE if the inventory item came through the network correctly.
    // Uses a simple crc check which is defeatable, but we want to detect
    // network mangling somehow.
    virtual BOOL unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);

    //--------------------------------------------------------------------
    // File Support
    //--------------------------------------------------------------------
public:
    virtual BOOL importLegacyStream(std::istream& input_stream);
    virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;

    //--------------------------------------------------------------------
    // Helper Functions
    //--------------------------------------------------------------------
public:
    LLSD asLLSD() const;
    void asLLSD( LLSD& sd ) const;
    bool fromLLSD(const LLSD& sd, bool is_new = true);

    //--------------------------------------------------------------------
    // Member Variables
    //--------------------------------------------------------------------
protected:
    LLPermissions mPermissions;
    LLUUID mAssetUUID;
    std::string mDescription;
    LLSaleInfo mSaleInfo;
    LLInventoryType::EType mInventoryType;
    U32 mFlags;
};

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLInventoryCategory
//
//   A category/folder of inventory items. Users come with a set of default
//   categories, and can create new ones as needed.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLInventoryCategory : public LLInventoryObject
{
public:
    typedef std::vector<LLPointer<LLInventoryCategory> > cat_array_t;

    //--------------------------------------------------------------------
    // Initialization
    //--------------------------------------------------------------------
public:
    LLInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
                        LLFolderType::EType preferred_type,
                        const std::string& name);
    LLInventoryCategory();
    LLInventoryCategory(const LLInventoryCategory* other);
    void copyCategory(const LLInventoryCategory* other); // LLRefCount requires custom copy
protected:
    virtual ~LLInventoryCategory();

    //--------------------------------------------------------------------
    // Accessors And Mutators
    //--------------------------------------------------------------------
public:
    LLFolderType::EType getPreferredType() const;
    void setPreferredType(LLFolderType::EType type);
    LLSD asLLSD() const;
    LLSD asAISCreateCatLLSD() const;
    bool fromLLSD(const LLSD& sd);

    //--------------------------------------------------------------------
    // Messaging
    //--------------------------------------------------------------------
public:
    virtual void packMessage(LLMessageSystem* msg) const;
    virtual void unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);

    //--------------------------------------------------------------------
    // File Support
    //--------------------------------------------------------------------
public:
    virtual BOOL importLegacyStream(std::istream& input_stream);
    virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;

    LLSD exportLLSD() const;
    bool importLLSD(const LLSD& cat_data);
    //--------------------------------------------------------------------
    // Member Variables
    //--------------------------------------------------------------------
protected:
    LLFolderType::EType mPreferredType; // Type that this category was "meant" to hold (although it may hold any type).
};


//-----------------------------------------------------------------------------
// Convertors
//
//   These functions convert between structured data and an inventory
//   item, appropriate for serialization.
//-----------------------------------------------------------------------------
LLSD ll_create_sd_from_inventory_item(LLPointer<LLInventoryItem> item);
LLSD ll_create_sd_from_inventory_category(LLPointer<LLInventoryCategory> cat);
LLPointer<LLInventoryCategory> ll_create_category_from_sd(const LLSD& sd_cat);

#endif // LL_LLINVENTORY_H