diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llfloaterimport.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/llfloaterimport.cpp | 660 |
1 files changed, 660 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterimport.cpp b/linden/indra/newview/llfloaterimport.cpp new file mode 100644 index 0000000..b7255db --- /dev/null +++ b/linden/indra/newview/llfloaterimport.cpp | |||
@@ -0,0 +1,660 @@ | |||
1 | /** | ||
2 | * @file llfloaterimport.cpp | ||
3 | * @brief LLFloaterImport class implementation | ||
4 | * | ||
5 | * Copyright (c) 2005-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | #include "llfloaterimport.h" | ||
31 | |||
32 | #include "llapr.h" | ||
33 | |||
34 | #include "llimagebmp.h" | ||
35 | #include "llimagetga.h" | ||
36 | #include "llimagejpeg.h" | ||
37 | |||
38 | #include "llagent.h" | ||
39 | #include "llbutton.h" | ||
40 | #include "llcombobox.h" | ||
41 | #include "lldrawable.h" | ||
42 | #include "lldrawpoolavatar.h" | ||
43 | #include "llface.h" | ||
44 | #include "llinventorymodel.h" | ||
45 | #include "lllineeditor.h" | ||
46 | #include "lltextbox.h" | ||
47 | #include "lltoolmgr.h" | ||
48 | #include "llui.h" | ||
49 | #include "lluploaddialog.h" | ||
50 | #include "llviewercamera.h" | ||
51 | #include "llviewermenu.h" | ||
52 | #include "llviewerwindow.h" | ||
53 | #include "llvoavatar.h" | ||
54 | #include "pipeline.h" | ||
55 | #include "viewer.h" | ||
56 | #include "llvieweruictrlfactory.h" | ||
57 | |||
58 | extern LLInventoryModel gInventory; | ||
59 | |||
60 | //statics | ||
61 | //LLUploadDialog *LLFloaterImport::sImportDialog = NULL; | ||
62 | LLUUID LLFloaterImport::sImportRequestID; | ||
63 | LLString LLFloaterImport::sOKText = LLString(); | ||
64 | |||
65 | const S32 PREVIEW_BORDER_WIDTH = 2; | ||
66 | const S32 PREVIEW_RESIZE_HANDLE_SIZE = S32(RESIZE_HANDLE_WIDTH * OO_SQRT2) + PREVIEW_BORDER_WIDTH; | ||
67 | const S32 PREVIEW_HPAD = PREVIEW_RESIZE_HANDLE_SIZE; | ||
68 | const S32 PREF_BUTTON_HEIGHT = 16; | ||
69 | const S32 PREVIEW_TEXTURE_HEIGHT = 300; | ||
70 | |||
71 | //----------------------------------------------------------------------------- | ||
72 | // LLFloaterImport() | ||
73 | //----------------------------------------------------------------------------- | ||
74 | LLFloaterImport::LLFloaterImport(const std::string filename) | ||
75 | : LLFloater("Import") | ||
76 | { | ||
77 | mFilenameAndPath = filename; | ||
78 | |||
79 | char file_path[256]; | ||
80 | strcpy(file_path, mFilenameAndPath.c_str()); | ||
81 | char *file_name = strrchr( file_path, gDirUtilp->getDirDelimiter()[0]); | ||
82 | file_name[0] = 0; | ||
83 | |||
84 | mFilename.assign(file_name + 1); | ||
85 | mFilePath.assign(file_path); | ||
86 | |||
87 | //LLString::toLower(mFilename); | ||
88 | |||
89 | LLXMLNode::parseFile(filename, mObjectFile, NULL); | ||
90 | } | ||
91 | |||
92 | //----------------------------------------------------------------------------- | ||
93 | // postBuild() | ||
94 | //----------------------------------------------------------------------------- | ||
95 | BOOL LLFloaterImport::postBuild() | ||
96 | { | ||
97 | LLString asset_name = mFilename; | ||
98 | LLString::replaceNonstandardASCII( asset_name, '?' ); | ||
99 | LLString::replaceChar(asset_name, '|', '?'); | ||
100 | LLString::stripNonprintable(asset_name); | ||
101 | LLString::trim(asset_name); | ||
102 | |||
103 | char* asset_name_str = (char*)asset_name.c_str(); | ||
104 | char* end_p = strrchr(asset_name_str, '.'); // strip extension if exists | ||
105 | if( !end_p ) | ||
106 | { | ||
107 | end_p = asset_name_str + strlen( asset_name_str ); | ||
108 | } | ||
109 | |||
110 | S32 len = llmin( (S32) (DB_INV_ITEM_NAME_STR_LEN), (S32) (end_p - asset_name_str) ); | ||
111 | |||
112 | asset_name = asset_name.substr( 0, len ); | ||
113 | |||
114 | setTitle(mFilename); | ||
115 | |||
116 | { | ||
117 | // Center the window | ||
118 | LLRect window_rect = gViewerWindow->getRootView()->getRect(); | ||
119 | |||
120 | S32 dialog_left = window_rect.mLeft + (window_rect.getWidth() - mRect.getWidth()) / 2; | ||
121 | S32 dialog_bottom = window_rect.mBottom + (window_rect.getHeight() - mRect.getHeight()) / 2; | ||
122 | |||
123 | translate( dialog_left - mRect.mLeft, dialog_bottom - mRect.mBottom ); | ||
124 | } | ||
125 | |||
126 | mNameEditor = LLViewerUICtrlFactory::getLineEditorByName(this, "name_form"); | ||
127 | mNameEditor->setMaxTextLength(DB_INV_ITEM_NAME_STR_LEN); | ||
128 | //mNameEditor->setCommitCallback(onCommit); | ||
129 | mNameEditor->setPrevalidate(&LLLineEditor::prevalidatePrintableNotPipe); | ||
130 | |||
131 | mNameEditor->setText(asset_name); | ||
132 | |||
133 | mDescEditor = LLViewerUICtrlFactory::getLineEditorByName(this, "description_form"); | ||
134 | mDescEditor->setMaxTextLength(DB_INV_ITEM_DESC_STR_LEN); | ||
135 | //mDescEditor->setCommitCallback(onCommit); | ||
136 | mDescEditor->setPrevalidate(&LLLineEditor::prevalidatePrintableNotPipe); | ||
137 | |||
138 | // Cancel button | ||
139 | mCancelBtn = LLViewerUICtrlFactory::getButtonByName(this, "cancel_btn"); | ||
140 | mCancelBtn->setClickedCallback(onBtnCancel); | ||
141 | mCancelBtn->setCallbackUserData(this); | ||
142 | |||
143 | // OK button | ||
144 | mOKBtn = LLViewerUICtrlFactory::getButtonByName(this, "ok_btn"); | ||
145 | mOKBtn->setClickedCallback(onBtnOK); | ||
146 | mOKBtn->setCallbackUserData(this); | ||
147 | setDefaultBtn(mOKBtn); | ||
148 | |||
149 | mImageLabel = LLViewerUICtrlFactory::getTextBoxByName(this, "preview_label"); | ||
150 | |||
151 | LLFontGL *default_font = LLFontGL::sSansSerif; | ||
152 | |||
153 | mImportList = LLViewerUICtrlFactory::getScrollListByName(this, "upload_list"); | ||
154 | |||
155 | bool object_file_read = false; | ||
156 | int object_count = 0, image_count = 0; | ||
157 | if (mObjectFile) | ||
158 | { | ||
159 | LLXMLNodeList object_list; | ||
160 | mObjectFile->findName("object", object_list); | ||
161 | LLXMLNodeList::iterator itor; | ||
162 | LLXMLNodeList::iterator itor2; | ||
163 | for (itor = object_list.begin(); itor != object_list.end(); ++itor) | ||
164 | { | ||
165 | LLXMLNode *object = itor->second; | ||
166 | LLXMLNodeList tasks_list; | ||
167 | object->getChildren("task", tasks_list, FALSE); | ||
168 | for (itor2 = tasks_list.begin(); itor2 != tasks_list.end(); ++itor2) | ||
169 | { | ||
170 | LLXMLNode *task = itor2->second; | ||
171 | LLXMLNodePtr temp_node; | ||
172 | if (!task->getChild("root", temp_node, FALSE)) | ||
173 | { | ||
174 | // This task is a root | ||
175 | LLString task_name = "(unnamed object)"; | ||
176 | LLXMLNodePtr task_name_node; | ||
177 | if (task->getChild("name", task_name_node, FALSE)) | ||
178 | { | ||
179 | task_name_node->getStringValue(1, &task_name); | ||
180 | } | ||
181 | { | ||
182 | LLScrollListItem *new_item = new LLScrollListItem(TRUE, task); | ||
183 | new_item->addColumn("OBJECT", default_font, 60); | ||
184 | LLString output_line; | ||
185 | char buffer[20]; | ||
186 | sprintf(buffer, "%d", (S32)tasks_list.size()); | ||
187 | output_line.append(buffer); | ||
188 | output_line.append(" prims"); | ||
189 | new_item->addColumn(output_line, default_font, 80); | ||
190 | new_item->addColumn(task_name, default_font); | ||
191 | new_item->setEnabled(FALSE); | ||
192 | mImportList->addItem(new_item); | ||
193 | } | ||
194 | mImportList->setCanSelect(TRUE); | ||
195 | mImportList->setAllowMultipleSelection(TRUE); | ||
196 | object_file_read = true; | ||
197 | object_count++; | ||
198 | break; | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | |||
203 | if (object_count > 0) | ||
204 | { | ||
205 | std::string::size_type pos = mFilenameAndPath.rfind("."); | ||
206 | if (pos != mFilenameAndPath.npos) | ||
207 | { | ||
208 | mInventoryPath = mFilenameAndPath.substr(0, pos); | ||
209 | } | ||
210 | else | ||
211 | { | ||
212 | mInventoryPath = mFilenameAndPath; | ||
213 | } | ||
214 | mInventoryPath.append("_inventory"); | ||
215 | |||
216 | LLXMLNodeList image_list; | ||
217 | mObjectFile->findName("sl:image", image_list); | ||
218 | std::vector<LLString> unique_images; | ||
219 | std::vector<LLUUID> unique_ids; | ||
220 | std::vector<bool> image_changed; | ||
221 | for (itor = image_list.begin(); itor != image_list.end(); ++itor) | ||
222 | { | ||
223 | LLXMLNode *image_node = itor->second; | ||
224 | LLString image_id = image_node->getID(); | ||
225 | |||
226 | LLUUID image_uuid; | ||
227 | image_node->getUUIDValue(1, &image_uuid); | ||
228 | |||
229 | bool found_image = false; | ||
230 | for (U32 image_num=0; image_num<unique_images.size(); ++image_num) | ||
231 | { | ||
232 | if (unique_images[image_num] == image_id) | ||
233 | { | ||
234 | found_image = true; | ||
235 | continue; | ||
236 | } | ||
237 | } | ||
238 | if (!found_image) | ||
239 | { | ||
240 | unique_images.push_back(image_id); | ||
241 | unique_ids.push_back(image_uuid); | ||
242 | |||
243 | LLString node_hash = "00000000000000000000000000000000"; | ||
244 | LLXMLNodePtr image_hash_node; | ||
245 | if (image_node->getChild("checksum", image_hash_node)) | ||
246 | { | ||
247 | image_hash_node->getStringValue(1, &node_hash); | ||
248 | } | ||
249 | |||
250 | llinfos << "Node hash: " << node_hash << llendl; | ||
251 | |||
252 | // Try to find image and get checksum | ||
253 | LLString image_path = mInventoryPath; | ||
254 | image_path.append(gDirUtilp->getDirDelimiter()); | ||
255 | image_path.append(image_id); | ||
256 | image_path.append(".tga"); | ||
257 | |||
258 | llinfos << "Getting hash for " << image_path << llendl; | ||
259 | |||
260 | char md5_hash_string[33]; | ||
261 | strcpy(md5_hash_string, "00000000000000000000000000000000"); | ||
262 | FILE *fCheck = LLFile::fopen(image_path.c_str(), "rb"); | ||
263 | if (fCheck) | ||
264 | { | ||
265 | LLMD5 my_md5_hash(fCheck); | ||
266 | my_md5_hash.hex_digest(md5_hash_string); | ||
267 | fclose(fCheck); | ||
268 | |||
269 | llinfos << "hash: " << md5_hash_string << llendl; | ||
270 | } | ||
271 | |||
272 | LoadPreviewImage(image_path, image_uuid); | ||
273 | |||
274 | if (memcmp(md5_hash_string, node_hash.c_str(), 32) == 0) | ||
275 | { | ||
276 | // Image has not changed | ||
277 | image_changed.push_back(false); | ||
278 | } | ||
279 | else | ||
280 | { | ||
281 | // Image has changed | ||
282 | image_changed.push_back(true); | ||
283 | } | ||
284 | } | ||
285 | } | ||
286 | for (U32 image_num=0; image_num<unique_images.size(); ++image_num) | ||
287 | { | ||
288 | LLString *image_file = new LLString(unique_images[image_num]); | ||
289 | LLScrollListItem *new_item = new LLScrollListItem(TRUE, image_file, unique_ids[image_num]); | ||
290 | new_item->addColumn("IMAGE", default_font, 60); | ||
291 | new_item->addColumn(image_changed[image_num]?"NEW":"NOT NEW", default_font, 80); | ||
292 | new_item->addColumn(unique_images[image_num].c_str(), default_font); | ||
293 | mImportList->addItem(new_item); | ||
294 | mImportList->setCanSelect(TRUE); | ||
295 | image_count++; | ||
296 | } | ||
297 | } | ||
298 | } | ||
299 | |||
300 | if (!object_file_read) | ||
301 | { | ||
302 | mImportList->addSimpleItem("Error: Invalid object file.", ADD_BOTTOM, FALSE); | ||
303 | mImportList->setCanSelect(FALSE); | ||
304 | mOKBtn->setEnabled(FALSE); | ||
305 | } | ||
306 | else | ||
307 | { | ||
308 | recalcCost(); | ||
309 | } | ||
310 | |||
311 | return TRUE; | ||
312 | } | ||
313 | |||
314 | void LLFloaterImport::LoadPreviewImage(LLString image_path, LLUUID image_uuid) | ||
315 | { | ||
316 | LLPointer<LLImageRaw> raw_image = new LLImageRaw; | ||
317 | LLPointer<LLImageTGA> tga_image = new LLImageTGA; | ||
318 | |||
319 | if (!tga_image->load(image_path)) | ||
320 | { | ||
321 | return; | ||
322 | } | ||
323 | |||
324 | if (!tga_image->decode(raw_image)) | ||
325 | { | ||
326 | return; | ||
327 | } | ||
328 | |||
329 | if( (tga_image->getComponents() != 3) && | ||
330 | (tga_image->getComponents() != 4) ) | ||
331 | { | ||
332 | tga_image->setLastError( "Image files with less than 3 or more than 4 components are not supported." ); | ||
333 | return; | ||
334 | } | ||
335 | |||
336 | raw_image->biasedScaleToPowerOfTwo(256); | ||
337 | |||
338 | mPreviewImages[image_uuid] = raw_image; | ||
339 | } | ||
340 | |||
341 | //----------------------------------------------------------------------------- | ||
342 | // LLFloaterImport() | ||
343 | //----------------------------------------------------------------------------- | ||
344 | LLFloaterImport::~LLFloaterImport() | ||
345 | { | ||
346 | if (mGLName) | ||
347 | { | ||
348 | glDeleteTextures(1, &mGLName ); | ||
349 | } | ||
350 | } | ||
351 | |||
352 | //----------------------------------------------------------------------------- | ||
353 | // recalcCost() | ||
354 | //----------------------------------------------------------------------------- | ||
355 | void LLFloaterImport::recalcCost() | ||
356 | { | ||
357 | /*S32 cost = 0; | ||
358 | LLScrollListItem *item = mImportList->getFirstData(); | ||
359 | while (item) | ||
360 | { | ||
361 | LLString item_type = item->getColumn(0)->getText(); | ||
362 | |||
363 | if (item_type == "IMAGE" && item->getSelected()) | ||
364 | { | ||
365 | cost += 10; // hypothetical image cost | ||
366 | } | ||
367 | if (item_type == "OBJECT") | ||
368 | { | ||
369 | cost += 10; // hypothetical object cost | ||
370 | } | ||
371 | item = mImportList->getNextData(); | ||
372 | } | ||
373 | |||
374 | char buffer[20]; | ||
375 | sOKText = "Upload (L$"; | ||
376 | sprintf(buffer, "%d", cost); | ||
377 | sOKText.append(buffer); | ||
378 | sOKText.append(")"); | ||
379 | mOKBtn->setLabelSelected(sOKText.c_str()); | ||
380 | mOKBtn->setLabelUnselected(sOKText.c_str()); | ||
381 | mOKBtn->setEnabled(TRUE);*/ | ||
382 | } | ||
383 | |||
384 | //----------------------------------------------------------------------------- | ||
385 | // draw() | ||
386 | //----------------------------------------------------------------------------- | ||
387 | void LLFloaterImport::draw() | ||
388 | { | ||
389 | LLFloater::draw(); | ||
390 | |||
391 | LLRect PreviewImageRect; | ||
392 | BOOL has_rect = childGetRect("dummy_preview", PreviewImageRect); | ||
393 | |||
394 | if (mCurrentPreviewImage.notNull() && has_rect) | ||
395 | { | ||
396 | gl_rect_2d_checkerboard(PreviewImageRect); | ||
397 | |||
398 | GLenum format_options[4] = { GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA }; | ||
399 | GLenum format = format_options[mCurrentPreviewImage->getComponents()-1]; | ||
400 | |||
401 | GLenum internal_format_options[4] = { GL_LUMINANCE8, GL_LUMINANCE8_ALPHA8, GL_RGB8, GL_RGBA8 }; | ||
402 | GLenum internal_format = internal_format_options[mCurrentPreviewImage->getComponents()-1]; | ||
403 | |||
404 | if (mGLName) | ||
405 | { | ||
406 | LLImageGL::bindExternalTexture( mGLName, 0, GL_TEXTURE_2D ); | ||
407 | } | ||
408 | else | ||
409 | { | ||
410 | glGenTextures(1, &mGLName ); | ||
411 | stop_glerror(); | ||
412 | |||
413 | LLImageGL::bindExternalTexture( mGLName, 0, GL_TEXTURE_2D ); | ||
414 | stop_glerror(); | ||
415 | |||
416 | glTexImage2D( | ||
417 | GL_TEXTURE_2D, 0, internal_format, | ||
418 | mCurrentPreviewImage->getWidth(), mCurrentPreviewImage->getHeight(), | ||
419 | 0, format, GL_UNSIGNED_BYTE, mCurrentPreviewImage->getData()); | ||
420 | stop_glerror(); | ||
421 | |||
422 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
423 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
424 | |||
425 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
426 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
427 | } | ||
428 | |||
429 | glColor3f(1.f, 1.f, 1.f); | ||
430 | glBegin( GL_QUADS ); | ||
431 | { | ||
432 | glTexCoord2f(0, 1); | ||
433 | glVertex2i(PreviewImageRect.mLeft, PreviewImageRect.mTop); | ||
434 | glTexCoord2f(0, 0); | ||
435 | glVertex2i(PreviewImageRect.mLeft, PreviewImageRect.mBottom); | ||
436 | glTexCoord2f(1, 0); | ||
437 | glVertex2i(PreviewImageRect.mRight, PreviewImageRect.mBottom); | ||
438 | glTexCoord2f(1, 1); | ||
439 | glVertex2i(PreviewImageRect.mRight, PreviewImageRect.mTop); | ||
440 | } | ||
441 | glEnd(); | ||
442 | |||
443 | LLImageGL::unbindTexture(0, GL_TEXTURE_2D); | ||
444 | |||
445 | stop_glerror(); | ||
446 | } | ||
447 | } | ||
448 | |||
449 | // static | ||
450 | void LLFloaterImport::finishImport(ImportAssetInfo *info) | ||
451 | { | ||
452 | llinfos << "Uploading object " << info->FilenameAndPath << "..." << llendl; | ||
453 | |||
454 | LLUUID new_file_id; | ||
455 | new_file_id.generate(); | ||
456 | bool generated_file = false; | ||
457 | |||
458 | { | ||
459 | // Copy file into a local directory | ||
460 | LLString new_file = "TEMP"; | ||
461 | new_file.append(new_file_id.getString()); | ||
462 | new_file.append(".slobject"); | ||
463 | |||
464 | S32 length; | ||
465 | apr_file_t* fIn = ll_apr_file_open(info->FilenameAndPath.c_str(), LL_APR_RB, &length); | ||
466 | if (fIn) | ||
467 | { | ||
468 | apr_file_t* fOut = ll_apr_file_open(new_file, LL_APR_WB); | ||
469 | if (fOut) | ||
470 | { | ||
471 | char *buffer = new char[length]; | ||
472 | ll_apr_file_read(fIn, buffer, length); | ||
473 | ll_apr_file_write(fOut, buffer, length); | ||
474 | delete buffer; | ||
475 | generated_file = true; | ||
476 | apr_file_close(fOut); | ||
477 | } | ||
478 | apr_file_close(fIn); | ||
479 | } | ||
480 | } | ||
481 | |||
482 | if (generated_file) | ||
483 | { | ||
484 | LLMessageSystem *msg = gMessageSystem; | ||
485 | msg->newMessageFast(_PREHASH_ObjectImport); | ||
486 | msg->nextBlockFast(_PREHASH_AgentData); | ||
487 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | ||
488 | msg->addUUIDFast(_PREHASH_FolderID, gInventory.findCategoryUUIDForType(LLAssetType::AT_OBJECT)); | ||
489 | msg->nextBlockFast(_PREHASH_AssetData); | ||
490 | msg->addUUIDFast(_PREHASH_FileID, new_file_id); | ||
491 | msg->addStringFast(_PREHASH_ObjectName, info->Name); | ||
492 | msg->addStringFast(_PREHASH_Description, info->Desc); | ||
493 | msg->sendReliable(gAgent.getRegionHost()); | ||
494 | |||
495 | LLUploadDialog::modalUploadDialog("Importing geometry..."); | ||
496 | |||
497 | sImportRequestID = new_file_id; | ||
498 | } | ||
499 | else | ||
500 | { | ||
501 | llinfos << "Failed to copy file." << llendl; | ||
502 | } | ||
503 | } | ||
504 | |||
505 | // static | ||
506 | void LLFloaterImport::asset_uploaded_callback(const LLUUID& uuid, void* user_data, S32 result) | ||
507 | { | ||
508 | llinfos << "LLFloaterImport: Finished uploading image." << llendl; | ||
509 | LLResourceData *resource_data = (LLResourceData*)user_data; | ||
510 | ImportAssetInfo *info = (ImportAssetInfo*)resource_data->mUserData; | ||
511 | |||
512 | info->NewImageIDList.push_back(resource_data->mAssetInfo.mUuid.getString()); | ||
513 | |||
514 | LLUploadDialog::modalUploadFinished(); | ||
515 | if (info->ImageFileQueue.size() == 0) | ||
516 | { | ||
517 | finishImport(info); | ||
518 | } | ||
519 | else | ||
520 | { | ||
521 | // Start the next download | ||
522 | LLString current_image = info->ImageFileQueue[0].c_str(); | ||
523 | info->ImageFileQueue.erase(info->ImageFileQueue.begin()); | ||
524 | |||
525 | upload_new_resource(current_image, info->Name, // file | ||
526 | info->Desc, 0, LLAssetType::AT_NONE, LLInventoryType::IT_NONE, | ||
527 | PERM_NONE, LLString::null, asset_uploaded_callback, info); | ||
528 | } | ||
529 | } | ||
530 | |||
531 | //----------------------------------------------------------------------------- | ||
532 | // static onBtnOK() | ||
533 | //----------------------------------------------------------------------------- | ||
534 | void LLFloaterImport::onBtnOK(void*userdata) | ||
535 | { | ||
536 | LLFloaterImport *fp =(LLFloaterImport*)userdata; | ||
537 | |||
538 | ImportAssetInfo *asset_info = new ImportAssetInfo(); | ||
539 | asset_info->Name = fp->mNameEditor->getText(); | ||
540 | asset_info->Desc = fp->mDescEditor->getText(); | ||
541 | asset_info->FilenameAndPath = fp->mFilenameAndPath; | ||
542 | asset_info->SourcePath = fp->mInventoryPath; | ||
543 | |||
544 | std::vector<LLScrollListItem*> items = fp->mImportList->getAllSelected(); | ||
545 | std::vector<LLScrollListItem*>::iterator itor; | ||
546 | if (items.size() > 0) | ||
547 | { | ||
548 | for (itor = items.begin(); itor != items.end(); ++itor) | ||
549 | { | ||
550 | LLUUID id = (*itor)->getUUID(); | ||
551 | |||
552 | //if (!id->isNull()) | ||
553 | LLString *image_id = (LLString *)(*itor)->getUserdata(); | ||
554 | if (image_id) | ||
555 | { | ||
556 | asset_info->OldImageIDList.push_back(id.getString()); | ||
557 | LLString image_file = fp->mInventoryPath; | ||
558 | image_file.append(gDirUtilp->getDirDelimiter()); | ||
559 | image_file.append(*image_id); | ||
560 | image_file.append(".tga"); | ||
561 | llinfos << "Uploading image " << image_file << "..." << llendl; | ||
562 | asset_info->ImageFileQueue.push_back(image_file); | ||
563 | } | ||
564 | } | ||
565 | if (asset_info->ImageFileQueue.size() == 0) | ||
566 | { | ||
567 | finishImport(asset_info); | ||
568 | } | ||
569 | else | ||
570 | { | ||
571 | // Start the first download | ||
572 | LLString current_image = asset_info->ImageFileQueue[0].c_str(); | ||
573 | asset_info->ImageFileQueue.erase(asset_info->ImageFileQueue.begin()); | ||
574 | |||
575 | upload_new_resource(current_image, asset_info->Name, // file | ||
576 | asset_info->Desc, 0, LLAssetType::AT_NONE, LLInventoryType::IT_NONE, | ||
577 | PERM_NONE, LLString::null, asset_uploaded_callback, asset_info); | ||
578 | } | ||
579 | } | ||
580 | else | ||
581 | { | ||
582 | finishImport(asset_info); | ||
583 | } | ||
584 | |||
585 | fp->onClose(false); | ||
586 | } | ||
587 | |||
588 | //----------------------------------------------------------------------------- | ||
589 | // static onBtnCancel() | ||
590 | //----------------------------------------------------------------------------- | ||
591 | void LLFloaterImport::onBtnCancel(void*userdata) | ||
592 | { | ||
593 | LLFloaterImport *fp =(LLFloaterImport*)userdata; | ||
594 | fp->onClose(false); | ||
595 | } | ||
596 | |||
597 | |||
598 | //----------------------------------------------------------------------------- | ||
599 | // virtual handleMouseDown() | ||
600 | //----------------------------------------------------------------------------- | ||
601 | BOOL LLFloaterImport::handleMouseDown(S32 x, S32 y, MASK mask) | ||
602 | { | ||
603 | BOOL ret = LLFloater::handleMouseDown(x, y, mask); | ||
604 | recalcCost(); | ||
605 | |||
606 | LLUUID current_preview_uuid; | ||
607 | LLString current_preview_name = "none"; | ||
608 | |||
609 | LLScrollListItem *item; | ||
610 | |||
611 | // Did we just select something? | ||
612 | item = mImportList->getLastSelectedItem(); | ||
613 | if (item) | ||
614 | { | ||
615 | current_preview_uuid = item->getUUID(); | ||
616 | current_preview_name = item->getColumn(2)->getText(); | ||
617 | } | ||
618 | else | ||
619 | { | ||
620 | // If not, see if exactly one object is selected | ||
621 | std::vector<LLScrollListItem*> items = mImportList->getAllSelected(); | ||
622 | std::vector<LLScrollListItem*>::iterator itor; | ||
623 | for (itor = items.begin(); itor != items.end(); ++itor) | ||
624 | { | ||
625 | if (current_preview_uuid.isNull()) | ||
626 | { | ||
627 | current_preview_uuid = (*itor)->getUUID(); | ||
628 | current_preview_name = (*itor)->getColumn(2)->getText(); | ||
629 | } | ||
630 | else | ||
631 | { | ||
632 | // More than one item is selected. Turn off preview | ||
633 | current_preview_uuid.setNull(); | ||
634 | current_preview_name = "none"; | ||
635 | break; | ||
636 | } | ||
637 | } | ||
638 | } | ||
639 | |||
640 | mCurrentPreviewImage = NULL; | ||
641 | if (current_preview_uuid.notNull()) | ||
642 | { | ||
643 | image_map_t::iterator itor; | ||
644 | itor = mPreviewImages.find(current_preview_uuid); | ||
645 | if (itor != mPreviewImages.end()) | ||
646 | { | ||
647 | mCurrentPreviewImage = itor->second; | ||
648 | if (mGLName) | ||
649 | { | ||
650 | glDeleteTextures(1, &mGLName ); | ||
651 | } | ||
652 | mGLName = 0; | ||
653 | } | ||
654 | } | ||
655 | LLString label_text = "Image Preview: "; | ||
656 | label_text.append(current_preview_name); | ||
657 | mImageLabel->setText(label_text); | ||
658 | |||
659 | return ret; | ||
660 | } | ||