Files
SingularityViewer/indra/newview/llviewerinventory.h
Aleric Inglewood cc9fc6b868 First attempt to deal with broken (pre multiwear) inventory items.
Since multiwear, the low 8 bit of inventory items, if they are of type
IT_WEARABLE, is used for the wearable type (WT_*). Older viewers and
bots (like Second Inventory) create inventory items with 0 in those
bits. This causes all those item to appear as shapes in multi-wear
capable viewers.

This gives rise to many problems:
1) You can't wear them, because the inventory and asset wearable type
mismatch, which makes Singularity just abort.
2) Before it aborts, it already removed your old shape, thinking you
are about to wear another shape - and told the server that you are
wearing this broken item now. The result is that you see no change,
until you relog when you are suddenly wearing the broken "shape"
and stay a cloud forever.

This commit detects the problem for AT_CLOTHING wearables, because
they are not compatible with the type 'shape' after all (which is
is AT_BODYPART). It still doesn't know what the wearable type is, but
sets the type temporarily to the new value WT_UNKNOWN. Since this is
at least not a shape anymore, it doesn't cause you shape to be removed
when wearing it. Moreover, once the asset is downloaded, the mismatch
is detected and corrected: you can now wear -say- pants, or other
clothing.

Inventory clothing items with an unknown wearable type now have a
red question mark icon in the inventory.

What does NOT work yet:

1) If you copy such an item and paste it, then the new copy has
a shape icon again (and all the previously mentioned problems).

2) If you wear broken hair, skin or eyes (which still show as
shapes in the inventory) then your shape is still removed, and
wearing them fails because they are not multiwear capable and you
are already wearing such a body part. What should be done here
is that the removed shape is added back and the real body part
that you're trying to wear is removed.

3) Although this code attempts to fix the mFlags in the inventory,
the icon in the inventory doesn't change from question mark to the
right thing.
2013-08-18 02:50:31 +02:00

389 lines
13 KiB
C++

