llfloaternamedesc.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llfloaternamedesc.h"
00035 
00036 // project includes
00037 #include "lllineeditor.h"
00038 #include "llresmgr.h"
00039 #include "lltextbox.h"
00040 #include "llbutton.h"
00041 #include "llviewerwindow.h"
00042 #include "llfocusmgr.h"
00043 #include "llradiogroup.h"
00044 #include "lldbstrings.h"
00045 #include "lldir.h"
00046 #include "llviewercontrol.h"
00047 #include "llviewermenufile.h"   // upload_new_resource()
00048 #include "lluictrlfactory.h"
00049 
00050 // linden includes
00051 #include "llassetstorage.h"
00052 #include "llinventorytype.h"
00053 
00054 const S32 PREVIEW_LINE_HEIGHT = 19;
00055 const S32 PREVIEW_CLOSE_BOX_SIZE = 16;
00056 const S32 PREVIEW_BORDER_WIDTH = 2;
00057 const S32 PREVIEW_RESIZE_HANDLE_SIZE = S32(RESIZE_HANDLE_WIDTH * OO_SQRT2) + PREVIEW_BORDER_WIDTH;
00058 const S32 PREVIEW_VPAD = 2;
00059 const S32 PREVIEW_HPAD = PREVIEW_RESIZE_HANDLE_SIZE;
00060 const S32 PREVIEW_HEADER_SIZE = 3 * PREVIEW_LINE_HEIGHT + PREVIEW_VPAD;
00061 const S32 PREF_BUTTON_WIDTH = 64;
00062 const S32 PREF_BUTTON_HEIGHT = 16;
00063 
00064 //-----------------------------------------------------------------------------
00065 // LLFloaterNameDesc()
00066 //-----------------------------------------------------------------------------
00067 LLFloaterNameDesc::LLFloaterNameDesc(const std::string& filename )
00068         :
00069         LLFloater("Name/Description Floater")
00070 {
00071         mFilenameAndPath = filename;
00072         mFilename.assign(strrchr( filename.c_str(), gDirUtilp->getDirDelimiter()[0]) + 1);
00073         // SL-5521 Maintain capitalization of filename when making the inventory item. JC
00074         //LLString::toLower(mFilename);
00075         mIsAudio = FALSE;
00076 }
00077 
00078 //-----------------------------------------------------------------------------
00079 // postBuild()
00080 //-----------------------------------------------------------------------------
00081 BOOL LLFloaterNameDesc::postBuild()
00082 {
00083         LLRect r;
00084 
00085         LLString asset_name = mFilename;
00086         LLString::replaceNonstandardASCII( asset_name, '?' );
00087         LLString::replaceChar(asset_name, '|', '?');
00088         LLString::stripNonprintable(asset_name);
00089         LLString::trim(asset_name);
00090 
00091         char* asset_name_str = (char*)asset_name.c_str();
00092         char* end_p = strrchr(asset_name_str, '.');              // strip extension if exists
00093         if( !end_p )
00094         {
00095                 end_p = asset_name_str + strlen( asset_name_str );              /* Flawfinder: ignore */
00096         }
00097         else
00098         if( !stricmp( end_p, ".wav") )
00099         {
00100                 mIsAudio = TRUE;
00101         }
00102                 
00103         S32 len = llmin( (S32) (DB_INV_ITEM_NAME_STR_LEN), (S32) (end_p - asset_name_str) );
00104 
00105         asset_name = asset_name.substr( 0, len );
00106 
00107         setTitle(mFilename);
00108 
00109         centerWithin(gViewerWindow->getRootView()->getRect());
00110 
00111         S32 line_width = getRect().getWidth() - 2 * PREVIEW_HPAD;
00112         S32 y = getRect().getHeight() - PREVIEW_LINE_HEIGHT;
00113 
00114         r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );
00115         y -= PREVIEW_LINE_HEIGHT;
00116 
00117         r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );    
00118 
00119         childSetCommitCallback("name_form", doCommit, this);
00120         childSetValue("name_form", LLSD(asset_name));
00121 
00122         LLLineEditor *NameEditor = getChild<LLLineEditor>("name_form");
00123         if (NameEditor)
00124         {
00125                 NameEditor->setMaxTextLength(DB_INV_ITEM_NAME_STR_LEN);
00126                 NameEditor->setPrevalidate(&LLLineEditor::prevalidatePrintableNotPipe);
00127         }
00128 
00129         y -= llfloor(PREVIEW_LINE_HEIGHT * 1.2f);
00130         y -= PREVIEW_LINE_HEIGHT;
00131 
00132         r.setLeftTopAndSize( PREVIEW_HPAD, y, line_width, PREVIEW_LINE_HEIGHT );  
00133         childSetCommitCallback("description_form", doCommit, this);
00134         LLLineEditor *DescEditor = getChild<LLLineEditor>("description_form");
00135         if (DescEditor)
00136         {
00137                 DescEditor->setMaxTextLength(DB_INV_ITEM_DESC_STR_LEN);
00138                 DescEditor->setPrevalidate(&LLLineEditor::prevalidatePrintableNotPipe);
00139         }
00140 
00141         y -= llfloor(PREVIEW_LINE_HEIGHT * 1.2f);
00142 
00143         // Cancel button
00144         childSetAction("cancel_btn", onBtnCancel, this);
00145 
00146         // OK button
00147         childSetAction("ok_btn", onBtnOK, this);
00148         setDefaultBtn("ok_btn");
00149 
00150         return TRUE;
00151 }
00152 
00153 //-----------------------------------------------------------------------------
00154 // LLFloaterNameDesc()
00155 //-----------------------------------------------------------------------------
00156 LLFloaterNameDesc::~LLFloaterNameDesc()
00157 {
00158         gFocusMgr.releaseFocusIfNeeded( this ); // calls onCommit()
00159 }
00160 
00161 // Sub-classes should override this function if they allow editing
00162 //-----------------------------------------------------------------------------
00163 // onCommit()
00164 //-----------------------------------------------------------------------------
00165 void LLFloaterNameDesc::onCommit()
00166 {
00167 }
00168 
00169 // static 
00170 //-----------------------------------------------------------------------------
00171 // onCommit()
00172 //-----------------------------------------------------------------------------
00173 void LLFloaterNameDesc::doCommit( class LLUICtrl *, void* userdata )
00174 {
00175         LLFloaterNameDesc* self = (LLFloaterNameDesc*) userdata;
00176         self->onCommit();
00177 }
00178 
00179 // static 
00180 //-----------------------------------------------------------------------------
00181 // onBtnOK()
00182 //-----------------------------------------------------------------------------
00183 void LLFloaterNameDesc::onBtnOK( void* userdata )
00184 {
00185         LLFloaterNameDesc *fp =(LLFloaterNameDesc *)userdata;
00186 
00187         fp->childDisable("ok_btn"); // don't allow inadvertent extra uploads
00188         
00189         upload_new_resource(fp->mFilenameAndPath, // file
00190                 fp->childGetValue("name_form").asString(), 
00191                 fp->childGetValue("description_form").asString(), 
00192                 0, LLAssetType::AT_NONE, LLInventoryType::IT_NONE);
00193         fp->close(false);
00194 }
00195 
00196 // static 
00197 //-----------------------------------------------------------------------------
00198 // onBtnCancel()
00199 //-----------------------------------------------------------------------------
00200 void LLFloaterNameDesc::onBtnCancel( void* userdata )
00201 {
00202         LLFloaterNameDesc *fp =(LLFloaterNameDesc *)userdata;
00203         fp->close(false);
00204 }

Generated on Fri May 16 08:33:29 2008 for SecondLife by  doxygen 1.5.5