1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
/**
* @file llfloaterexperiences.cpp
* @brief LLFloaterExperiences class implementation
*
* $LicenseInfo:firstyear=2012&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2012, 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 "llpanelexperiences.h"
#include "llfloaterexperiences.h"
#include "llagent.h"
#include "llfloaterregioninfo.h"
#include "lltabcontainer.h"
#include "lltrans.h"
#include "llexperiencecache.h"
#include "llevents.h"
#include "llnotificationsutil.h"
#include "llpanelexperiencelog.h"
#define SHOW_RECENT_TAB (0)
class LLExperienceListResponder : public LLHTTPClient::Responder
{
public:
typedef std::map<std::string, std::string> NameMap;
LLExperienceListResponder(const LLHandle<LLFloaterExperiences>& parent, NameMap& nameMap, const std::string& errorMessage="ErrorMessage"):mParent(parent),mErrorMessage(errorMessage)
{
mNameMap.swap(nameMap);
}
LLHandle<LLFloaterExperiences> mParent;
NameMap mNameMap;
const std::string mErrorMessage;
virtual void result(const LLSD& content)
{
if(mParent.isDead())
return;
LLFloaterExperiences* parent=mParent.get();
LLTabContainer* tabs = parent->getChild<LLTabContainer>("xp_tabs");
NameMap::iterator it = mNameMap.begin();
while(it != mNameMap.end())
{
if(content.has(it->first))
{
LLPanelExperiences* tab = (LLPanelExperiences*)tabs->getPanelByName(it->second);
if(tab)
{
const LLSD& ids = content[it->first];
tab->setExperienceList(ids);
tab->enableButton(ids.beginArray() == ids.endArray());
}
}
++it;
}
}
virtual void error(U32 status, const std::string& reason)
{
LLSD subs;
subs["ERROR_MESSAGE"] = reason;
LLNotificationsUtil::add(mErrorMessage, subs);
}
};
LLFloaterExperiences::LLFloaterExperiences(const LLSD& data)
:LLFloater(data)
{
}
LLPanelExperiences* LLFloaterExperiences::addTab(const std::string& name, bool select)
{
LLPanelExperiences* newPanel = LLPanelExperiences::create(name);
getChild<LLTabContainer>("xp_tabs")->addTabPanel(LLTabContainer::TabPanelParams().
panel(newPanel).
label(LLTrans::getString(name)).
select_tab(select));
return newPanel;
}
BOOL LLFloaterExperiences::postBuild()
{
addTab("Allowed_Experiences_Tab", true);
addTab("Blocked_Experiences_Tab", false);
addTab("Admin_Experiences_Tab", false);
addTab("Contrib_Experiences_Tab", false);
LLPanelExperiences* owned = addTab("Owned_Experiences_Tab", false);
owned->setButtonAction("acquire", boost::bind(&LLFloaterExperiences::sendPurchaseRequest, this));
owned->enableButton(false);
#if SHOW_RECENT_TAB
addTab("Recent_Experiences_Tab", false);
#endif //SHOW_RECENT_TAB
getChild<LLTabContainer>("xp_tabs")->addTabPanel(new LLPanelExperienceLog());
resizeToTabs();
LLEventPumps::instance().obtain("experience_permission").listen("LLFloaterExperiences",
boost::bind(&LLFloaterExperiences::updatePermissions, this, _1));
return TRUE;
}
void LLFloaterExperiences::clearFromRecent(const LLSD& ids)
{
#if SHOW_RECENT_TAB
LLTabContainer* tabs = getChild<LLTabContainer>("xp_tabs");
LLPanelExperiences* tab = (LLPanelExperiences*)tabs->getPanelByName("Recent_Experiences_Tab");
if(!tab)
return;
tab->removeExperiences(ids);
#endif // SHOW_RECENT_TAB
}
void LLFloaterExperiences::setupRecentTabs()
{
#if SHOW_RECENT_TAB
LLTabContainer* tabs = getChild<LLTabContainer>("xp_tabs");
LLPanelExperiences* tab = (LLPanelExperiences*)tabs->getPanelByName("Recent_Experiences_Tab");
if(!tab)
return;
LLSD recent;
const LLExperienceCache::cache_t& experiences = LLExperienceCache::getCached();
LLExperienceCache::cache_t::const_iterator it = experiences.begin();
while( it != experiences.end() )
{
if(!it->second.has(LLExperienceCache::MISSING))
{
recent.append(it->first);
}
++it;
}
tab->setExperienceList(recent);
#endif // SHOW_RECENT_TAB
}
void LLFloaterExperiences::resizeToTabs()
{
const S32 TAB_WIDTH_PADDING = 16;
LLTabContainer* tabs = getChild<LLTabContainer>("xp_tabs");
LLRect rect = getRect();
if(rect.getWidth() < tabs->getTotalTabWidth() + TAB_WIDTH_PADDING)
{
rect.mRight = rect.mLeft + tabs->getTotalTabWidth() + TAB_WIDTH_PADDING;
}
reshape(rect.getWidth(), rect.getHeight(), FALSE);
}
void LLFloaterExperiences::refreshContents()
{
setupRecentTabs();
LLViewerRegion* region = gAgent.getRegion();
if (region)
{
LLExperienceListResponder::NameMap nameMap;
std::string lookup_url=region->getCapability("GetExperiences");
if(!lookup_url.empty())
{
nameMap["experiences"]="Allowed_Experiences_Tab";
nameMap["blocked"]="Blocked_Experiences_Tab";
LLHTTPClient::get(lookup_url, new LLExperienceListResponder(getDerivedHandle<LLFloaterExperiences>(), nameMap));
}
lookup_url = region->getCapability("GetAdminExperiences");
if(!lookup_url.empty())
{
nameMap["experience_ids"]="Admin_Experiences_Tab";
LLHTTPClient::get(lookup_url, new LLExperienceListResponder(getDerivedHandle<LLFloaterExperiences>(), nameMap));
}
lookup_url = region->getCapability("GetCreatorExperiences");
if(!lookup_url.empty())
{
nameMap["experience_ids"]="Contrib_Experiences_Tab";
LLHTTPClient::get(lookup_url, new LLExperienceListResponder(getDerivedHandle<LLFloaterExperiences>(), nameMap));
}
lookup_url = region->getCapability("AgentExperiences");
if(!lookup_url.empty())
{
nameMap["experience_ids"]="Owned_Experiences_Tab";
LLHTTPClient::get(lookup_url, new LLExperienceListResponder(getDerivedHandle<LLFloaterExperiences>(), nameMap));
}
}
}
void LLFloaterExperiences::onOpen( const LLSD& key )
{
LLViewerRegion* region = gAgent.getRegion();
if(region)
{
if(region->capabilitiesReceived())
{
refreshContents();
return;
}
region->setCapabilitiesReceivedCallback(boost::bind(&LLFloaterExperiences::refreshContents, this));
return;
}
}
bool LLFloaterExperiences::updatePermissions( const LLSD& permission )
{
LLTabContainer* tabs = getChild<LLTabContainer>("xp_tabs");
LLUUID experience;
std::string permission_string;
if(permission.has("experience"))
{
experience = permission["experience"].asUUID();
permission_string = permission[experience.asString()]["permission"].asString();
}
LLPanelExperiences* tab = (LLPanelExperiences*)tabs->getPanelByName("Allowed_Experiences_Tab");
if(tab)
{
if(permission.has("experiences"))
{
tab->setExperienceList(permission["experiences"]);
}
else if(experience.notNull())
{
if(permission_string != "Allow")
{
tab->removeExperience(experience);
}
else
{
tab->addExperience(experience);
}
}
}
tab = (LLPanelExperiences*)tabs->getPanelByName("Blocked_Experiences_Tab");
if(tab)
{
if(permission.has("blocked"))
{
tab->setExperienceList(permission["blocked"]);
}
else if(experience.notNull())
{
if(permission_string != "Block")
{
tab->removeExperience(experience);
}
else
{
tab->addExperience(experience);
}
}
}
return false;
}
void LLFloaterExperiences::onClose( bool app_quitting )
{
LLEventPumps::instance().obtain("experience_permission").stopListening("LLFloaterExperiences");
LLFloater::onClose(app_quitting);
}
void LLFloaterExperiences::sendPurchaseRequest() const
{
LLViewerRegion* region = gAgent.getRegion();
std::string url = region->getCapability("AgentExperiences");
if(!url.empty())
{
LLSD content;
LLExperienceListResponder::NameMap nameMap;
nameMap["experience_ids"]="Owned_Experiences_Tab";
LLHTTPClient::post(url, content, new LLExperienceListResponder(getDerivedHandle<LLFloaterExperiences>(), nameMap, "ExperienceAcquireFailed"));
}
}
|