aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloaterpostcard.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llfloaterpostcard.cpp
parentREADME.txt (diff)
downloadmeta-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 'linden/indra/newview/llfloaterpostcard.cpp')
-rw-r--r--linden/indra/newview/llfloaterpostcard.cpp338
1 files changed, 338 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterpostcard.cpp b/linden/indra/newview/llfloaterpostcard.cpp
new file mode 100644
index 0000000..d6c66e3
--- /dev/null
+++ b/linden/indra/newview/llfloaterpostcard.cpp
@@ -0,0 +1,338 @@
1/**
2 * @file llfloaterpostcard.cpp
3 * @brief Postcard send floater, allows setting name, e-mail address, etc.
4 *
5 * Copyright (c) 2004-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 "llfloaterpostcard.h"
31
32#include "llfontgl.h"
33#include "llsys.h"
34#include "llgl.h"
35#include "v3dmath.h"
36#include "lldir.h"
37
38#include "llagent.h"
39#include "llui.h"
40#include "lllineeditor.h"
41#include "llviewertexteditor.h"
42#include "llbutton.h"
43#include "llviewercontrol.h"
44#include "llviewernetwork.h"
45#include "llvieweruictrlfactory.h"
46#include "lluploaddialog.h"
47#include "llviewerstats.h"
48#include "llviewerwindow.h"
49#include "llstatusbar.h"
50#include "llviewerregion.h"
51#include "lleconomy.h"
52
53#include "llgl.h"
54#include "llglheaders.h"
55#include "llimagejpeg.h"
56#include "llimagej2c.h"
57#include "llvfile.h"
58#include "llvfs.h"
59#include "viewer.h"
60
61///----------------------------------------------------------------------------
62/// Local function declarations, constants, enums, and typedefs
63///----------------------------------------------------------------------------
64
65LLLinkedList<LLFloaterPostcard> LLFloaterPostcard::sInstances;
66
67///----------------------------------------------------------------------------
68/// Class LLFloaterPostcard
69///----------------------------------------------------------------------------
70
71LLFloaterPostcard::LLFloaterPostcard(LLImageJPEG* jpeg, LLImageGL *img, const LLVector2& img_scale, const LLVector3d& pos_taken_global)
72: LLFloater("Postcard Floater"),
73 mViewerImage(img),
74 mJPEGImage(jpeg),
75 mImageScale(img_scale),
76 mPosTakenGlobal(pos_taken_global)
77{
78 init();
79}
80
81
82void LLFloaterPostcard::init()
83{
84 // pick up the user's up-to-date email address
85 if(!gAgent.getID().isNull())
86 {
87 // we're logged in, so we can get this info.
88 gMessageSystem->newMessageFast(_PREHASH_UserInfoRequest);
89 gMessageSystem->nextBlockFast(_PREHASH_AgentData);
90 gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
91 gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
92 gAgent.sendReliableMessage();
93 }
94
95 sInstances.addData(this);
96}
97
98// Destroys the object
99LLFloaterPostcard::~LLFloaterPostcard()
100{
101 sInstances.removeData(this);
102 mJPEGImage = NULL; // deletes image
103}
104
105BOOL LLFloaterPostcard::postBuild()
106{
107 childSetAction("cancel_btn", onClickCancel, this);
108 childSetAction("send_btn", onClickSend, this);
109
110 childDisable("from_form");
111 childSetAction("publish_help_btn", onClickPublishHelp, this);
112
113 if (gAgent.mAccess < SIM_ACCESS_MATURE)
114 {
115 // Disable these buttons if they are PG (Teen) users
116 childDisable("allow_publish_check");
117 childHide("allow_publish_check");
118 childDisable("publish_help_btn");
119 childHide("publish_help_btn");
120 childDisable("mature_check");
121 childHide("mature_check");
122 }
123
124 LLString name_string;
125 gAgent.buildFullname(name_string);
126
127 childSetValue("name_form", LLSD(name_string));
128
129 // XUI:translate
130 LLString msg("Postcard from ");
131 msg += gSecondLife;
132 childSetValue("subject_form", LLSD(msg));
133
134 LLTextEditor *MsgField = LLUICtrlFactory::getTextEditorByName(this, "msg_form");
135 if (MsgField)
136 {
137 MsgField->setText("Check this out!");
138 MsgField->setWordWrap(TRUE);
139 }
140
141 childSetFocus("to_form", TRUE);
142
143 return TRUE;
144}
145
146
147// static
148LLFloaterPostcard* LLFloaterPostcard::showFromSnapshot(LLImageJPEG *jpeg, LLImageGL *img, const LLVector2 &image_scale, const LLVector3d& pos_taken_global)
149{
150 // Take the images from the caller
151 // It's now our job to clean them up
152 LLFloaterPostcard *instance = new LLFloaterPostcard(jpeg, img, image_scale, pos_taken_global);
153
154 gUICtrlFactory->buildFloater(instance, "floater_postcard.xml");
155
156 S32 left, top;
157 gFloaterView->getNewFloaterPosition(&left, &top);
158 instance->setOrigin(left, top - instance->getRect().getHeight());
159
160 instance->open();
161
162 return instance;
163}
164
165void LLFloaterPostcard::draw()
166{
167 LLGLSUIDefault gls_ui;
168 LLFloater::draw();
169
170 if(getVisible() && !mMinimized && mViewerImage.notNull() && mJPEGImage.notNull())
171 {
172 LLRect rect(mRect);
173
174 // first set the max extents of our preview
175 rect.translate(-rect.mLeft, -rect.mBottom);
176 rect.mLeft += 280;
177 rect.mRight -= 10;
178 rect.mTop -= 20;
179 rect.mBottom = rect.mTop - 130;
180
181 // then fix the aspect ratio
182 F32 ratio = (F32)mJPEGImage->getWidth() / (F32)mJPEGImage->getHeight();
183 if ((F32)rect.getWidth() / (F32)rect.getHeight() >= ratio)
184 {
185 rect.mRight = (S32)((F32)rect.mLeft + ((F32)rect.getHeight() * ratio));
186 }
187 else
188 {
189 rect.mBottom = (S32)((F32)rect.mTop - ((F32)rect.getWidth() / ratio));
190 }
191 {
192 LLGLSNoTexture gls_no_texture;
193 gl_rect_2d(rect, LLColor4(0.f, 0.f, 0.f, 1.f));
194 rect.stretch(-1);
195 }
196 {
197
198 glMatrixMode(GL_TEXTURE);
199 glPushMatrix();
200 {
201 glScalef(mImageScale.mV[VX], mImageScale.mV[VY], 1.f);
202 glMatrixMode(GL_MODELVIEW);
203 gl_draw_scaled_image(rect.mLeft,
204 rect.mBottom,
205 rect.getWidth(),
206 rect.getHeight(),
207 mViewerImage,
208 LLColor4::white);
209 }
210 glMatrixMode(GL_TEXTURE);
211 glPopMatrix();
212 glMatrixMode(GL_MODELVIEW);
213 }
214 }
215}
216
217// static
218void LLFloaterPostcard::onClickCancel(void* data)
219{
220 if (data)
221 {
222 LLFloaterPostcard *self = (LLFloaterPostcard *)data;
223
224 self->onClose(false);
225 }
226}
227
228// static
229void LLFloaterPostcard::onClickSend(void* data)
230{
231 if (data)
232 {
233 LLFloaterPostcard *self = (LLFloaterPostcard *)data;
234
235 LLString from(self->childGetValue("from_form").asString().c_str());
236 LLString to(self->childGetValue("to_form").asString().c_str());
237
238 if (to.empty() || to.find('@') == std::string::npos)
239 {
240 gViewerWindow->alertXml("PromptRecipientEmail");
241 return;
242 }
243
244 if (from.empty() || from.find('@') == std::string::npos)
245 {
246 gViewerWindow->alertXml("PromptSelfEmail");
247 return;
248 }
249
250 if (self->mJPEGImage.notNull())
251 {
252 // upload the image
253 self->mTransactionID.generate();
254 self->mAssetID = self->mTransactionID.makeAssetID(gAgent.getSecureSessionID());
255 LLVFile::writeFile(self->mJPEGImage->getData(), self->mJPEGImage->getDataSize(), gVFS, self->mAssetID, LLAssetType::AT_IMAGE_JPEG);
256
257 gAssetStorage->storeAssetData(self->mTransactionID, LLAssetType::AT_IMAGE_JPEG, &uploadCallback, (void *)self, FALSE);
258
259 LLUploadDialog::modalUploadDialog("Uploading...\n\nPostcard");
260
261 // don't destroy the window until the upload is done
262 // this way we keep the information in the form
263 self->setVisible(FALSE);
264
265 // also remove any dependency on another floater
266 // so that we can be sure to outlive it while we
267 // need to.
268 LLFloater* dependee = self->getDependee();
269 if (dependee)
270 dependee->removeDependentFloater(self);
271 }
272 else
273 {
274 gViewerWindow->alertXml("ErrorProcessingSnapshot");
275 }
276 }
277}
278
279// static
280void LLFloaterPostcard::onClickPublishHelp(void* data)
281{
282 gViewerWindow->alertXml("ClickPublishHelpPostcard");
283}
284
285// static
286void LLFloaterPostcard::uploadCallback(const LLUUID& asset_id, void *user_data, S32 result) // StoreAssetData callback (fixed)
287{
288 LLFloaterPostcard *self = (LLFloaterPostcard *)user_data;
289
290 LLUploadDialog::modalUploadFinished();
291
292 if (result)
293 {
294 LLStringBase<char>::format_map_t args;
295 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(result));
296 gViewerWindow->alertXml("ErrorUploadingPostcard", args);
297 }
298 else
299 {
300 // only create the postcard once the upload succeeds
301
302 // request the postcard
303 LLMessageSystem* msg = gMessageSystem;
304 msg->newMessage("SendPostcard");
305 msg->nextBlock("AgentData");
306 msg->addUUID("AgentID", gAgent.getID());
307 msg->addUUID("SessionID", gAgent.getSessionID());
308 msg->addUUID("AssetID", self->mAssetID);
309 msg->addVector3d("PosGlobal", self->mPosTakenGlobal);
310 msg->addString("To", self->childGetValue("to_form").asString());
311 msg->addString("From", self->childGetValue("from_form").asString());
312 msg->addString("Name", self->childGetValue("name_form").asString());
313 msg->addString("Subject", self->childGetValue("subject_form").asString());
314 msg->addString("Msg", self->childGetValue("msg_form").asString());
315 msg->addBOOL("AllowPublish", self->childGetValue("allow_publish_check").asBoolean());
316 msg->addBOOL("MaturePublish", self->childGetValue("mature_check").asBoolean());
317 gAgent.sendReliableMessage();
318 }
319
320 self->close();
321}
322
323// static
324void LLFloaterPostcard::updateUserInfo(const char *email)
325{
326 LLFloaterPostcard *instance;
327
328 sInstances.resetList();
329 while ((instance = sInstances.getNextData()))
330 {
331 const LLString& text = instance->childGetValue("from_form").asString();
332 if (text.empty())
333 {
334 // there's no text in this field yet, pre-populate
335 instance->childSetValue("from_form", LLSD(email));
336 }
337 }
338}