PageRenderTime 425ms CodeModel.GetById 201ms app.highlight 20ms RepoModel.GetById 201ms app.codeStats 1ms

/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
  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
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llfloaternamedesc.h"
 30
 31// project includes
 32#include "lllineeditor.h"
 33#include "llresmgr.h"
 34#include "lltextbox.h"
 35#include "llbutton.h"
 36#include "llviewerwindow.h"
 37#include "llfocusmgr.h"
 38#include "llrootview.h"
 39#include "llradiogroup.h"
 40#include "lldbstrings.h"
 41#include "lldir.h"
 42#include "llfloaterperms.h"
 43#include "llviewercontrol.h"
 44#include "llviewermenufile.h"	// upload_new_resource()
 45#include "lluictrlfactory.h"
 46#include "llstring.h"
 47#include "lleconomy.h"
 48
 49// linden includes
 50#include "llassetstorage.h"
 51#include "llinventorytype.h"
 52
 53const S32 PREVIEW_LINE_HEIGHT = 19;
 54const S32 PREVIEW_CLOSE_BOX_SIZE = 16;
 55const S32 PREVIEW_BORDER_WIDTH = 2;
 56const S32 PREVIEW_RESIZE_HANDLE_SIZE = S32(RESIZE_HANDLE_WIDTH * OO_SQRT2) + PREVIEW_BORDER_WIDTH;
 57const S32 PREVIEW_VPAD = 2;
 58const S32 PREVIEW_HPAD = PREVIEW_RESIZE_HANDLE_SIZE;
 59const S32 PREVIEW_HEADER_SIZE = 3 * PREVIEW_LINE_HEIGHT + PREVIEW_VPAD;
 60const S32 PREF_BUTTON_WIDTH = 64;
 61const S32 PREF_BUTTON_HEIGHT = 16;
 62
 63//-----------------------------------------------------------------------------
 64// LLFloaterNameDesc()
 65//-----------------------------------------------------------------------------
 66LLFloaterNameDesc::LLFloaterNameDesc(const LLSD& filename )
 67	: LLFloater(filename),
 68	  mIsAudio(FALSE)	  
 69{
 70	mFilenameAndPath = filename.asString();
 71	mFilename = gDirUtilp->getBaseFileName(mFilenameAndPath, false);
 72}
 73
 74//-----------------------------------------------------------------------------
 75// postBuild()
 76//-----------------------------------------------------------------------------
 77BOOL LLFloaterNameDesc::postBuild()
 78{
 79	LLRect r;
 80
 81	std::string asset_name = mFilename;
 82	LLStringUtil::replaceNonstandardASCII( asset_name, '?' );
 83	LLStringUtil::replaceChar(asset_name, '|', '?');
 84	LLStringUtil::stripNonprintable(asset_name);
 85	LLStringUtil::trim(asset_name);
 86
 87	asset_name = gDirUtilp->getBaseFileName(asset_name, true); // no extsntion
 88
 89	setTitle(mFilename);
 90
 91	centerWithin(gViewerWindow->getRootView()->getRect());
 92
 93	S32 line_width = getRect().getWidth() - 2 * PREVIEW_HPAD;
 94	S32 y = getRect().getHeight() - PREVIEW_LINE_HEIGHT;
 95
 96	r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );
 97	y -= PREVIEW_LINE_HEIGHT;
 98
 99	r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );    
