hbfloateruploadasset.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * @file hbfloateruploadasset.cpp
  3. * @brief HBFloaterUploadAsset class implementation
  4. * This is a full rewrite of LL's LLFloaterNameDesc class.
  5. *
  6. * $LicenseInfo:firstyear=2023&license=viewergpl$
  7. *
  8. * Copyright (c) 2023, Henri Beauchamp.
  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 "hbfloateruploadasset.h"
  35. #include "llbutton.h"
  36. #include "lldir.h"
  37. #include "lleconomy.h"
  38. #include "lllineeditor.h"
  39. #include "lluictrlfactory.h"
  40. #include "llfloaterimagepreview.h"
  41. #include "llfloaterperms.h"
  42. #include "llviewerassetupload.h"
  43. #include "llviewercontrol.h"
  44. HBFloaterUploadAsset::HBFloaterUploadAsset(const std::string& filename,
  45. S32 inventory_type)
  46. : LLFloater("asset upload"),
  47. mFilenameAndPath(filename),
  48. mFilename(gDirUtil.getBaseFileName(filename, false)),
  49. mInventoryType(inventory_type),
  50. mTempAsset(false)
  51. {
  52. }
  53. bool HBFloaterUploadAsset::postBuild()
  54. {
  55. setTitle(mFilename);
  56. std::string asset_name = mFilename;
  57. LLStringUtil::replaceNonstandardASCII(asset_name, '?');
  58. LLStringUtil::replaceChar(asset_name, '|', '?');
  59. LLStringUtil::stripNonprintable(asset_name);
  60. LLStringUtil::trim(asset_name);
  61. mNameEditor = getChild<LLLineEditor>("name_form");
  62. mNameEditor->setText(gDirUtil.getBaseFileName(asset_name, true));
  63. mNameEditor->setMaxTextLength(DB_INV_ITEM_NAME_STR_LEN);
  64. mNameEditor->setPrevalidate(&LLLineEditor::prevalidatePrintableNotPipe);
  65. mDescEditor = getChild<LLLineEditor>("description_form");
  66. mDescEditor->setMaxTextLength(DB_INV_ITEM_DESC_STR_LEN);
  67. mDescEditor->setPrevalidate(&LLLineEditor::prevalidatePrintableNotPipe);
  68. mCost = getExpectedUploadCost();
  69. // OK button
  70. mUploadButton = getChild<LLButton>("ok_btn");
  71. mUploadButton->setClickedCallback(onBtnOK, this);
  72. mUploadButton->setLabelArg("[AMOUNT]", llformat("%d", mCost));
  73. setDefaultBtn(mUploadButton);
  74. // Cancel button
  75. childSetAction("cancel_btn", onBtnCancel, this);
  76. center();
  77. return true;
  78. }
  79. //virtual
  80. S32 HBFloaterUploadAsset::getExpectedUploadCost() const
  81. {
  82. switch (mInventoryType)
  83. {
  84. case LLInventoryType::IT_TEXTURE:
  85. return LLEconomy::getInstance()->getTextureUploadCost();
  86. case LLInventoryType::IT_SOUND:
  87. return LLEconomy::getInstance()->getSoundUploadCost();
  88. case LLInventoryType::IT_ANIMATION:
  89. return LLEconomy::getInstance()->getAnimationUploadCost();
  90. default:
  91. break;
  92. }
  93. return 0;
  94. }
  95. //virtual
  96. void HBFloaterUploadAsset::uploadAsset()
  97. {
  98. // Upload a chargeable asset.
  99. LLResourceUploadInfo::ptr_t
  100. info(new LLNewFileResourceUploadInfo(mFilenameAndPath,
  101. mNameEditor->getText(),
  102. mDescEditor->getText(), 0,
  103. LLFolderType::FT_NONE,
  104. LLInventoryType::IT_NONE,
  105. LLFloaterPerms::getNextOwnerPerms(),
  106. LLFloaterPerms::getGroupPerms(),
  107. LLFloaterPerms::getEveryonePerms(),
  108. mCost));
  109. upload_new_resource(info, NULL, NULL, mTempAsset);
  110. }
  111. //static
  112. void HBFloaterUploadAsset::onBtnOK(void* userdata)
  113. {
  114. HBFloaterUploadAsset* self = (HBFloaterUploadAsset*)userdata;
  115. if (self)
  116. {
  117. // Do not allow inadvertent duplicate uploads
  118. self->mUploadButton->setEnabled(false);
  119. // This is potentially overridden. HB
  120. self->uploadAsset();
  121. // Whatever the result, we are done: close the floater.
  122. self->close();
  123. }
  124. }
  125. //static
  126. void HBFloaterUploadAsset::onBtnCancel(void* userdata)
  127. {
  128. HBFloaterUploadAsset* self = (HBFloaterUploadAsset*)userdata;
  129. if (self)
  130. {
  131. self->close();
  132. }
  133. }
  134. ///////////////////////////////////////////////////////////////////////////////
  135. // HBFloaterUploadSound class
  136. ///////////////////////////////////////////////////////////////////////////////
  137. HBFloaterUploadSound::HBFloaterUploadSound(const std::string& filename)
  138. : HBFloaterUploadAsset(filename, LLInventoryType::IT_SOUND)
  139. {
  140. LLUICtrlFactory::getInstance()->buildFloater(this,
  141. "floater_sound_preview.xml");
  142. }