/** * @file llpanelexperiencelisteditor.cpp * @brief Editor for building a list of experiences * * $LicenseInfo:firstyear=2014&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2010, 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 "llpanelexperiencelisteditor.h" #include "llbutton.h" #include "llexperiencecache.h" #include "llfloaterexperiencepicker.h" #include "llfloaterreg.h" #include "llhandle.h" #include "llscrolllistctrl.h" #include "llviewerregion.h" #include "llagent.h" static LLPanelInjector t_panel_experience_list_editor("panel_experience_list_editor"); LLPanelExperienceListEditor::LLPanelExperienceListEditor() :mItems(NULL) ,mProfile(NULL) ,mRemove(NULL) ,mChangedCallback(NULL) ,mReadonly(false) { } BOOL LLPanelExperienceListEditor::postBuild() { mItems = getChild("experience_list"); mAdd = getChild("btn_add"); mRemove = getChild("btn_remove"); mProfile = getChild("btn_profile"); childSetAction("btn_add", boost::bind(&LLPanelExperienceListEditor::onAdd, this)); childSetAction("btn_remove", boost::bind(&LLPanelExperienceListEditor::onRemove, this)); childSetAction("btn_profile", boost::bind(&LLPanelExperienceListEditor::onProfile, this)); mItems->setCommitCallback(boost::bind(&LLPanelExperienceListEditor::checkButtonsEnabled, this)); checkButtonsEnabled(); return TRUE; } const uuid_list_t& LLPanelExperienceListEditor::getExperienceIds() const { return mExperienceIds; } void LLPanelExperienceListEditor::addExperienceIds( const uuid_vec_t& experience_ids ) { mExperienceIds.insert(experience_ids.begin(), experience_ids.end()); onItems(); } void LLPanelExperienceListEditor::setExperienceIds( const LLSD& experience_ids ) { mExperienceIds.clear(); mExperienceIds.insert(experience_ids.beginArray(), experience_ids.endArray()); onItems(); } void LLPanelExperienceListEditor::addExperience( const LLUUID& id ) { mExperienceIds.insert(id); onItems(); } void LLPanelExperienceListEditor::onAdd() { if(!mPicker.isDead()) { mPicker.get()->setFrontmost(TRUE); } else { mKey.generateNewID(); LLFloaterExperiencePicker* picker=LLFloaterExperiencePicker::show(boost::bind(&LLPanelExperienceListEditor::addExperienceIds, this, _1), mKey, FALSE, TRUE, mAdd); picker->addFilters(mFilters.begin(), mFilters.end()); mPicker = picker->getDerivedHandle(); } } void LLPanelExperienceListEditor::onRemove() { std::vector items= mItems->getAllSelected(); std::vector::iterator it = items.begin(); for(/**/; it != items.end(); ++it) { if((*it) != NULL) { mExperienceIds.erase((*it)->getValue()); } } onItems(); } void LLPanelExperienceListEditor::onProfile() { LLScrollListItem* item = mItems->getFirstSelected(); if(item) { LLFloaterReg::showInstance("experience_profile", item->getUUID(), true); } } void LLPanelExperienceListEditor::checkButtonsEnabled() { mAdd->setEnabled(!mReadonly); int selected = mItems->getNumSelected(); mRemove->setEnabled(!mReadonly && selected>0); mProfile->setEnabled(selected==1); } void LLPanelExperienceListEditor::onItems() { mItems->deleteAllItems(); LLSD item; uuid_list_t::iterator it = mExperienceIds.begin(); for(/**/; it != mExperienceIds.end(); ++it) { const LLUUID& experience = *it; item["id"]=experience; LLSD& columns = item["columns"]; columns[0]["column"] = "experience_name"; columns[0]["value"] = getString("loading"); mItems->addElement(item); LLExperienceCache::get(experience, boost::bind(&LLPanelExperienceListEditor::experienceDetailsCallback, getDerivedHandle(), _1)); } if(mItems->getItemCount() == 0) { mItems->setCommentText(getString("no_results")); } checkButtonsEnabled(); if(mChangedCallback) { (*mChangedCallback)(); } } void LLPanelExperienceListEditor::experienceDetailsCallback( LLHandle panel, const LLSD& experience ) { if(!panel.isDead()) { panel.get()->onExperienceDetails(experience); } } void LLPanelExperienceListEditor::onExperienceDetails( const LLSD& experience ) { LLScrollListItem* item = mItems->getItem(experience[LLExperienceCache::EXPERIENCE_ID]); if(!item) return; item->getColumn(0)->setValue(experience[LLExperienceCache::NAME]); } LLPanelExperienceListEditor::~LLPanelExperienceListEditor() { if(!mPicker.isDead()) { mPicker.get()->closeFloater(); } delete mChangedCallback; } void LLPanelExperienceListEditor::loading() { mItems->clear(); mItems->setCommentText( getString("loading")); } void LLPanelExperienceListEditor::setReadonly( bool val ) { mReadonly = val; setCtrlsEnabled(!mReadonly); checkButtonsEnabled(); }