llfloaterauction.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /**
  2. * @file llfloaterauction.cpp
  3. * @author James Cook, Ian Wilkes
  4. * @brief Implementation of the auction floater.
  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. #include "llviewerprecompiledheaders.h"
  34. #include "llfloaterauction.h"
  35. #include "llfilesystem.h"
  36. #include "llgl.h"
  37. #include "llimagej2c.h"
  38. #include "llimagetga.h"
  39. #include "llparcel.h"
  40. #include "llrender.h"
  41. #include "lluictrlfactory.h"
  42. #include "llagent.h"
  43. #include "llviewercontrol.h"
  44. #include "llviewerdisplay.h"
  45. #include "llviewerparcelmgr.h"
  46. #include "llviewerregion.h"
  47. #include "llviewertexturelist.h"
  48. #include "llviewerwindow.h"
  49. //-----------------------------------------------------------------------------
  50. // Local function definitions
  51. //-----------------------------------------------------------------------------
  52. // StoreAssetData callback (fixed)
  53. void auction_tga_upload_done(const LLUUID& asset_id, void* user_data,
  54. S32 status, LLExtStat ext_status)
  55. {
  56. std::string* name = (std::string*)(user_data);
  57. llinfos << "Upload of asset '" << *name << "' " << asset_id << " returned "
  58. << status << llendl;
  59. delete name;
  60. gWindowp->decBusyCount();
  61. if (0 == status)
  62. {
  63. gNotifications.add("UploadWebSnapshotDone");
  64. }
  65. else
  66. {
  67. LLSD args;
  68. args["REASON"] = std::string(LLAssetStorage::getErrorString(status));
  69. gNotifications.add("UploadAuctionSnapshotFail", args);
  70. }
  71. }
  72. // StoreAssetData callback (fixed)
  73. void auction_j2c_upload_done(const LLUUID& asset_id, void* user_data,
  74. S32 status, LLExtStat ext_status)
  75. {
  76. std::string* name = (std::string*)(user_data);
  77. llinfos << "Upload of asset '" << *name << "' " << asset_id << " returned "
  78. << status << llendl;
  79. delete name;
  80. gWindowp->decBusyCount();
  81. if (status == 0)
  82. {
  83. gNotifications.add("UploadSnapshotDone");
  84. }
  85. else
  86. {
  87. LLSD args;
  88. args["REASON"] = std::string(LLAssetStorage::getErrorString(status));
  89. gNotifications.add("UploadAuctionSnapshotFail", args);
  90. }
  91. }
  92. //-----------------------------------------------------------------------------
  93. // LLFloaterAuction class proper
  94. //-----------------------------------------------------------------------------
  95. LLFloaterAuction::LLFloaterAuction(const LLSD&)
  96. : mParcelID(-1)
  97. {
  98. LLUICtrlFactory::getInstance()->buildFloater(this, "floater_auction.xml");
  99. childSetAction("snapshot_btn", onClickSnapshot, this);
  100. childSetAction("ok_btn", onClickOK, this);
  101. }
  102. //virtual
  103. void LLFloaterAuction::onOpen()
  104. {
  105. mParcelp = gViewerParcelMgr.getParcelSelection();
  106. LLViewerRegion* regionp = gViewerParcelMgr.getSelectionRegion();
  107. LLParcel* parcelp = mParcelp->getParcel();
  108. if (parcelp && regionp && !parcelp->getForSale())
  109. {
  110. mParcelHost = regionp->getHost();
  111. mParcelID = parcelp->getLocalID();
  112. childSetText("parcel_text", parcelp->getName());
  113. childEnable("snapshot_btn");
  114. childEnable("ok_btn");
  115. }
  116. else
  117. {
  118. mParcelHost.invalidate();
  119. if (parcelp && parcelp->getForSale())
  120. {
  121. childSetText("parcel_text", getString("already for sale"));
  122. }
  123. else
  124. {
  125. childSetText("parcel_text", LLStringUtil::null);
  126. }
  127. mParcelID = -1;
  128. childSetEnabled("snapshot_btn", false);
  129. childSetEnabled("ok_btn", false);
  130. }
  131. mImageID.setNull();
  132. mImage = NULL;
  133. }
  134. void LLFloaterAuction::draw()
  135. {
  136. LLFloater::draw();
  137. if (!isMinimized() && mImage.notNull())
  138. {
  139. LLRect rect;
  140. if (childGetRect("snapshot_icon", rect))
  141. {
  142. {
  143. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  144. gl_rect_2d(rect, LLColor4(0.f, 0.f, 0.f, 1.f));
  145. rect.stretch(-1);
  146. }
  147. {
  148. LLGLSUIDefault gls_ui;
  149. gGL.color3f(1.f, 1.f, 1.f);
  150. gl_draw_scaled_image(rect.mLeft, rect.mBottom,
  151. rect.getWidth(), rect.getHeight(),
  152. mImage);
  153. }
  154. }
  155. }
  156. }
  157. // static
  158. void LLFloaterAuction::onClickSnapshot(void* data)
  159. {
  160. LLFloaterAuction* self = (LLFloaterAuction*)(data);
  161. if (!self) return;
  162. LLPointer<LLImageRaw> raw = new LLImageRaw;
  163. gForceRenderLandFence = self->childGetValue("fence_check").asBoolean();
  164. bool success = gViewerWindowp->rawSnapshot(raw,
  165. gViewerWindowp->getWindowWidth(),
  166. gViewerWindowp->getWindowHeight(),
  167. true, false, false, false);
  168. gForceRenderLandFence = false;
  169. if (success)
  170. {
  171. self->mTransactionID.generate();
  172. self->mImageID = self->mTransactionID.makeAssetID(gAgent.getSecureSessionID());
  173. if (!gSavedSettings.getBool("QuietSnapshotsToDisk"))
  174. {
  175. gViewerWindowp->playSnapshotAnimAndSound();
  176. }
  177. llinfos << "Writing TGA..." << llendl;
  178. LLPointer<LLImageTGA> tga = new LLImageTGA;
  179. tga->encode(raw);
  180. LLFileSystem tga_file(self->mImageID, LLFileSystem::OVERWRITE);
  181. tga_file.write(tga->getData(), tga->getDataSize());
  182. raw->biasedScaleToPowerOfTwo(gMaxImageSizeDefault);
  183. llinfos << "Writing J2C..." << llendl;
  184. LLPointer<LLImageJ2C> j2c = new LLImageJ2C;
  185. j2c->encode(raw);
  186. LLFileSystem j2c_file(self->mImageID, LLFileSystem::OVERWRITE);
  187. j2c_file.write(j2c->getData(), j2c->getDataSize());
  188. self->mImage = LLViewerTextureManager::getLocalTexture((LLImageRaw*)raw,
  189. false);
  190. gGL.getTexUnit(0)->bind(self->mImage);
  191. self->mImage->setAddressMode(LLTexUnit::TAM_CLAMP);
  192. }
  193. else
  194. {
  195. llwarns << "Unable to take snapshot" << llendl;
  196. }
  197. }
  198. // static
  199. void LLFloaterAuction::onClickOK(void* data)
  200. {
  201. LLFloaterAuction* self = (LLFloaterAuction*)(data);
  202. if (!self) return;
  203. if (self->mImageID.notNull())
  204. {
  205. if (!gAssetStoragep)
  206. {
  207. llwarns << "No valid asset storage. Aborted." << llendl;
  208. return;
  209. }
  210. LLSD parcel_name = self->childGetValue("parcel_text");
  211. // create the asset
  212. std::string* name = new std::string(parcel_name.asString());
  213. gAssetStoragep->storeAssetData(self->mTransactionID,
  214. LLAssetType::AT_IMAGE_TGA,
  215. auction_tga_upload_done, (void*)name,
  216. false);
  217. gWindowp->incBusyCount();
  218. std::string* j2c_name = new std::string(parcel_name.asString());
  219. gAssetStoragep->storeAssetData(self->mTransactionID,
  220. LLAssetType::AT_TEXTURE,
  221. auction_j2c_upload_done,
  222. (void*)j2c_name, false);
  223. gWindowp->incBusyCount();
  224. gNotifications.add("UploadingAuctionSnapshot");
  225. }
  226. LLMessageSystem* msg = gMessageSystemp;
  227. msg->newMessage("ViewerStartAuction");
  228. msg->nextBlock("AgentData");
  229. msg->addUUID("AgentID", gAgentID);
  230. msg->addUUID("SessionID", gAgentSessionID);
  231. msg->nextBlock("ParcelData");
  232. msg->addS32("LocalID", self->mParcelID);
  233. msg->addUUID("SnapshotID", self->mImageID);
  234. msg->sendReliable(self->mParcelHost);
  235. // Clean up floater, and get out
  236. self->mImageID.setNull();
  237. self->mImage = NULL;
  238. self->mParcelID = -1;
  239. self->mParcelHost.invalidate();
  240. self->close();
  241. }