diff options
author | Mike Antipov <mantipov@productengine.com> | 2010-05-21 13:16:41 +0300 |
---|---|---|
committer | Mike Antipov <mantipov@productengine.com> | 2010-05-21 13:16:41 +0300 |
commit | 74393326562cc6c283c72ea6c4a3dfc3ffbaee08 (patch) | |
tree | 81d3ad03826d56a8e06e5ee4c003549e6505c3b5 /indra | |
parent | 5c370550bf216c24841879b5041f9b9d40fb459c (diff) |
EXT-6710 FIXED Implemented functionality to give multiselected inventory items to several selected avatars in avatar picker:
1. Select items to share
2. Click Share; Resident chooser opens
3. Select residents to share with, click SELECT
4. Selected items are transferred to selected users
5. Pop-up toast confirms transfer
Some implementation notes:
* Avatar Picker is not closed when give inventory requests are sent (to be enable change selection and offer other items to other avatars)
* Select button is enableŠ² if all selected items can be offered.
* Disabling of the "Share" menu item in the Inventory context menu is syncronized with check (before sending offer) whether item can be offered at all
Reviewed by Richard Nelson at https://codereview.productengine.com/secondlife/r/364/
--HG--
branch : product-engine
Diffstat (limited to 'indra')
-rw-r--r-- | indra/newview/llavataractions.cpp | 102 | ||||
-rw-r--r-- | indra/newview/llfloateravatarpicker.cpp | 12 | ||||
-rw-r--r-- | indra/newview/llinventorybridge.cpp | 6 |
3 files changed, 112 insertions, 8 deletions
diff --git a/indra/newview/llavataractions.cpp b/indra/newview/llavataractions.cpp index 00d9bbe18b..875ed72a12 100644 --- a/indra/newview/llavataractions.cpp +++ b/indra/newview/llavataractions.cpp @@ -54,7 +54,9 @@ #include "llfloaterreg.h" #include "llfloaterpay.h" #include "llfloaterworldmap.h" +#include "llgiveinventory.h" #include "llinventorymodel.h" // for gInventory.findCategoryUUIDForType +#include "llinventorypanel.h" #include "llimview.h" // for gIMMgr #include "llmutelist.h" #include "llnotificationsutil.h" // for LLNotificationsUtil @@ -429,13 +431,107 @@ void LLAvatarActions::share(const LLUUID& id) } } +namespace action_give_inventory +{ + typedef std::set<LLUUID> uuid_set_t; + + /** + * Checks My Inventory visibility. + */ + static bool is_give_inventory_acceptable() + { + LLInventoryPanel* active_panel = LLInventoryPanel::getActiveInventoryPanel(FALSE); + if (NULL == active_panel) return false; + + // check selection in the panel + const uuid_set_t inventory_selected_uuids = active_panel->getRootFolder()->getSelectionList(); + if (inventory_selected_uuids.empty()) return false; // nothing selected + + bool acceptable = false; + uuid_set_t::const_iterator it = inventory_selected_uuids.begin(); + const uuid_set_t::const_iterator it_end = inventory_selected_uuids.end(); + for (; it != it_end; ++it) + { + LLViewerInventoryCategory* inv_cat = gInventory.getCategory(*it); + // any category can be offered. + if (inv_cat) + { + acceptable = true; + continue; + } + + LLViewerInventoryItem* inv_item = gInventory.getItem(*it); + // check if inventory item can be given + if (LLGiveInventory::isInventoryGiveAcceptable(inv_item)) + { + acceptable = true; + continue; + } + + // there are neither item nor category in inventory + acceptable = false; + break; + } + return acceptable; + } + + /** + * Performs "give inventory" operations for provided avatars. + * + * Sends one requests to give all selected inventory items for each passed avatar. + * Avatars are represent by two vectors: names and UUIDs which must be sychronized with each other. + * + * @param avatar_names - avatar names request to be sent. + * @param avatar_uuids - avatar names request to be sent. + */ + static void give_inventory(const std::vector<std::string>& avatar_names, const uuid_vec_t& avatar_uuids) + { + llassert(avatar_names.size() == avatar_uuids.size()); + + LLInventoryPanel* active_panel = LLInventoryPanel::getActiveInventoryPanel(FALSE); + if (NULL == active_panel) return; + + const uuid_set_t inventory_selected_uuids = active_panel->getRootFolder()->getSelectionList(); + if (inventory_selected_uuids.empty()) return; + + S32 count = llmin(avatar_names.size(), avatar_uuids.size()); + + // iterate through avatars + for(S32 i = 0; i < count; ++i) + { + const std::string& avatar_name = avatar_names[i]; + const LLUUID& avatar_uuid = avatar_uuids[i]; + + // Start up IM before give the item + const LLUUID session_id = gIMMgr->addSession(avatar_name, IM_NOTHING_SPECIAL, avatar_uuid); + + uuid_set_t::const_iterator it = inventory_selected_uuids.begin(); + const uuid_set_t::const_iterator it_end = inventory_selected_uuids.end(); + + // iterate through selected inventory objects + for (; it != it_end; ++it) + { + LLViewerInventoryCategory* inv_cat = gInventory.getCategory(*it); + if (inv_cat) + { + LLGiveInventory::doGiveInventoryCategory(avatar_uuid, inv_cat, session_id); + break; + } + LLViewerInventoryItem* inv_item = gInventory.getItem(*it); + LLGiveInventory::doGiveInventoryItem(avatar_uuid, inv_item, session_id); + } + } + } +} + //static void LLAvatarActions::shareWithAvatars() { - LLFloaterAvatarPicker* picker = - LLFloaterAvatarPicker::show(NULL, FALSE, TRUE); - picker->setOkBtnEnableCb(boost::lambda::constant(false)); + using namespace action_give_inventory; + LLFloaterAvatarPicker* picker = + LLFloaterAvatarPicker::show(boost::bind(give_inventory, _1, _2), TRUE, FALSE); + picker->setOkBtnEnableCb(boost::bind(is_give_inventory_acceptable)); LLNotificationsUtil::add("ShareNotification"); } diff --git a/indra/newview/llfloateravatarpicker.cpp b/indra/newview/llfloateravatarpicker.cpp index d1e99fbd61..b40c19c2c6 100644 --- a/indra/newview/llfloateravatarpicker.cpp +++ b/indra/newview/llfloateravatarpicker.cpp @@ -314,6 +314,18 @@ void LLFloaterAvatarPicker::populateFriend() void LLFloaterAvatarPicker::draw() { + // sometimes it is hard to determine when Select/Ok button should be disabled (see LLAvatarActions::shareWithAvatars). + // lets check this via mOkButtonValidateSignal callback periodically. + static LLFrameTimer timer; + if (timer.hasExpired()) + { + timer.setTimerExpirySec(0.33f); // three times per second should be enough. + + // simulate list changes. + onList(); + timer.start(); + } + LLFloater::draw(); if (!mNearMeListComplete && childGetVisibleTab("ResidentChooserTabs") == getChild<LLPanel>("NearMePanel")) { diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp index 2c59cee2ee..2d27c89074 100644 --- a/indra/newview/llinventorybridge.cpp +++ b/indra/newview/llinventorybridge.cpp @@ -1017,11 +1017,7 @@ BOOL LLInvFVBridge::canShare() const { if (!LLInventoryCollectFunctor::itemTransferCommonlyAllowed(item)) return FALSE; - if (!item->getPermissions().allowOperationBy(PERM_TRANSFER, gAgent.getID())) - return FALSE; - if (!item->getPermissions().allowCopyBy(gAgent.getID())) - return FALSE; - return TRUE; + return (BOOL)LLGiveInventory::isInventoryGiveAcceptable(item); } // All categories can be given. |