/**
* @file llviewerinventory.h
* @brief Declaration of the inventory bits that only used on the viewer.
*
* $LicenseInfo:firstyear=2002&license=viewergpl$
* Second Life Viewer Source Code
* Copyright (c) 2002-2009, Linden Research, Inc.
*
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#ifndef LL_LLVIEWERINVENTORY_H
#define LL_LLVIEWERINVENTORY_H
#include "llinventory.h"
#include "llframetimer.h"
#include "llwearable.h"
#include "llui.h" //for LLDestroyClass
#include <boost/signals2.hpp> // boost::signals2::trackable
class LLFolderView;
class LLFolderBridge;
class LLViewerInventoryCategory;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLViewerInventoryItem
//
// An inventory item represents something that the current user has in
// their inventory.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLViewerInventoryItem : public LLInventoryItem, public boost::signals2::trackable
{
public:
typedef LLDynamicArray<LLPointer<LLViewerInventoryItem> > item_array_t;
protected:
~LLViewerInventoryItem( void ); // ref counted
public:
virtual LLAssetType::EType getType() const;
virtual const LLUUID& getAssetUUID() const;
virtual const LLUUID& getProtectedAssetUUID() const; // returns LLUUID::null if current agent does not have permission to expose this asset's UUID to the user
virtual const std::string& getName() const;
virtual const LLPermissions& getPermissions() const;
virtual const bool getIsFullPerm() const; // 'fullperm' in the popular sense: modify-ok & copy-ok & transfer-ok, no special god rules applied
virtual const LLUUID& getCreatorUUID() const;
virtual const std::string& getDescription() const;
virtual const LLSaleInfo& getSaleInfo() const;
virtual LLInventoryType::EType getInventoryType() const;
virtual bool isWearableType() const;
virtual LLWearableType::EType getWearableType() const;
virtual U32 getFlags() const;
virtual time_t getCreationDate() const;
virtual U32 getCRC32() const; // really more of a checksum.
// construct a complete viewer inventory item
LLViewerInventoryItem(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,
time_t creation_date_utc);
// construct a viewer inventory item which has the minimal amount
// of information to use in the UI.
LLViewerInventoryItem(
const LLUUID& item_id,
const LLUUID& parent_id,
const std::string& name,
LLInventoryType::EType inv_type);
// construct an invalid and incomplete viewer inventory item.
// usually useful for unpacking or importing or what have you.
// *NOTE: it is important to call setComplete() if you expect the
// operations to provide all necessary information.
LLViewerInventoryItem();
// 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
LLViewerInventoryItem(const LLViewerInventoryItem* other);
LLViewerInventoryItem(const LLInventoryItem* other);
void copyViewerItem(const LLViewerInventoryItem* other);
/*virtual*/ void copyItem(const LLInventoryItem* other);
// construct a new clone of this item - it creates a new viewer
// inventory item using the copy constructor, and returns it.
// It is up to the caller to delete (unref) the item.
void cloneViewerItem(LLPointer<LLViewerInventoryItem>& newitem) const;
// virtual methods
virtual void removeFromServer( void );
virtual void updateParentOnServer(BOOL restamp) const;
virtual void updateServer(BOOL is_new) const;
void fetchFromServer(void) const;
//virtual void packMessage(LLMessageSystem* msg) const;
virtual BOOL unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
virtual BOOL unpackMessage(LLSD item);
virtual BOOL importFile(LLFILE* fp);
virtual BOOL importLegacyStream(std::istream& input_stream);
// file handling on the viewer. These are not meant for anything
// other than cacheing.
bool exportFileLocal(LLFILE* fp) const;
bool importFileLocal(LLFILE* fp);
// new methods
BOOL isComplete() const { return mIsComplete; }
BOOL isFinished() const { return mIsComplete; }
void setComplete(BOOL complete) { mIsComplete = complete; }
//void updateAssetOnServer() const;
virtual void packMessage(LLMessageSystem* msg) const;
virtual void setTransactionID(const LLTransactionID& transaction_id);
struct comparePointers
{
bool operator()(const LLPointer<LLViewerInventoryItem>& a, const LLPointer<LLViewerInventoryItem>& b)
{
return a->getName().compare(b->getName()) < 0;
}
};
LLTransactionID getTransactionID() const { return mTransactionID; }
bool getIsBrokenLink() const; // true if the baseitem this points to doesn't exist in memory.
LLViewerInventoryItem *getLinkedItem() const;
LLViewerInventoryCategory *getLinkedCategory() const;
// Checks the items permissions (for owner, group, or everyone) and returns true if all mask bits are set.
bool checkPermissionsSet(PermissionMask mask) const;
PermissionMask getPermissionMask() const;
// callback
void onCallingCardNameLookup(const LLUUID& id, const std::string& name, bool is_group);
// If this is a broken link, try to fix it and any other identical link.
BOOL regenerateLink();
//<singu>
// Change WT_UNKNOWN to the type retrieved from the asset.
void setWearableType(LLWearableType::EType type);
//</singu>
public:
BOOL mIsComplete;
LLTransactionID mTransactionID;
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class LLViewerInventoryCategory
//
// An instance of this class represents a category of inventory
// items. Users come with a set of default categories, and can create
// new ones as needed.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLViewerInventoryCategory : public LLInventoryCategory
{
public:
typedef LLDynamicArray<LLPointer<LLViewerInventoryCategory> > cat_array_t;
protected:
~LLViewerInventoryCategory();
public:
LLViewerInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
LLFolderType::EType preferred_type,
const std::string& name,
const LLUUID& owner_id);
LLViewerInventoryCategory(const LLUUID& owner_id);
// Create a copy of an inventory category from a pointer to another category
// Note: Because InventoryCategorys are ref counted, reference copy (a = b)
// is prohibited
LLViewerInventoryCategory(const LLViewerInventoryCategory* other);
void copyViewerCategory(const LLViewerInventoryCategory* other);
virtual void removeFromServer();
virtual void updateParentOnServer(BOOL restamp_children) const;
virtual void updateServer(BOOL is_new) const;
const LLUUID& getOwnerID() const { return mOwnerID; }
// Version handling
enum { VERSION_UNKNOWN = -1, VERSION_INITIAL = 1 };
S32 getVersion() const { return mVersion; }
void setVersion(S32 version) { mVersion = version; }
// Returns true if a fetch was issued.
bool fetch();
// used to help make caching more robust - for example, if
// someone is getting 4 packets but logs out after 3. the viewer
// may never know the cache is wrong.
enum { DESCENDENT_COUNT_UNKNOWN = -1 };
S32 getDescendentCount() const { return mDescendentCount; }
void setDescendentCount(S32 descendents) { mDescendentCount = descendents; }
// file handling on the viewer. These are not meant for anything
// other than caching.
bool exportFileLocal(LLFILE* fp) const;
bool importFileLocal(LLFILE* fp);
void determineFolderType();
void changeType(LLFolderType::EType new_folder_type);
private:
friend class LLInventoryModel;
void localizeName(); // intended to be called from the LLInventoryModel
protected:
LLUUID mOwnerID;
S32 mVersion;
S32 mDescendentCount;
LLFrameTimer mDescendentsRequested;
};
class LLInventoryCallback : public LLRefCount
{
public:
virtual void fire(const LLUUID& inv_item) = 0;
};
class LLViewerJointAttachment;
//void rez_attachment_cb(const LLUUID& inv_item, LLViewerJointAttachment *attachmentp);
// [SL:KB] - Patch: Appearance-DnDWear | Checked: 2010-09-28 (Catznip-3.0.0a) | Added: Catznip-2.2.0a
void rez_attachment_cb(const LLUUID& inv_item, LLViewerJointAttachment *attachmentp, bool replace);
// [/SL:KB]
void activate_gesture_cb(const LLUUID& inv_item);
void create_gesture_cb(const LLUUID& inv_item);
class AddFavoriteLandmarkCallback : public LLInventoryCallback
{
public:
AddFavoriteLandmarkCallback() : mTargetLandmarkId(LLUUID::null) {}
void setTargetLandmarkId(const LLUUID& target_uuid) { mTargetLandmarkId = target_uuid; }
private:
void fire(const LLUUID& inv_item);
LLUUID mTargetLandmarkId;
};
typedef boost::function<void(const LLUUID&)> inventory_func_type;
void no_op_inventory_func(const LLUUID&); // A do-nothing inventory_func
typedef boost::function<void()> nullary_func_type;
void no_op(); // A do-nothing nullary func.
// Shim between inventory callback and boost function/callable
class LLBoostFuncInventoryCallback: public LLInventoryCallback
{
public:
LLBoostFuncInventoryCallback(inventory_func_type fire_func,
nullary_func_type destroy_func = no_op):
mFireFunc(fire_func),
mDestroyFunc(destroy_func)
{
}
// virtual
void fire(const LLUUID& item_id)
{
mFireFunc(item_id);
}
// virtual
~LLBoostFuncInventoryCallback()
{
mDestroyFunc();
}
private:
inventory_func_type mFireFunc;
nullary_func_type mDestroyFunc;
};
// misc functions
//void inventory_reliable_callback(void**, S32 status);
class LLInventoryCallbackManager : public LLDestroyClass<LLInventoryCallbackManager>
{
friend class LLDestroyClass<LLInventoryCallbackManager>;
public:
LLInventoryCallbackManager();
~LLInventoryCallbackManager();
void fire(U32 callback_id, const LLUUID& item_id);
U32 registerCB(LLPointer<LLInventoryCallback> cb);
private:
typedef std::map<U32, LLPointer<LLInventoryCallback> > callback_map_t;
callback_map_t mMap;
U32 mLastCallback;
static LLInventoryCallbackManager *sInstance;
static void destroyClass();
public:
static bool is_instantiated() { return sInstance != NULL; }
};
extern LLInventoryCallbackManager gInventoryCallbacks;
#define NOT_WEARABLE (LLWearableType::EType)0
// *TODO: Find a home for these
void create_inventory_item(const LLUUID& agent_id, const LLUUID& session_id,
const LLUUID& parent, const LLTransactionID& transaction_id,
const std::string& name,
const std::string& desc, LLAssetType::EType asset_type,
LLInventoryType::EType inv_type, LLWearableType::EType wtype,
U32 next_owner_perm,
LLPointer<LLInventoryCallback> cb);
void create_inventory_callingcard(const LLUUID& avatar_id, const LLUUID& parent = LLUUID::null, LLPointer<LLInventoryCallback> cb=NULL);
/**
* @brief Securely create a new inventory item by copying from another.
*/
void copy_inventory_item(
const LLUUID& agent_id,
const LLUUID& current_owner,
const LLUUID& item_id,
const LLUUID& parent_id,
const std::string& new_name,
LLPointer<LLInventoryCallback> cb);
void link_inventory_item(
const LLUUID& agent_id,
const LLUUID& item_id,
const LLUUID& parent_id,
const std::string& new_name,
const std::string& new_description,
const LLAssetType::EType asset_type,
LLPointer<LLInventoryCallback> cb);
void move_inventory_item(
const LLUUID& agent_id,
const LLUUID& session_id,
const LLUUID& item_id,
const LLUUID& parent_id,
const std::string& new_name,
LLPointer<LLInventoryCallback> cb);
const LLUUID get_folder_by_itemtype(const LLInventoryItem *src);
void copy_inventory_from_notecard(const LLUUID& destination_id,
const LLUUID& object_id,
const LLUUID& notecard_inv_id,
const LLInventoryItem *src,
U32 callback_id = 0);
void menu_create_inventory_item(LLFolderView* root,
LLFolderBridge* bridge,
const LLSD& userdata,
const LLUUID& default_parent_uuid = LLUUID::null);
#endif // LL_LLVIEWERINVENTORY_H