summaryrefslogtreecommitdiff
path: root/indra/newview/llpanelexperiences.cpp
blob: 02a3c4c410824159c803be6c1bcf0455a1273a2f (plain)
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
#include "llviewerprecompiledheaders.h"


#include "llpanelprofile.h"
#include "lluictrlfactory.h"
#include "llexperiencecache.h"
#include "llagent.h"

#include "llpanelexperiences.h"


static LLRegisterPanelClassWrapper<LLPanelExperiences> register_experiences_panel("experiences_panel");


LLPanelExperiences::LLPanelExperiences(  )
	:	mExperiencesList(NULL),
	mExperiencesAccTab(NULL),
	mProfilePanel(NULL),
	mPanelExperienceInfo(NULL),
	mNoExperiences(false)
{

}

void* LLPanelExperiences::create( void* data )
{
	return new LLPanelExperiences();
}

void ExperienceResult(LLHandle<LLPanelExperiences> panel, const LLSD& experience)
{
	LLPanelExperiences* experiencePanel = panel.get();
	if(experiencePanel)
	{
		experiencePanel->addExperienceInfo(experience);
	}
}

class LLExperienceListResponder : public LLHTTPClient::Responder
{
public:
	LLExperienceListResponder(const LLHandle<LLPanelExperiences>& parent):mParent(parent)
	{
	}

	LLHandle<LLPanelExperiences> mParent;

	virtual void result(const LLSD& content)
	{
		if(mParent.isDead())
			return;

		LLSD experiences = content["experiences"];
		LLSD::array_const_iterator it = experiences.beginArray();
		for( /**/ ; it != experiences.endArray(); ++it)
		{
			LLUUID public_key = it->asUUID();

			LLExperienceCache::get(public_key, LLExperienceCache::PUBLIC_KEY, boost::bind(ExperienceResult, mParent, _1));
		}
	}
};

void LLPanelExperiences::addExperienceInfo(const LLSD& experience)
{
	LLExperienceItem* item = new LLExperienceItem();
	if(experience.has(LLExperienceCache::NAME))
	{
		item->setExperienceName(experience[LLExperienceCache::NAME].asString());
	}
	else if(experience.has("error"))
	{
		item->setExperienceName(experience["error"].asString());
	}

	if(experience.has(LLExperienceCache::PUBLIC_KEY))
	{
		item->setExperienceDescription(experience[LLExperienceCache::PUBLIC_KEY].asString());
	}

	mExperiencesList->addItem(item);

}


BOOL LLPanelExperiences::postBuild( void )
{
	mExperiencesList = getChild<LLFlatListView>("experiences_list");
	if(hasString("no_experiences"))
	{
		mExperiencesList->setNoItemsCommentText(getString("no_experiences"));
	}


	LLViewerRegion* region = gAgent.getRegion();
	if (region)
	{
		std::string lookup_url=region->getCapability("GetExperiences"); 
		if(!lookup_url.empty())
		{
			LLHTTPClient::get(lookup_url, new LLExperienceListResponder(getDerivedHandle<LLPanelExperiences>()));
		}
	}

	mExperiencesAccTab = getChild<LLAccordionCtrlTab>("tab_experiences");
	mExperiencesAccTab->setDropDownStateChangedCallback(boost::bind(&LLPanelExperiences::onAccordionStateChanged, this, mExperiencesAccTab));
	mExperiencesAccTab->setDisplayChildren(true);

	return TRUE;
}

void LLPanelExperiences::onOpen( const LLSD& key )
{
	LLPanel::onOpen(key);
}

void LLPanelExperiences::onClosePanel()
{
	if (mPanelExperienceInfo)
	{
		onPanelExperienceClose(mPanelExperienceInfo);
	}
}

void LLPanelExperiences::updateData()
{
	if(isDirty())
	{
		mNoExperiences = false;
	}
}

LLExperienceItem* LLPanelExperiences::getSelectedExperienceItem()
{
	LLPanel* selected_item = mExperiencesList->getSelectedItem();
	if (!selected_item) return NULL;

	return dynamic_cast<LLExperienceItem*>(selected_item);
}

void LLPanelExperiences::setProfilePanel( LLPanelProfile* profile_panel )
{
	mProfilePanel = profile_panel;
}

