summaryrefslogtreecommitdiff
path: root/indra/llinventory/llinventorytype.cpp
blob: 8fa8983d3c418f17346ede78072061e4a8cf556f (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
/**
 * @file llinventorytype.cpp
 * @brief Inventory item type, more specific than an asset type.
 *
 * $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$
 */

#include "linden_common.h"

#include "llinventorytype.h"
#include "lldictionary.h"
#include "llmemory.h"
#include "llsingleton.h"

static const std::string empty_string;

///----------------------------------------------------------------------------
/// Class LLInventoryType
///----------------------------------------------------------------------------
struct InventoryEntry : public LLDictionaryEntry
{
    InventoryEntry(const std::string &name, // unlike asset type names, not limited to 8 characters; need not match asset type names
                   const std::string &human_name, // for decoding to human readable form; put any and as many printable characters you want in each one.
                   int num_asset_types = 0, ...)
        :
        LLDictionaryEntry(name),
        mHumanName(human_name)
    {
        va_list argp;
        va_start(argp, num_asset_types);
        // Read in local textures
        for (U8 i=0; i < num_asset_types; i++)
        {
            LLAssetType::EType t = (LLAssetType::EType)va_arg(argp,int);
            mAssetTypes.push_back(t);
        }
        va_end(argp);
    }

    const std::string mHumanName;
    typedef std::vector<LLAssetType::EType> asset_vec_t;
    asset_vec_t mAssetTypes;
};

class LLInventoryDictionary : public LLSingleton<LLInventoryDictionary>,
                              public LLDictionary<LLInventoryType::EType, InventoryEntry>
{
    LLSINGLETON(LLInventoryDictionary);
};

LLInventoryDictionary::LLInventoryDictionary()
{
    addEntry(LLInventoryType::IT_TEXTURE,             new InventoryEntry("texture",   "texture",       1, LLAssetType::AT_TEXTURE));
    addEntry(LLInventoryType::IT_SOUND,               new InventoryEntry("sound",     "sound",         1, LLAssetType::AT_SOUND));
    addEntry(LLInventoryType::IT_CALLINGCARD,         new InventoryEntry("callcard",  "calling card",  1, LLAssetType::AT_CALLINGCARD));
    addEntry(LLInventoryType::IT_LANDMARK,            new InventoryEntry("landmark",  "landmark",      1, LLAssetType::AT_LANDMARK));
    addEntry(LLInventoryType::IT_OBJECT,              new InventoryEntry("object",    "object",        1, LLAssetType::AT_OBJECT));
    addEntry(LLInventoryType::IT_NOTECARD,            new InventoryEntry("notecard",  "note card",     1, LLAssetType::AT_NOTECARD));
    addEntry(LLInventoryType::IT_CATEGORY,            new InventoryEntry("category",  "folder"         ));
    addEntry(LLInventoryType::IT_ROOT_CATEGORY,       new InventoryEntry("root",      "root"           ));
    addEntry(LLInventoryType::IT_LSL,                 new InventoryEntry("script",    "script",        2, LLAssetType::AT_LSL_TEXT, LLAssetType::AT_LSL_BYTECODE));
    addEntry(LLInventoryType::IT_SNAPSHOT,            new InventoryEntry("snapshot",  "snapshot",      1, LLAssetType::AT_TEXTURE));
    addEntry(LLInventoryType::IT_ATTACHMENT,          new InventoryEntry("attach",    "attachment",    1, LLAssetType::AT_OBJECT));
    addEntry(LLInventoryType::IT_WEARABLE,            new InventoryEntry("wearable",  "wearable",      2, LLAssetType::AT_CLOTHING, LLAssetType::AT_BODYPART));
    addEntry(LLInventoryType::IT_ANIMATION,           new InventoryEntry("animation", "animation",     1, LLAssetType::AT_ANIMATION));
    addEntry(LLInventoryType::IT_GESTURE,             new InventoryEntry("gesture",   "gesture",       1, LLAssetType::AT_GESTURE));
    addEntry(LLInventoryType::IT_MESH,                new InventoryEntry("mesh",      "mesh",          1, LLAssetType::AT_MESH));
    addEntry(LLInventoryType::IT_GLTF,                new InventoryEntry("gltf",      "gltf",          1, LLAssetType::AT_GLTF));
    addEntry(LLInventoryType::IT_GLTF_BIN,            new InventoryEntry("glbin",     "glbin",         1, LLAssetType::AT_GLTF_BIN));
    addEntry(LLInventoryType::IT_WIDGET,              new InventoryEntry("widget",    "widget",        1, LLAssetType::AT_WIDGET));
    addEntry(LLInventoryType::IT_PERSON,              new InventoryEntry("person",    "person",        1, LLAssetType::AT_PERSON));
    addEntry(LLInventoryType::IT_SETTINGS,            new InventoryEntry("settings",  "settings",      1, LLAssetType::AT_SETTINGS));
    addEntry(LLInventoryType::IT_MATERIAL,            new InventoryEntry("material",  "render material", 1, LLAssetType::AT_MATERIAL));
}


// Maps asset types to the default inventory type for that kind of asset.
// Thus, "Lost and Found" is a "Category"
static const LLInventoryType::EType
DEFAULT_ASSET_FOR_INV_TYPE[LLAssetType::AT_COUNT] =
{
    LLInventoryType::IT_TEXTURE,        // 0    AT_TEXTURE
    LLInventoryType::IT_SOUND,          // 1    AT_SOUND
    LLInventoryType::IT_CALLINGCARD,    // 2    AT_CALLINGCARD
    LLInventoryType::IT_LANDMARK,       // 3    AT_LANDMARK
    LLInventoryType::IT_LSL,            // 4    AT_SCRIPT
    LLInventoryType::IT_WEARABLE,       // 5    AT_CLOTHING
    LLInventoryType::IT_OBJECT,         // 6    AT_OBJECT
    LLInventoryType::IT_NOTECARD,       // 7    AT_NOTECARD
    LLInventoryType::IT_CATEGORY,       // 8    AT_CATEGORY
    LLInventoryType::IT_NONE,           // 9    (null entry)
    LLInventoryType::IT_LSL,            // 10   AT_LSL_TEXT
    LLInventoryType::IT_LSL,            // 11   AT_LSL_BYTECODE
    LLInventoryType::IT_TEXTURE,        // 12   AT_TEXTURE_TGA
    LLInventoryType::IT_WEARABLE,       // 13   AT_BODYPART
    LLInventoryType::IT_CATEGORY,       // 14   AT_TRASH
    LLInventoryType::IT_CATEGORY,       // 15   AT_SNAPSHOT_CATEGORY
    LLInventoryType::IT_CATEGORY,       // 16   AT_LOST_AND_FOUND
    LLInventoryType::IT_SOUND,          // 17   AT_SOUND_WAV
    LLInventoryType::IT_NONE,           // 18   AT_IMAGE_TGA
    LLInventoryType::IT_NONE,           // 19   AT_IMAGE_JPEG
    LLInventoryType::IT_ANIMATION,      // 20   AT_ANIMATION
    LLInventoryType::IT_GESTURE,        // 21   AT_GESTURE
    LLInventoryType::IT_NONE,           // 22   AT_SIMSTATE

    LLInventoryType::IT_NONE,           // 23   AT_LINK
    LLInventoryType::IT_NONE,           // 24   AT_LINK_FOLDER

    LLInventoryType::IT_NONE,           // 25   AT_NONE
    LLInventoryType::IT_NONE,           // 26   AT_NONE
    LLInventoryType::IT_NONE,           // 27   AT_NONE
    LLInventoryType::IT_NONE,           // 28   AT_NONE
    LLInventoryType::IT_NONE,           // 29   AT_NONE
    LLInventoryType::IT_NONE,           // 30   AT_NONE
    LLInventoryType::IT_NONE,           // 31   AT_NONE
    LLInventoryType::IT_NONE,           // 32   AT_NONE
    LLInventoryType::IT_NONE,           // 33   AT_NONE
    LLInventoryType::IT_NONE,           // 34   AT_NONE
    LLInventoryType::IT_NONE,           // 35   AT_NONE
    LLInventoryType::IT_NONE,           // 36   AT_NONE
    LLInventoryType::IT_NONE,           // 37   AT_NONE
    LLInventoryType::IT_NONE,           // 38   AT_NONE
    LLInventoryType::IT_NONE,           // 39   AT_NONE
    LLInventoryType::IT_WIDGET,         // 40   AT_WIDGET
    LLInventoryType::IT_NONE,           // 41   AT_NONE
    LLInventoryType::IT_NONE,           // 42   AT_NONE
    LLInventoryType::IT_NONE,           // 43   AT_NONE
    LLInventoryType::IT_NONE,           // 44   AT_NONE
    LLInventoryType::IT_PERSON,         // 45   AT_PERSON
    LLInventoryType::IT_NONE,           // 46   AT_NONE
    LLInventoryType::IT_NONE,           // 47   AT_NONE
    LLInventoryType::IT_NONE,           // 48   AT_NONE
    LLInventoryType::IT_MESH,           // 49   AT_MESH

    LLInventoryType::IT_NONE,           // 50   AT_RESERVED_1
    LLInventoryType::IT_NONE,           // 51   AT_RESERVED_2
    LLInventoryType::IT_NONE,           // 52   AT_RESERVED_3
    LLInventoryType::IT_NONE,           // 53   AT_RESERVED_4
    LLInventoryType::IT_NONE,           // 54   AT_RESERVED_5
    LLInventoryType::IT_NONE,           // 55   AT_RESERVED_6

    LLInventoryType::IT_SETTINGS,       // 56   AT_SETTINGS
    LLInventoryType::IT_MATERIAL,       // 57   AT_MATERIAL
    LLInventoryType::IT_GLTF,           // 58   AT_GLTF
    LLInventoryType::IT_GLTF_BIN,       // 59   AT_GLTF_BIN
};

// static
const std::string &LLInventoryType::lookup(EType type)
{
    const InventoryEntry *entry = LLInventoryDictionary::getInstance()->lookup(type);
    if (!entry) return empty_string;
    return entry->mName;
}

// static
LLInventoryType::EType LLInventoryType::lookup(const std::string& name)
{
    return LLInventoryDictionary::getInstance()->lookup(name);
}

// XUI:translate
// translation from a type to a human readable form.
// static
const std::string &LLInventoryType::lookupHumanReadable(EType type)
{
    const InventoryEntry *entry = LLInventoryDictionary::getInstance()->lookup(type);
    if (!entry) return empty_string;
    return entry->mHumanName;
}

// return the default inventory for the given asset type.
// static
LLInventoryType::EType LLInventoryType::defaultForAssetType(LLAssetType::EType asset_type)
{
    if((asset_type >= 0) && (asset_type < LLAssetType::AT_COUNT))
    {
        return DEFAULT_ASSET_FOR_INV_TYPE[S32(asset_type)];
    }
    else
    {
        return IT_UNKNOWN;
    }
}


// add any types that we don't want the user to be able to change permissions on.
// static
bool LLInventoryType::cannotRestrictPermissions(LLInventoryType::EType type)
{
    switch(type)
    {
        case IT_CALLINGCARD:
        case IT_LANDMARK:
            return true;
        default:
            return false;
    }
}

// Should show permissions that apply only to objects rezed in world.
bool LLInventoryType::showInWorldPermissions(LLInventoryType::EType type)
{
    return (type != IT_SETTINGS);
}

bool inventory_and_asset_types_match(LLInventoryType::EType inventory_type,
                                     LLAssetType::EType asset_type)
{
    // Links can be of any inventory type.
    if (LLAssetType::lookupIsLinkType(asset_type))
        return true;

    const InventoryEntry *entry = LLInventoryDictionary::getInstance()->lookup(inventory_type);
    if (!entry) return false;

    for (InventoryEntry::asset_vec_t::const_iterator iter = entry->mAssetTypes.begin();
         iter != entry->mAssetTypes.end();
         iter++)
    {
        const LLAssetType::EType type = (*iter);
        if(type == asset_type)
        {
            return true;
        }
    }
    return false;
}