aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llwearablelist.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llwearablelist.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llwearablelist.cpp')
-rw-r--r--linden/indra/newview/llwearablelist.cpp344
1 files changed, 344 insertions, 0 deletions
diff --git a/linden/indra/newview/llwearablelist.cpp b/linden/indra/newview/llwearablelist.cpp
new file mode 100644
index 0000000..28af5eb
--- /dev/null
+++ b/linden/indra/newview/llwearablelist.cpp
@@ -0,0 +1,344 @@
1/**
2 * @file llwearablelist.cpp
3 * @brief LLWearableList class implementation
4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "llwearablelist.h"
31
32#include "message.h"
33#include "llassetstorage.h"
34#include "llagent.h"
35#include "llvoavatar.h"
36#include "llviewerinventory.h"
37//#include "llfloaterchat.h"
38#include "llviewerstats.h"
39#include "llnotify.h"
40
41// Globals
42LLWearableList gWearableList;
43
44
45struct LLWearableArrivedData
46{
47 LLWearableArrivedData(
48 LLAssetType::EType asset_type,
49 const LLString& wearable_name,
50 void(*asset_arrived_callback)(LLWearable*, void* userdata),
51 void* userdata )
52 :
53 mAssetType( asset_type ),
54 mCallback( asset_arrived_callback ),
55 mUserdata( userdata ),
56 mName( wearable_name )
57 {}
58
59 LLAssetType::EType mAssetType;
60 void (*mCallback)(LLWearable*, void* userdata);
61 void* mUserdata;
62 LLString mName;
63};
64
65
66
67////////////////////////////////////////////////////////////////////////////
68// LLWearableList
69
70LLWearableList::~LLWearableList()
71{
72 mList.deleteAllData();
73}
74
75void LLWearableList::getAsset( const LLAssetID& assetID, const LLString& wearable_name, LLAssetType::EType asset_type, void(*asset_arrived_callback)(LLWearable*, void* userdata), void* userdata )
76{
77 llassert( (asset_type == LLAssetType::AT_CLOTHING) || (asset_type == LLAssetType::AT_BODYPART) );
78 LLWearable* instance = mList.getIfThere( assetID );
79 if( instance )
80 {
81 asset_arrived_callback( instance, userdata );
82 }
83 else
84 {
85 gAssetStorage->getAssetData(
86 assetID,
87 asset_type,
88 LLWearableList::processGetAssetReply,
89 (void*)new LLWearableArrivedData( asset_type, wearable_name, asset_arrived_callback, userdata ),
90 TRUE);
91 }
92}
93
94// static
95void LLWearableList::processGetAssetReply( const char* filename, const LLAssetID& uuid, void* userdata, S32 status )
96{
97 BOOL success = FALSE;
98 LLWearableArrivedData* data = (LLWearableArrivedData*) userdata;
99
100 if( !filename )
101 {
102 llinfos << "Bad Wearable Asset: missing file." << llendl;
103 }
104 else
105 if( status >= 0 )
106 {
107 // read the file
108 FILE* fp = LLFile::fopen(filename, "rb");
109 if( !fp )
110 {
111 llinfos << "Bad Wearable Asset: unable to open file: '" << filename << "'" << llendl;
112 }
113 else
114 {
115 LLWearable *wearable = new LLWearable(uuid);
116 if( wearable->importFile( fp ) )
117 {
118// llinfos << "processGetAssetReply()" << llendl;
119// wearable->dump();
120
121 gWearableList.mList[ uuid ] = wearable;
122 if( data->mCallback )
123 {
124 data->mCallback( wearable, data->mUserdata );
125 }
126 success = TRUE;
127 }
128 else
129 {
130 LLString::format_map_t args;
131 // XUI:translate
132 args["[TYPE]"] = LLAssetType::lookupHumanReadable(data->mAssetType);
133 if (data->mName.empty())
134 {
135 LLNotifyBox::showXml("FailedToLoadWearableUnnamed", args);
136 }
137 else
138 {
139 args["[DESC]"] = data->mName;
140 LLNotifyBox::showXml("FailedToLoadWearable", args);
141 }
142 delete wearable;
143 }
144
145 fclose( fp );
146 if(filename)
147 {
148 LLFile::remove(filename);
149 }
150 }
151 }
152 else
153 {
154 if(filename)
155 {
156 LLFile::remove(filename);
157 }
158 if( gViewerStats )
159 {
160 gViewerStats->incStat( LLViewerStats::ST_DOWNLOAD_FAILED );
161 }
162
163 llwarns << "Wearable download failed: " << LLAssetStorage::getErrorString( status ) << " " << uuid << llendl;
164 switch( status )
165 {
166 case LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE:
167 {
168 LLString::format_map_t args;
169 // XUI:translate
170 args["[TYPE]"] = LLAssetType::lookupHumanReadable(data->mAssetType);
171 if (data->mName.empty())
172 {
173 LLNotifyBox::showXml("FailedToFindWearableUnnamed", args);
174 }
175 else
176 {
177 args["[DESC]"] = data->mName;
178 LLNotifyBox::showXml("FailedToFindWearable", args);
179 }
180
181 // Asset does not exist in the database.
182 // Can't load asset, so return NULL
183 if( data->mCallback )
184 {
185 data->mCallback( NULL, data->mUserdata );
186 }
187 break;
188 }
189 default:
190 {
191 // Try again
192 gAssetStorage->getAssetData(uuid,
193 data->mAssetType,
194 LLWearableList::processGetAssetReply,
195 userdata); // re-use instead of deleting.
196 return;
197 }
198 }
199 }
200
201 delete data;
202}
203
204
205LLWearable* LLWearableList::createLegacyWearableFromAvatar( EWearableType type )
206{
207 llinfos << "LLWearableList::createLegacyWearableFromAvatar" << llendl;
208
209 LLTransactionID tid;
210 LLAssetID new_asset_id;
211 tid.generate();
212 new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
213
214 LLWearable* wearable = new LLWearable( tid );
215 wearable->setType( type );
216 wearable->setName( wearable->getTypeLabel() );
217 wearable->setDescription( "Recovered from lost asset." );
218
219 LLVOAvatar* avatar = gAgent.getAvatarObject();
220 LLPermissions perm;
221 perm.init( avatar->getID(), avatar->getID(), LLUUID::null, LLUUID::null );
222 perm.initMasks(PERM_TRANSFER, PERM_TRANSFER, PERM_NONE, PERM_NONE, PERM_MOVE | PERM_TRANSFER);
223 wearable->setPermissions( perm );
224
225 // Save info is the default.
226
227 wearable->readFromAvatar();
228
229 mList[ new_asset_id ] = wearable;
230
231 // Send to the dataserver
232 wearable->saveNewAsset();
233
234 return wearable;
235}
236
237
238// Creates a new wearable just like the old_wearable but with data copied over from item
239LLWearable* LLWearableList::createWearableMatchedToInventoryItem( LLWearable* old_wearable, LLViewerInventoryItem* item )
240{
241 lldebugs << "LLWearableList::createWearableMatchedToInventoryItem()" << llendl;
242
243 LLTransactionID tid;
244 LLAssetID new_asset_id;
245 new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
246
247 LLWearable* wearable = new LLWearable( tid );
248 wearable->copyDataFrom( old_wearable );
249
250 wearable->setName( item->getName() );
251 wearable->setDescription( item->getDescription() );
252 wearable->setPermissions( item->getPermissions() );
253 wearable->setSaleInfo( item->getSaleInfo() );
254
255 mList[ new_asset_id ] = wearable;
256
257 // Send to the dataserver
258 wearable->saveNewAsset();
259
260 return wearable;
261}
262
263LLWearable* LLWearableList::createCopyFromAvatar( LLWearable* old_wearable, const std::string& new_name )
264{
265 lldebugs << "LLWearableList::createCopyFromAvatar()" << llendl;
266
267 LLTransactionID tid;
268 LLAssetID new_asset_id;
269 tid.generate();
270 new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
271
272 LLWearable* wearable = new LLWearable( tid );
273 wearable->copyDataFrom( old_wearable );
274 LLPermissions perm(old_wearable->getPermissions());
275 perm.setOwnerAndGroup(LLUUID::null, gAgent.getID(), LLUUID::null, true);
276 wearable->setPermissions(perm);
277 wearable->readFromAvatar(); // update from the avatar
278
279 if (!new_name.empty()) wearable->setName(new_name);
280
281 mList[ new_asset_id ] = wearable;
282
283 // Send to the dataserver
284 wearable->saveNewAsset();
285
286 return wearable;
287}
288
289
290LLWearable* LLWearableList::createCopy( LLWearable* old_wearable )
291{
292 lldebugs << "LLWearableList::createCopy()" << llendl;
293
294 LLTransactionID tid;
295 LLAssetID new_asset_id;
296 tid.generate();
297 new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
298
299 LLWearable* wearable = new LLWearable( tid );
300 wearable->copyDataFrom( old_wearable );
301 LLPermissions perm(old_wearable->getPermissions());
302 perm.setOwnerAndGroup(LLUUID::null, gAgent.getID(), LLUUID::null, true);
303 wearable->setPermissions(perm);
304 mList[ new_asset_id ] = wearable;
305
306 // Send to the dataserver
307 wearable->saveNewAsset();
308
309 return wearable;
310}
311
312LLWearable* LLWearableList::createNewWearable( EWearableType type )
313{
314 lldebugs << "LLWearableList::createNewWearable()" << llendl;
315
316 LLTransactionID tid;
317 LLAssetID new_asset_id;
318 tid.generate();
319 new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
320
321 LLWearable* wearable = new LLWearable( tid );
322 wearable->setType( type );
323
324 LLString name = "New ";
325 name.append( wearable->getTypeLabel() );
326 wearable->setName( name );
327
328 LLPermissions perm;
329 perm.init(gAgent.getID(), gAgent.getID(), LLUUID::null, LLUUID::null);
330 perm.initMasks(PERM_ALL, PERM_ALL, PERM_NONE, PERM_NONE, PERM_MOVE | PERM_TRANSFER);
331 wearable->setPermissions(perm);
332
333 // Description and sale info have default values.
334
335 wearable->setParamsToDefaults();
336 wearable->setTexturesToDefaults();
337
338 mList[ new_asset_id ] = wearable;
339
340 // Send to the dataserver
341 wearable->saveNewAsset();
342
343 return wearable;
344}