PageRenderTime 33ms CodeModel.GetById 2ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llfloateropenobject.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 255 lines | 174 code | 41 blank | 40 comment | 16 complexity | 968ea3adce911e7eb12f7f5c11ab1569 MD5 | raw file
  1/** 
  2 * @file llfloateropenobject.cpp
  3 * @brief LLFloaterOpenObject class implementation
  4 *
  5 * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27/*
 28 * Shows the contents of an object.
 29 * A floater wrapper for LLPanelObjectInventory
 30 */
 31
 32#include "llviewerprecompiledheaders.h"
 33
 34#include "llfloateropenobject.h"
 35
 36#include "llcachename.h"
 37#include "llbutton.h"
 38#include "llnotificationsutil.h"
 39#include "lltextbox.h"
 40
 41#include "llinventorybridge.h"
 42#include "llfloaterinventory.h"
 43#include "llinventorymodel.h"
 44#include "llinventorypanel.h"
 45#include "llpanelobjectinventory.h"
 46#include "llfloaterreg.h"
 47#include "llselectmgr.h"
 48#include "lluiconstants.h"
 49#include "llviewerobject.h"
 50#include "lluictrlfactory.h"
 51#include "llviewerwindow.h"
 52
 53
 54LLFloaterOpenObject::LLFloaterOpenObject(const LLSD& key)
 55:	LLFloater(key),
 56	mPanelInventoryObject(NULL),
 57	mDirty(TRUE)
 58{
 59	mCommitCallbackRegistrar.add("OpenObject.MoveToInventory",	boost::bind(&LLFloaterOpenObject::onClickMoveToInventory, this));
 60	mCommitCallbackRegistrar.add("OpenObject.MoveAndWear",		boost::bind(&LLFloaterOpenObject::onClickMoveAndWear, this));
 61}
 62
 63LLFloaterOpenObject::~LLFloaterOpenObject()
 64{
 65//	sInstance = NULL;
 66}
 67
 68// virtual
 69BOOL LLFloaterOpenObject::postBuild()
 70{
 71	getChild<LLUICtrl>("object_name")->setTextArg("[DESC]", std::string("Object") ); // *Note: probably do not want to translate this
 72	mPanelInventoryObject = getChild<LLPanelObjectInventory>("object_contents");
 73	
 74	refresh();
 75	return TRUE;
 76}
 77
 78void LLFloaterOpenObject::onOpen(const LLSD& key)
 79{
 80	LLObjectSelectionHandle object_selection = LLSelectMgr::getInstance()->getSelection();
 81	if (object_selection->getRootObjectCount() != 1)
 82	{
 83		LLNotificationsUtil::add("UnableToViewContentsMoreThanOne");
 84		closeFloater();
 85		return;
 86	}
 87	if(!(object_selection->getPrimaryObject())) 
 88	{
 89		closeFloater();
 90		return;
 91	}
 92	mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
 93	refresh();
 94}
 95
 96void LLFloaterOpenObject::refresh()
 97{
 98	mPanelInventoryObject->refresh();
 99
100	std::string name = "";
101	BOOL enabled = FALSE;
102
103	LLSelectNode* node = mObjectSelection->getFirstRootNode();
104	if (node) 
105	{
106		name = node->mName;
107		enabled = TRUE;
108	}
109	else
110	{
111		name = "";
112		enabled = FALSE;
113	}
114	
115	getChild<LLUICtrl>("object_name")->setTextArg("[DESC]", name);
116	getChildView("copy_to_inventory_button")->setEnabled(enabled);
117	getChildView("copy_and_wear_button")->setEnabled(enabled);
118
119}
120
121void LLFloaterOpenObject::draw()
122{
123	if (mDirty)
124	{
125		refresh();
126		mDirty = FALSE;
127	}
128	LLFloater::draw();
129}
130
131void LLFloaterOpenObject::dirty()
132{
133	mDirty = TRUE;
134}
135
136
137
138void LLFloaterOpenObject::moveToInventory(bool wear)
139{
140	if (mObjectSelection->getRootObjectCount() != 1)
141	{
142		LLNotificationsUtil::add("OnlyCopyContentsOfSingleItem");
143		return;
144	}
145
146	LLSelectNode* node = mObjectSelection->getFirstRootNode();
147	if (!node) return;
148	LLViewerObject* object = node->getObject();
149	if (!object) return;
150
151	LLUUID object_id = object->getID();
152	std::string name = node->mName;
153
154	// Either create a sub-folder of clothing, or of the root folder.
155	LLUUID parent_category_id;
156	if (wear)
157	{
158		parent_category_id = gInventory.findCategoryUUIDForType(
159			LLFolderType::FT_CLOTHING);
160	}
161	else
162	{
163		parent_category_id = gInventory.getRootFolderID();
164	}
165	
166	LLCategoryCreate* cat_data = new LLCategoryCreate(object_id, wear);
167	
168	LLUUID category_id = gInventory.createNewCategory(parent_category_id, 
169													  LLFolderType::FT_NONE, 
170													  name,
171													  callbackCreateInventoryCategory,
172													  (void*)cat_data);
173
174	//If we get a null category ID, we are using a capability in createNewCategory and we will
175	//handle the following in the callbackCreateInventoryCategory routine.
176	if ( category_id.notNull() )
177	{
178		delete cat_data;
179		
180		LLCatAndWear* data = new LLCatAndWear;
181		data->mCatID = category_id;
182		data->mWear = wear;
183		data->mFolderResponded = false;
184
185		// Copy and/or move the items into the newly created folder.
186		// Ignore any "you're going to break this item" messages.
187		BOOL success = move_inv_category_world_to_agent(object_id, category_id, TRUE,
188														callbackMoveInventory, 
189														(void*)data);
190		if (!success)
191		{
192			delete data;
193			data = NULL;
194
195			LLNotificationsUtil::add("OpenObjectCannotCopy");
196		}
197	}
198}
199
200// static
201void LLFloaterOpenObject::callbackCreateInventoryCategory(const LLSD& result, void* data)
202{
203	LLCategoryCreate* cat_data = (LLCategoryCreate*)data;
204	
205	LLUUID category_id = result["folder_id"].asUUID();
206	LLCatAndWear* wear_data = new LLCatAndWear;
207
208	wear_data->mCatID = category_id;
209	wear_data->mWear = cat_data->mWear;
210	wear_data->mFolderResponded = true;
211	
212	// Copy and/or move the items into the newly created folder.
213	// Ignore any "you're going to break this item" messages.
214	BOOL success = move_inv_category_world_to_agent(cat_data->mObjectID, category_id, TRUE,
215													callbackMoveInventory, 
216													(void*)wear_data);
217	if (!success)
218	{
219		delete wear_data;
220		wear_data = NULL;
221		
222		LLNotificationsUtil::add("OpenObjectCannotCopy");
223	}
224	delete cat_data;	
225}
226
227// static
228void LLFloaterOpenObject::callbackMoveInventory(S32 result, void* data)
229{
230	LLCatAndWear* cat = (LLCatAndWear*)data;
231
232	if (result == 0)
233	{
234		LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel();
235		if (active_panel)
236		{
237			active_panel->setSelection(cat->mCatID, TAKE_FOCUS_NO);
238		}
239	}
240
241	delete cat;
242}
243
244void LLFloaterOpenObject::onClickMoveToInventory()
245{
246	moveToInventory(false);
247	closeFloater();
248}
249
250void LLFloaterOpenObject::onClickMoveAndWear()
251{
252	moveToInventory(true);
253	closeFloater();
254}
255