diff options
Diffstat (limited to 'indra/newview/llpreviewtexture.cpp')
-rw-r--r-- | indra/newview/llpreviewtexture.cpp | 139 |
1 files changed, 78 insertions, 61 deletions
diff --git a/indra/newview/llpreviewtexture.cpp b/indra/newview/llpreviewtexture.cpp index 5e19d770a6..259332a3ff 100644 --- a/indra/newview/llpreviewtexture.cpp +++ b/indra/newview/llpreviewtexture.cpp @@ -66,23 +66,24 @@ const F32 PREVIEW_TEXTURE_MIN_ASPECT = 0.005f; LLPreviewTexture::LLPreviewTexture(const LLSD& key) : LLPreview(key), - mLoadingFullImage( FALSE ), - mShowKeepDiscard(FALSE), - mCopyToInv(FALSE), - mIsCopyable(FALSE), - mIsFullPerm(FALSE), - mUpdateDimensions(TRUE), + mLoadingFullImage( false ), + mSavingMultiple(false), + mShowKeepDiscard(false), + mCopyToInv(false), + mIsCopyable(false), + mIsFullPerm(false), + mUpdateDimensions(true), mLastHeight(0), mLastWidth(0), mAspectRatio(0.f), - mPreviewToSave(FALSE), + mPreviewToSave(false), mImage(NULL), mImageOldBoostLevel(LLGLTexture::BOOST_NONE) { updateImageID(); if (key.has("save_as")) { - mPreviewToSave = TRUE; + mPreviewToSave = true; } } @@ -126,7 +127,7 @@ void LLPreviewTexture::populateRatioList() } // virtual -BOOL LLPreviewTexture::postBuild() +bool LLPreviewTexture::postBuild() { if (mCopyToInv) { @@ -158,7 +159,7 @@ BOOL LLPreviewTexture::postBuild() getChild<LLUICtrl>("desc")->setValue(item->getDescription()); getChild<LLLineEditor>("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe); } - BOOL source_library = mObjectUUID.isNull() && gInventory.isObjectDescendentOf(item->getUUID(), gInventory.getLibraryRootFolderID()); + bool source_library = mObjectUUID.isNull() && gInventory.isObjectDescendentOf(item->getUUID(), gInventory.getLibraryRootFolderID()); if (source_library) { getChildView("Discard")->setEnabled(false); @@ -283,7 +284,7 @@ void LLPreviewTexture::draw() // virtual -BOOL LLPreviewTexture::canSaveAs() const +bool LLPreviewTexture::canSaveAs() const { return mIsFullPerm && !mLoadingFullImage && mImage.notNull() && !mImage->isMissingAsset(); } @@ -304,60 +305,44 @@ void LLPreviewTexture::saveTextureToFile(const std::vector<std::string>& filenam const LLInventoryItem* item = getItem(); if (item && mPreviewToSave) { - mPreviewToSave = FALSE; + mPreviewToSave = false; LLFloaterReg::showTypedInstance<LLPreviewTexture>("preview_texture", item->getUUID()); } // remember the user-approved/edited file name. mSaveFileName = filenames[0]; - mLoadingFullImage = TRUE; + mSavingMultiple = false; + mLoadingFullImage = true; getWindow()->incBusyCount(); + LL_DEBUGS("FileSaveAs") << "Scheduling saving file to " << mSaveFileName << LL_ENDL; + mImage->forceToSaveRawImage(0);//re-fetch the raw image if the old one is removed. mImage->setLoadedCallback(LLPreviewTexture::onFileLoadedForSave, - 0, TRUE, FALSE, new LLUUID(mItemUUID), &mCallbackTextureList); + 0, true, false, new LLUUID(mItemUUID), &mCallbackTextureList); } void LLPreviewTexture::saveMultipleToFile(const std::string& file_name) { std::string texture_location(gSavedSettings.getString("TextureSaveLocation")); - std::string texture_name = file_name.empty() ? getItem()->getName() : file_name; - - std::string filepath; - S32 i = 0; - S32 err = 0; - std::string extension(".png"); - do - { - filepath = texture_location; - filepath += gDirUtilp->getDirDelimiter(); - filepath += texture_name; - - if (i != 0) - { - filepath += llformat("_%.3d", i); - } + std::string texture_name = LLDir::getScrubbedFileName(file_name.empty() ? getItem()->getName() : file_name); - filepath += extension; + mSaveFileName = texture_location + gDirUtilp->getDirDelimiter() + texture_name + ".png"; - llstat stat_info; - err = LLFile::stat( filepath, &stat_info ); - i++; - } while (-1 != err); // Search until the file is not found (i.e., stat() gives an error). - - - mSaveFileName = filepath; - mLoadingFullImage = TRUE; + mSavingMultiple = true; + mLoadingFullImage = true; getWindow()->incBusyCount(); + LL_DEBUGS("FileSaveAs") << "Scheduling saving file to " << mSaveFileName << LL_ENDL; + mImage->forceToSaveRawImage(0);//re-fetch the raw image if the old one is removed. mImage->setLoadedCallback(LLPreviewTexture::onFileLoadedForSave, - 0, TRUE, FALSE, new LLUUID(mItemUUID), &mCallbackTextureList); + 0, true, false, new LLUUID(mItemUUID), &mCallbackTextureList); } // virtual -void LLPreviewTexture::reshape(S32 width, S32 height, BOOL called_from_parent) +void LLPreviewTexture::reshape(S32 width, S32 height, bool called_from_parent) { LLPreview::reshape(width, height, called_from_parent); @@ -412,7 +397,7 @@ void LLPreviewTexture::onFocusReceived() void LLPreviewTexture::openToSave() { - mPreviewToSave = TRUE; + mPreviewToSave = true; } void LLPreviewTexture::hideCtrlButtons() @@ -426,12 +411,12 @@ void LLPreviewTexture::hideCtrlButtons() } // static -void LLPreviewTexture::onFileLoadedForSave(BOOL success, +void LLPreviewTexture::onFileLoadedForSave(bool success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, - BOOL final, + bool final, void* userdata) { LLUUID* item_uuid = (LLUUID*) userdata; @@ -445,14 +430,45 @@ void LLPreviewTexture::onFileLoadedForSave(BOOL success, if( self ) { self->getWindow()->decBusyCount(); - self->mLoadingFullImage = FALSE; + self->mLoadingFullImage = false; } } if( self && final && success ) { + LL_DEBUGS("FileSaveAs") << "Saving file to " << self->mSaveFileName << LL_ENDL; const U32 ext_length = 3; std::string extension = self->mSaveFileName.substr( self->mSaveFileName.length() - ext_length); + + std::string filepath; + if (self->mSavingMultiple) + { + std::string part_path = self->mSaveFileName.substr(0, self->mSaveFileName.length() - ext_length - 1); + + S32 i = 0; + S32 err = 0; + do + { + filepath = part_path; + + if (i != 0) + { + filepath += llformat("_%.3d", i); + } + + filepath += "."; + filepath += extension; + + llstat stat_info; + err = LLFile::stat(filepath, &stat_info); + i++; + } while (-1 != err); // Search until the file is not found (i.e., stat() gives an error). + } + else + { + filepath = self->mSaveFileName; + } + LLStringUtil::toLower(extension); // We only support saving in PNG or TGA format LLPointer<LLImageFormatted> image; @@ -468,13 +484,13 @@ void LLPreviewTexture::onFileLoadedForSave(BOOL success, if( image && !image->encode( src, 0 ) ) { LLSD args; - args["FILE"] = self->mSaveFileName; + args["FILE"] = filepath; LLNotificationsUtil::add("CannotEncodeFile", args); } - else if( image && !image->save( self->mSaveFileName ) ) + else if( image && !image->save(filepath) ) { LLSD args; - args["FILE"] = self->mSaveFileName; + args["FILE"] = filepath; LLNotificationsUtil::add("CannotWriteFile", args); } else @@ -482,6 +498,7 @@ void LLPreviewTexture::onFileLoadedForSave(BOOL success, self->mSavedFileTimer.reset(); self->mSavedFileTimer.setTimerExpirySec( SECONDS_TO_SHOW_FILE_SAVED_MSG ); } + LL_DEBUGS("FileSaveAs") << "Done saving file to " << filepath << LL_ENDL; self->mSaveFileName.clear(); } @@ -530,12 +547,12 @@ void LLPreviewTexture::updateDimensions() // Reshape the floater only when required if (mUpdateDimensions) { - mUpdateDimensions = FALSE; + mUpdateDimensions = false; //reshape floater reshape(getRect().getWidth(), getRect().getHeight()); - gFloaterView->adjustToFitScreen(this, FALSE); + gFloaterView->adjustToFitScreen(this, false); LLRect dim_rect(getChildView("dimensions")->getRect()); LLRect aspect_label_rect(getChildView("aspect_ratio")->getRect()); @@ -547,7 +564,7 @@ void LLPreviewTexture::updateDimensions() // Return true if everything went fine, false if we somewhat modified the ratio as we bumped on border values bool LLPreviewTexture::setAspectRatio(const F32 width, const F32 height) { - mUpdateDimensions = TRUE; + mUpdateDimensions = true; // We don't allow negative width or height. Also, if height is positive but too small, we reset to default // A default 0.f value for mAspectRatio means "unconstrained" in the rest of the code @@ -595,7 +612,7 @@ void LLPreviewTexture::loadAsset() mImage->setBoostLevel(LLGLTexture::BOOST_PREVIEW); mImage->forceToSaveRawImage(0) ; mAssetStatus = PREVIEW_ASSET_LOADING; - mUpdateDimensions = TRUE; + mUpdateDimensions = true; updateDimensions(); getChildView("save_tex_btn")->setEnabled(canSaveAs()); if (mObjectUUID.notNull()) @@ -606,7 +623,7 @@ void LLPreviewTexture::loadAsset() else { // check that we can remove item - BOOL source_library = gInventory.isObjectDescendentOf(mItemUUID, gInventory.getLibraryRootFolderID()); + bool source_library = gInventory.isObjectDescendentOf(mItemUUID, gInventory.getLibraryRootFolderID()); if (source_library) { getChildView("Discard")->setEnabled(false); @@ -656,7 +673,7 @@ void LLPreviewTexture::adjustAspectRatio() std::string ratio = std::to_string(num)+":" + std::to_string(denom); mRatiosList.push_back(ratio); combo->add(ratio); - combo->setCurrentByIndex(mRatiosList.size()- 1); + combo->setCurrentByIndex(static_cast<S32>(mRatiosList.size()) - 1); } else { @@ -674,7 +691,7 @@ void LLPreviewTexture::adjustAspectRatio() } } - mUpdateDimensions = TRUE; + mUpdateDimensions = true; } void LLPreviewTexture::updateImageID() @@ -687,9 +704,9 @@ void LLPreviewTexture::updateImageID() // here's the old logic... //mShowKeepDiscard = item->getPermissions().getCreator() != gAgent.getID(); // here's the new logic... 'cos we hate disappearing buttons. - mShowKeepDiscard = TRUE; + mShowKeepDiscard = true; - mCopyToInv = FALSE; + mCopyToInv = false; LLPermissions perm(item->getPermissions()); mIsCopyable = perm.allowCopyBy(gAgent.getID(), gAgent.getGroupID()) && perm.allowTransferTo(gAgent.getID()); mIsFullPerm = item->checkPermissionsSet(PERM_ITEM_UNRESTRICTED); @@ -697,10 +714,10 @@ void LLPreviewTexture::updateImageID() else // not an item, assume it's an asset id { mImageID = mItemUUID; - mShowKeepDiscard = FALSE; - mCopyToInv = TRUE; - mIsCopyable = TRUE; - mIsFullPerm = TRUE; + mShowKeepDiscard = false; + mCopyToInv = true; + mIsCopyable = true; + mIsFullPerm = true; } } |