From a408bac29378072fbf36864164149458c978cfcc Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:44:59 -0500 Subject: Second Life viewer sources 1.17.1.0 --- linden/indra/newview/llfloaterpostcard.cpp | 148 +++++++++++++++++++---------- 1 file changed, 100 insertions(+), 48 deletions(-) (limited to 'linden/indra/newview/llfloaterpostcard.cpp') diff --git a/linden/indra/newview/llfloaterpostcard.cpp b/linden/indra/newview/llfloaterpostcard.cpp index 2c80300..82bab03 100644 --- a/linden/indra/newview/llfloaterpostcard.cpp +++ b/linden/indra/newview/llfloaterpostcard.cpp @@ -76,12 +76,12 @@ LLFloaterPostcard::LLFloaterPostcard(LLImageJPEG* jpeg, LLImageGL *img, const LL mJPEGImage(jpeg), mViewerImage(img), mImageScale(img_scale), - mPosTakenGlobal(pos_taken_global) + mPosTakenGlobal(pos_taken_global), + mHasFirstMsgFocus(false) { init(); } - void LLFloaterPostcard::init() { // pick up the user's up-to-date email address @@ -128,25 +128,24 @@ BOOL LLFloaterPostcard::postBuild() gAgent.buildFullname(name_string); childSetValue("name_form", LLSD(name_string)); - - // XUI:translate - LLString msg("Postcard from "); - msg += gSecondLife; - childSetValue("subject_form", LLSD(msg)); LLTextEditor *MsgField = LLUICtrlFactory::getTextEditorByName(this, "msg_form"); if (MsgField) { - MsgField->setText("Check this out!"); MsgField->setWordWrap(TRUE); - } - childSetFocus("to_form", TRUE); + // For the first time a user focusess to .the msg box, all text will be selected. + MsgField->setFocusChangedCallback(onMsgFormFocusRecieved); + MsgField->setCallbackUserData(this); + } + childSetFocus("to_form", TRUE); + return TRUE; } + // static LLFloaterPostcard* LLFloaterPostcard::showFromSnapshot(LLImageJPEG *jpeg, LLImageGL *img, const LLVector2 &image_scale, const LLVector3d& pos_taken_global) { @@ -267,46 +266,16 @@ void LLFloaterPostcard::onClickSend(void* data) return; } - if (self->mJPEGImage.notNull()) + LLString subject(self->childGetValue("subject_form").asString().c_str()); + if(subject.empty() || !self->mHasFirstMsgFocus) { - self->mTransactionID.generate(); - self->mAssetID = self->mTransactionID.makeAssetID(gAgent.getSecureSessionID()); - LLVFile::writeFile(self->mJPEGImage->getData(), self->mJPEGImage->getDataSize(), gVFS, self->mAssetID, LLAssetType::AT_IMAGE_JPEG); - - // upload the image - std::string url = gAgent.getRegion()->getCapability("SendPostcard"); - if(!url.empty()) - { - llinfos << "Send Postcard via capability" << llendl; - LLSD body = LLSD::emptyMap(); - // the capability already encodes: agent ID, region ID - body["pos-global"] = self->mPosTakenGlobal.getValue(); - body["to"] = self->childGetValue("to_form").asString(); - body["from"] = self->childGetValue("from_form").asString(); - body["name"] = self->childGetValue("name_form").asString(); - body["subject"] = self->childGetValue("subject_form").asString(); - body["msg"] = self->childGetValue("msg_form").asString(); - body["allow-publish"] = self->childGetValue("allow_publish_check").asBoolean(); - body["mature-publish"] = self->childGetValue("mature_check").asBoolean(); - LLHTTPClient::post(url, body, new LLSendPostcardResponder(body, self->mAssetID, LLAssetType::AT_IMAGE_JPEG)); - } - else - { - gAssetStorage->storeAssetData(self->mTransactionID, LLAssetType::AT_IMAGE_JPEG, &uploadCallback, (void *)self, FALSE); - } - - LLUploadDialog::modalUploadDialog("Uploading...\n\nPostcard"); - - // don't destroy the window until the upload is done - // this way we keep the information in the form - self->setVisible(FALSE); + gViewerWindow->alertXml("PromptMissingSubjMsg", missingSubjMsgAlertCallback, self); + return; + } - // also remove any dependency on another floater - // so that we can be sure to outlive it while we - // need to. - LLFloater* dependee = self->getDependee(); - if (dependee) - dependee->removeDependentFloater(self); + if (self->mJPEGImage.notNull()) + { + self->sendPostcard(); } else { @@ -375,3 +344,86 @@ void LLFloaterPostcard::updateUserInfo(const char *email) } } } + +void LLFloaterPostcard::onMsgFormFocusRecieved(LLUICtrl* receiver, void* data) +{ + LLFloaterPostcard* self = (LLFloaterPostcard *)data; + if(self) + { + LLTextEditor* msgForm = LLUICtrlFactory::getTextEditorByName(self, "msg_form"); + if(msgForm && msgForm == receiver && msgForm->hasFocus() && !(self->mHasFirstMsgFocus)) + { + self->mHasFirstMsgFocus = true; + msgForm->setText(LLString("")); + } + } +} + +void LLFloaterPostcard::missingSubjMsgAlertCallback(S32 option, void* data) +{ + if(data) + { + LLFloaterPostcard* self = static_cast(data); + if(0 == option) + { + // User clicked OK + if((self->childGetValue("subject_form").asString()).empty()) + { + // Stuff the subject back into the form. + self->childSetValue("subject_form", self->childGetText("default_subject")); + } + + if(!self->mHasFirstMsgFocus) + { + // The user never switched focus to the messagee window. + // Using the default string. + // XUI: translate + self->childSetValue("msg_form", self->childGetText("default_message")); + } + + self->sendPostcard(); + } + } +} + +void LLFloaterPostcard::sendPostcard() +{ + mTransactionID.generate(); + mAssetID = mTransactionID.makeAssetID(gAgent.getSecureSessionID()); + LLVFile::writeFile(mJPEGImage->getData(), mJPEGImage->getDataSize(), gVFS, mAssetID, LLAssetType::AT_IMAGE_JPEG); + + // upload the image + std::string url = gAgent.getRegion()->getCapability("SendPostcard"); + if(!url.empty()) + { + llinfos << "Send Postcard via capability" << llendl; + LLSD body = LLSD::emptyMap(); + // the capability already encodes: agent ID, region ID + body["pos-global"] = mPosTakenGlobal.getValue(); + body["to"] = childGetValue("to_form").asString(); + body["from"] = childGetValue("from_form").asString(); + body["name"] = childGetValue("name_form").asString(); + body["subject"] = childGetValue("subject_form").asString(); + body["msg"] = childGetValue("msg_form").asString(); + body["allow-publish"] = childGetValue("allow_publish_check").asBoolean(); + body["mature-publish"] = childGetValue("mature_check").asBoolean(); + LLHTTPClient::post(url, body, new LLSendPostcardResponder(body, mAssetID, LLAssetType::AT_IMAGE_JPEG)); + } + else + { + gAssetStorage->storeAssetData(mTransactionID, LLAssetType::AT_IMAGE_JPEG, &uploadCallback, (void *)this, FALSE); + } + + LLUploadDialog::modalUploadDialog("Uploading...\n\nPostcard"); + + // don't destroy the window until the upload is done + // this way we keep the information in the form + setVisible(FALSE); + + // also remove any dependency on another floater + // so that we can be sure to outlive it while we + // need to. + LLFloater* dependee = getDependee(); + if (dependee) + dependee->removeDependentFloater(this); +} -- cgit v1.1