llfloaternamedesc.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:7k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfloaternamedesc.cpp
  3.  * @brief LLFloaterNameDesc class implementation
  4.  *
  5.  * $LicenseInfo:firstyear=2002&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2002-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloaternamedesc.h"
  34. // project includes
  35. #include "lllineeditor.h"
  36. #include "llresmgr.h"
  37. #include "lltextbox.h"
  38. #include "llbutton.h"
  39. #include "llviewerwindow.h"
  40. #include "llfocusmgr.h"
  41. #include "llrootview.h"
  42. #include "llradiogroup.h"
  43. #include "lldbstrings.h"
  44. #include "lldir.h"
  45. #include "llfloaterperms.h"
  46. #include "llviewercontrol.h"
  47. #include "llviewermenufile.h" // upload_new_resource()
  48. #include "lluictrlfactory.h"
  49. #include "llstring.h"
  50. #include "lleconomy.h"
  51. // linden includes
  52. #include "llassetstorage.h"
  53. #include "llinventorytype.h"
  54. const S32 PREVIEW_LINE_HEIGHT = 19;
  55. const S32 PREVIEW_CLOSE_BOX_SIZE = 16;
  56. const S32 PREVIEW_BORDER_WIDTH = 2;
  57. const S32 PREVIEW_RESIZE_HANDLE_SIZE = S32(RESIZE_HANDLE_WIDTH * OO_SQRT2) + PREVIEW_BORDER_WIDTH;
  58. const S32 PREVIEW_VPAD = 2;
  59. const S32 PREVIEW_HPAD = PREVIEW_RESIZE_HANDLE_SIZE;
  60. const S32 PREVIEW_HEADER_SIZE = 3 * PREVIEW_LINE_HEIGHT + PREVIEW_VPAD;
  61. const S32 PREF_BUTTON_WIDTH = 64;
  62. const S32 PREF_BUTTON_HEIGHT = 16;
  63. //-----------------------------------------------------------------------------
  64. // LLFloaterNameDesc()
  65. //-----------------------------------------------------------------------------
  66. LLFloaterNameDesc::LLFloaterNameDesc(const LLSD& filename )
  67. : LLFloater(filename),
  68.   mIsAudio(FALSE)   
  69. {
  70. mFilenameAndPath = filename.asString();
  71. mFilename = gDirUtilp->getBaseFileName(mFilenameAndPath, false);
  72. }
  73. //-----------------------------------------------------------------------------
  74. // postBuild()
  75. //-----------------------------------------------------------------------------
  76. BOOL LLFloaterNameDesc::postBuild()
  77. {
  78. LLRect r;
  79. std::string asset_name = mFilename;
  80. LLStringUtil::replaceNonstandardASCII( asset_name, '?' );
  81. LLStringUtil::replaceChar(asset_name, '|', '?');
  82. LLStringUtil::stripNonprintable(asset_name);
  83. LLStringUtil::trim(asset_name);
  84. asset_name = gDirUtilp->getBaseFileName(asset_name, true); // no extsntion
  85. setTitle(mFilename);
  86. centerWithin(gViewerWindow->getRootView()->getRect());
  87. S32 line_width = getRect().getWidth() - 2 * PREVIEW_HPAD;
  88. S32 y = getRect().getHeight() - PREVIEW_LINE_HEIGHT;
  89. r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );
  90. y -= PREVIEW_LINE_HEIGHT;
  91. r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );    
  92. getChild<LLUICtrl>("name_form")->setCommitCallback(boost::bind(&LLFloaterNameDesc::doCommit, this));
  93. childSetValue("name_form", LLSD(asset_name));
  94. LLLineEditor *NameEditor = getChild<LLLineEditor>("name_form");
  95. if (NameEditor)
  96. {
  97. NameEditor->setMaxTextLength(DB_INV_ITEM_NAME_STR_LEN);
  98. NameEditor->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
  99. }
  100. y -= llfloor(PREVIEW_LINE_HEIGHT * 1.2f);
  101. y -= PREVIEW_LINE_HEIGHT;
  102. r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );  
  103. getChild<LLUICtrl>("description_form")->setCommitCallback(boost::bind(&LLFloaterNameDesc::doCommit, this));
  104. LLLineEditor *DescEditor = getChild<LLLineEditor>("description_form");
  105. if (DescEditor)
  106. {
  107. DescEditor->setMaxTextLength(DB_INV_ITEM_DESC_STR_LEN);
  108. DescEditor->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
  109. }
  110. y -= llfloor(PREVIEW_LINE_HEIGHT * 1.2f);
  111. // Cancel button
  112. getChild<LLUICtrl>("cancel_btn")->setCommitCallback(boost::bind(&LLFloaterNameDesc::onBtnCancel, this));
  113. childSetLabelArg("ok_btn", "[AMOUNT]", llformat("%d", LLGlobalEconomy::Singleton::getInstance()->getPriceUpload() ));
  114. setDefaultBtn("ok_btn");
  115. return TRUE;
  116. }
  117. //-----------------------------------------------------------------------------
  118. // LLFloaterNameDesc()
  119. //-----------------------------------------------------------------------------
  120. LLFloaterNameDesc::~LLFloaterNameDesc()
  121. {
  122. gFocusMgr.releaseFocusIfNeeded( this ); // calls onCommit()
  123. }
  124. // Sub-classes should override this function if they allow editing
  125. //-----------------------------------------------------------------------------
  126. // onCommit()
  127. //-----------------------------------------------------------------------------
  128. void LLFloaterNameDesc::onCommit()
  129. {
  130. }
  131. //-----------------------------------------------------------------------------
  132. // onCommit()
  133. //-----------------------------------------------------------------------------
  134. void LLFloaterNameDesc::doCommit()
  135. {
  136. onCommit();
  137. }
  138. //-----------------------------------------------------------------------------
  139. // onBtnOK()
  140. //-----------------------------------------------------------------------------
  141. void LLFloaterNameDesc::onBtnOK( )
  142. {
  143. childDisable("ok_btn"); // don't allow inadvertent extra uploads
  144. LLAssetStorage::LLStoreAssetCallback callback = NULL;
  145. 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).
  146. void *nruserdata = NULL;
  147. std::string display_name = LLStringUtil::null;
  148. upload_new_resource(mFilenameAndPath, // file
  149.     childGetValue("name_form").asString(), 
  150.     childGetValue("description_form").asString(), 
  151.     0, LLFolderType::FT_NONE, LLInventoryType::IT_NONE,
  152.     LLFloaterPerms::getNextOwnerPerms(), LLFloaterPerms::getGroupPerms(), LLFloaterPerms::getEveryonePerms(),
  153.     display_name, callback, expected_upload_cost, nruserdata);
  154. closeFloater(false);
  155. }
  156. //-----------------------------------------------------------------------------
  157. // onBtnCancel()
  158. //-----------------------------------------------------------------------------
  159. void LLFloaterNameDesc::onBtnCancel()
  160. {
  161. closeFloater(false);
  162. }
  163. //-----------------------------------------------------------------------------
  164. // LLFloaterSoundPreview()
  165. //-----------------------------------------------------------------------------
  166. LLFloaterSoundPreview::LLFloaterSoundPreview(const LLSD& filename )
  167. : LLFloaterNameDesc(filename)
  168. {
  169. mIsAudio = TRUE;
  170. }
  171. BOOL LLFloaterSoundPreview::postBuild()
  172. {
  173. if (!LLFloaterNameDesc::postBuild())
  174. {
  175. return FALSE;
  176. }
  177. getChild<LLUICtrl>("ok_btn")->setCommitCallback(boost::bind(&LLFloaterNameDesc::onBtnOK, this));
  178. return TRUE;
  179. }