aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llassetuploadresponders.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/llassetuploadresponders.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/llassetuploadresponders.cpp')
-rw-r--r--linden/indra/newview/llassetuploadresponders.cpp216
1 files changed, 216 insertions, 0 deletions
diff --git a/linden/indra/newview/llassetuploadresponders.cpp b/linden/indra/newview/llassetuploadresponders.cpp
new file mode 100644
index 0000000..1c094bb
--- /dev/null
+++ b/linden/indra/newview/llassetuploadresponders.cpp
@@ -0,0 +1,216 @@
1/**
2 * @file llmapresponders.h
3 * @brief Processes responses received for asset upload requests.
4 *
5 * Copyright (c) 2006-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 "llassetuploadresponders.h"
31
32#include "llagent.h"
33#include "llfloaterbuycurrency.h"
34#include "lleconomy.h"
35#include "llfilepicker.h"
36#include "llfocusmgr.h"
37#include "llnotify.h"
38#include "llinventorymodel.h"
39#include "llinventoryview.h"
40#include "llpermissionsflags.h"
41#include "lluploaddialog.h"
42#include "llviewermenu.h" // for upload_new_resource()
43#include "llviewerwindow.h"
44#include "viewer.h"
45
46LLNewAgentInventoryResponder::LLNewAgentInventoryResponder(const LLUUID& uuid,
47 const LLSD &post_data)
48 : LLHTTPClient::Responder()
49{
50 mUUID = uuid;
51 mPostData = post_data;
52}
53
54// virtual
55void LLNewAgentInventoryResponder::error(U32 statusNum, const std::string& reason)
56{
57 llinfos << "LLNewAgentInventoryResponder::error " << statusNum << llendl;
58 LLStringBase<char>::format_map_t args;
59 switch(statusNum)
60 {
61 case 400:
62 args["[FILE]"] = mPostData["inventory_type"].asString();
63 args["[REASON]"] = "invalid parameters in upload request";
64 gViewerWindow->alertXml("CannotUploadReason", args);
65 break;
66 case 402:
67 //(result["message"].asString() == "insufficient funds")
68 LLFloaterBuyCurrency::buyCurrency("Uploading costs", gGlobalEconomy->getPriceUpload());
69 break;
70 case 500:
71 default:
72 args["[FILE]"] = mPostData["inventory_type"].asString();
73 args["[REASON]"] = "the server is experiencing unexpected difficulties";
74 gViewerWindow->alertXml("CannotUploadReason", args);
75 break;
76 }
77 LLUploadDialog::modalUploadFinished();
78}
79
80//virtual
81void LLNewAgentInventoryResponder::result(const LLSD& result)
82{
83 lldebugs << "LLNewAgentInventoryResponder::result from capabilities" << llendl;
84
85 if (!result["success"])
86 {
87 LLStringBase<char>::format_map_t args;
88 args["[FILE]"] = mPostData["inventory_type"].asString();
89 args["[REASON]"] = "the server is experiencing unexpected difficulties";
90 gViewerWindow->alertXml("CannotUploadReason", args);
91 return;
92 }
93
94 std::string uploader = result["uploader"];
95 LLAssetType::EType asset_type = LLAssetType::lookup(mPostData["asset_type"].asString().c_str());
96 LLInventoryType::EType inventory_type = LLInventoryType::lookup(mPostData["inventory_type"].asString().c_str());
97 // request succeeded
98 if (!uploader.empty())
99 {
100 LLHTTPClient::postFile(uploader, mUUID, asset_type, this);
101 }
102 // upload succeeded
103 else
104 {
105 // rename the file in the VFS to the actual asset id
106 gVFS->renameFile(mUUID, asset_type, result["new_asset"].asUUID(), asset_type);
107
108 // TODO: only request for textures, sound, and animation uploads
109 // Update money and ownership credit information
110 // since it probably changed on the server
111 if (mPostData["asset_type"].asString() == "texture" ||
112 mPostData["asset_type"].asString() == "sound" ||
113 mPostData["asset_type"].asString() == "animatn")
114 {
115 gMessageSystem->newMessageFast(_PREHASH_MoneyBalanceRequest);
116 gMessageSystem->nextBlockFast(_PREHASH_AgentData);
117 gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
118 gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
119 gMessageSystem->nextBlockFast(_PREHASH_MoneyData);
120 gMessageSystem->addUUIDFast(_PREHASH_TransactionID, LLUUID::null );
121 gAgent.sendReliableMessage();
122
123 LLString::format_map_t args;
124 args["[AMOUNT]"] = llformat("%d",gGlobalEconomy->getPriceUpload());
125 LLNotifyBox::showXml("UploadPayment", args);
126 }
127 // Actually add the upload to viewer inventory
128 llinfos << "Adding " << result["new_inventory_item"].asUUID() << " "
129 << result["new_asset"].asUUID() << " to inventory." << llendl;
130 if(mPostData["folder_id"].asUUID().notNull())
131 {
132 LLPermissions perm;
133 U32 next_owner_perm;
134 perm.init(gAgent.getID(), gAgent.getID(), LLUUID::null, LLUUID::null);
135 if (mPostData["inventory_type"].asString() == "snapshot")
136 {
137 next_owner_perm = PERM_ALL;
138 }
139 else
140 {
141 next_owner_perm = PERM_MOVE | PERM_TRANSFER;
142 }
143 perm.initMasks(PERM_ALL, PERM_ALL, PERM_NONE, PERM_NONE, next_owner_perm);
144 S32 creation_date_now = time_corrected();
145 LLPointer<LLViewerInventoryItem> item
146 = new LLViewerInventoryItem(result["new_inventory_item"].asUUID(),
147 mPostData["folder_id"].asUUID(),
148 perm,
149 result["new_asset"].asUUID(),
150 asset_type,
151 inventory_type,
152 mPostData["name"].asString(),
153 mPostData["description"].asString(),
154 LLSaleInfo::DEFAULT,
155 LLInventoryItem::II_FLAGS_NONE,
156 creation_date_now);
157 gInventory.updateItem(item);
158 gInventory.notifyObservers();
159
160 // Show the preview panel for textures and sounds to let
161 // user know that the image (or snapshot) arrived intact.
162 LLInventoryView* view = LLInventoryView::getActiveInventory();
163 if(view)
164 {
165 LLUICtrl* focus_ctrl = gFocusMgr.getKeyboardFocus();
166 LLFocusMgr::FocusLostCallback callback = gFocusMgr.getFocusCallback();
167
168 view->getPanel()->setSelection(result["new_inventory_item"].asUUID(), TAKE_FOCUS_NO);
169 if((LLAssetType::AT_TEXTURE == asset_type)
170 || (LLAssetType::AT_SOUND == asset_type))
171 {
172 view->getPanel()->openSelected();
173 }
174 //LLInventoryView::dumpSelectionInformation((void*)view);
175 // restore keyboard focus
176 gFocusMgr.setKeyboardFocus(focus_ctrl, callback);
177 }
178 }
179 else
180 {
181 llwarns << "Can't find a folder to put it in" << llendl;
182 }
183
184 // remove the "Uploading..." message
185 LLUploadDialog::modalUploadFinished();
186
187 // *NOTE: This is a pretty big hack. What this does is check
188 // the file picker if there are any more pending uploads. If
189 // so, upload that file.
190 const char* next_file = LLFilePicker::instance().getNextFile();
191 if(next_file)
192 {
193 const char* name = LLFilePicker::instance().getDirname();
194
195 LLString asset_name = name;
196 LLString::replaceNonstandardASCII( asset_name, '?' );
197 LLString::replaceChar(asset_name, '|', '?');
198 LLString::stripNonprintable(asset_name);
199 LLString::trim(asset_name);
200
201 char* asset_name_str = (char*)asset_name.c_str();
202 char* end_p = strrchr(asset_name_str, '.'); // strip extension if exists
203 if( !end_p )
204 {
205 end_p = asset_name_str + strlen( asset_name_str );
206 }
207
208 S32 len = llmin( (S32) (DB_INV_ITEM_NAME_STR_LEN), (S32) (end_p - asset_name_str) );
209
210 asset_name = asset_name.substr( 0, len );
211
212 upload_new_resource(next_file, asset_name, asset_name,
213 0, LLAssetType::AT_NONE, LLInventoryType::IT_NONE);
214 }
215 }
216}