100
101	getChild<LLUICtrl>("name_form")->setCommitCallback(boost::bind(&LLFloaterNameDesc::doCommit, this));
102	getChild<LLUICtrl>("name_form")->setValue(LLSD(asset_name));
103
104	LLLineEditor *NameEditor = getChild<LLLineEditor>("name_form");
105	if (NameEditor)
106	{
107		NameEditor->setMaxTextLength(DB_INV_ITEM_NAME_STR_LEN);
108		NameEditor->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
109	}
110
111	y -= llfloor(PREVIEW_LINE_HEIGHT * 1.2f);
112	y -= PREVIEW_LINE_HEIGHT;
113
114	r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );  
115	getChild<LLUICtrl>("description_form")->setCommitCallback(boost::bind(&LLFloaterNameDesc::doCommit, this));
116	LLLineEditor *DescEditor = getChild<LLLineEditor>("description_form");
117	if (DescEditor)
118	{
119		DescEditor->setMaxTextLength(DB_INV_ITEM_DESC_STR_LEN);
120		DescEditor->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
121	}
122
123	y -= llfloor(PREVIEW_LINE_HEIGHT * 1.2f);
124
125	// Cancel button
126	getChild<LLUICtrl>("cancel_btn")->setCommitCallback(boost::bind(&LLFloaterNameDesc::onBtnCancel, this));
127
128	getChild<LLUICtrl>("ok_btn")->setLabelArg("[AMOUNT]", llformat("%d", LLGlobalEconomy::Singleton::getInstance()->getPriceUpload() ));
129	
130	setDefaultBtn("ok_btn");
131	
132	return TRUE;
133}
134
135//-----------------------------------------------------------------------------
136// LLFloaterNameDesc()
137//-----------------------------------------------------------------------------
138LLFloaterNameDesc::~LLFloaterNameDesc()
139{
140	gFocusMgr.releaseFocusIfNeeded( this ); // calls onCommit()
141}
142
143// Sub-classes should override this function if they allow editing
144//-----------------------------------------------------------------------------
145// onCommit()
146//-----------------------------------------------------------------------------
147void LLFloaterNameDesc::onCommit()
148{
149}
150
151//-----------------------------------------------------------------------------
152// onCommit()
153//-----------------------------------------------------------------------------
154void LLFloaterNameDesc::doCommit()
155{
156	onCommit();
157}
158
159//-----------------------------------------------------------------------------
160// onBtnOK()
161//-----------------------------------------------------------------------------
162void LLFloaterNameDesc::onBtnOK( )
163{
164	getChildView("ok_btn")->setEnabled(FALSE); // don't allow inadvertent extra uploads
165	
166	LLAssetStorage::LLStoreAssetCallback callback = NULL;
167	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).
168	void *nruserdata = NULL;
169	std::string display_name = LLStringUtil::null;
170	upload_new_resource(mFilenameAndPath, // file
171			    getChild<LLUICtrl>("name_form")->getValue().asString(), 
172			    getChild<LLUICtrl>("description_form")->getValue().asString(), 
173			    0, LLFolderType::FT_NONE, LLInventoryType::IT_NONE,
174			    LLFloaterPerms::getNextOwnerPerms(), LLFloaterPerms::getGroupPerms(), LLFloaterPerms::getEveryonePerms(),
175			    display_name, callback, expected_upload_cost, nruserdata);
176	closeFloater(false);
177}
178
179//-----------------------------------------------------------------------------
180// onBtnCancel()
181//-----------------------------------------------------------------------------
182void LLFloaterNameDesc::onBtnCancel()
183{
184	closeFloater(false);
185}
186
187
188//-----------------------------------------------------------------------------
189// LLFloaterSoundPreview()
190//-----------------------------------------------------------------------------
191
192LLFloaterSoundPreview::LLFloaterSoundPreview(const LLSD& filename )
193	: LLFloaterNameDesc(filename)
194{
195	mIsAudio = TRUE;
196}
197
198BOOL LLFloaterSoundPreview::postBuild()
199{
200	if (!LLFloaterNameDesc::postBuild())
201	{
202		return FALSE;
203	}
204	getChild<LLUICtrl>("ok_btn")->setCommitCallback(boost::bind(&LLFloaterNameDesc::onBtnOK, this));
205	return TRUE;
206}
207
208
209//-----------------------------------------------------------------------------
210// LLFloaterScriptPreview()
211//-----------------------------------------------------------------------------
212
213LLFloaterScriptPreview::LLFloaterScriptPreview(const LLSD& filename )
214	: LLFloaterNameDesc(filename)
215{
216	mIsText = TRUE;
217}
218
219BOOL LLFloaterScriptPreview::postBuild()
220{
221	if (!LLFloaterNameDesc::postBuild())
222	{
223		return FALSE;
224	}
225	getChild<LLUICtrl>("ok_btn")->setCommitCallback(boost::bind(&LLFloaterNameDesc::onBtnOK, this));
226	return TRUE;
227}