diff options
Diffstat (limited to 'indra/newview/llviewermenufile.cpp')
-rw-r--r-- | indra/newview/llviewermenufile.cpp | 287 |
1 files changed, 158 insertions, 129 deletions
diff --git a/indra/newview/llviewermenufile.cpp b/indra/newview/llviewermenufile.cpp index 90355b7166..dc05d98228 100644 --- a/indra/newview/llviewermenufile.cpp +++ b/indra/newview/llviewermenufile.cpp @@ -46,6 +46,7 @@ #include "llimagetga.h" #include "llinventorymodel.h" // gInventory #include "llresourcedata.h" +#include "lltoast.h" #include "llfloaterperms.h" #include "llstatusbar.h" #include "llviewercontrol.h" // gSavedSettings @@ -134,18 +135,35 @@ void LLFilePickerThread::getFile() //virtual void LLFilePickerThread::run() { - LLFilePicker picker; #if LL_WINDOWS - if (picker.getOpenFile(mFilter, false)) + bool blocking = false; +#else + bool blocking = true; // modal +#endif + + LLFilePicker picker; + + if (mIsSaveDialog) { - mFile = picker.getFirstFile(); + if (picker.getSaveFile(mSaveFilter, mProposedName, blocking)) + { + mResponses.push_back(picker.getFirstFile()); + } } -#else - if (picker.getOpenFile(mFilter, true)) + else { - mFile = picker.getFirstFile(); + bool result = mIsGetMultiple ? picker.getMultipleOpenFiles(mLoadFilter, blocking) : picker.getOpenFile(mLoadFilter, blocking); + if (result) + { + std::string filename = picker.getFirstFile(); // consider copying mFiles directly + do + { + mResponses.push_back(filename); + filename = picker.getNextFile(); + } + while (mIsGetMultiple && !filename.empty()); + } } -#endif { LLMutexLock lock(sMutex); @@ -178,13 +196,47 @@ void LLFilePickerThread::clearDead() while (!sDeadQ.empty()) { LLFilePickerThread* thread = sDeadQ.front(); - thread->notify(thread->mFile); + thread->notify(thread->mResponses); delete thread; sDeadQ.pop(); } } } +LLFilePickerReplyThread::LLFilePickerReplyThread(const file_picked_signal_t::slot_type& cb, LLFilePicker::ELoadFilter filter, bool get_multiple) + : LLFilePickerThread(filter, get_multiple), + mLoadFilter(filter), + mSaveFilter(LLFilePicker::FFSAVE_ALL), + mFilePickedSignal(NULL) +{ + mFilePickedSignal = new file_picked_signal_t(); + mFilePickedSignal->connect(cb); +} + +LLFilePickerReplyThread::LLFilePickerReplyThread(const file_picked_signal_t::slot_type& cb, LLFilePicker::ESaveFilter filter, const std::string &proposed_name) + : LLFilePickerThread(filter, proposed_name), + mLoadFilter(LLFilePicker::FFLOAD_ALL), + mSaveFilter(filter), + mFilePickedSignal(NULL) +{ + mFilePickedSignal = new file_picked_signal_t(); + mFilePickedSignal->connect(cb); +} + +LLFilePickerReplyThread::~LLFilePickerReplyThread() +{ + delete mFilePickedSignal; +} + +void LLFilePickerReplyThread::notify(const std::vector<std::string>& filenames) +{ + if (filenames.empty()) return; + + if (mFilePickedSignal) + { + (*mFilePickedSignal)(filenames, mLoadFilter, mSaveFilter); + } +} //============================================================================ @@ -231,54 +283,21 @@ std::string build_extensions_string(LLFilePicker::ELoadFilter filter) } } -/** - char* upload_pick(void* data) - If applicable, brings up a file chooser in which the user selects a file - to upload for a particular task. If the file is valid for the given action, - returns the string to the full path filename, else returns NULL. - Data is the load filter for the type of file as defined in LLFilePicker. -**/ -const std::string upload_pick(void* data) +const bool check_file_extension(const std::string& filename, LLFilePicker::ELoadFilter type) { - if( gAgentCamera.cameraMouselook() ) - { - gAgentCamera.changeCameraToDefault(); - // This doesn't seem necessary. JC - // display(); - } - - LLFilePicker::ELoadFilter type; - if(data) - { - type = (LLFilePicker::ELoadFilter)((intptr_t)data); - } - else - { - type = LLFilePicker::FFLOAD_ALL; - } - - LLFilePicker& picker = LLFilePicker::instance(); - if (!picker.getOpenFile(type)) - { - LL_INFOS() << "Couldn't import objects from file" << LL_ENDL; - return std::string(); - } - - - const std::string& filename = picker.getFirstFile(); std::string ext = gDirUtilp->getExtension(filename); //strincmp doesn't like NULL pointers if (ext.empty()) { std::string short_name = gDirUtilp->getBaseFileName(filename); - + // No extension LLSD args; args["FILE"] = short_name; LLNotificationsUtil::add("NoFileExtension", args); - return std::string(); + return false; } else { @@ -290,7 +309,7 @@ const std::string upload_pick(void* data) std::string valid_extensions = build_extensions_string(type); BOOL ext_valid = FALSE; - + typedef boost::tokenizer<boost::char_separator<char> > tokenizer; boost::char_separator<char> sep(" "); tokenizer tokens(valid_extensions, sep); @@ -299,9 +318,9 @@ const std::string upload_pick(void* data) //now loop over all valid file extensions //and compare them to the extension of the file //to be uploaded - for( token_iter = tokens.begin(); - token_iter != tokens.end() && ext_valid != TRUE; - ++token_iter) + for (token_iter = tokens.begin(); + token_iter != tokens.end() && ext_valid != TRUE; + ++token_iter) { const std::string& cur_token = *token_iter; @@ -321,42 +340,103 @@ const std::string upload_pick(void* data) args["EXTENSION"] = ext; args["VALIDS"] = valid_extensions; LLNotificationsUtil::add("InvalidFileExtension", args); - return std::string(); + return false; } }//end else (non-null extension) + return true; +} - //valid file extension +const void upload_single_file(const std::vector<std::string>& filenames, LLFilePicker::ELoadFilter type) +{ + std::string filename = filenames[0]; + if (!check_file_extension(filename, type)) return; - //now we check to see - //if the file is actually a valid image/sound/etc. - if (type == LLFilePicker::FFLOAD_WAV) + if (!filename.empty()) { - // pre-qualify wavs to make sure the format is acceptable - std::string error_msg; - if (check_for_invalid_wav_formats(filename,error_msg)) + if (type == LLFilePicker::FFLOAD_WAV) { - LL_INFOS() << error_msg << ": " << filename << LL_ENDL; - LLSD args; - args["FILE"] = filename; - LLNotificationsUtil::add( error_msg, args ); - return std::string(); + // pre-qualify wavs to make sure the format is acceptable + std::string error_msg; + if (check_for_invalid_wav_formats(filename, error_msg)) + { + LL_INFOS() << error_msg << ": " << filename << LL_ENDL; + LLSD args; + args["FILE"] = filename; + LLNotificationsUtil::add(error_msg, args); + return; + } + else + { + LLFloaterReg::showInstance("upload_sound", LLSD(filename)); + } + } + if (type == LLFilePicker::FFLOAD_IMAGE) + { + LLFloaterReg::showInstance("upload_image", LLSD(filename)); } - }//end if a wave/sound file + if (type == LLFilePicker::FFLOAD_ANIM) + { + if (filename.rfind(".anim") != std::string::npos) + { + LLFloaterReg::showInstance("upload_anim_anim", LLSD(filename)); + } + else + { + LLFloaterReg::showInstance("upload_anim_bvh", LLSD(filename)); + } + } + } + return; +} - - return filename; + +const void upload_bulk(const std::vector<std::string>& filenames, LLFilePicker::ELoadFilter type) +{ + // TODO: + // Check user balance for entire cost + // Charge user entire cost + // Loop, uploading + // If an upload fails, refund the user for that one + // + // Also fix single upload to charge first, then refund + + S32 expected_upload_cost = LLGlobalEconomy::getInstance()->getPriceUpload(); + for (std::vector<std::string>::const_iterator in_iter = filenames.begin(); in_iter != filenames.end(); ++in_iter) + { + std::string filename = (*in_iter); + if (!check_file_extension(filename, type)) continue; + + std::string name = gDirUtilp->getBaseFileName(filename, true); + std::string asset_name = name; + LLStringUtil::replaceNonstandardASCII(asset_name, '?'); + LLStringUtil::replaceChar(asset_name, '|', '?'); + LLStringUtil::stripNonprintable(asset_name); + LLStringUtil::trim(asset_name); + + LLResourceUploadInfo::ptr_t uploadInfo(new LLNewFileResourceUploadInfo( + filename, + asset_name, + asset_name, 0, + LLFolderType::FT_NONE, LLInventoryType::IT_NONE, + LLFloaterPerms::getNextOwnerPerms("Uploads"), + LLFloaterPerms::getGroupPerms("Uploads"), + LLFloaterPerms::getEveryonePerms("Uploads"), + expected_upload_cost)); + + upload_new_resource(uploadInfo, NULL, NULL); + } } class LLFileUploadImage : public view_listener_t { bool handleEvent(const LLSD& userdata) { - std::string filename = upload_pick((void *)LLFilePicker::FFLOAD_IMAGE); - if (!filename.empty()) + if (gAgentCamera.cameraMouselook()) { - LLFloaterReg::showInstance("upload_image", LLSD(filename)); + gAgentCamera.changeCameraToDefault(); } - return TRUE; + (new LLFilePickerReplyThread(boost::bind(&upload_single_file, _1, _2), LLFilePicker::FFLOAD_IMAGE, false))->getFile(); + return true; } }; @@ -378,11 +458,11 @@ class LLFileUploadSound : public view_listener_t { bool handleEvent(const LLSD& userdata) { - std::string filename = upload_pick((void*)LLFilePicker::FFLOAD_WAV); - if (!filename.empty()) + if (gAgentCamera.cameraMouselook()) { - LLFloaterReg::showInstance("upload_sound", LLSD(filename)); + gAgentCamera.changeCameraToDefault(); } + (new LLFilePickerReplyThread(boost::bind(&upload_single_file, _1, _2), LLFilePicker::FFLOAD_WAV, false))->getFile(); return true; } }; @@ -391,18 +471,11 @@ class LLFileUploadAnim : public view_listener_t { bool handleEvent(const LLSD& userdata) { - const std::string filename = upload_pick((void*)LLFilePicker::FFLOAD_ANIM); - if (!filename.empty()) + if (gAgentCamera.cameraMouselook()) { - if (filename.rfind(".anim") != std::string::npos) - { - LLFloaterReg::showInstance("upload_anim_anim", LLSD(filename)); - } - else - { - LLFloaterReg::showInstance("upload_anim_bvh", LLSD(filename)); - } + gAgentCamera.changeCameraToDefault(); } + (new LLFilePickerReplyThread(boost::bind(&upload_single_file, _1, _2), LLFilePicker::FFLOAD_ANIM, false))->getFile(); return true; } }; @@ -411,55 +484,11 @@ class LLFileUploadBulk : public view_listener_t { bool handleEvent(const LLSD& userdata) { - if( gAgentCamera.cameraMouselook() ) + if (gAgentCamera.cameraMouselook()) { gAgentCamera.changeCameraToDefault(); } - - // TODO: - // Check extensions for uploadability, cost - // Check user balance for entire cost - // Charge user entire cost - // Loop, uploading - // If an upload fails, refund the user for that one - // - // Also fix single upload to charge first, then refund - - LLFilePicker& picker = LLFilePicker::instance(); - if (picker.getMultipleOpenFiles()) - { - std::string filename = picker.getFirstFile(); - S32 expected_upload_cost = LLGlobalEconomy::getInstance()->getPriceUpload(); - - while (!filename.empty()) - { - std::string name = gDirUtilp->getBaseFileName(filename, true); - - std::string asset_name = name; - LLStringUtil::replaceNonstandardASCII( asset_name, '?' ); - LLStringUtil::replaceChar(asset_name, '|', '?'); - LLStringUtil::stripNonprintable(asset_name); - LLStringUtil::trim(asset_name); - - LLResourceUploadInfo::ptr_t uploadInfo(new LLNewFileResourceUploadInfo( - filename, - asset_name, - asset_name, 0, - LLFolderType::FT_NONE, LLInventoryType::IT_NONE, - LLFloaterPerms::getNextOwnerPerms("Uploads"), - LLFloaterPerms::getGroupPerms("Uploads"), - LLFloaterPerms::getEveryonePerms("Uploads"), - expected_upload_cost)); - - upload_new_resource(uploadInfo, NULL, NULL); - - filename = picker.getNextFile(); - } - } - else - { - LL_INFOS() << "Couldn't import objects from file" << LL_ENDL; - } + (new LLFilePickerReplyThread(boost::bind(&upload_bulk, _1, _2), LLFilePicker::FFLOAD_ALL, true))->getFile(); return true; } }; @@ -482,7 +511,7 @@ class LLFileEnableCloseWindow : public view_listener_t bool frontmost_fl_exists = (NULL != gFloaterView->getFrontmostClosableFloater()); bool frontmost_snapshot_fl_exists = (NULL != gSnapshotFloaterView->getFrontmostClosableFloater()); - return frontmost_fl_exists || frontmost_snapshot_fl_exists; + return !LLNotificationsUI::LLToast::isAlertToastShown() && (frontmost_fl_exists || frontmost_snapshot_fl_exists); } }; @@ -519,7 +548,7 @@ class LLFileEnableCloseAllWindows : public view_listener_t bool is_floaters_snapshot_opened = (floater_snapshot && floater_snapshot->isInVisibleChain()) || (floater_outfit_snapshot && floater_outfit_snapshot->isInVisibleChain()); bool open_children = gFloaterView->allChildrenClosed() && !is_floaters_snapshot_opened; - return !open_children; + return !open_children && !LLNotificationsUI::LLToast::isAlertToastShown(); } }; |