// Checked: 2010-04-18 (RLVa-1.1.3b) | Modified: RLVa-1.2.0e
void RlvFloaterBehaviour::refreshAll()
{
    LLCtrlListInterface* pBhvrList = childGetListInterface("behaviour_list");
    if (!pBhvrList)
        return;
    pBhvrList->operateOnAll(LLCtrlListInterface::OP_DELETE);

    if (!gAgentAvatarp)
        return;

    //
    // Set-up a row we can just reuse
    //
    LLSD sdRow;
    LLSD& sdColumns = sdRow["columns"];
    sdColumns[0]["column"] = "behaviour";
    sdColumns[0]["type"] = "text";
    sdColumns[1]["column"] = "name";
    sdColumns[1]["type"] = "text";

    //
    // List behaviours
    //
    const RlvHandler::rlv_object_map_t* pRlvObjects = gRlvHandler.getObjectMap();
    for (RlvHandler::rlv_object_map_t::const_iterator itObj = pRlvObjects->begin(), endObj = pRlvObjects->end(); itObj != endObj; ++itObj)
    {
        sdColumns[1]["value"] = rlvGetItemNameFromObjID(itObj->first);

        const rlv_command_list_t* pCommands = itObj->second.getCommandList();
        for (rlv_command_list_t::const_iterator itCmd = pCommands->begin(), endCmd = pCommands->end(); itCmd != endCmd; ++itCmd)
        {
            std::string strBhvr = itCmd->asString();

            LLUUID idOption(itCmd->getOption());
            if (idOption.notNull())
            {
                std::string strLookup;
                if ( (gCacheName->getFullName(idOption, strLookup)) || (gCacheName->getGroupName(idOption, strLookup)) )
                {
                    if (strLookup.find("???") == std::string::npos)
                        strBhvr.assign(itCmd->getBehaviour()).append(":").append(strLookup);
                }
                else if (m_PendingLookup.end() == m_PendingLookup.find(idOption))
                {
                    m_PendingLookup[idOption] = gCacheName->get(idOption, false, boost::bind(&RlvFloaterBehaviour::onAvatarNameLookup,this,_1));
                }
            }

            sdColumns[0]["value"] = strBhvr;

            pBhvrList->addElement(sdRow, ADD_BOTTOM);
        }
    }
}
// Checked: 2011-05-26 (RLVa-1.3.1c) | Added: RLVa-1.3.1c
void RlvFloaterBehaviours::onBtnCopyToClipboard() const
{
	std::ostringstream strRestrictions;

	strRestrictions << RlvStrings::getVersion() << "\n";

	const RlvHandler::rlv_object_map_t* pObjects = gRlvHandler.getObjectMap();
	for (RlvHandler::rlv_object_map_t::const_iterator itObj = pObjects->begin(), endObj = pObjects->end(); itObj != endObj; ++itObj)
	{
		strRestrictions << "\n" << rlvGetItemNameFromObjID(itObj->first) << ":\n";

		const rlv_command_list_t* pCommands = itObj->second.getCommandList();
		for (rlv_command_list_t::const_iterator itCmd = pCommands->begin(), endCmd = pCommands->end(); itCmd != endCmd; ++itCmd)
		{
			std::string strOption; LLUUID idOption;
			if ( (itCmd->hasOption()) && (idOption.set(itCmd->getOption(), FALSE)) && (idOption.notNull()) )
			{
				LLAvatarName avName;
				if (gObjectList.findObject(idOption))
					strOption = rlvGetItemNameFromObjID(idOption, true);
				else if (LLAvatarNameCache::get(idOption, &avName))
					strOption = (!avName.getAccountName().empty()) ? avName.getAccountName() : avName.getDisplayName();
				else if (!gCacheName->getGroupName(idOption, strOption))
					strOption = itCmd->getOption();
			}

			strRestrictions << "  -> " << itCmd->asString();
			if ( (!strOption.empty()) && (strOption != itCmd->getOption()) )
				strRestrictions << "  [" << strOption << "]";
			if (RLV_RET_SUCCESS != itCmd->getReturnType())
				strRestrictions << "  (" << RlvStrings::getStringFromReturnCode(itCmd->getReturnType()) << ")";
			strRestrictions << "\n";
		}
	}

	LLWString wstrRestrictions = utf8str_to_wstring(strRestrictions.str());
	gClipboard.copyFromSubstring(wstrRestrictions, 0, wstrRestrictions.length());
}
// Checked: 2012-07-29 (RLVa-1.4.7)
std::string rlvFolderLockSourceToTarget(RlvFolderLocks::folderlock_source_t lockSource)
{
	switch (lockSource.first)
	{
		case RlvFolderLocks::ST_ATTACHMENT:
			{
				std::string strAttachName = rlvGetItemNameFromObjID(boost::get<LLUUID>(lockSource.second));
				return llformat("Attachment (%s)", strAttachName.c_str());
			}
		case RlvFolderLocks::ST_ATTACHMENTPOINT:
			{
				const LLViewerJointAttachment* pAttachPt = RlvAttachPtLookup::getAttachPoint(boost::get<S32>(lockSource.second));
				return llformat("Attachment point (%s)", (pAttachPt) ? pAttachPt->getName().c_str() : "Unknown");
			}
		case RlvFolderLocks::ST_FOLDER:
			{
				return "Folder: <todo>";
			}
		case RlvFolderLocks::ST_ROOTFOLDER:
			{
				return "Root folder";
			}
		case RlvFolderLocks::ST_SHAREDPATH:
			{
				const std::string& strPath = boost::get<std::string>(lockSource.second);
				return llformat("Shared path (#RLV%s%s)", (!strPath.empty()) ? "/" : "", strPath.c_str());
			}
		case RlvFolderLocks::ST_WEARABLETYPE:
			{
				const std::string& strTypeName = LLWearableType::getTypeName(boost::get<LLWearableType::EType>(lockSource.second));
				return llformat("Wearable type (%s)", strTypeName.c_str());
			}
		default:
			{
				return "(Unknown)";
			}
	}
}
// Checked: 2010-03-18 (RLVa-1.2.0)
void RlvFloaterLocks::refreshAll() const
{
	LLScrollListCtrl* pLockList = getChild<LLScrollListCtrl>("lock_list");
	pLockList->operateOnAll(LLCtrlListInterface::OP_DELETE);

	if (!isAgentAvatarValid())
		return;

	//
	// Set-up a row we can just reuse
	//
	LLSD sdRow;
	LLSD& sdColumns = sdRow["columns"];
	sdColumns[0]["column"] = "lock_type";   sdColumns[0]["type"] = "text";
	sdColumns[1]["column"] = "lock_addrem"; sdColumns[1]["type"] = "text";
	sdColumns[2]["column"] = "lock_target"; sdColumns[2]["type"] = "text";
	sdColumns[3]["column"] = "lock_origin"; sdColumns[3]["type"] = "text";

	//
	// List attachment locks
	//
	sdColumns[0]["value"] = "Attachment";
	sdColumns[1]["value"] = "rem";

	const RlvAttachmentLocks::rlv_attachobjlock_map_t& attachObjRem = gRlvAttachmentLocks.getAttachObjLocks();
	for (RlvAttachmentLocks::rlv_attachobjlock_map_t::const_iterator itAttachObj = attachObjRem.begin(); 
			itAttachObj != attachObjRem.end(); ++itAttachObj)
	{
		sdColumns[2]["value"] = rlvGetItemNameFromObjID(itAttachObj->first);
		sdColumns[3]["value"] = rlvGetItemNameFromObjID(itAttachObj->second);

		pLockList->addElement(sdRow, ADD_BOTTOM);
	}

	//
	// List attachment point locks
	//
	sdColumns[0]["value"] = "Attachment Point";

	sdColumns[1]["value"] = "add";
	const RlvAttachmentLocks::rlv_attachptlock_map_t& attachPtAdd = gRlvAttachmentLocks.getAttachPtLocks(RLV_LOCK_ADD);
	for (RlvAttachmentLocks::rlv_attachptlock_map_t::const_iterator itAttachPt = attachPtAdd.begin(); 
			itAttachPt != attachPtAdd.end(); ++itAttachPt)
	{
		const LLViewerJointAttachment* pAttachPt = 
			get_if_there(gAgentAvatarp->mAttachmentPoints, itAttachPt->first, static_cast<LLViewerJointAttachment*>(NULL));
		sdColumns[2]["value"] = pAttachPt->getName();
		sdColumns[3]["value"] = rlvGetItemNameFromObjID(itAttachPt->second);

		pLockList->addElement(sdRow, ADD_BOTTOM);
	}

	sdColumns[1]["value"] = "rem";
	const RlvAttachmentLocks::rlv_attachptlock_map_t& attachPtRem = gRlvAttachmentLocks.getAttachPtLocks(RLV_LOCK_REMOVE);
	for (RlvAttachmentLocks::rlv_attachptlock_map_t::const_iterator itAttachPt = attachPtRem.begin(); 
			itAttachPt != attachPtRem.end(); ++itAttachPt)
	{
		const LLViewerJointAttachment* pAttachPt = 
			get_if_there(gAgentAvatarp->mAttachmentPoints, itAttachPt->first, static_cast<LLViewerJointAttachment*>(NULL));
		sdColumns[2]["value"] = pAttachPt->getName();
		sdColumns[3]["value"] = rlvGetItemNameFromObjID(itAttachPt->second);

		pLockList->addElement(sdRow, ADD_BOTTOM);
	}

	//
	// List wearable type locks
	//
	sdColumns[0]["value"] = "Wearable Type";

	sdColumns[1]["value"] = "add";
	const RlvWearableLocks::rlv_wearabletypelock_map_t& wearableTypeAdd = gRlvWearableLocks.getWearableTypeLocks(RLV_LOCK_ADD);
	for (RlvWearableLocks::rlv_wearabletypelock_map_t::const_iterator itWearableType = wearableTypeAdd.begin(); 
			itWearableType != wearableTypeAdd.end(); ++itWearableType)
	{
		sdColumns[2]["value"] = LLWearableType::getTypeLabel(itWearableType->first);
		sdColumns[3]["value"] = rlvGetItemNameFromObjID(itWearableType->second);

		pLockList->addElement(sdRow, ADD_BOTTOM);
	}

	sdColumns[1]["value"] = "rem";
	const RlvWearableLocks::rlv_wearabletypelock_map_t& wearableTypeRem = gRlvWearableLocks.getWearableTypeLocks(RLV_LOCK_REMOVE);
	for (RlvWearableLocks::rlv_wearabletypelock_map_t::const_iterator itWearableType = wearableTypeRem.begin(); 
			itWearableType != wearableTypeRem.end(); ++itWearableType)
	{
		sdColumns[2]["value"] = LLWearableType::getTypeName(itWearableType->first);
		sdColumns[3]["value"] = rlvGetItemNameFromObjID(itWearableType->second);

		pLockList->addElement(sdRow, ADD_BOTTOM);
	}

	//
	// List "nostrip" (soft) locks
	//
	sdColumns[1]["value"] = "nostrip";
	sdColumns[3]["value"] = "(Agent)";

	LLInventoryModel::cat_array_t folders; LLInventoryModel::item_array_t items;
	LLFindWearablesEx f(true, true);
	gInventory.collectDescendentsIf(LLAppearanceMgr::instance().getCOF(), folders, items, FALSE, f);

	for (LLInventoryModel::item_array_t::const_iterator itItem = items.begin(); itItem != items.end(); ++itItem)
	{
		const LLViewerInventoryItem* pItem = *itItem;
		if (!RlvForceWear::instance().isStrippable(pItem->getUUID()))
		{
			sdColumns[0]["value"] = rlvGetItemType(pItem);
			sdColumns[2]["value"] = rlvGetItemName(pItem);

			pLockList->addElement(sdRow, ADD_BOTTOM);
		}
	}

	//
	// List folder locks
	//
	{
		// Folder lock descriptors
		const RlvFolderLocks::folderlock_list_t& folderLocks = RlvFolderLocks::instance().getFolderLocks();
		for (RlvFolderLocks::folderlock_list_t::const_iterator itFolderLock = folderLocks.begin(); 
				itFolderLock != folderLocks.end(); ++itFolderLock)
		{
			const RlvFolderLocks::folderlock_descr_t* pLockDescr = *itFolderLock;
			if (pLockDescr)
			{
				sdColumns[0]["value"] = "Folder Descriptor";
				sdColumns[1]["value"] =
					rlvLockMaskToString(pLockDescr->eLockType) + "/" +
					rlvFolderLockPermissionToString(pLockDescr->eLockPermission) + "/" +
					rlvFolderLockScopeToString(pLockDescr->eLockScope);
				sdColumns[2]["value"] = rlvFolderLockSourceToTarget(pLockDescr->lockSource);
				sdColumns[3]["value"] = rlvGetItemNameFromObjID(pLockDescr->idRlvObj);

				pLockList->addElement(sdRow, ADD_BOTTOM);
			}
		}
	}

	{
		// Folder locked attachments and wearables
		uuid_vec_t idItems;
		const uuid_vec_t& folderLockAttachmentsIds = RlvFolderLocks::instance().getAttachmentLookups();
		idItems.insert(idItems.end(), folderLockAttachmentsIds.begin(), folderLockAttachmentsIds.end());
		const uuid_vec_t& folderLockWearabels = RlvFolderLocks::instance().getWearableLookups();
		idItems.insert(idItems.end(), folderLockWearabels.begin(), folderLockWearabels.end());

		for (uuid_vec_t::const_iterator itItemId = idItems.begin(); itItemId != idItems.end(); ++itItemId)
		{
			const LLViewerInventoryItem* pItem = gInventory.getItem(*itItemId);
			if (pItem)
			{
				sdColumns[0]["value"] = rlvGetItemType(pItem);
				sdColumns[1]["value"] = rlvLockMaskToString(RLV_LOCK_REMOVE);
				sdColumns[2]["value"] = rlvGetItemName(pItem);
				sdColumns[3]["value"] = "<Folder Lock>";

				pLockList->addElement(sdRow, ADD_BOTTOM);
			}
		}
	}
}
// Checked: 2011-05-23 (RLVa-1.3.1c) | Modified: RLVa-1.3.1c
void RlvFloaterBehaviours::refreshAll()
{
	LLCtrlListInterface* pBhvrList = childGetListInterface("behaviour_list");
	LLCtrlListInterface* pExceptList = childGetListInterface("exception_list");
	if ( (!pBhvrList) || (!pExceptList) )
		return;
	pBhvrList->operateOnAll(LLCtrlListInterface::OP_DELETE);
	pExceptList->operateOnAll(LLCtrlListInterface::OP_DELETE);

	if (!isAgentAvatarValid())
		return;

	//
	// Set-up a row we can just reuse
	//
	LLSD sdBhvrRow; LLSD& sdBhvrColumns = sdBhvrRow["columns"];
	sdBhvrColumns[0] = LLSD().with("column", "behaviour").with("type", "text");
	sdBhvrColumns[1] = LLSD().with("column", "issuer").with("type", "text");

	LLSD sdExceptRow; LLSD& sdExceptColumns = sdExceptRow["columns"];
	sdExceptColumns[0] = LLSD().with("column", "behaviour").with("type", "text");
	sdExceptColumns[1] = LLSD().with("column", "option").with("type", "text");
	sdExceptColumns[2] = LLSD().with("column", "issuer").with("type", "text");

	//
	// List behaviours
	//
	const RlvHandler::rlv_object_map_t* pObjects = gRlvHandler.getObjectMap();
	for (RlvHandler::rlv_object_map_t::const_iterator itObj = pObjects->begin(), endObj = pObjects->end(); itObj != endObj; ++itObj)
	{
		const std::string strIssuer = rlvGetItemNameFromObjID(itObj->first);

		const rlv_command_list_t* pCommands = itObj->second.getCommandList();
		for (rlv_command_list_t::const_iterator itCmd = pCommands->begin(), endCmd = pCommands->end(); itCmd != endCmd; ++itCmd)
		{
			std::string strOption; LLUUID idOption;
			if ( (itCmd->hasOption()) && (idOption.set(itCmd->getOption(), FALSE)) && (idOption.notNull()) )
			{
				LLAvatarName avName;
				if (gObjectList.findObject(idOption))
				{
					strOption = rlvGetItemNameFromObjID(idOption, true);
				}
				else if (LLAvatarNameCache::get(idOption, &avName))
				{
					strOption = (!avName.getAccountName().empty()) ? avName.getAccountName() : avName.getDisplayName();
				}
				else if (!gCacheName->getGroupName(idOption, strOption))
				{
					if (m_PendingLookup.end() == std::find(m_PendingLookup.begin(), m_PendingLookup.end(), idOption))
					{
						LLAvatarNameCache::get(idOption, boost::bind(&RlvFloaterBehaviours::onAvatarNameLookup, this, _1, _2));
						m_PendingLookup.push_back(idOption);
					}
					strOption = itCmd->getOption();
				}
			}

			if ( (itCmd->hasOption()) && (rlvGetShowException(itCmd->getBehaviourType())) )
			{
				// List under the "Exception" tab
				sdExceptRow["enabled"] = gRlvHandler.isException(itCmd->getBehaviourType(), idOption);
				sdExceptColumns[0]["value"] = itCmd->getBehaviour();
				sdExceptColumns[1]["value"] = strOption;
				sdExceptColumns[2]["value"] = strIssuer;
				pExceptList->addElement(sdExceptRow, ADD_BOTTOM);
			}
			else
			{
				// List under the "Restrictions" tab
				sdBhvrRow["enabled"] = (RLV_RET_SUCCESS == itCmd->getReturnType());
				sdBhvrColumns[0]["value"] = (strOption.empty()) ? itCmd->asString() : itCmd->getBehaviour() + ":" + strOption;
				sdBhvrColumns[1]["value"] = strIssuer;
				pBhvrList->addElement(sdBhvrRow, ADD_BOTTOM);
			}
		}
	}
}