First pass at functional experience list floater

master
dolphin 2013-10-03 12:59:44 -07:00
parent aed3cbce26
commit e510fa3ee0
7 changed files with 191 additions and 333 deletions

View File

@ -2,13 +2,139 @@
#include "llpanelexperiences.h"
#include "llfloaterexperiences.h"
#include "llagent.h"
#include "llfloaterregioninfo.h"
#include "lltabcontainer.h"
#include "lltrans.h"
#include "llexperiencecache.h"
class LLExperienceListResponder : public LLHTTPClient::Responder
{
public:
typedef std::map<std::string, std::string> NameMap;
LLExperienceListResponder(const LLHandle<LLFloaterExperiences>& parent, NameMap& nameMap):mParent(parent)
{
mNameMap.swap(nameMap);
}
LLHandle<LLFloaterExperiences> mParent;
NameMap mNameMap;
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);
parent->clearFromRecent(ids);
}
}
++it;
}
}
};
LLFloaterExperiences::LLFloaterExperiences(const LLSD& data)
:LLFloater(data)
{
}
void LLFloaterExperiences::addTab(const std::string& name, bool select)
{
getChild<LLTabContainer>("xp_tabs")->addTabPanel(LLTabContainer::TabPanelParams().
panel(LLPanelExperiences::create(name)).
label(LLTrans::getString(name)).
select_tab(select));
}
BOOL LLFloaterExperiences::postBuild()
{
addTab("Allowed_Experiences_Tab", true);
addTab("Blocked_Experiences_Tab", false);
addTab("Admin_Experiences_Tab", false);
addTab("Contrib_Experiences_Tab", false);
addTab("Recent_Experiences_Tab", false);
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("GetAdminExperiences");
if(!lookup_url.empty())
{
nameMap["experience_ids"]="Contrib_Experiences_Tab";
LLHTTPClient::get(lookup_url, new LLExperienceListResponder(getDerivedHandle<LLFloaterExperiences>(), nameMap));
}
}
return TRUE;
}
void LLFloaterExperiences::clearFromRecent(const LLSD& ids)
{
LLTabContainer* tabs = getChild<LLTabContainer>("xp_tabs");
LLPanelExperiences* tab = (LLPanelExperiences*)tabs->getPanelByName("Recent_Experiences_Tab");
if(!tab)
return;
tab->removeExperiences(ids);
}
void LLFloaterExperiences::setupRecentTabs()
{
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);
}

View File

@ -35,9 +35,14 @@ class LLFloaterExperiences :
public:
LLFloaterExperiences(const LLSD& data);
void clearFromRecent(const LLSD& ids);
protected:
/*virtual*/ BOOL postBuild();
void setupRecentTabs();
void addTab(const std::string& name, bool select);
private:
};

View File

@ -7,82 +7,18 @@
#include "llagent.h"
#include "llpanelexperiences.h"
#include "llslurl.h"
static LLRegisterPanelClassWrapper<LLPanelExperiences> register_experiences_panel("experiences_panel");
LLPanelExperiences::LLPanelExperiences( )
: mExperiencesList(NULL),
mExperiencesAccTab(NULL),
mProfilePanel(NULL),
mPanelExperienceInfo(NULL),
mNoExperiences(false)
: mExperiencesList(NULL)
{
buildFromFile("panel_experiences.xml");
}
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, 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::DESCRIPTION))
{
item->setExperienceDescription(experience[LLExperienceCache::DESCRIPTION].asString());
}
mExperiencesList->addItem(item);
}
BOOL LLPanelExperiences::postBuild( void )
{
mExperiencesList = getChild<LLFlatListView>("experiences_list");
@ -91,44 +27,10 @@ BOOL LLPanelExperiences::postBuild( void )
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()
{
@ -138,165 +40,50 @@ LLExperienceItem* LLPanelExperiences::getSelectedExperienceItem()
return dynamic_cast<LLExperienceItem*>(selected_item);
}
void LLPanelExperiences::setProfilePanel( LLPanelProfile* profile_panel )
void LLPanelExperiences::setExperienceList( const LLSD& experiences )
{
mProfilePanel = profile_panel;
mExperiencesList->clear();
LLSD::array_const_iterator it = experiences.beginArray();
for( /**/ ; it != experiences.endArray(); ++it)
{
LLUUID public_key = it->asUUID();
LLExperienceItem* item = new LLExperienceItem();
item->init(public_key);
mExperiencesList->addItem(item, public_key);
}
}
void LLPanelExperiences::onListCommit( const LLFlatListView* f_list )
LLPanelExperiences* LLPanelExperiences::create(const std::string& name)
{
if(f_list == mExperiencesList)
{
mExperiencesList->resetSelection(true);
}
else
{
llwarns << "Unknown list" << llendl;
}
//updateButtons();
LLPanelExperiences* panel= new LLPanelExperiences();
panel->setName(name);
return panel;
}
void LLPanelExperiences::onAccordionStateChanged( const LLAccordionCtrlTab* acc_tab )
void LLPanelExperiences::removeExperiences( const LLSD& ids )
{
if(!mExperiencesAccTab->getDisplayChildren())
{
mExperiencesList->resetSelection(true);
}
LLSD::array_const_iterator it = ids.beginArray();
for( /**/ ; it != ids.endArray(); ++it)
{
mExperiencesList->removeItemByUUID(it->asUUID());
}
}
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");
buildFromFile("panel_experience_list_item.xml");
}
void LLExperienceItem::init( LLSD* experience_data )
void LLExperienceItem::init( const LLUUID& id)
{
if(experience_data)
{
setExperienceDescription(experience_data->has(LLExperienceCache::DESCRIPTION)?(*experience_data)[LLExperienceCache::DESCRIPTION].asString() : std::string());
setExperienceName(experience_data->has(LLExperienceCache::NAME)?(*experience_data)[LLExperienceCache::NAME].asString() : std::string());
}
getChild<LLUICtrl>("experience_name")->setValue(LLSLURL("experience", id, "profile").getSLURLString());
}
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);
}

