llfloaterbuy.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /**
  2. * @file llfloaterbuy.cpp
  3. * @author James Cook
  4. * @brief LLFloaterBuy class implementation
  5. *
  6. * $LicenseInfo:firstyear=2004&license=viewergpl$
  7. *
  8. * Copyright (c) 2004-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. /**
  34. * Floater that appears when buying an object, giving a preview of its contents
  35. * and their permissions.
  36. */
  37. #include "llviewerprecompiledheaders.h"
  38. #include "llfloaterbuy.h"
  39. #include "llalertdialog.h"
  40. #include "llscrolllistctrl.h"
  41. #include "lluictrlfactory.h"
  42. #include "llagent.h" // For gAgentID
  43. #include "llinventoryicon.h" // For getIconName
  44. #include "llinventorymodel.h" // For gInventory
  45. #include "llselectmgr.h"
  46. #include "llviewerobject.h"
  47. LLFloaterBuy::LLFloaterBuy(const LLSD&)
  48. {
  49. LLUICtrlFactory::getInstance()->buildFloater(this,
  50. "floater_buy_object.xml");
  51. }
  52. //virtual
  53. LLFloaterBuy::~LLFloaterBuy()
  54. {
  55. // Drop reference to current selection so that it goes away
  56. mObjectSelection = NULL;
  57. }
  58. //virtual
  59. bool LLFloaterBuy::postBuild()
  60. {
  61. mObjectsList = getChild<LLScrollListCtrl>("object_list");
  62. mObjectsList->setEnabled(false);
  63. mItemsList = getChild<LLScrollListCtrl>("item_list");
  64. mItemsList->setEnabled(false);
  65. childSetAction("cancel_btn", onClickCancel, this);
  66. childSetAction("buy_btn", onClickBuy, this);
  67. setDefaultBtn("cancel_btn"); // To avoid accidental buy (SL-43130)
  68. return true;
  69. }
  70. void LLFloaterBuy::reset()
  71. {
  72. mObjectsList->deleteAllItems();
  73. mItemsList->deleteAllItems();
  74. }
  75. //static
  76. void LLFloaterBuy::show(const LLSaleInfo& sale_info)
  77. {
  78. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  79. if (selection->getRootObjectCount() != 1)
  80. {
  81. gNotifications.add("BuyOneObjectOnly");
  82. return;
  83. }
  84. // Create a new instance only if needed
  85. LLFloaterBuy* self = getInstance();
  86. // Clean up the lists...
  87. self->reset();
  88. self->open();
  89. self->setFocus(true);
  90. self->mSaleInfo = sale_info;
  91. self->mObjectSelection = gSelectMgr.getEditSelection();
  92. // Always center the dialog. User can change the size, but purchases are
  93. // important and should be center screen. This also avoids problems where
  94. // the user resizes the application window mid-session and the saved rect
  95. // is off-center.
  96. self->center();
  97. LLSelectNode* node = selection->getFirstRootNode();
  98. if (!node) return;
  99. // Set title based on sale type
  100. LLUIString title;
  101. switch (sale_info.getSaleType())
  102. {
  103. case LLSaleInfo::FS_ORIGINAL:
  104. title = self->getString("title_buy_text");
  105. break;
  106. case LLSaleInfo::FS_COPY:
  107. default:
  108. title = self->getString("title_buy_copy_text");
  109. }
  110. title.setArg("[NAME]", node->mName);
  111. self->setTitle(title);
  112. LLUUID owner_id;
  113. std::string owner_name;
  114. bool owners_identical = gSelectMgr.selectGetOwner(owner_id, owner_name);
  115. if (!owners_identical)
  116. {
  117. gNotifications.add("BuyObjectOneOwner");
  118. return;
  119. }
  120. // Update the display
  121. // Display next owner permissions
  122. LLSD row;
  123. // Compute icon for this item
  124. std::string icon_name =
  125. LLInventoryIcon::getIconName(LLAssetType::AT_OBJECT,
  126. LLInventoryType::IT_OBJECT, 0x0, false);
  127. row["columns"][0]["column"] = "icon";
  128. row["columns"][0]["type"] = "icon";
  129. row["columns"][0]["value"] = icon_name;
  130. // Append the permissions that you will acquire (not the current
  131. // permissions).
  132. U32 next_owner_mask = node->mPermissions->getMaskNextOwner();
  133. std::string text = node->mName;
  134. if (!(next_owner_mask & PERM_COPY))
  135. {
  136. text.append(self->getString("no_copy_text"));
  137. }
  138. if (!(next_owner_mask & PERM_MODIFY))
  139. {
  140. text.append(self->getString("no_modify_text"));
  141. }
  142. if (!(next_owner_mask & PERM_TRANSFER))
  143. {
  144. text.append(self->getString("no_transfer_text"));
  145. }
  146. row["columns"][1]["column"] = "text";
  147. row["columns"][1]["value"] = text;
  148. row["columns"][1]["font"] = "SANSSERIF";
  149. // Add after columns added so appropriate heights are correct.
  150. self->mObjectsList->addElement(row);
  151. self->childSetTextArg("buy_text", "[AMOUNT]",
  152. llformat("%d", sale_info.getSalePrice()));
  153. self->childSetTextArg("buy_text", "[NAME]", owner_name);
  154. // Must do this after the floater is created, because sometimes the
  155. // inventory is already there and the callback is called immediately.
  156. LLViewerObject* obj = selection->getFirstRootObject();
  157. if (obj)
  158. {
  159. self->registerVOInventoryListener(obj, NULL);
  160. self->requestVOInventory();
  161. }
  162. }
  163. void LLFloaterBuy::inventoryChanged(LLViewerObject* obj,
  164. LLInventoryObject::object_list_t* inv,
  165. S32 serial_num, void* data)
  166. {
  167. if (!obj)
  168. {
  169. llwarns << "No object !" << llendl;
  170. return;
  171. }
  172. if (!inv)
  173. {
  174. llwarns << "No inventory !" << llendl;
  175. removeVOInventoryListener();
  176. return;
  177. }
  178. std::string icon_name;
  179. for (LLInventoryObject::object_list_t::const_iterator it = inv->begin(),
  180. end = inv->end();
  181. it != end; ++it)
  182. {
  183. LLInventoryObject* obj = *it;
  184. // Skip folders, so we know we have inventory items only and also skip
  185. // the mysterious blank InventoryObject
  186. if (!obj || obj->getType() == LLAssetType::AT_CATEGORY ||
  187. obj->getType() == LLAssetType::AT_NONE)
  188. {
  189. continue;
  190. }
  191. LLInventoryItem* inv_item = (LLInventoryItem*)obj;
  192. // Skip items we can't transfer
  193. if (!inv_item->getPermissions().allowTransferTo(gAgentID))
  194. {
  195. continue;
  196. }
  197. // Create the line in the list
  198. LLSD row;
  199. // Compute icon for this item
  200. bool item_is_multi = false;
  201. if ((inv_item->getFlags() & LLInventoryItem::II_FLAGS_LANDMARK_VISITED) ||
  202. (inv_item->getFlags() & LLInventoryItem::II_FLAGS_OBJECT_HAS_MULTIPLE_ITEMS))
  203. {
  204. item_is_multi = true;
  205. }
  206. icon_name = LLInventoryIcon::getIconName(inv_item->getType(),
  207. inv_item->getInventoryType(),
  208. inv_item->getFlags(),
  209. item_is_multi);
  210. row["columns"][0]["column"] = "icon";
  211. row["columns"][0]["type"] = "icon";
  212. row["columns"][0]["value"] = icon_name;
  213. // Append the permissions that you will acquire (not the current
  214. // permissions).
  215. U32 next_owner_mask = inv_item->getPermissions().getMaskNextOwner();
  216. std::string text = obj->getName();
  217. if (!(next_owner_mask & PERM_COPY))
  218. {
  219. text.append(" (no copy)");
  220. }
  221. if (!(next_owner_mask & PERM_MODIFY))
  222. {
  223. text.append(" (no modify)");
  224. }
  225. if (!(next_owner_mask & PERM_TRANSFER))
  226. {
  227. text.append(" (no transfer)");
  228. }
  229. row["columns"][1]["column"] = "text";
  230. row["columns"][1]["value"] = text;
  231. row["columns"][1]["font"] = "SANSSERIF";
  232. mItemsList->addElement(row);
  233. }
  234. removeVOInventoryListener();
  235. }
  236. //static
  237. void LLFloaterBuy::onClickBuy(void* data)
  238. {
  239. LLFloaterBuy* self = (LLFloaterBuy*)data;
  240. if (self)
  241. {
  242. // Put the items where we put new folders.
  243. LLUUID category_id =
  244. gInventory.findCategoryUUIDForType(LLFolderType::FT_OBJECT);
  245. // *NOTE: does not work for multiple objects buy, which UI does not
  246. // currently support sale info is used for verification only, if it
  247. // does not match region info then the sale is cancelled.
  248. gSelectMgr.sendBuy(gAgentID, category_id, self->mSaleInfo);
  249. self->close();
  250. }
  251. }
  252. //static
  253. void LLFloaterBuy::onClickCancel(void* data)
  254. {
  255. LLFloaterBuy* self = (LLFloaterBuy*)data;
  256. if (self)
  257. {
  258. self->close();
  259. }
  260. }