PageRenderTime 67ms CodeModel.GetById 12ms app.highlight 49ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llfloaterbulkpermission.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 364 lines | 239 code | 39 blank | 86 comment | 38 complexity | 7ffd57304fb0c69dcb9e48ad5abdfa8d MD5 | raw file
  1/** 
  2 * @file llfloaterbulkpermissions.cpp
  3 * @author Michelle2 Zenovka
  4 * @brief A floater which allows task inventory item's properties to be changed on mass.
  5 *
  6 * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28
 29#include "llviewerprecompiledheaders.h"
 30#include "llfloaterbulkpermission.h"
 31#include "llfloaterperms.h" // for utilities
 32#include "llagent.h"
 33#include "llchat.h"
 34#include "llinventorydefines.h"
 35#include "llviewerwindow.h"
 36#include "llviewerobject.h"
 37#include "llviewerobjectlist.h"
 38#include "llviewerregion.h"
 39#include "lscript_rt_interface.h"
 40#include "llviewercontrol.h"
 41#include "llviewerinventory.h"
 42#include "llviewerobject.h"
 43#include "llviewerregion.h"
 44#include "llresmgr.h"
 45#include "llbutton.h"
 46#include "lldir.h"
 47#include "llviewerstats.h"
 48#include "lluictrlfactory.h"
 49#include "llselectmgr.h"
 50#include "llcheckboxctrl.h"
 51
 52#include "roles_constants.h" // for GP_OBJECT_MANIPULATE
 53
 54
 55LLFloaterBulkPermission::LLFloaterBulkPermission(const LLSD& seed) 
 56:	LLFloater(seed),
 57	mDone(FALSE)
 58{
 59	mID.generate();
 60	mCommitCallbackRegistrar.add("BulkPermission.Apply",	boost::bind(&LLFloaterBulkPermission::onApplyBtn, this));
 61	mCommitCallbackRegistrar.add("BulkPermission.Close",	boost::bind(&LLFloaterBulkPermission::onCloseBtn, this));
 62	mCommitCallbackRegistrar.add("BulkPermission.CheckAll",	boost::bind(&LLFloaterBulkPermission::onCheckAll, this));
 63	mCommitCallbackRegistrar.add("BulkPermission.UncheckAll",	boost::bind(&LLFloaterBulkPermission::onUncheckAll, this));
 64	mCommitCallbackRegistrar.add("BulkPermission.CommitCopy",	boost::bind(&LLFloaterBulkPermission::onCommitCopy, this));
 65}
 66
 67BOOL LLFloaterBulkPermission::postBuild()
 68{
 69	return TRUE;
 70}
 71
 72void LLFloaterBulkPermission::doApply()
 73{
 74	// Inspects a stream of selected object contents and adds modifiable ones to the given array.
 75	class ModifiableGatherer : public LLSelectedNodeFunctor
 76	{
 77	public:
 78		ModifiableGatherer(LLDynamicArray<LLUUID>& q) : mQueue(q) {}
 79		virtual bool apply(LLSelectNode* node)
 80		{
 81			if( node->allowOperationOnNode(PERM_MODIFY, GP_OBJECT_MANIPULATE) )
 82			{
 83				mQueue.put(node->getObject()->getID());
 84			}
 85			return true;
 86		}
 87	private:
 88		LLDynamicArray<LLUUID>& mQueue;
 89	};
 90	LLScrollListCtrl* list = getChild<LLScrollListCtrl>("queue output");
 91	list->deleteAllItems();
 92	ModifiableGatherer gatherer(mObjectIDs);
 93	LLSelectMgr::getInstance()->getSelection()->applyToNodes(&gatherer);
 94	if(mObjectIDs.empty())
 95	{
 96		list->setCommentText(getString("nothing_to_modify_text"));
 97	}
 98	else
 99	{
100		mDone = FALSE;
101		if (!start())
102		{
103			llwarns << "Unexpected bulk permission change failure." << llendl;
104		}
105	}
106}
107
108
109// This is the callback method for the viewer object currently being
110// worked on.
111// NOT static, virtual!
112void LLFloaterBulkPermission::inventoryChanged(LLViewerObject* viewer_object,
113											 LLInventoryObject::object_list_t* inv,
114											 S32,
115											 void* q_id)
116{
117	//llinfos << "changed object: " << viewer_object->getID() << llendl;
118
119	//Remove this listener from the object since its
120	//listener callback is now being executed.
121	
122	//We remove the listener here because the function
123	//removeVOInventoryListener removes the listener from a ViewerObject
124	//which it internally stores.
125	
126	//If we call this further down in the function, calls to handleInventory
127	//and nextObject may update the interally stored viewer object causing
128	//the removal of the incorrect listener from an incorrect object.
129	
130	//Fixes SL-6119:Recompile scripts fails to complete
131	removeVOInventoryListener();
132
133	if (viewer_object && inv && (viewer_object->getID() == mCurrentObjectID) )
134	{
135		handleInventory(viewer_object, inv);
136	}
137	else
138	{
139		// something went wrong...
140		// note that we're not working on this one, and move onto the
141		// next object in the list.
142		llwarns << "No inventory for " << mCurrentObjectID << llendl;
143		nextObject();
144	}
145}
146
147void LLFloaterBulkPermission::onApplyBtn()
148{
149	doApply();
150}
151
152void LLFloaterBulkPermission::onCloseBtn()
153{
154	closeFloater();
155}
156
157//static 
158void LLFloaterBulkPermission::onCommitCopy()
159{
160	// Implements fair use
161	BOOL copyable = gSavedSettings.getBOOL("BulkChangeNextOwnerCopy");
162	if(!copyable)
163	{
164		gSavedSettings.setBOOL("BulkChangeNextOwnerTransfer", TRUE);
165	}
166	LLCheckBoxCtrl* xfer =getChild<LLCheckBoxCtrl>("next_owner_transfer");
167	xfer->setEnabled(copyable);
168}
169
170BOOL LLFloaterBulkPermission::start()
171{
172	// note: number of top-level objects to modify is mObjectIDs.count().
173	getChild<LLScrollListCtrl>("queue output")->setCommentText(getString("start_text"));
174	return nextObject();
175}
176
177// Go to the next object and start if found. Returns false if no objects left, true otherwise.
178BOOL LLFloaterBulkPermission::nextObject()
179{
180	S32 count;
181	BOOL successful_start = FALSE;
182	do
183	{
184		count = mObjectIDs.count();
185		//llinfos << "Objects left to process = " << count << llendl;
186		mCurrentObjectID.setNull();
187		if(count > 0)
188		{
189			successful_start = popNext();
190			//llinfos << (successful_start ? "successful" : "unsuccessful") << llendl; 
191		}
192	} while((mObjectIDs.count() > 0) && !successful_start);
193
194	if(isDone() && !mDone)
195	{
196		getChild<LLScrollListCtrl>("queue output")->setCommentText(getString("done_text"));
197		mDone = TRUE;
198	}
199	return successful_start;
200}
201
202// Pop the top object off of the queue.
203// Return TRUE if the queue has started, otherwise FALSE.
204BOOL LLFloaterBulkPermission::popNext()
205{
206	// get the head element from the container, and attempt to get its inventory.
207	BOOL rv = FALSE;
208	S32 count = mObjectIDs.count();
209	if(mCurrentObjectID.isNull() && (count > 0))
210	{
211		mCurrentObjectID = mObjectIDs.get(0);
212		//llinfos << "mCurrentID: " << mCurrentObjectID << llendl;
213		mObjectIDs.remove(0);
214		LLViewerObject* obj = gObjectList.findObject(mCurrentObjectID);
215		if(obj)
216		{
217			//llinfos << "requesting inv for " << mCurrentObjectID << llendl;
218			LLUUID* id = new LLUUID(mID);
219			registerVOInventoryListener(obj,id);
220			requestVOInventory();
221			rv = TRUE;
222		}
223		else
224		{
225			llinfos<<"NULL LLViewerObject" <<llendl;
226		}
227	}
228
229	return rv;
230}
231
232
233void LLFloaterBulkPermission::doCheckUncheckAll(BOOL check)
234{
235	gSavedSettings.setBOOL("BulkChangeIncludeAnimations", check);
236	gSavedSettings.setBOOL("BulkChangeIncludeBodyParts" , check);
237	gSavedSettings.setBOOL("BulkChangeIncludeClothing"  , check);
238	gSavedSettings.setBOOL("BulkChangeIncludeGestures"  , check);
239	gSavedSettings.setBOOL("BulkChangeIncludeNotecards" , check);
240	gSavedSettings.setBOOL("BulkChangeIncludeObjects"   , check);
241	gSavedSettings.setBOOL("BulkChangeIncludeScripts"   , check);
242	gSavedSettings.setBOOL("BulkChangeIncludeSounds"    , check);
243	gSavedSettings.setBOOL("BulkChangeIncludeTextures"  , check);
244}
245
246
247void LLFloaterBulkPermission::handleInventory(LLViewerObject* viewer_obj, LLInventoryObject::object_list_t* inv)
248{
249	LLScrollListCtrl* list = getChild<LLScrollListCtrl>("queue output");
250
251	LLInventoryObject::object_list_t::const_iterator it = inv->begin();
252	LLInventoryObject::object_list_t::const_iterator end = inv->end();
253	for ( ; it != end; ++it)
254	{
255		LLAssetType::EType asstype = (*it)->getType();
256		if(
257			( asstype == LLAssetType::AT_ANIMATION && gSavedSettings.getBOOL("BulkChangeIncludeAnimations")) ||
258			( asstype == LLAssetType::AT_BODYPART  && gSavedSettings.getBOOL("BulkChangeIncludeBodyParts" )) ||
259			( asstype == LLAssetType::AT_CLOTHING  && gSavedSettings.getBOOL("BulkChangeIncludeClothing"  )) ||
260			( asstype == LLAssetType::AT_GESTURE   && gSavedSettings.getBOOL("BulkChangeIncludeGestures"  )) ||
261			( asstype == LLAssetType::AT_NOTECARD  && gSavedSettings.getBOOL("BulkChangeIncludeNotecards" )) ||
262			( asstype == LLAssetType::AT_OBJECT    && gSavedSettings.getBOOL("BulkChangeIncludeObjects"   )) ||
263			( asstype == LLAssetType::AT_LSL_TEXT  && gSavedSettings.getBOOL("BulkChangeIncludeScripts"   )) ||
264			( asstype == LLAssetType::AT_SOUND     && gSavedSettings.getBOOL("BulkChangeIncludeSounds"    )) ||
265			( asstype == LLAssetType::AT_TEXTURE   && gSavedSettings.getBOOL("BulkChangeIncludeTextures"  )))
266		{
267			LLViewerObject* object = gObjectList.findObject(viewer_obj->getID());
268
269			if (object)
270			{
271				LLInventoryItem* item = (LLInventoryItem*)((LLInventoryObject*)(*it));
272				LLViewerInventoryItem* new_item = (LLViewerInventoryItem*)item;
273				LLPermissions perm(new_item->getPermissions());
274
275				// chomp the inventory name so it fits in the scroll window nicely
276				// and the user can see the [OK]
277				std::string invname;
278				invname=item->getName().substr(0,item->getName().size() < 30 ? item->getName().size() : 30 );
279				
280				LLUIString status_text = getString("status_text");
281				status_text.setArg("[NAME]", invname.c_str());
282				// Check whether we appear to have the appropriate permissions to change permission on this item.
283				// Although the server will disallow any forbidden changes, it is a good idea to guess correctly
284				// so that we can warn the user. The risk of getting this check wrong is therefore the possibility
285				// of incorrectly choosing to not attempt to make a valid change.
286				//
287				// Trouble is this is extremely difficult to do and even when we know the results
288				// it is difficult to design the best messaging. Therefore in this initial implementation
289				// we'll always try to set the requested permissions and consider all cases successful
290				// and perhaps later try to implement a smarter, friendlier solution. -MG
291				if(true
292					//gAgent.allowOperation(PERM_MODIFY, perm, GP_OBJECT_MANIPULATE) // for group and everyone masks
293					//|| something else // for next owner perms
294					)
295				{
296					perm.setMaskNext(LLFloaterPerms::getNextOwnerPerms("BulkChange"));
297					perm.setMaskEveryone(LLFloaterPerms::getEveryonePerms("BulkChange"));
298					perm.setMaskGroup(LLFloaterPerms::getGroupPerms("BulkChange"));
299					new_item->setPermissions(perm); // here's the beef
300					updateInventory(object,new_item,TASK_INVENTORY_ITEM_KEY,FALSE);
301					//status_text.setArg("[STATUS]", getString("status_ok_text"));
302					status_text.setArg("[STATUS]", "");
303				}
304				else
305				{
306					//status_text.setArg("[STATUS]", getString("status_bad_text"));
307					status_text.setArg("[STATUS]", "");
308				}
309				
310				list->setCommentText(status_text.getString());
311
312				//TODO if we are an object inside an object we should check a recuse flag and if set
313				//open the inventory of the object and recurse - Michelle2 Zenovka
314
315				//	if(recurse &&  ( (*it)->getType() == LLAssetType::AT_OBJECT && processObject))
316				//	{
317				//		I think we need to get the UUID of the object inside the inventory
318				//		call item->fetchFromServer();
319				//		we need a call back to say item has arrived *sigh*
320				//		we then need to do something like
321				//		LLUUID* id = new LLUUID(mID);
322				//		registerVOInventoryListener(obj,id);
323				//		requestVOInventory();
324				//	}
325			}
326		}
327	}
328
329	nextObject();
330}
331
332
333// Avoid inventory callbacks etc by just fire and forgetting the message with the permissions update
334// we could do this via LLViewerObject::updateInventory but that uses inventory call backs and buggers
335// us up and we would have a dodgy item iterator
336
337void LLFloaterBulkPermission::updateInventory(LLViewerObject* object, LLViewerInventoryItem* item, U8 key, bool is_new)
338{
339	LLMemType mt(LLMemType::MTYPE_OBJECT);
340	
341	// This slices the object into what we're concerned about on the viewer. 
342	// The simulator will take the permissions and transfer ownership.
343	LLPointer<LLViewerInventoryItem> task_item =
344		new LLViewerInventoryItem(item->getUUID(), mID, item->getPermissions(),
345								  item->getAssetUUID(), item->getType(),
346								  item->getInventoryType(),
347								  item->getName(), item->getDescription(),
348								  item->getSaleInfo(),
349								  item->getFlags(),
350								  item->getCreationDate());
351	task_item->setTransactionID(item->getTransactionID());
352	LLMessageSystem* msg = gMessageSystem;
353	msg->newMessageFast(_PREHASH_UpdateTaskInventory);
354	msg->nextBlockFast(_PREHASH_AgentData);
355	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
356	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
357	msg->nextBlockFast(_PREHASH_UpdateData);
358	msg->addU32Fast(_PREHASH_LocalID, object->mLocalID);
359	msg->addU8Fast(_PREHASH_Key, key);
360	msg->nextBlockFast(_PREHASH_InventoryData);
361	task_item->packMessage(msg);
362	msg->sendReliable(object->getRegion()->getHost());
363}
364