aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloaterbuycontents.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/llfloaterbuycontents.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/llfloaterbuycontents.cpp')
-rw-r--r--linden/indra/newview/llfloaterbuycontents.cpp294
1 files changed, 294 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterbuycontents.cpp b/linden/indra/newview/llfloaterbuycontents.cpp
new file mode 100644
index 0000000..4f6f52e
--- /dev/null
+++ b/linden/indra/newview/llfloaterbuycontents.cpp
@@ -0,0 +1,294 @@
1/**
2 * @file llfloaterbuycontents.cpp
3 * @author James Cook
4 * @brief LLFloaterBuyContents 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 * Shows the contents of an object and their permissions when you
31 * click "Buy..." on an object with "Sell Contents" checked.
32 */
33
34#include "llviewerprecompiledheaders.h"
35
36#include "llfloaterbuycontents.h"
37
38#include "llcachename.h"
39
40#include "llagent.h" // for agent id
41#include "llalertdialog.h"
42#include "llcheckboxctrl.h"
43#include "llinventorymodel.h" // for gInventory
44#include "llinventoryview.h" // for get_item_icon
45#include "llselectmgr.h"
46#include "llscrolllistctrl.h"
47#include "llviewerobject.h"
48#include "llviewerregion.h"
49#include "llvieweruictrlfactory.h"
50#include "llviewerwindow.h"
51
52LLFloaterBuyContents* LLFloaterBuyContents::sInstance = NULL;
53
54LLFloaterBuyContents::LLFloaterBuyContents()
55: LLFloater("floater_buy_contents", "FloaterBuyContentsRect", "")
56{
57 gUICtrlFactory->buildFloater(this, "floater_buy_contents.xml");
58
59 childSetAction("cancel_btn", onClickCancel, this);
60 childSetAction("buy_btn", onClickBuy, this);
61
62 childDisable("item_list");
63 childDisable("buy_btn");
64 childDisable("wear_check");
65
66 setDefaultBtn("buy_btn");
67}
68
69LLFloaterBuyContents::~LLFloaterBuyContents()
70{
71 gSelectMgr->deselectAll();
72
73 sInstance = NULL;
74}
75
76
77// static
78void LLFloaterBuyContents::show(const LLSaleInfo& sale_info)
79{
80 if (gSelectMgr->getRootObjectCount() != 1)
81 {
82 gViewerWindow->alertXml("BuyContentsOneOnly");
83 return;
84 }
85
86 // Create a new instance only if needed
87 if (sInstance)
88 {
89 LLScrollListCtrl* list = LLUICtrlFactory::getScrollListByName(sInstance, "item_list");
90 if (list) list->deleteAllItems();
91 }
92 else
93 {
94 sInstance = new LLFloaterBuyContents();
95 }
96
97 sInstance->open();
98 sInstance->setFocus(TRUE);
99
100 // Always center the dialog. User can change the size,
101 // but purchases are important and should be center screen.
102 // This also avoids problems where the user resizes the application window
103 // mid-session and the saved rect is off-center.
104 sInstance->center();
105
106 LLUUID owner_id;
107 LLString owner_name;
108 BOOL owners_identical = gSelectMgr->selectGetOwner(owner_id, owner_name);
109 if (!owners_identical)
110 {
111 gViewerWindow->alertXml("BuyContentsOneOwner");
112 return;
113 }
114
115 sInstance->mSaleInfo = sale_info;
116
117 // Update the display
118 LLSelectNode* node = gSelectMgr->getFirstRootNode();
119 if (!node) return;
120 if(node->mPermissions->isGroupOwned())
121 {
122 char group_name[MAX_STRING];
123 gCacheName->getGroupName(owner_id, group_name);
124 owner_name.assign(group_name);
125 }
126
127 sInstance->childSetTextArg("contains_text", "[NAME]", node->mName);
128 sInstance->childSetTextArg("buy_text", "[AMOUNT]", llformat("%d", sale_info.getSalePrice()));
129 sInstance->childSetTextArg("buy_text", "[NAME]", owner_name);
130
131 // Must do this after the floater is created, because
132 // sometimes the inventory is already there and
133 // the callback is called immediately.
134 LLViewerObject* obj = gSelectMgr->getFirstRootObject();
135 sInstance->registerVOInventoryListener(obj,NULL);
136 sInstance->requestVOInventory();
137}
138
139
140void LLFloaterBuyContents::inventoryChanged(LLViewerObject* obj,
141 InventoryObjectList* inv,
142 S32 serial_num,
143 void* data)
144{
145 if (!obj)
146 {
147 llwarns << "No object in LLFloaterBuyContents::inventoryChanged" << llendl;
148 return;
149 }
150
151 if (!inv)
152 {
153 llwarns << "No inventory in LLFloaterBuyContents::inventoryChanged"
154 << llendl;
155 removeVOInventoryListener();
156 return;
157 }
158
159 LLCtrlListInterface *item_list = childGetListInterface("item_list");
160 if (!item_list)
161 {
162 removeVOInventoryListener();
163 return;
164 }
165
166 // default to turning off the buy button.
167 childDisable("buy_btn");
168
169 LLUUID owner_id;
170 BOOL is_group_owned;
171 LLAssetType::EType asset_type;
172 LLInventoryType::EType inv_type;
173 S32 wearable_count = 0;
174
175 InventoryObjectList::const_iterator it = inv->begin();
176 InventoryObjectList::const_iterator end = inv->end();
177
178 for ( ; it != end; ++it )
179 {
180 asset_type = (*it)->getType();
181
182 // Skip folders, so we know we have inventory items only
183 if (asset_type == LLAssetType::AT_CATEGORY)
184 continue;
185
186 // Skip root folders, so we know we have inventory items only
187 if (asset_type == LLAssetType::AT_ROOT_CATEGORY)
188 continue;
189
190 LLInventoryItem* inv_item = (LLInventoryItem*)((LLInventoryObject*)(*it));
191 inv_type = inv_item->getInventoryType();
192
193 // Count clothing items for later
194 if (LLInventoryType::IT_WEARABLE == inv_type)
195 {
196 wearable_count++;
197 }
198
199 // Skip items the object's owner can't copy (and hence can't sell)
200 if (!inv_item->getPermissions().getOwnership(owner_id, is_group_owned))
201 continue;
202
203 if (!inv_item->getPermissions().allowCopyBy(owner_id, owner_id))
204 continue;
205
206 // Skip items we can't transfer
207 if (!inv_item->getPermissions().allowTransferTo(gAgent.getID()))
208 continue;
209
210 // There will be at least one item shown in the display, so go
211 // ahead and enable the buy button.
212 childEnable("buy_btn");
213
214 // Create the line in the list
215 LLSD row;
216 LLUUID icon_id = get_item_icon_uuid(inv_item->getType(),
217 inv_item->getInventoryType(),
218 inv_item->getFlags());
219 row["columns"][0]["column"] = "icon";
220 row["columns"][0]["type"] = "icon";
221 row["columns"][0]["value"] = icon_id;
222
223 // Append the permissions that you will acquire (not the current
224 // permissions).
225 U32 next_owner_mask = inv_item->getPermissions().getMaskNextOwner();
226 LLString text = (*it)->getName();
227
228 // *TODO: Move into shared library function.
229 if (!(next_owner_mask & PERM_COPY))
230 {
231 text.append(" (no copy)"); // XUI:translate
232 }
233 if (!(next_owner_mask & PERM_MODIFY))
234 {
235 text.append(" (no modify)"); // XUI:translate
236 }
237 if (!(next_owner_mask & PERM_TRANSFER))
238 {
239 text.append(" (no transfer)"); // XUI:translate
240 }
241
242 row["columns"][1]["column"] = "text";
243 row["columns"][1]["value"] = text;
244 row["columns"][1]["font"] = "SANSSERIF";
245
246 item_list->addElement(row);
247 }
248
249 if (wearable_count > 0)
250 {
251 childEnable("wear_check");
252 childSetValue("wear_check", LLSD(false) );
253 }
254
255 removeVOInventoryListener();
256}
257
258
259// static
260void LLFloaterBuyContents::onClickBuy(void*)
261{
262 // Make sure this wasn't selected through other mechanisms
263 // (ie, being the default button and pressing enter.
264 if(!sInstance->childIsEnabled("buy_btn"))
265 {
266 // We shouldn't be enabled. Just close.
267 sInstance->close();
268 return;
269 }
270
271 // We may want to wear this item
272 if (sInstance->childGetValue("wear_check"))
273 {
274 LLInventoryView::sWearNewClothing = TRUE;
275 }
276
277 // Put the items where we put new folders.
278 LLUUID category_id;
279 category_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_CATEGORY);
280
281 // *NOTE: doesn't work for multiple object buy, which UI does not
282 // currently support sale info is used for verification only, if
283 // it doesn't match region info then sale is canceled.
284 gSelectMgr->sendBuy(gAgent.getID(), category_id, sInstance->mSaleInfo);
285
286 sInstance->close();
287}
288
289
290// static
291void LLFloaterBuyContents::onClickCancel(void*)
292{
293 sInstance->close();
294}