void LLPanelExperiences::onListCommit( const LLFlatListView* f_list )
{
	if(f_list == mExperiencesList)
	{
		mExperiencesList->resetSelection(true);
	}
	else
	{
		llwarns << "Unknown list" << llendl;
	}
	
	//updateButtons();
}

void LLPanelExperiences::onAccordionStateChanged( const LLAccordionCtrlTab* acc_tab )
{
	if(!mExperiencesAccTab->getDisplayChildren())
	{
		mExperiencesList->resetSelection(true);
	}

}

void LLPanelExperiences::openExperienceInfo()
{
	LLSD selected_value = mExperiencesList->getSelectedValue();
	if(selected_value.isUndefined())
	{
		return;
	}

	LLExperienceItem* experience = (LLExperienceItem*)mExperiencesList->getSelectedItem();

	createExperienceInfoPanel();

	LLSD params;
	params["experience_name"] = experience->getExperienceName();
	params["experience_desc"] = experience->getExperienceDescription();

	getProfilePanel()->openPanel(mPanelExperienceInfo, params);

}


void LLPanelExperiences::createExperienceInfoPanel()
{
	if(!mPanelExperienceInfo)
	{
		mPanelExperienceInfo = LLPanelExperienceInfo::create();
		mPanelExperienceInfo->setExitCallback(boost::bind(&LLPanelExperiences::onPanelExperienceClose, this, mPanelExperienceInfo));
		mPanelExperienceInfo->setVisible(FALSE);
	}
}

void LLPanelExperiences::onPanelExperienceClose( LLPanel* panel )
{
	getProfilePanel()->closePanel(panel);
}

LLPanelProfile* LLPanelExperiences::getProfilePanel()
{
	llassert_always(NULL != mProfilePanel);
	
	return mProfilePanel;
}











LLExperienceItem::LLExperienceItem()
{
	buildFromFile("panel_experience_info.xml");
}

void LLExperienceItem::init( LLSD* experience_data )
{
	if(experience_data)
	{
		setExperienceDescription(experience_data->has(LLExperienceCache::PUBLIC_KEY)?(*experience_data)[LLExperienceCache::PUBLIC_KEY].asString() : std::string());
		setExperienceName(experience_data->has(LLExperienceCache::NAME)?(*experience_data)[LLExperienceCache::NAME].asString() : std::string());
	}
}

void LLExperienceItem::setExperienceDescription( const std::string& val )
{
	mExperienceDescription = val;
	getChild<LLUICtrl>("experience_desc")->setValue(val);
}

void LLExperienceItem::setExperienceName( const std::string& val )
{
	mExperienceName = val;
	getChild<LLUICtrl>("experience_name")->setValue(val);
}

BOOL LLExperienceItem::postBuild()
{
	return TRUE;
}

void LLExperienceItem::update()
{

}

void LLExperienceItem::processProperties( void* data, EAvatarProcessorType type )
{

}

LLExperienceItem::~LLExperienceItem()
{

}


void LLPanelExperienceInfo::setExperienceName( const std::string& name )
{
	getChild<LLUICtrl>("experience_name")->setValue(name);
}

void LLPanelExperienceInfo::setExperienceDesc( const std::string& desc )
{
	getChild<LLUICtrl>("experience_desc")->setValue(desc);
}

void LLPanelExperienceInfo::onOpen( const LLSD& key )
{
	setExperienceName(key["experience_name"]);
	setExperienceDesc(key["experience_desc"]);

	/*
	LLAvatarPropertiesProcessor::getInstance()->addObserver(
	getAvatarId(), this);
	LLAvatarPropertiesProcessor::getInstance()->sendPickInfoRequest(
	getAvatarId(), getPickId());
	*/
}

LLPanelExperienceInfo* LLPanelExperienceInfo::create()
{
	LLPanelExperienceInfo* panel = new LLPanelExperienceInfo();
	panel->buildFromFile("panel_experience_info.xml");
	return panel;
}

void LLPanelExperienceInfo::setExitCallback( const commit_callback_t& cb )
{
	getChild<LLButton>("back_btn")->setClickedCallback(cb);
}