00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llfloaternamedesc.h"
00035
00036
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"
00048 #include "llvieweruictrlfactory.h"
00049
00050
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
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
00074
00075 mIsAudio = FALSE;
00076 }
00077
00078
00079
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, '.');
00093 if( !end_p )
00094 {
00095 end_p = asset_name_str + strlen( asset_name_str );
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 centerWindow();
00110
00111 S32 line_width = mRect.getWidth() - 2 * PREVIEW_HPAD;
00112 S32 y = mRect.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 = LLViewerUICtrlFactory::getLineEditorByName(this, "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 = LLViewerUICtrlFactory::getLineEditorByName(this, "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 if (mIsAudio)
00144 {
00145 LLSD bitrate = gSavedSettings.getS32("AudioDefaultBitrate");
00146
00147 childSetValue("bitrate", bitrate);
00148 }
00149
00150
00151 childSetAction("cancel_btn", onBtnCancel, this);
00152
00153
00154 childSetAction("ok_btn", onBtnOK, this);
00155 setDefaultBtn("ok_btn");
00156
00157 return TRUE;
00158 }
00159
00160
00161
00162
00163 LLFloaterNameDesc::~LLFloaterNameDesc()
00164 {
00165 gFocusMgr.releaseFocusIfNeeded( this );
00166 }
00167
00168
00169
00170
00171 void LLFloaterNameDesc::centerWindow()
00172 {
00173 LLRect window_rect = gViewerWindow->getRootView()->getRect();
00174
00175 S32 dialog_left = window_rect.mLeft + (window_rect.getWidth() - mRect.getWidth()) / 2;
00176 S32 dialog_bottom = window_rect.mBottom + (window_rect.getHeight() - mRect.getHeight()) / 2;
00177
00178 translate( dialog_left - mRect.mLeft, dialog_bottom - mRect.mBottom );
00179 }
00180
00181
00182
00183
00184
00185 void LLFloaterNameDesc::onCommit()
00186 {
00187 }
00188
00189
00190
00191
00192
00193 void LLFloaterNameDesc::doCommit( class LLUICtrl *, void* userdata )
00194 {
00195 LLFloaterNameDesc* self = (LLFloaterNameDesc*) userdata;
00196 self->onCommit();
00197 }
00198
00199
00200
00201
00202
00203 void LLFloaterNameDesc::onBtnOK( void* userdata )
00204 {
00205 LLFloaterNameDesc *fp =(LLFloaterNameDesc *)userdata;
00206
00207 fp->childDisable("ok_btn");
00208
00209 S32 bitrate = 0;
00210
00211 if (fp->mIsAudio)
00212 {
00213 bitrate = fp->childGetValue("bitrate").asInteger();
00214 }
00215 upload_new_resource(fp->mFilenameAndPath,
00216 fp->childGetValue("name_form").asString(),
00217 fp->childGetValue("description_form").asString(),
00218 bitrate, LLAssetType::AT_NONE, LLInventoryType::IT_NONE);
00219 fp->close(false);
00220 }
00221
00222
00223
00224
00225
00226 void LLFloaterNameDesc::onBtnCancel( void* userdata )
00227 {
00228 LLFloaterNameDesc *fp =(LLFloaterNameDesc *)userdata;
00229 fp->close(false);
00230 }