aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloaterbuy.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llfloaterbuy.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llfloaterbuy.cpp')
-rw-r--r--linden/indra/newview/llfloaterbuy.cpp308
1 files changed, 308 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterbuy.cpp b/linden/indra/newview/llfloaterbuy.cpp
new file mode 100644
index 0000000..04b56bf
--- /dev/null
+++ b/linden/indra/newview/llfloaterbuy.cpp
@@ -0,0 +1,308 @@
1/**
2 * @file llfloaterbuy.cpp
3 * @author James Cook
4 * @brief LLFloaterBuy class implementation
5 *
6 * Copyright (c) 2004-2007, Linden Research, Inc.
7 *
8 * The source code in this file ("Source Code") is provided by Linden Lab
9 * to you under the terms of the GNU General Public License, version 2.0
10 * ("GPL"), unless you have obtained a separate licensing agreement
11 * ("Other License"), formally executed by you and Linden Lab. Terms of
12 * the GPL can be found in doc/GPL-license.txt in this distribution, or
13 * online at http://secondlife.com/developers/opensource/gplv2
14 *
15 * There are special exceptions to the terms and conditions of the GPL as
16 * it is applied to this Source Code. View the full text of the exception
17 * in the file doc/FLOSS-exception.txt in this software distribution, or
18 * online at http://secondlife.com/developers/opensource/flossexception
19 *
20 * By copying, modifying or distributing this software, you acknowledge
21 * that you have read and understood your obligations described above,
22 * and agree to abide by those obligations.
23 *
24 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
25 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
26 * COMPLETENESS OR PERFORMANCE.
27 */
28
29/**
30 * Floater that appears when buying an object, giving a preview
31 * of its contents and their permissions.
32 */
33
34#include "llviewerprecompiledheaders.h"
35
36#include "llfloaterbuy.h"
37
38#include "llagent.h" // for agent id
39#include "llalertdialog.h"
40#include "llinventorymodel.h" // for gInventory
41#include "llinventoryview.h" // for get_item_icon
42#include "llselectmgr.h"
43#include "llscrolllistctrl.h"
44#include "llviewerobject.h"
45#include "llvieweruictrlfactory.h"
46#include "llviewerwindow.h"
47
48LLFloaterBuy* LLFloaterBuy::sInstance = NULL;
49
50LLFloaterBuy::LLFloaterBuy()
51: LLFloater("floater_buy_object", "FloaterBuyRect", "")
52{
53 gUICtrlFactory->buildFloater(this, "floater_buy_object.xml");
54
55 childDisable("object_list");
56 childDisable("item_list");
57
58 childSetAction("cancel_btn", onClickCancel, this);
59 childSetAction("buy_btn", onClickBuy, this);
60
61 setDefaultBtn("buy_btn");
62}
63
64LLFloaterBuy::~LLFloaterBuy()
65{
66 gSelectMgr->deselectAll();
67
68 sInstance = NULL;
69}
70
71void LLFloaterBuy::reset()
72{
73 LLScrollListCtrl* object_list = LLUICtrlFactory::getScrollListByName(this, "object_list");
74 if (object_list) object_list->deleteAllItems();
75
76 LLScrollListCtrl* item_list = LLUICtrlFactory::getScrollListByName(this, "item_list");
77 if (item_list) item_list->deleteAllItems();
78}
79
80// static
81void LLFloaterBuy::show(const LLSaleInfo& sale_info)
82{
83 if (gSelectMgr->getRootObjectCount() != 1)
84 {
85 gViewerWindow->alertXml("BuyOneObjectOnly");
86 return;
87 }
88
89 // Create a new instance only if one doesn't exist
90 if (sInstance)
91 {
92 // Clean up the lists...
93 sInstance->reset();
94 }
95 else
96 {
97 sInstance = new LLFloaterBuy();
98 }
99
100 sInstance->open();
101 sInstance->setFocus(TRUE);
102 sInstance->mSaleInfo = sale_info;
103
104 // Always center the dialog. User can change the size,
105 // but purchases are important and should be center screen.
106 // This also avoids problems where the user resizes the application window
107 // mid-session and the saved rect is off-center.
108 sInstance->center();
109
110 LLSelectNode* node = gSelectMgr->getFirstRootNode();
111 if (!node) return;
112
113 // Set title based on sale type
114 std::ostringstream title;
115 switch (sale_info.getSaleType())
116 {
117 case LLSaleInfo::FS_ORIGINAL:
118 title << "Buy " << node->mName; // XUI:translate
119 break;
120 case LLSaleInfo::FS_COPY:
121 default:
122 title << "Buy Copy of " << node->mName; // XUI:translate
123 break;
124 }
125 sInstance->setTitle(title.str());
126
127 LLUUID owner_id;
128 LLString owner_name;
129 BOOL owners_identical = gSelectMgr->selectGetOwner(owner_id, owner_name);
130 if (!owners_identical)
131 {
132 gViewerWindow->alertXml("BuyObjectOneOwner");
133 return;
134 }
135
136 LLCtrlListInterface *object_list = sInstance->childGetListInterface("object_list");
137 if (!object_list)
138 {
139 return;
140 }
141
142 // Update the display
143 // Display next owner permissions
144 LLSD row;
145
146 // Compute icon for this item
147 LLUUID icon_id = get_item_icon_uuid(LLAssetType::AT_OBJECT,
148 LLInventoryType::IT_OBJECT,
149 0x0);
150 row["columns"][0]["column"] = "icon";
151 row["columns"][0]["type"] = "icon";
152 row["columns"][0]["value"] = icon_id;
153
154 // Append the permissions that you will acquire (not the current
155 // permissions).
156 U32 next_owner_mask = node->mPermissions->getMaskNextOwner();
157 LLString text = node->mName;
158 if (!(next_owner_mask & PERM_COPY))
159 {
160 text.append(" (no copy)"); // XUI:translate
161 }
162 if (!(next_owner_mask & PERM_MODIFY))
163 {
164 text.append(" (no modify)"); // XUI:translate
165 }
166 if (!(next_owner_mask & PERM_TRANSFER))
167 {
168 text.append(" (no transfer)"); // XUI:translate
169 }
170
171 row["columns"][1]["column"] = "text";
172 row["columns"][1]["value"] = text;
173 row["columns"][1]["font"] = "SANSSERIF";
174
175 // Add after columns added so appropriate heights are correct.
176 object_list->addElement(row);
177
178 sInstance->childSetTextArg("buy_text", "[AMOUNT]", llformat("%d", sale_info.getSalePrice()));
179 sInstance->childSetTextArg("buy_text", "[NAME]", owner_name);
180
181 // Must do this after the floater is created, because
182 // sometimes the inventory is already there and
183 // the callback is called immediately.
184 LLViewerObject* obj = gSelectMgr->getFirstRootObject();
185 sInstance->registerVOInventoryListener(obj,NULL);
186 sInstance->requestVOInventory();
187}
188
189
190void LLFloaterBuy::inventoryChanged(LLViewerObject* obj,
191 InventoryObjectList* 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 InventoryObjectList::const_iterator it = inv->begin();
217 InventoryObjectList::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 root folders, so we know we have inventory items only
227 if (obj->getType() == LLAssetType::AT_ROOT_CATEGORY)
228 continue;
229
230 // Skip the mysterious blank InventoryObject
231 if (obj->getType() == LLAssetType::AT_NONE)
232 continue;
233
234
235 LLInventoryItem* inv_item = (LLInventoryItem*)(obj);
236
237 // Skip items we can't transfer
238 if (!inv_item->getPermissions().allowTransferTo(gAgent.getID()))
239 continue;
240
241 // Create the line in the list
242 LLSD row;
243
244 // Compute icon for this item
245 LLUUID icon_id = get_item_icon_uuid(inv_item->getType(),
246 inv_item->getInventoryType(),
247 inv_item->getFlags());
248 row["columns"][0]["column"] = "icon";
249 row["columns"][0]["type"] = "icon";
250 row["columns"][0]["value"] = icon_id;
251
252 // Append the permissions that you will acquire (not the current
253 // permissions).
254 U32 next_owner_mask = inv_item->getPermissions().getMaskNextOwner();
255 LLString text = obj->getName();
256 if (!(next_owner_mask & PERM_COPY))
257 {
258 text.append(" (no copy)");
259 }
260 if (!(next_owner_mask & PERM_MODIFY))
261 {
262 text.append(" (no modify)");
263 }
264 if (!(next_owner_mask & PERM_TRANSFER))
265 {
266 text.append(" (no transfer)");
267 }
268
269 row["columns"][1]["column"] = "text";
270 row["columns"][1]["value"] = text;
271 row["columns"][1]["font"] = "SANSSERIF";
272
273 item_list->addElement(row);
274 }
275 removeVOInventoryListener();
276}
277
278
279// static
280void LLFloaterBuy::onClickBuy(void*)
281{
282 if (!sInstance)
283 {
284 llinfos << "LLFloaterBuy::onClickBuy no sInstance!" << llendl;
285 return;
286 }
287
288 // Put the items where we put new folders.
289 LLUUID category_id;
290 category_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_OBJECT);
291
292 // *NOTE: doesn't work for multiple object buy, which UI does not
293 // currently support sale info is used for verification only, if
294 // it doesn't match region info then sale is canceled.
295 gSelectMgr->sendBuy(gAgent.getID(), category_id, sInstance->mSaleInfo );
296
297 sInstance->close();
298}
299
300
301// static
302void LLFloaterBuy::onClickCancel(void*)
303{
304 if (sInstance)
305 {
306 sInstance->close();
307 }
308}