00001
00032 #ifndef LL_LLINVENTORYMODEL_H
00033 #define LL_LLINVENTORYMODEL_H
00034
00035 #include "llassettype.h"
00036 #include "lldarray.h"
00037 #include "lluuid.h"
00038 #include "llpermissionsflags.h"
00039 #include "llstring.h"
00040
00041 #include <map>
00042 #include <set>
00043 #include <string>
00044 #include <vector>
00045
00046
00047
00048
00049
00050
00051
00052
00053 class LLInventoryObserver
00054 {
00055 public:
00056
00057
00058
00059 enum
00060 {
00061 NONE = 0,
00062 LABEL = 1,
00063 INTERNAL = 2,
00064 ADD = 4,
00065 REMOVE = 8,
00066 STRUCTURE = 16,
00067 CALLING_CARD = 32,
00068 ALL = 0xffffffff
00069 };
00070 virtual ~LLInventoryObserver() {};
00071 virtual void changed(U32 mask) = 0;
00072 };
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 class LLInventoryObject;
00086 class LLInventoryItem;
00087 class LLInventoryCategory;
00088 class LLViewerInventoryItem;
00089 class LLViewerInventoryCategory;
00090 class LLViewerInventoryItem;
00091 class LLViewerInventoryCategory;
00092 class LLMessageSystem;
00093 class LLInventoryCollectFunctor;
00094 class LLAlertDialog;
00095
00096 class LLInventoryModel
00097 {
00098 public:
00099 typedef enum e_has_children
00100 {
00101 CHILDREN_NO,
00102 CHILDREN_YES,
00103 CHILDREN_MAYBE
00104 }EHasChildren;
00105
00106
00107 typedef LLDynamicArray<LLPointer<LLViewerInventoryCategory> > cat_array_t;
00108 typedef LLDynamicArray<LLPointer<LLViewerInventoryItem> > item_array_t;
00109
00110 LLInventoryModel();
00111 ~LLInventoryModel();
00112
00113 class fetchDescendentsResponder: public LLHTTPClient::Responder
00114 {
00115 public:
00116 fetchDescendentsResponder(const LLSD& request_sd) : mRequestSD(request_sd) {};
00117 void result(const LLSD& content);
00118 void error(U32 status, const std::string& reason);
00119 static void onClickRetry(S32 option, void* userdata);
00120 static void appendRetryList(LLSD retry_sd);
00121 public:
00122 typedef std::vector<LLViewerInventoryCategory*> folder_ref_t;
00123 protected:
00124 LLSD mRequestSD;
00125 static LLSD sRetrySD;
00126 static LLAlertDialog *sRetryDialog;
00127 };
00128
00129
00130
00131
00132
00133
00134
00135 BOOL isObjectDescendentOf(const LLUUID& obj_id, const LLUUID& cat_id);
00136
00137
00138
00139
00140 LLInventoryObject* getObject(const LLUUID& id) const;
00141
00142
00143
00144
00145 LLViewerInventoryItem* getItem(const LLUUID& id) const;
00146
00147
00148
00149
00150 LLViewerInventoryCategory* getCategory(const LLUUID& id) const;
00151
00152
00153 S32 getItemCount() const;
00154 S32 getCategoryCount() const;
00155
00156
00157
00158
00159
00160
00161
00162 void getDirectDescendentsOf(const LLUUID& cat_id,
00163 cat_array_t*& categories,
00164 item_array_t*& items) const;
00165
00166
00167
00168
00169
00170
00171
00172 enum { EXCLUDE_TRASH = FALSE, INCLUDE_TRASH = TRUE };
00173 void collectDescendents(const LLUUID& id,
00174 cat_array_t& categories,
00175 item_array_t& items,
00176 BOOL include_trash);
00177
00178 void collectDescendentsIf(const LLUUID& id,
00179 cat_array_t& categories,
00180 item_array_t& items,
00181 BOOL include_trash,
00182 LLInventoryCollectFunctor& add);
00183
00184
00185
00186
00187 bool isInventoryUsable();
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 U32 updateItem(const LLViewerInventoryItem* item);
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 void updateCategory(const LLViewerInventoryCategory* cat);
00215
00216
00217
00218
00219 void moveObject(const LLUUID& object_id, const LLUUID& cat_id);
00220
00221
00222
00223
00224
00225 void deleteObject(const LLUUID& id);
00226
00227
00228
00229
00230
00231
00232
00233 void purgeDescendentsOf(const LLUUID& id);
00234
00235
00236
00237
00238
00239 void deleteFromServer(LLDynamicArray<LLUUID>& category_ids,
00240 LLDynamicArray<LLUUID>& item_ids);
00241
00242
00243
00244 void addObserver(LLInventoryObserver* observer);
00245 void removeObserver(LLInventoryObserver* observer);
00246 BOOL containsObserver(LLInventoryObserver* observer);
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 LLUUID findCategoryUUIDForType(LLAssetType::EType preferred_type, bool create_folder = true);
00261
00262
00263
00264
00265 void notifyObservers();
00266
00267
00268
00269
00270
00271
00272
00273 void addChangedMask(U32 mask, const LLUUID& referent);
00274
00275 const std::set<LLUUID>& getChangedIDs() { return mChangedItemIDs; }
00276
00277
00278
00279
00280
00281
00282 void fetchDescendentsOf(const LLUUID& folder_id);
00283
00284
00285 static void bulkFetch(std::string url);
00286
00287
00288
00289
00290
00291 void cache(const LLUUID& parent_folder_id, const LLUUID& agent_id);
00292
00293
00294
00295 void appendPath(const LLUUID& id, LLString& path);
00296
00297
00298 static void registerCallbacks(LLMessageSystem* msg);
00299
00300
00301
00302
00303
00304
00305
00306 LLUUID createNewCategory(const LLUUID& parent_id,
00307 LLAssetType::EType preferred_type,
00308 const LLString& name);
00309
00310
00311
00312 typedef std::map<std::string, std::string> response_t;
00313 typedef std::vector<response_t> options_t;
00314 bool loadSkeleton(const options_t& options, const LLUUID& owner_id);
00315 bool loadMeat(const options_t& options, const LLUUID& owner_id);
00316
00317
00318
00319 void buildParentChildMap();
00320
00321
00322
00323
00324
00325
00326
00327 struct LLCategoryUpdate
00328 {
00329 LLCategoryUpdate() : mDescendentDelta(0) {}
00330 LLCategoryUpdate(const LLUUID& category_id, S32 delta) :
00331 mCategoryID(category_id),
00332 mDescendentDelta(delta) {}
00333 LLUUID mCategoryID;
00334 S32 mDescendentDelta;
00335 };
00336 typedef std::vector<LLCategoryUpdate> update_list_t;
00337
00338
00339
00340 struct LLInitializedS32
00341 {
00342 LLInitializedS32() : mValue(0) {}
00343 LLInitializedS32(S32 value) : mValue(value) {}
00344 S32 mValue;
00345 LLInitializedS32& operator++() { ++mValue; return *this; }
00346 LLInitializedS32& operator--() { --mValue; return *this; }
00347 };
00348 typedef std::map<LLUUID, LLInitializedS32> update_map_t;
00349
00350
00351
00352
00353 void accountForUpdate(const LLCategoryUpdate& update);
00354 void accountForUpdate(const update_list_t& updates);
00355 void accountForUpdate(const update_map_t& updates);
00356
00357
00358 EHasChildren categoryHasChildren(const LLUUID& cat_id) const;
00359
00360
00361
00362 bool isCategoryComplete(const LLUUID& cat_id) const;
00363
00364
00365
00366 static void startBackgroundFetch(const LLUUID& cat_id = LLUUID::null);
00367 static void stopBackgroundFetch();
00368 static BOOL backgroundFetchActive();
00369 static bool isEverythingFetched();
00370 static void backgroundFetch(void*);
00371 static void incrBulkFetch(S16 fetching) { sBulkFetchCount+=fetching; if (sBulkFetchCount<0) sBulkFetchCount=0; }
00372 protected:
00373
00374
00375
00376
00377
00378 void addCategory(LLViewerInventoryCategory* category);
00379 void addItem(LLViewerInventoryItem* item);
00380
00381
00382
00383 LLUUID findCatUUID(LLAssetType::EType preferred_type);
00384
00385
00386 void empty();
00387
00388
00389
00390
00391
00392
00393
00394
00395 static bool loadFromFile(
00396 const char* filename,
00397 cat_array_t& categories,
00398 item_array_t& items);
00399 static bool saveToFile(
00400 const char* filename,
00401 const cat_array_t& categories,
00402 const item_array_t& items);
00403
00404
00405
00406 static void processUpdateCreateInventoryItem(LLMessageSystem* msg, void**);
00407 static void processRemoveInventoryItem(LLMessageSystem* msg, void**);
00408 static void processUpdateInventoryFolder(LLMessageSystem* msg, void**);
00409 static void processRemoveInventoryFolder(LLMessageSystem* msg, void**);
00410
00411
00412
00413 static void processSaveAssetIntoInventory(LLMessageSystem* msg, void**);
00414 static void processBulkUpdateInventory(LLMessageSystem* msg, void**);
00415 static void processInventoryDescendents(LLMessageSystem* msg, void**);
00416 static void processMoveInventoryItem(LLMessageSystem* msg, void**);
00417 static void processFetchInventoryReply(LLMessageSystem* msg, void**);
00418 static bool isBulkFetchProcessingComplete();
00419
00420 bool messageUpdateCore(LLMessageSystem* msg, bool do_accounting);
00421
00422 protected:
00423
00424 U32 mModifyMask;
00425 typedef std::set<LLUUID> changed_items_t;
00426 changed_items_t mChangedItemIDs;
00427
00428
00429
00430
00431
00432
00433 typedef std::map<LLUUID, LLPointer<LLViewerInventoryCategory> > cat_map_t;
00434 typedef std::map<LLUUID, LLPointer<LLViewerInventoryItem> > item_map_t;
00435
00436 cat_map_t mCategoryMap;
00437 item_map_t mItemMap;
00438
00439
00440 mutable LLPointer<LLViewerInventoryItem> mLastItem;
00441
00442
00443 typedef std::map<LLUUID, cat_array_t*> parent_cat_map_t;
00444 typedef std::map<LLUUID, item_array_t*> parent_item_map_t;
00445 parent_cat_map_t mParentChildCategoryTree;
00446 parent_item_map_t mParentChildItemTree;
00447
00448 typedef std::set<LLInventoryObserver*> observer_list_t;
00449 observer_list_t mObservers;
00450
00451
00452 static cat_map_t sBulkFetchMap;
00453 static BOOL sBackgroundFetchActive;
00454 static BOOL sTimelyFetchPending;
00455 static BOOL sAllFoldersFetched;
00456 static BOOL sFullFetchStarted;
00457 static S32 sNumFetchRetries;
00458 static LLFrameTimer sFetchTimer;
00459 static F32 sMinTimeBetweenFetches;
00460 static F32 sMaxTimeBetweenFetches;
00461 static S16 sBulkFetchCount;
00462
00463
00464 bool mIsAgentInvUsable;
00465
00466 public:
00467
00468 void dumpInventory();
00469 };
00470
00471
00472 extern LLInventoryModel gInventory;
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484 class LLInventoryCollectFunctor
00485 {
00486 public:
00487 virtual ~LLInventoryCollectFunctor(){};
00488 virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item) = 0;
00489 };
00490
00491
00492
00493
00494
00495
00496
00497 class LLViewerInventoryItem;
00498
00499 class LLAssetIDMatches : public LLInventoryCollectFunctor
00500 {
00501 public:
00502 LLAssetIDMatches(const LLUUID& asset_id) : mAssetID(asset_id) {}
00503 virtual ~LLAssetIDMatches() {}
00504 bool operator()(LLInventoryCategory* cat, LLInventoryItem* item);
00505
00506 protected:
00507 LLUUID mAssetID;
00508 };
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518 class LLIsType : public LLInventoryCollectFunctor
00519 {
00520 public:
00521 LLIsType(LLAssetType::EType type) : mType(type) {}
00522 virtual ~LLIsType() {}
00523 virtual bool operator()(LLInventoryCategory* cat,
00524 LLInventoryItem* item);
00525 protected:
00526 LLAssetType::EType mType;
00527 };
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537 class LLIsNotType : public LLInventoryCollectFunctor
00538 {
00539 public:
00540 LLIsNotType(LLAssetType::EType type) : mType(type) {}
00541 virtual ~LLIsNotType() {}
00542 virtual bool operator()(LLInventoryCategory* cat,
00543 LLInventoryItem* item);
00544 protected:
00545 LLAssetType::EType mType;
00546 };
00547
00548 class LLIsTypeWithPermissions : public LLInventoryCollectFunctor
00549 {
00550 public:
00551 LLIsTypeWithPermissions(LLAssetType::EType type, const PermissionBit perms, const LLUUID &agent_id, const LLUUID &group_id)
00552 : mType(type), mPerm(perms), mAgentID(agent_id), mGroupID(group_id) {}
00553 virtual ~LLIsTypeWithPermissions() {}
00554 virtual bool operator()(LLInventoryCategory* cat,
00555 LLInventoryItem* item);
00556 protected:
00557 LLAssetType::EType mType;
00558 PermissionBit mPerm;
00559 LLUUID mAgentID;
00560 LLUUID mGroupID;
00561 };
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593 class LLBuddyCollector : public LLInventoryCollectFunctor
00594 {
00595 public:
00596 LLBuddyCollector() {}
00597 virtual ~LLBuddyCollector() {}
00598 virtual bool operator()(LLInventoryCategory* cat,
00599 LLInventoryItem* item);
00600 };
00601
00602
00603
00604
00605
00606
00607
00608
00609 class LLUniqueBuddyCollector : public LLInventoryCollectFunctor
00610 {
00611 public:
00612 LLUniqueBuddyCollector() {}
00613 virtual ~LLUniqueBuddyCollector() {}
00614 virtual bool operator()(LLInventoryCategory* cat,
00615 LLInventoryItem* item);
00616
00617 protected:
00618 std::set<LLUUID> mSeen;
00619 };
00620
00621
00622
00623
00624
00625
00626
00627 class LLParticularBuddyCollector : public LLInventoryCollectFunctor
00628 {
00629 public:
00630 LLParticularBuddyCollector(const LLUUID& id) : mBuddyID(id) {}
00631 virtual ~LLParticularBuddyCollector() {}
00632 virtual bool operator()(LLInventoryCategory* cat,
00633 LLInventoryItem* item);
00634 protected:
00635 LLUUID mBuddyID;
00636 };
00637
00638
00639
00640
00641
00642
00643
00644
00645 class LLNameCategoryCollector : public LLInventoryCollectFunctor
00646 {
00647 public:
00648 LLNameCategoryCollector(const char* name) : mName(name) {}
00649 virtual ~LLNameCategoryCollector() {}
00650 virtual bool operator()(LLInventoryCategory* cat,
00651 LLInventoryItem* item);
00652 protected:
00653 std::string mName;
00654 };
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667 class LLInventoryCompletionObserver : public LLInventoryObserver
00668 {
00669 public:
00670 LLInventoryCompletionObserver() {}
00671 virtual void changed(U32 mask);
00672
00673 void watchItem(const LLUUID& id);
00674
00675 protected:
00676 virtual void done() = 0;
00677
00678 typedef std::vector<LLUUID> item_ref_t;
00679 item_ref_t mComplete;
00680 item_ref_t mIncomplete;
00681 };
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692 class LLInventoryFetchObserver : public LLInventoryObserver
00693 {
00694 public:
00695 LLInventoryFetchObserver() {}
00696 virtual void changed(U32 mask);
00697
00698 typedef std::vector<LLUUID> item_ref_t;
00699
00700 bool isEverythingComplete() const;
00701 void fetchItems(const item_ref_t& ids);
00702 virtual void done() = 0;
00703
00704 protected:
00705 item_ref_t mComplete;
00706 item_ref_t mIncomplete;
00707 };
00708
00709
00710
00711
00712
00713
00714
00715
00716 class LLInventoryFetchDescendentsObserver : public LLInventoryObserver
00717 {
00718 public:
00719 LLInventoryFetchDescendentsObserver() {}
00720 virtual void changed(U32 mask);
00721
00722 typedef std::vector<LLUUID> folder_ref_t;
00723 void fetchDescendents(const folder_ref_t& ids);
00724 bool isEverythingComplete() const;
00725 virtual void done() = 0;
00726
00727 protected:
00728 bool isComplete(LLViewerInventoryCategory* cat);
00729 folder_ref_t mIncompleteFolders;
00730 folder_ref_t mCompleteFolders;
00731 };
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741 class LLInventoryFetchComboObserver : public LLInventoryObserver
00742 {
00743 public:
00744 LLInventoryFetchComboObserver() : mDone(false) {}
00745 virtual void changed(U32 mask);
00746
00747 typedef std::vector<LLUUID> folder_ref_t;
00748 typedef std::vector<LLUUID> item_ref_t;
00749 void fetch(const folder_ref_t& folder_ids, const item_ref_t& item_ids);
00750
00751 virtual void done() = 0;
00752
00753 protected:
00754 bool mDone;
00755 folder_ref_t mCompleteFolders;
00756 folder_ref_t mIncompleteFolders;
00757 item_ref_t mCompleteItems;
00758 item_ref_t mIncompleteItems;
00759 };
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770 class LLInventoryExistenceObserver : public LLInventoryObserver
00771 {
00772 public:
00773 LLInventoryExistenceObserver() {}
00774 virtual void changed(U32 mask);
00775
00776 void watchItem(const LLUUID& id);
00777
00778 protected:
00779 virtual void done() = 0;
00780
00781 typedef std::vector<LLUUID> item_ref_t;
00782 item_ref_t mExist;
00783 item_ref_t mMIA;
00784 };
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796 class LLInventoryAddedObserver : public LLInventoryObserver
00797 {
00798 public:
00799 LLInventoryAddedObserver() : mAdded() {}
00800 virtual void changed(U32 mask);
00801
00802 protected:
00803 virtual void done() = 0;
00804
00805 typedef std::vector<LLUUID> item_ref_t;
00806 item_ref_t mAdded;
00807 };
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819 class LLInventoryTransactionObserver : public LLInventoryObserver
00820 {
00821 public:
00822 LLInventoryTransactionObserver(const LLTransactionID& transaction_id);
00823 virtual void changed(U32 mask);
00824
00825 protected:
00826 typedef std::vector<LLUUID> folder_ref_t;
00827 typedef std::vector<LLUUID> item_ref_t;
00828 virtual void done(const folder_ref_t& folders, const item_ref_t& items) = 0;
00829
00830 LLTransactionID mTransactionID;
00831 };
00832
00833
00834 #endif // LL_LLINVENTORYMODEL_H
00835