llfloatermarketplace.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /**
  2. * @file llfloatermarketplace.cpp
  3. * @brief LLFloaterMarketplaceValidation and LLFloaterAssociateListing classes
  4. *
  5. * $LicenseInfo:firstyear=2014&license=viewergpl$
  6. *
  7. * Copyright (c) 2014, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloatermarketplace.h"
  34. #include "lllineeditor.h"
  35. #include "llnotifications.h"
  36. #include "lltexteditor.h"
  37. #include "lluictrlfactory.h"
  38. #include "llinventorybridge.h"
  39. #include "llmarketplacefunctions.h"
  40. #include "llviewerinventory.h"
  41. // static variables
  42. LLFloaterMarketplaceValidation::instances_map_t LLFloaterMarketplaceValidation::sInstances;
  43. LLFloaterAssociateListing::instances_map_t LLFloaterAssociateListing::sInstances;
  44. //
  45. // LLFloaterMarketplaceValidation class
  46. //
  47. //static
  48. void LLFloaterMarketplaceValidation::show(const LLUUID& folder_id)
  49. {
  50. LLFloaterMarketplaceValidation* self = NULL;
  51. instances_map_t::iterator it = sInstances.find(folder_id);
  52. if (it == sInstances.end())
  53. {
  54. self = new LLFloaterMarketplaceValidation(folder_id);
  55. }
  56. else
  57. {
  58. self = it->second;
  59. }
  60. if (self)
  61. {
  62. self->open();
  63. self->setFocus(true);
  64. }
  65. }
  66. LLFloaterMarketplaceValidation::LLFloaterMarketplaceValidation(const LLUUID& folder_id)
  67. : LLFloater(folder_id.asString()),
  68. mFolderId(folder_id),
  69. mTitleSet(false)
  70. {
  71. sInstances[folder_id] = this;
  72. LLUICtrlFactory::getInstance()->buildFloater(this,
  73. "floater_marketplace_validation.xml");
  74. }
  75. LLFloaterMarketplaceValidation::~LLFloaterMarketplaceValidation()
  76. {
  77. sInstances.erase(mFolderId);
  78. }
  79. bool LLFloaterMarketplaceValidation::postBuild()
  80. {
  81. mEditor = getChild<LLTextEditor>("validation_text");
  82. mEditor->setEnabled(false);
  83. childSetAction("OK", onButtonOK, this);
  84. // Define a bold style for errors
  85. mBoldStyle = new LLStyle;
  86. mBoldStyle->setVisible(true);
  87. mBoldStyle->mBold = true;
  88. mBoldStyle->setFontName(LLStringUtil::null);
  89. mBoldStyle->setColor(LLUI::sTextFgReadOnlyColor);
  90. return true;
  91. }
  92. void LLFloaterMarketplaceValidation::onOpen()
  93. {
  94. mGotMessages = false;
  95. mEditor->clear();
  96. // Validates the folder
  97. LLViewerInventoryCategory* cat = NULL;
  98. if (mFolderId.notNull())
  99. {
  100. cat = gInventory.getCategory(mFolderId);
  101. }
  102. if (cat)
  103. {
  104. std::string text = getString("scanning") + " " + cat->getName();
  105. mEditor->appendText(text, false, false);
  106. if (!mTitleSet)
  107. {
  108. text = getTitle() + " - " + getString("auditing") + " " +
  109. cat->getName();
  110. setTitle(text);
  111. mTitleSet = true;
  112. }
  113. LLMarketplace::validateListings(cat,
  114. boost::bind(&LLFloaterMarketplaceValidation::appendMessage,
  115. this, _1, _2, _3), false);
  116. if (!mGotMessages)
  117. {
  118. // Display a no error message
  119. mEditor->appendText(getString("no_error"), false, true);
  120. }
  121. }
  122. else
  123. {
  124. mEditor->appendText(getString("null_cat"), false, false);
  125. }
  126. }
  127. void LLFloaterMarketplaceValidation::appendMessage(std::string& message,
  128. S32 depth,
  129. LLError::ELevel level)
  130. {
  131. if (level == LLError::LEVEL_ERROR)
  132. {
  133. mEditor->appendText(message, false, true, mBoldStyle);
  134. mGotMessages = true;
  135. }
  136. else if (level == LLError::LEVEL_WARN)
  137. {
  138. mEditor->appendText(message, false, true);
  139. mGotMessages = true;
  140. }
  141. }
  142. //static
  143. void LLFloaterMarketplaceValidation::onButtonOK(void* userdata)
  144. {
  145. LLFloaterMarketplaceValidation* self = (LLFloaterMarketplaceValidation*)userdata;
  146. if (self)
  147. {
  148. self->close();
  149. }
  150. }
  151. //
  152. // LLFloaterAssociateListing class
  153. //
  154. //static
  155. void LLFloaterAssociateListing::show(const LLUUID& folder_id)
  156. {
  157. LLFloaterAssociateListing* self = NULL;
  158. instances_map_t::iterator it = sInstances.find(folder_id);
  159. if (it == sInstances.end())
  160. {
  161. self = new LLFloaterAssociateListing(folder_id);
  162. }
  163. else
  164. {
  165. self = it->second;
  166. }
  167. if (self)
  168. {
  169. self->open();
  170. self->setFocus(true);
  171. }
  172. }
  173. //static
  174. LLFloaterAssociateListing* LLFloaterAssociateListing::getInstance(const LLUUID& folder_id)
  175. {
  176. instances_map_t::iterator it = sInstances.find(folder_id);
  177. return it == sInstances.end() ? NULL : it->second;
  178. }
  179. LLFloaterAssociateListing::LLFloaterAssociateListing(const LLUUID& folder_id)
  180. : LLFloater(folder_id.asString()),
  181. mFolderId(folder_id)
  182. {
  183. sInstances[folder_id] = this;
  184. LLUICtrlFactory::getInstance()->buildFloater(this,
  185. "floater_associate_listing.xml");
  186. }
  187. LLFloaterAssociateListing::~LLFloaterAssociateListing()
  188. {
  189. sInstances.erase(mFolderId);
  190. }
  191. bool LLFloaterAssociateListing::postBuild()
  192. {
  193. mInputLine = getChild<LLLineEditor>("listing_id");
  194. childSetAction("OK", onButtonOK, this);
  195. childSetAction("Cancel", onButtonCancel, this);
  196. std::string text = getString("invalid");
  197. if (mFolderId.notNull())
  198. {
  199. LLViewerInventoryCategory* cat = gInventory.getCategory(mFolderId);
  200. if (cat)
  201. {
  202. text = getString("associating") + " " + cat->getName();
  203. }
  204. }
  205. childSetValue("prompt", LLSD(text));
  206. return true;
  207. }
  208. bool LLFloaterAssociateListing::handleKeyHere(KEY key, MASK mask)
  209. {
  210. if (key == KEY_RETURN && mask == MASK_NONE)
  211. {
  212. apply();
  213. return true;
  214. }
  215. else if (key == KEY_ESCAPE && mask == MASK_NONE)
  216. {
  217. close();
  218. return true;
  219. }
  220. return LLFloater::handleKeyHere(key, mask);
  221. }
  222. bool apply_callback(const LLSD& notification, const LLSD& response)
  223. {
  224. if (LLNotification::getSelectedOption(notification, response) == 0) // yes
  225. {
  226. const LLUUID& folder_id = notification["payload"]["folder_id"].asUUID();
  227. LLFloaterAssociateListing* floater;
  228. floater = LLFloaterAssociateListing::getInstance(folder_id);
  229. if (floater)
  230. {
  231. floater->apply(false);
  232. }
  233. }
  234. return false;
  235. }
  236. void LLFloaterAssociateListing::apply(bool user_confirm)
  237. {
  238. if (mFolderId.notNull())
  239. {
  240. S32 id = mInputLine->getValue().asInteger();
  241. if (id > 0)
  242. {
  243. // Get the number of version folders in this listing
  244. LLInventoryModel::cat_array_t* categories;
  245. LLInventoryModel::item_array_t* items;
  246. gInventory.getDirectDescendentsOf(mFolderId, categories, items);
  247. S32 versions = categories->size();
  248. // Check if the id exists in the merchant SLM DB: note that this
  249. // record might exist in the LLMarketplaceData structure even if
  250. // unseen in the UI, for instance, if its listing_uuid doesn't
  251. // exist in the merchant inventory
  252. LLMarketplaceData* marketdata = LLMarketplaceData::getInstance();
  253. LLUUID listing_uuid = marketdata->getListingFolder(id);
  254. if (user_confirm && versions != 1 && listing_uuid.notNull() &&
  255. marketdata->getActivationState(listing_uuid))
  256. {
  257. // Look for user confirmation before unlisting
  258. LLSD payload;
  259. payload["folder_id"] = mFolderId;
  260. gNotifications.add("ConfirmMerchantUnlist", LLSD(), payload,
  261. apply_callback);
  262. return;
  263. }
  264. // Associate the id with the user chosen folder
  265. marketdata->associateListing(mFolderId, listing_uuid,id);
  266. // Update the folder widgets now that the action is launched
  267. LLMarketplace::updateCategory(listing_uuid);
  268. LLMarketplace::updateCategory(mFolderId);
  269. gInventory.notifyObservers();
  270. }
  271. else
  272. {
  273. gNotifications.add("AlertMerchantListingInvalidID");
  274. }
  275. }
  276. close();
  277. }
  278. //static
  279. void LLFloaterAssociateListing::onButtonOK(void* userdata)
  280. {
  281. LLFloaterAssociateListing* self = (LLFloaterAssociateListing*)userdata;
  282. if (self)
  283. {
  284. self->apply();
  285. }
  286. }
  287. //static
  288. void LLFloaterAssociateListing::onButtonCancel(void* userdata)
  289. {
  290. LLFloaterAssociateListing* self = (LLFloaterAssociateListing*)userdata;
  291. if (self)
  292. {
  293. self->close();
  294. }
  295. }