From 65e144d9fec4bb441050e73136ed95b48e6e363c Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Wed, 2 Nov 2011 19:05:13 +0200 Subject: STORM-1580 WIP Initial commit for PO review. --- indra/newview/llpostcard.cpp | 160 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 indra/newview/llpostcard.cpp (limited to 'indra/newview/llpostcard.cpp') diff --git a/indra/newview/llpostcard.cpp b/indra/newview/llpostcard.cpp new file mode 100644 index 0000000000..5f57f3a856 --- /dev/null +++ b/indra/newview/llpostcard.cpp @@ -0,0 +1,160 @@ +/** + * @file llpostcard.cpp + * @brief Sending postcards. + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "llpostcard.h" + +#include "llvfile.h" +#include "llvfs.h" +#include "llviewerregion.h" + +#include "message.h" + +#include "llagent.h" +#include "llassetuploadresponders.h" + +/////////////////////////////////////////////////////////////////////////////// +// misc + +static void postcard_upload_callback(const LLUUID& asset_id, void *user_data, S32 result, LLExtStat ext_status) +{ + LLSD* postcard_data = (LLSD*)user_data; + + if (result) + { + // TODO: display the error messages in UI + llwarns << "Failed to send postcard: " << LLAssetStorage::getErrorString(result) << llendl; + LLPostCard::reportPostResult(false); + } + else + { + // only create the postcard once the upload succeeds + + // request the postcard + const LLSD& data = *postcard_data; + LLMessageSystem* msg = gMessageSystem; + msg->newMessage("SendPostcard"); + msg->nextBlock("AgentData"); + msg->addUUID("AgentID", gAgent.getID()); + msg->addUUID("SessionID", gAgent.getSessionID()); + msg->addUUID("AssetID", data["asset-id"].asUUID()); + msg->addVector3d("PosGlobal", LLVector3d(data["pos-global"])); + msg->addString("To", data["to"]); + msg->addString("From", data["from"]); + msg->addString("Name", data["name"]); + msg->addString("Subject", data["subject"]); + msg->addString("Msg", data["msg"]); + msg->addBOOL("AllowPublish", FALSE); + msg->addBOOL("MaturePublish", FALSE); + gAgent.sendReliableMessage(); + + LLPostCard::reportPostResult(true); + } + + delete postcard_data; +} + + +/////////////////////////////////////////////////////////////////////////////// +// LLPostcardSendResponder + +class LLPostcardSendResponder : public LLAssetUploadResponder +{ + LOG_CLASS(LLPostcardSendResponder); + +public: + LLPostcardSendResponder(const LLSD &post_data, + const LLUUID& vfile_id, + LLAssetType::EType asset_type): + LLAssetUploadResponder(post_data, vfile_id, asset_type) + { + } + + /*virtual*/ void uploadComplete(const LLSD& content) + { + llinfos << "Postcard sent" << llendl; + LL_DEBUGS("Snapshots") << "content: " << content << llendl; + LLPostCard::reportPostResult(true); + } + + /*virtual*/ void uploadFailure(const LLSD& content) + { + llwarns << "Sending postcard failed: " << content << llendl; + LLPostCard::reportPostResult(false); + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// LLPostCard + +LLPostCard::result_callback_t LLPostCard::mResultCallback; + +// static +void LLPostCard::send(LLPointer image, const LLSD& postcard_data) +{ +#if 0 + static LLTransactionID transaction_id; + static LLAssetID asset_id; +#else + LLTransactionID transaction_id; + LLAssetID asset_id; +#endif + + transaction_id.generate(); + asset_id = transaction_id.makeAssetID(gAgent.getSecureSessionID()); + LLVFile::writeFile(image->getData(), image->getDataSize(), gVFS, asset_id, LLAssetType::AT_IMAGE_JPEG); + + // upload the image + std::string url = gAgent.getRegion()->getCapability("SendPostcard"); + if (!url.empty()) + { + llinfos << "Sending postcard via capability" << llendl; + // the capability already encodes: agent ID, region ID + LL_DEBUGS("Snapshots") << "url: " << url << llendl; + LL_DEBUGS("Snapshots") << "body: " << postcard_data << llendl; + LL_DEBUGS("Snapshots") << "data size: " << image->getDataSize() << llendl; + LLHTTPClient::post(url, postcard_data, + new LLPostcardSendResponder(postcard_data, asset_id, LLAssetType::AT_IMAGE_JPEG)); + } + else + { + llinfos << "Sending postcard" << llendl; + LLSD* data = new LLSD(postcard_data); + (*data)["asset-id"] = asset_id; + gAssetStorage->storeAssetData(transaction_id, LLAssetType::AT_IMAGE_JPEG, + &postcard_upload_callback, (void *)data, FALSE); + } +} + +// static +void LLPostCard::reportPostResult(bool ok) +{ + if (mResultCallback) + { + mResultCallback(ok); + } +} -- cgit v1.3 From db955093c9bf6275223538816a2302ce91ef6e9b Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Mon, 7 Nov 2011 23:58:44 +0200 Subject: STORM-1691 WIP Visual fixes in the Postcard panel. --- indra/newview/llpanelsnapshotpostcard.cpp | 16 +++----- indra/newview/llpostcard.cpp | 5 --- .../default/xui/en/panel_postcard_message.xml | 46 ++++++++-------------- 3 files changed, 22 insertions(+), 45 deletions(-) (limited to 'indra/newview/llpostcard.cpp') diff --git a/indra/newview/llpanelsnapshotpostcard.cpp b/indra/newview/llpanelsnapshotpostcard.cpp index 0db15deec9..6867c7af4e 100644 --- a/indra/newview/llpanelsnapshotpostcard.cpp +++ b/indra/newview/llpanelsnapshotpostcard.cpp @@ -75,6 +75,7 @@ private: void onSend(); bool mHasFirstMsgFocus; + std::string mAgentEmail; }; static LLRegisterPanelClassWrapper panel_class("llpanelsnapshotpostcard"); @@ -95,8 +96,6 @@ BOOL LLPanelSnapshotPostcard::postBuild() // pick up the user's up-to-date email address gAgent.sendAgentUserInfoRequest(); - getChildView("from_form")->setEnabled(FALSE); - std::string name_string; LLAgentUI::buildFullname(name_string); getChild("name_form")->setValue(LLSD(name_string)); @@ -128,12 +127,9 @@ S32 LLPanelSnapshotPostcard::notify(const LLSD& info) return 0; } - LLUICtrl* from_input = getChild("from_form"); - const std::string& text = from_input->getValue().asString(); - if (text.empty()) + if (mAgentEmail.empty()) { - // there's no text in this field yet, pre-populate - from_input->setValue(info["agent-email"]); + mAgentEmail = info["agent-email"].asString(); } return 1; @@ -176,14 +172,13 @@ bool LLPanelSnapshotPostcard::missingSubjMsgAlertCallback(const LLSD& notificati void LLPanelSnapshotPostcard::sendPostcard() { - std::string from(getChild("from_form")->getValue().asString()); std::string to(getChild("to_form")->getValue().asString()); std::string subject(getChild("subject_form")->getValue().asString()); LLSD postcard = LLSD::emptyMap(); postcard["pos-global"] = LLFloaterSnapshot::getPosTakenGlobal().getValue(); postcard["to"] = to; - postcard["from"] = from; + postcard["from"] = mAgentEmail; postcard["name"] = getChild("name_form")->getValue().asString(); postcard["subject"] = subject; postcard["msg"] = getChild("msg_form")->getValue().asString(); @@ -246,7 +241,6 @@ void LLPanelSnapshotPostcard::onTabButtonPress(S32 btn_idx) void LLPanelSnapshotPostcard::onSend() { // Validate input. - std::string from(getChild("from_form")->getValue().asString()); std::string to(getChild("to_form")->getValue().asString()); boost::regex email_format("[A-Za-z0-9.%+-_]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}(,[ \t]*[A-Za-z0-9.%+-_]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,})*"); @@ -257,7 +251,7 @@ void LLPanelSnapshotPostcard::onSend() return; } - if (from.empty() || !boost::regex_match(from, email_format)) + if (mAgentEmail.empty() || !boost::regex_match(mAgentEmail, email_format)) { LLNotificationsUtil::add("PromptSelfEmail"); return; diff --git a/indra/newview/llpostcard.cpp b/indra/newview/llpostcard.cpp index 5f57f3a856..4f2d6da7e5 100644 --- a/indra/newview/llpostcard.cpp +++ b/indra/newview/llpostcard.cpp @@ -116,13 +116,8 @@ LLPostCard::result_callback_t LLPostCard::mResultCallback; // static void LLPostCard::send(LLPointer image, const LLSD& postcard_data) { -#if 0 - static LLTransactionID transaction_id; - static LLAssetID asset_id; -#else LLTransactionID transaction_id; LLAssetID asset_id; -#endif transaction_id.generate(); asset_id = transaction_id.makeAssetID(gAgent.getSecureSessionID()); diff --git a/indra/newview/skins/default/xui/en/panel_postcard_message.xml b/indra/newview/skins/default/xui/en/panel_postcard_message.xml index c2a3c70b6e..e9f322f590 100644 --- a/indra/newview/skins/default/xui/en/panel_postcard_message.xml +++ b/indra/newview/skins/default/xui/en/panel_postcard_message.xml @@ -10,18 +10,20 @@ bottom="35" follows="top|left" font="SansSerif" + height="16" layout="topleft" left="12" name="to_label" - top="10"> - Recipient's Email: + top="10" + width="60"> + To: @@ -31,35 +33,18 @@ bottom_delta="23" follows="top|left" font="SansSerif" + height="16" layout="topleft" left="12" - name="from_label"> - Your Email: + name="name_label" + width="60"> + From: - - Your Name: - - + name="subject_label" + width="60"> Subject: + name="msg_label" + right="-10"> Message: