llfloaterauction.cpp

Go to the documentation of this file.
00001 
00033 #include "llviewerprecompiledheaders.h"
00034 #include "llfloaterauction.h"
00035 
00036 #include "lldir.h"
00037 #include "llgl.h"
00038 #include "llimagej2c.h"
00039 #include "llimagetga.h"
00040 #include "llparcel.h"
00041 #include "llvfile.h"
00042 #include "llvfs.h"
00043 
00044 #include "llagent.h"
00045 #include "llcombobox.h"
00046 #include "llnotify.h"
00047 #include "llsavedsettingsglue.h"
00048 #include "llviewerimagelist.h"
00049 #include "llviewerparcelmgr.h"
00050 #include "llviewerregion.h"
00051 #include "lluictrlfactory.h"
00052 #include "llviewerwindow.h"
00053 #include "llviewerdisplay.h"
00054 #include "llviewercontrol.h"
00055 #include "llui.h"
00056 #include "llglimmediate.h"
00057 
00061 
00062 void auction_j2c_upload_done(const LLUUID& asset_id,
00063                                                            void* user_data, S32 status, LLExtStat ext_status);
00064 void auction_tga_upload_done(const LLUUID& asset_id,
00065                                                            void* user_data, S32 status, LLExtStat ext_status);
00066 
00070 
00071 LLFloaterAuction* LLFloaterAuction::sInstance = NULL;
00072 
00073 // Default constructor
00074 LLFloaterAuction::LLFloaterAuction() :
00075         LLFloater("floater_auction"),
00076         mParcelID(-1)
00077 {
00078         LLUICtrlFactory::getInstance()->buildFloater(this, "floater_auction.xml");
00079 
00080         childSetValue("fence_check",
00081                 LLSD( gSavedSettings.getBOOL("AuctionShowFence") ) );
00082         childSetCommitCallback("fence_check",
00083                 LLSavedSettingsGlue::setBOOL, (void*)"AuctionShowFence");
00084 
00085         childSetAction("snapshot_btn", onClickSnapshot, this);
00086         childSetAction("ok_btn", onClickOK, this);
00087 }
00088 
00089 // Destroys the object
00090 LLFloaterAuction::~LLFloaterAuction()
00091 {
00092         sInstance = NULL;
00093 }
00094 
00095 // static
00096 void LLFloaterAuction::show()
00097 {
00098         if(!sInstance)
00099         {
00100                 sInstance = new LLFloaterAuction();
00101                 sInstance->center();
00102                 sInstance->setFocus(TRUE);
00103         }
00104         sInstance->initialize();
00105         sInstance->open();      /*Flawfinder: ignore*/
00106 }
00107 
00108 void LLFloaterAuction::initialize()
00109 {
00110         mParcelp = LLViewerParcelMgr::getInstance()->getParcelSelection();
00111         LLViewerRegion* region = LLViewerParcelMgr::getInstance()->getSelectionRegion();
00112         LLParcel* parcelp = mParcelp->getParcel();
00113         if(parcelp && region && !parcelp->getForSale())
00114         {
00115                 mParcelHost = region->getHost();
00116                 mParcelID = parcelp->getLocalID();
00117 
00118                 childSetText("parcel_text", parcelp->getName());
00119                 childEnable("snapshot_btn");
00120                 childEnable("ok_btn");
00121         }
00122         else
00123         {
00124                 mParcelHost.invalidate();
00125                 if(parcelp && parcelp->getForSale())
00126                 {
00127                         childSetText("parcel_text", getString("already for sale"));
00128                 }
00129                 else
00130                 {
00131                         childSetText("parcel_text", LLString::null);
00132                 }
00133                 mParcelID = -1;
00134                 childSetEnabled("snapshot_btn", false);
00135                 childSetEnabled("ok_btn", false);
00136         }
00137         mImageID.setNull();
00138         mImage = NULL;
00139 }
00140 
00141 void LLFloaterAuction::draw()
00142 {
00143         LLFloater::draw();
00144 
00145         if(!isMinimized() && mImage.notNull()) 
00146         {
00147                 LLRect rect;
00148                 if (childGetRect("snapshot_icon", rect))
00149                 {
00150                         {
00151                                 LLGLSNoTexture gls_no_texture;
00152                                 gl_rect_2d(rect, LLColor4(0.f, 0.f, 0.f, 1.f));
00153                                 rect.stretch(-1);
00154                         }
00155                         {
00156                                 LLGLSUIDefault gls_ui;
00157                                 gGL.color3f(1.f, 1.f, 1.f);
00158                                 gl_draw_scaled_image(rect.mLeft,
00159                                                                          rect.mBottom,
00160                                                                          rect.getWidth(),
00161                                                                          rect.getHeight(),
00162                                                                          mImage);
00163                         }
00164                 }
00165         }
00166 }
00167 
00168 
00169 // static
00170 void LLFloaterAuction::onClickSnapshot(void* data)
00171 {
00172         LLFloaterAuction* self = (LLFloaterAuction*)(data);
00173 
00174         LLPointer<LLImageRaw> raw = new LLImageRaw;
00175 
00176         gForceRenderLandFence = self->childGetValue("fence_check").asBoolean();
00177         BOOL success = gViewerWindow->rawSnapshot(raw,
00178                                                                                           gViewerWindow->getWindowWidth(),
00179                                                                                           gViewerWindow->getWindowHeight(),
00180                                                                                           TRUE, FALSE,
00181                                                                                           FALSE, FALSE);
00182         gForceRenderLandFence = FALSE;
00183 
00184         if (success)
00185         {
00186                 self->mTransactionID.generate();
00187                 self->mImageID = self->mTransactionID.makeAssetID(gAgent.getSecureSessionID());
00188 
00189                 if(!gSavedSettings.getBOOL("QuietSnapshotsToDisk"))
00190                 {
00191                         gViewerWindow->playSnapshotAnimAndSound();
00192                 }
00193                 llinfos << "Writing TGA..." << llendl;
00194 
00195                 LLPointer<LLImageTGA> tga = new LLImageTGA;
00196                 tga->encode(raw);
00197                 LLVFile::writeFile(tga->getData(), tga->getDataSize(), gVFS, self->mImageID, LLAssetType::AT_IMAGE_TGA);
00198                 
00199                 raw->biasedScaleToPowerOfTwo(LLViewerImage::MAX_IMAGE_SIZE_DEFAULT);
00200 
00201                 llinfos << "Writing J2C..." << llendl;
00202 
00203                 LLPointer<LLImageJ2C> j2c = new LLImageJ2C;
00204                 j2c->encode(raw, 0.0f);
00205                 LLVFile::writeFile(j2c->getData(), j2c->getDataSize(), gVFS, self->mImageID, LLAssetType::AT_TEXTURE);
00206 
00207                 self->mImage = new LLImageGL((LLImageRaw*)raw, FALSE);
00208                 self->mImage->bind();
00209                 self->mImage->setClamp(TRUE, TRUE);
00210         }
00211         else
00212         {
00213                 llwarns << "Unable to take snapshot" << llendl;
00214         }
00215 }
00216 
00217 // static
00218 void LLFloaterAuction::onClickOK(void* data)
00219 {
00220         LLFloaterAuction* self = (LLFloaterAuction*)(data);
00221 
00222         if(self->mImageID.notNull())
00223         {
00224                 LLSD parcel_name = self->childGetValue("parcel_text");
00225 
00226         // create the asset
00227                 LLString* name = new LLString(parcel_name.asString());
00228                 gAssetStorage->storeAssetData(self->mTransactionID, LLAssetType::AT_IMAGE_TGA,
00229                                                                         &auction_tga_upload_done,
00230                                                                         (void*)name,
00231                                                                         FALSE);
00232                 self->getWindow()->incBusyCount();
00233 
00234                 LLString* j2c_name = new LLString(parcel_name.asString());
00235                 gAssetStorage->storeAssetData(self->mTransactionID, LLAssetType::AT_TEXTURE,
00236                                                                    &auction_j2c_upload_done,
00237                                                                    (void*)j2c_name,
00238                                                                    FALSE);
00239                 self->getWindow()->incBusyCount();
00240 
00241                 LLNotifyBox::showXml("UploadingAuctionSnapshot");
00242 
00243         }
00244         LLMessageSystem* msg = gMessageSystem;
00245 
00246         msg->newMessage("ViewerStartAuction");
00247 
00248         msg->nextBlock("AgentData");
00249         msg->addUUID("AgentID", gAgent.getID());
00250         msg->addUUID("SessionID", gAgent.getSessionID());
00251         msg->nextBlock("ParcelData");
00252         msg->addS32("LocalID", self->mParcelID);
00253         msg->addUUID("SnapshotID", self->mImageID);
00254         msg->sendReliable(self->mParcelHost);
00255 
00256         // clean up floater, and get out
00257         self->mImageID.setNull();
00258         self->mImage = NULL;
00259         self->mParcelID = -1;
00260         self->mParcelHost.invalidate();
00261         self->close();
00262 }
00263 
00264 
00268 
00269 void auction_tga_upload_done(const LLUUID& asset_id, void* user_data, S32 status, LLExtStat ext_status) // StoreAssetData callback (fixed)
00270 {
00271         LLString* name = (LLString*)(user_data);
00272         llinfos << "Upload of asset '" << *name << "' " << asset_id
00273                         << " returned " << status << llendl;
00274         delete name;
00275 
00276         gViewerWindow->getWindow()->decBusyCount();
00277 
00278         if (0 == status)
00279         {
00280                 LLNotifyBox::showXml("UploadWebSnapshotDone");
00281         }
00282         else
00283         {
00284                 LLStringBase<char>::format_map_t args;
00285                 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status));
00286                 gViewerWindow->alertXml("UploadAuctionSnapshotFail", args);
00287         }
00288 }
00289 
00290 void auction_j2c_upload_done(const LLUUID& asset_id, void* user_data, S32 status, LLExtStat ext_status) // StoreAssetData callback (fixed)
00291 {
00292         LLString* name = (LLString*)(user_data);
00293         llinfos << "Upload of asset '" << *name << "' " << asset_id
00294                         << " returned " << status << llendl;
00295         delete name;
00296 
00297         gViewerWindow->getWindow()->decBusyCount();
00298 
00299         if (0 == status)
00300         {
00301                 LLNotifyBox::showXml("UploadSnapshotDone");
00302         }
00303         else
00304         {
00305                 LLStringBase<char>::format_map_t args;
00306                 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status));
00307                 gViewerWindow->alertXml("UploadAuctionSnapshotFail", args);
00308         }
00309 }

Generated on Fri May 16 08:33:22 2008 for SecondLife by  doxygen 1.5.5