PageRenderTime 567ms CodeModel.GetById 241ms app.highlight 178ms RepoModel.GetById 144ms app.codeStats 0ms

/indra/newview/llfloaterbuy.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 306 lines | 198 code | 50 blank | 58 comment | 27 complexity | 8f1f2c8ce2929454219aa576be2caa5b MD5 | raw file
  1/** 
  2 * @file llfloaterbuy.cpp
  3 * @author James Cook
  4 * @brief LLFloaterBuy class implementation
  5 *
  6 * $LicenseInfo:firstyear=2004&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 * Floater that appears when buying an object, giving a preview
 30 * of its contents and their permissions.
 31 */
 32
 33#include "llviewerprecompiledheaders.h"
 34
 35#include "llfloaterbuy.h"
 36
 37#include "llagent.h"			// for agent id
 38#include "llinventorymodel.h"	// for gInventory
 39#include "llfloaterreg.h"
 40#include "llinventoryicon.h"
 41#include "llinventorydefines.h"
 42#include "llinventoryfunctions.h"
 43#include "llnotificationsutil.h"
 44#include "llselectmgr.h"
 45#include "llscrolllistctrl.h"
 46#include "llviewerobject.h"
 47#include "lluictrlfactory.h"
 48#include "llviewerwindow.h"
 49#include "lltrans.h"
 50
 51LLFloaterBuy::LLFloaterBuy(const LLSD& key)
 52:	LLFloater(key)
 53{
 54}
 55
 56BOOL LLFloaterBuy::postBuild()
 57{
 58	getChildView("object_list")->setEnabled(FALSE);
 59	getChildView("item_list")->setEnabled(FALSE);
 60
 61	getChild<LLUICtrl>("cancel_btn")->setCommitCallback( boost::bind(&LLFloaterBuy::onClickCancel, this));
 62	getChild<LLUICtrl>("buy_btn")->setCommitCallback( boost::bind(&LLFloaterBuy::onClickBuy, this));
 63
 64	setDefaultBtn("cancel_btn"); // to avoid accidental buy (SL-43130)
 65	
 66	// Always center the dialog.  User can change the size,
 67	// but purchases are important and should be center screen.
 68	// This also avoids problems where the user resizes the application window
 69	// mid-session and the saved rect is off-center.
 70	center();
 71
 72	return TRUE;
 73}
 74
 75LLFloaterBuy::~LLFloaterBuy()
 76{
 77	mObjectSelection = NULL;
 78}
 79
 80void LLFloaterBuy::reset()
 81{
 82	LLScrollListCtrl* object_list = getChild<LLScrollListCtrl>("object_list");
 83	if (object_list) object_list->deleteAllItems();
 84
 85	LLScrollListCtrl* item_list = getChild<LLScrollListCtrl>("item_list");
 86	if (item_list) item_list->deleteAllItems();
 87}
 88
 89// static
 90void LLFloaterBuy::show(const LLSaleInfo& sale_info)
 91{
 92	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
 93
 94	if (selection->getRootObjectCount() != 1)
 95	{
 96		LLNotificationsUtil::add("BuyOneObjectOnly");
 97		return;
 98	}
 99	
100	LLFloaterBuy* floater = LLFloaterReg::showTypedInstance<LLFloaterBuy>("buy_object");
101	if (!floater)
102		return;
103	
104	// Clean up the lists...
105	floater->reset();
106	floater->mSaleInfo = sale_info;
107	floater->mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
108	
109	LLSelectNode* node = selection->getFirstRootNode();
110	if (!node)
111		return;
112	
113	// Set title based on sale type
114	LLUIString title;
115	switch (sale_info.getSaleType())
116	{
117	  case LLSaleInfo::FS_ORIGINAL:
118		title = floater->getString("title_buy_text");
119		break;
120	  case LLSaleInfo::FS_COPY:
121	  default:
122		title = floater->getString("title_buy_copy_text");
123		break;
124	}
125	title.setArg("[NAME]", node->mName);
126	floater->setTitle(title);
127
128	LLUUID owner_id;
129	std::string owner_name;
130	BOOL owners_identical = LLSelectMgr::getInstance()->selectGetOwner(owner_id, owner_name);
131	if (!owners_identical)
132	{
133		LLNotificationsUtil::add("BuyObjectOneOwner");
134		return;
135	}
136
137	LLCtrlListInterface *object_list = floater->childGetListInterface("object_list");
138	if (!object_list)
139	{
140		return;
141	}
142
143	// Update the display
144	// Display next owner permissions
145	LLSD row;
146
147	// Compute icon for this item
148	std::string icon_name = LLInventoryIcon::getIconName(LLAssetType::AT_OBJECT, 
149									 LLInventoryType::IT_OBJECT);
150
151	row["columns"][0]["column"] = "icon";
152	row["columns"][0]["type"] = "icon";
153	row["columns"][0]["value"] = icon_name;
154	
155	// Append the permissions that you will acquire (not the current
156	// permissions).
157	U32 next_owner_mask = node->mPermissions->getMaskNextOwner();
158	std::string text = node->mName;
159	if (!(next_owner_mask & PERM_COPY))
160	{
161		text.append(floater->getString("no_copy_text"));
162	}
163	if (!(next_owner_mask & PERM_MODIFY))
164	{
165		text.append(floater->getString("no_modify_text"));
166	}
167	if (!(next_owner_mask & PERM_TRANSFER))
168	{
169		text.append(floater->getString("no_transfer_text"));
170	}
171
172	row["columns"][1]["column"] = "text";
173	row["columns"][1]["value"] = text;
174	row["columns"][1]["font"] = "SANSSERIF";
175
176	// Add after columns added so appropriate heights are correct.
177	object_list->addElement(row);
178
179	floater->getChild<LLUICtrl>("buy_text")->setTextArg("[AMOUNT]", llformat("%d", sale_info.getSalePrice()));
180	floater->getChild<LLUICtrl>("buy_name_text")->setTextArg("[NAME]", owner_name);
181
182	// Must do this after the floater is created, because
183	// sometimes the inventory is already there and 
184	// the callback is called immediately.
185	LLViewerObject* obj = selection->getFirstRootObject();
186	floater->registerVOInventoryListener(obj,NULL);
187	floater->requestVOInventory();
188}
189
190void LLFloaterBuy::inventoryChanged(LLViewerObject* obj,
191								 LLInventoryObject::object_list_t* inv,
192								 S32 serial_num,
193								 void* data)
194{
195	if (!obj)
196	{
197		llwarns << "No object in LLFloaterBuy::inventoryChanged" << llendl;
198		return;
199	}
200
201	if (!inv)
202	{
203		llwarns << "No inventory in LLFloaterBuy::inventoryChanged"
204			<< llendl;
205		removeVOInventoryListener();
206		return;
207	}
208
209	LLCtrlListInterface *item_list = childGetListInterface("item_list");
210	if (!item_list)
211	{
212		removeVOInventoryListener();
213		return;
214	}
215
216	LLInventoryObject::object_list_t::const_iterator it = inv->begin();
217	LLInventoryObject::object_list_t::const_iterator end = inv->end();
218	for ( ; it != end; ++it )
219	{
220		LLInventoryObject* obj = (LLInventoryObject*)(*it);
221			
222		// Skip folders, so we know we have inventory items only
223		if (obj->getType() == LLAssetType::AT_CATEGORY)
224			continue;
225
226		// Skip the mysterious blank InventoryObject 
227		if (obj->getType() == LLAssetType::AT_NONE)
228			continue;
229
230
231		LLInventoryItem* inv_item = (LLInventoryItem*)(obj);
232
233		// Skip items we can't transfer
234		if (!inv_item->getPermissions().allowTransferTo(gAgent.getID())) 
235			continue;
236
237		// Create the line in the list
238		LLSD row;
239
240		// Compute icon for this item
241		BOOL item_is_multi = FALSE;
242		if ( inv_item->getFlags() & LLInventoryItemFlags::II_FLAGS_LANDMARK_VISITED 
243			|| inv_item->getFlags() & LLInventoryItemFlags::II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS)
244		{
245			item_is_multi = TRUE;
246		}
247
248		std::string icon_name = LLInventoryIcon::getIconName(inv_item->getType(), 
249							 inv_item->getInventoryType(),
250							 inv_item->getFlags(),
251							 item_is_multi);
252		row["columns"][0]["column"] = "icon";
253		row["columns"][0]["type"] = "icon";
254		row["columns"][0]["value"] = icon_name;
255				
256		// Append the permissions that you will acquire (not the current
257		// permissions).
258		U32 next_owner_mask = inv_item->getPermissions().getMaskNextOwner();
259		std::string text = obj->getName();
260		if (!(next_owner_mask & PERM_COPY))
261		{
262			text.append(LLTrans::getString("no_copy"));
263		}
264		if (!(next_owner_mask & PERM_MODIFY))
265		{
266			text.append(LLTrans::getString("no_modify"));
267		}
268		if (!(next_owner_mask & PERM_TRANSFER))
269		{
270			text.append(LLTrans::getString("no_transfer"));
271		}
272
273		row["columns"][1]["column"] = "text";
274		row["columns"][1]["value"] = text;
275		row["columns"][1]["font"] = "SANSSERIF";
276
277		item_list->addElement(row);
278	}
279	removeVOInventoryListener();
280}
281
282void LLFloaterBuy::onClickBuy()
283{
284	// Put the items where we put new folders.
285	LLUUID category_id;
286	category_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_OBJECT);
287
288	// *NOTE: doesn't work for multiple object buy, which UI does not
289	// currently support sale info is used for verification only, if
290	// it doesn't match region info then sale is canceled.
291	LLSelectMgr::getInstance()->sendBuy(gAgent.getID(), category_id, mSaleInfo );
292
293	closeFloater();
294}
295
296
297void LLFloaterBuy::onClickCancel()
298{
299	closeFloater();
300}
301
302// virtual
303void LLFloaterBuy::onClose(bool app_quitting)
304{
305	mObjectSelection.clear();
306}