View File

@ -34,86 +34,37 @@
class LLExperienceItem;
class LLPanelProfile;
class LLPanelExperienceInfo
: public LLPanel
{
public:
static LLPanelExperienceInfo* create();
void onOpen(const LLSD& key);
void setExperienceName( const std::string& name );
void setExperienceDesc( const std::string& desc );
virtual void setExitCallback(const commit_callback_t& cb);
};
class LLPanelExperiences
: public LLPanel /*LLPanelProfileTab*/
: public LLPanel
{
public:
LLPanelExperiences();
LLPanelExperiences();
static void* create(void* data);
static LLPanelExperiences* create(const std::string& name);
/*virtual*/ BOOL postBuild(void);
/*virtual*/ void onOpen(const LLSD& key);
/*virtual*/ void onClosePanel();
void updateData();
void setExperienceList(const LLSD& experiences);
LLExperienceItem* getSelectedExperienceItem();
void setProfilePanel(LLPanelProfile* profile_panel);
void addExperienceInfo(const LLSD& experience);
LLExperienceItem* getSelectedExperienceItem();
void removeExperiences( const LLSD& ids );
protected:
void onListCommit(const LLFlatListView* f_list);
void onAccordionStateChanged(const LLAccordionCtrlTab* acc_tab);
void openExperienceInfo();
void createExperienceInfoPanel();
void onPanelExperienceClose(LLPanel* panel);
LLPanelProfile* getProfilePanel();
private:
LLFlatListView* mExperiencesList;
LLAccordionCtrlTab* mExperiencesAccTab;
LLPanelProfile* mProfilePanel;
LLPanelExperienceInfo* mPanelExperienceInfo;
bool mNoExperiences;
};
class LLExperienceItem
: public LLPanel
//, public LLAvatarPropertiesObserver
{
public:
LLExperienceItem();
~LLExperienceItem();
void init(LLSD* experience_data);
/*virtual*/ BOOL postBuild();
void update();
/*virtual*/ void processProperties(void* data, EAvatarProcessorType type);
void setCreatorID(const LLUUID& val) { mCreatorID = val; }
void setExperienceDescription(const std::string& val);
void setExperienceName(const std::string& val);
const LLUUID& getCreatorID() const { return mCreatorID; }
const std::string& getExperienceName() const { return mExperienceName; }
const std::string& getExperienceDescription() const { return mExperienceDescription; }
void init(const LLUUID& experience_id);
protected:
LLUUID mCreatorID;
std::string mExperienceName;
std::string mExperienceDescription;
};
#endif // LL_LLPANELEXPERIENCES_H

View File

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<floater
positioning="cascading"
can_close="true"
can_resize="true"
height="400"
help_topic="sidebar_experiences"
width="300"
min_height="300"
min_width="300"
layout="topleft"
@ -13,17 +12,16 @@
save_rect="false"
single_instance="true"
reuse_instance="false"
title="EXPERIENCES"
width="400">
<panel
bg_opaque_color="0 0.5 0 0.3"
title="EXPERIENCES">
<tab_container
top="3"
left="3"
layout="topleft"
right="-3"
width="294"
follows="all"
height="300"
class="experiences_panel"
filename="panel_experiences.xml"
>
</panel>
height="394"
name="xp_tabs">
</tab_container>
</floater>

View File

@ -4,37 +4,23 @@
layout="topleft"
top="3"
left="3"
right="-3"
bottom="-3"
width="200"
height="300"
label="Experiences"
bg_opaque_color="0 0.5 0 0.3"
follows="all">
<string
name="no_experiences"
value="No experiences."/>
<accordion
fit_parent="true"
<flat_list_view
name="experiences_list"
layout="topleft"
top="0"
left="3"
right="-3"
bottom="-3"
single_expansion="true"
follows="all">
<accordion_tab
name="tab_experiences"
layout="topleft"
top="0"
left="0"
right="-3"
title="Experiences"
follows="all">
<flat_list_view
name="experiences_list"
layout="topleft"
top="0"
left="0"
follows="all"/>
</accordion_tab>
</accordion>
left="0"
width="200"
height="300"
follows="all"
>
</flat_list_view>
</panel>

View File

@ -3925,6 +3925,11 @@ Try enclosing path to the editor with double quotes.
<string name="experience_tools_experience">Experience</string>
<string name="ExperienceNameNull">(no experience)</string>
<string name="GRID_WIDE">Grid-wide</string>
<string name="Allowed_Experiences_Tab">Allowed</string>
<string name="Blocked_Experiences_Tab">Blocked</string>
<string name="Contrib_Experiences_Tab">Contributor</string>
<string name="Admin_Experiences_Tab">Admin</string>
<string name="Recent_Experiences_Tab">Recent</string>
<!-- Conversation log messages -->
<string name="logging_calls_disabled_log_empty">