PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llfloaternamedesc.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 227 lines | 134 code | 37 blank | 56 comment | 4 complexity | 8f6f0abb0b33d9c47574cb75a9283df3 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloaternamedesc.cpp
  3. * @brief LLFloaterNameDesc class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llfloaternamedesc.h"
  28. // project includes
  29. #include "lllineeditor.h"
  30. #include "llresmgr.h"
  31. #include "lltextbox.h"
  32. #include "llbutton.h"
  33. #include "llviewerwindow.h"
  34. #include "llfocusmgr.h"
  35. #include "llrootview.h"
  36. #include "llradiogroup.h"
  37. #include "lldbstrings.h"
  38. #include "lldir.h"
  39. #include "llfloaterperms.h"
  40. #include "llviewercontrol.h"
  41. #include "llviewermenufile.h" // upload_new_resource()
  42. #include "lluictrlfactory.h"
  43. #include "llstring.h"
  44. #include "lleconomy.h"
  45. // linden includes
  46. #include "llassetstorage.h"
  47. #include "llinventorytype.h"
  48. const S32 PREVIEW_LINE_HEIGHT = 19;
  49. const S32 PREVIEW_CLOSE_BOX_SIZE = 16;
  50. const S32 PREVIEW_BORDER_WIDTH = 2;
  51. const S32 PREVIEW_RESIZE_HANDLE_SIZE = S32(RESIZE_HANDLE_WIDTH * OO_SQRT2) + PREVIEW_BORDER_WIDTH;
  52. const S32 PREVIEW_VPAD = 2;
  53. const S32 PREVIEW_HPAD = PREVIEW_RESIZE_HANDLE_SIZE;
  54. const S32 PREVIEW_HEADER_SIZE = 3 * PREVIEW_LINE_HEIGHT + PREVIEW_VPAD;
  55. const S32 PREF_BUTTON_WIDTH = 64;
  56. const S32 PREF_BUTTON_HEIGHT = 16;
  57. //-----------------------------------------------------------------------------
  58. // LLFloaterNameDesc()
  59. //-----------------------------------------------------------------------------
  60. LLFloaterNameDesc::LLFloaterNameDesc(const LLSD& filename )
  61. : LLFloater(filename),
  62. mIsAudio(FALSE)
  63. {
  64. mFilenameAndPath = filename.asString();
  65. mFilename = gDirUtilp->getBaseFileName(mFilenameAndPath, false);
  66. }
  67. //-----------------------------------------------------------------------------
  68. // postBuild()
  69. //-----------------------------------------------------------------------------
  70. BOOL LLFloaterNameDesc::postBuild()
  71. {
  72. LLRect r;
  73. std::string asset_name = mFilename;
  74. LLStringUtil::replaceNonstandardASCII( asset_name, '?' );
  75. LLStringUtil::replaceChar(asset_name, '|', '?');
  76. LLStringUtil::stripNonprintable(asset_name);
  77. LLStringUtil::trim(asset_name);
  78. asset_name = gDirUtilp->getBaseFileName(asset_name, true); // no extsntion
  79. setTitle(mFilename);
  80. centerWithin(gViewerWindow->getRootView()->getRect());
  81. S32 line_width = getRect().getWidth() - 2 * PREVIEW_HPAD;
  82. S32 y = getRect().getHeight() - PREVIEW_LINE_HEIGHT;
  83. r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );
  84. y -= PREVIEW_LINE_HEIGHT;
  85. r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );
  86. getChild<LLUICtrl>("name_form")->setCommitCallback(boost::bind(&LLFloaterNameDesc::doCommit, this));
  87. getChild<LLUICtrl>("name_form")->setValue(LLSD(asset_name));
  88. LLLineEditor *NameEditor = getChild<LLLineEditor>("name_form");
  89. if (NameEditor)
  90. {
  91. NameEditor->setMaxTextLength(DB_INV_ITEM_NAME_STR_LEN);
  92. NameEditor->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
  93. }
  94. y -= llfloor(PREVIEW_LINE_HEIGHT * 1.2f);
  95. y -= PREVIEW_LINE_HEIGHT;
  96. r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );
  97. getChild<LLUICtrl>("description_form")->setCommitCallback(boost::bind(&LLFloaterNameDesc::doCommit, this));
  98. LLLineEditor *DescEditor = getChild<LLLineEditor>("description_form");
  99. if (DescEditor)
  100. {
  101. DescEditor->setMaxTextLength(DB_INV_ITEM_DESC_STR_LEN);
  102. DescEditor->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
  103. }
  104. y -= llfloor(PREVIEW_LINE_HEIGHT * 1.2f);
  105. // Cancel button
  106. getChild<LLUICtrl>("cancel_btn")->setCommitCallback(boost::bind(&LLFloaterNameDesc::onBtnCancel, this));
  107. getChild<LLUICtrl>("ok_btn")->setLabelArg("[AMOUNT]", llformat("%d", LLGlobalEconomy::Singleton::getInstance()->getPriceUpload() ));
  108. setDefaultBtn("ok_btn");
  109. return TRUE;
  110. }
  111. //-----------------------------------------------------------------------------
  112. // LLFloaterNameDesc()
  113. //-----------------------------------------------------------------------------
  114. LLFloaterNameDesc::~LLFloaterNameDesc()
  115. {
  116. gFocusMgr.releaseFocusIfNeeded( this ); // calls onCommit()
  117. }
  118. // Sub-classes should override this function if they allow editing
  119. //-----------------------------------------------------------------------------
  120. // onCommit()
  121. //-----------------------------------------------------------------------------
  122. void LLFloaterNameDesc::onCommit()
  123. {
  124. }
  125. //-----------------------------------------------------------------------------
  126. // onCommit()
  127. //-----------------------------------------------------------------------------
  128. void LLFloaterNameDesc::doCommit()
  129. {
  130. onCommit();
  131. }
  132. //-----------------------------------------------------------------------------
  133. // onBtnOK()
  134. //-----------------------------------------------------------------------------
  135. void LLFloaterNameDesc::onBtnOK( )
  136. {
  137. getChildView("ok_btn")->setEnabled(FALSE); // don't allow inadvertent extra uploads
  138. LLAssetStorage::LLStoreAssetCallback callback = NULL;
  139. S32 expected_upload_cost = LLGlobalEconomy::Singleton::getInstance()->getPriceUpload(); // kinda hack - assumes that unsubclassed LLFloaterNameDesc is only used for uploading chargeable assets, which it is right now (it's only used unsubclassed for the sound upload dialog, and THAT should be a subclass).
  140. void *nruserdata = NULL;
  141. std::string display_name = LLStringUtil::null;
  142. upload_new_resource(mFilenameAndPath, // file
  143. getChild<LLUICtrl>("name_form")->getValue().asString(),
  144. getChild<LLUICtrl>("description_form")->getValue().asString(),
  145. 0, LLFolderType::FT_NONE, LLInventoryType::IT_NONE,
  146. LLFloaterPerms::getNextOwnerPerms(), LLFloaterPerms::getGroupPerms(), LLFloaterPerms::getEveryonePerms(),
  147. display_name, callback, expected_upload_cost, nruserdata);
  148. closeFloater(false);
  149. }
  150. //-----------------------------------------------------------------------------
  151. // onBtnCancel()
  152. //-----------------------------------------------------------------------------
  153. void LLFloaterNameDesc::onBtnCancel()
  154. {
  155. closeFloater(false);
  156. }
  157. //-----------------------------------------------------------------------------
  158. // LLFloaterSoundPreview()
  159. //-----------------------------------------------------------------------------
  160. LLFloaterSoundPreview::LLFloaterSoundPreview(const LLSD& filename )
  161. : LLFloaterNameDesc(filename)
  162. {
  163. mIsAudio = TRUE;
  164. }
  165. BOOL LLFloaterSoundPreview::postBuild()
  166. {
  167. if (!LLFloaterNameDesc::postBuild())
  168. {
  169. return FALSE;
  170. }
  171. getChild<LLUICtrl>("ok_btn")->setCommitCallback(boost::bind(&LLFloaterNameDesc::onBtnOK, this));
  172. return TRUE;
  173. }
  174. //-----------------------------------------------------------------------------
  175. // LLFloaterScriptPreview()
  176. //-----------------------------------------------------------------------------
  177. LLFloaterScriptPreview::LLFloaterScriptPreview(const LLSD& filename )
  178. : LLFloaterNameDesc(filename)
  179. {
  180. mIsText = TRUE;
  181. }
  182. BOOL LLFloaterScriptPreview::postBuild()
  183. {
  184. if (!LLFloaterNameDesc::postBuild())
  185. {
  186. return FALSE;
  187. }
  188. getChild<LLUICtrl>("ok_btn")->setCommitCallback(boost::bind(&LLFloaterNameDesc::onBtnOK, this));
  189. return TRUE;
  190. }