summaryrefslogtreecommitdiff
path: root/indra/newview/llfloaterexperiences.cpp
blob: 398ced26325cf031361238a5279f30bea5072629 (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
#include "llviewerprecompiledheaders.h"

#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);
}