PageRenderTime 41ms CodeModel.GetById 15ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llpaneloutfitsinventory.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 325 lines | 205 code | 53 blank | 67 comment | 21 complexity | 22d66bc2f312ee8ee63b402abb162185 MD5 | raw file
  1/**
  2 * @file llpaneloutfitsinventory.cpp
  3 * @brief Outfits inventory panel
  4 *
  5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llpaneloutfitsinventory.h"
 30
 31#include "llnotificationsutil.h"
 32#include "lltabcontainer.h"
 33
 34#include "llfloatersidepanelcontainer.h"
 35#include "llinventoryfunctions.h"
 36#include "llinventorymodelbackgroundfetch.h"
 37#include "llagentwearables.h"
 38#include "llappearancemgr.h"
 39#include "lloutfitobserver.h"
 40#include "lloutfitslist.h"
 41#include "llpanelwearing.h"
 42#include "llsaveoutfitcombobtn.h"
 43#include "llsidepanelappearance.h"
 44#include "llviewerfoldertype.h"
 45
 46static const std::string OUTFITS_TAB_NAME = "outfitslist_tab";
 47static const std::string COF_TAB_NAME = "cof_tab";
 48
 49static LLRegisterPanelClassWrapper<LLPanelOutfitsInventory> t_inventory("panel_outfits_inventory");
 50
 51LLPanelOutfitsInventory::LLPanelOutfitsInventory() :
 52	mMyOutfitsPanel(NULL),
 53	mCurrentOutfitPanel(NULL),
 54	mActivePanel(NULL),
 55	mInitialized(false)
 56{
 57	gAgentWearables.addLoadedCallback(boost::bind(&LLPanelOutfitsInventory::onWearablesLoaded, this));
 58	gAgentWearables.addLoadingStartedCallback(boost::bind(&LLPanelOutfitsInventory::onWearablesLoading, this));
 59
 60	LLOutfitObserver& observer = LLOutfitObserver::instance();
 61	observer.addBOFChangedCallback(boost::bind(&LLPanelOutfitsInventory::updateVerbs, this));
 62	observer.addCOFChangedCallback(boost::bind(&LLPanelOutfitsInventory::updateVerbs, this));
 63	observer.addOutfitLockChangedCallback(boost::bind(&LLPanelOutfitsInventory::updateVerbs, this));
 64}
 65
 66LLPanelOutfitsInventory::~LLPanelOutfitsInventory()
 67{
 68}
 69
 70// virtual
 71BOOL LLPanelOutfitsInventory::postBuild()
 72{
 73	initTabPanels();
 74	initListCommandsHandlers();
 75
 76	// Fetch your outfits folder so that the links are in memory.
 77	// ( This is only necessary if we want to show a warning if a user deletes an item that has a
 78	// a link in an outfit, see "ConfirmItemDeleteHasLinks". )
 79	const LLUUID &outfits_cat = gInventory.findCategoryUUIDForType(LLFolderType::FT_OUTFIT, false);
 80	if (outfits_cat.notNull())
 81	{
 82		LLInventoryModelBackgroundFetch::instance().start(outfits_cat);
 83	}
 84	
 85	mSaveComboBtn.reset(new LLSaveOutfitComboBtn(this, true));
 86
 87	return TRUE;
 88}
 89
 90// virtual
 91void LLPanelOutfitsInventory::onOpen(const LLSD& key)
 92{
 93	if (!mInitialized)
 94	{
 95		LLSidepanelAppearance* panel_appearance = getAppearanceSP();
 96		if (panel_appearance)
 97		{
 98			// *TODO: move these methods to LLPanelOutfitsInventory?
 99			panel_appearance->fetchInventory();
100			panel_appearance->refreshCurrentOutfitName();
101		}
102		mInitialized = true;
103	}
104
105	// Make sure we know which tab is selected, update the filter,
106	// and update verbs.
107	onTabChange();
108	
109	// *TODO: Auto open the first outfit newly created so new users can see sample outfit contents
110	/*
111	static bool should_open_outfit = true;
112	if (should_open_outfit && gAgent.isFirstLogin())
113	{
114		LLInventoryPanel* outfits_panel = getChild<LLInventoryPanel>(OUTFITS_TAB_NAME);
115		if (outfits_panel)
116		{
117			LLUUID my_outfits_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_MY_OUTFITS);
118			LLFolderViewFolder* my_outfits_folder = outfits_panel->getRootFolder()->getFolderByID(my_outfits_id);
119			if (my_outfits_folder)
120			{
121				LLFolderViewFolder* first_outfit = dynamic_cast<LLFolderViewFolder*>(my_outfits_folder->getFirstChild());
122				if (first_outfit)
123				{
124					first_outfit->setOpen(TRUE);
125				}
126			}
127		}
128	}
129	should_open_outfit = false;
130	*/
131}
132
133void LLPanelOutfitsInventory::updateVerbs()
134{
135	if (mListCommands)
136	{
137		updateListCommands();
138	}
139}
140
141// virtual
142void LLPanelOutfitsInventory::onSearchEdit(const std::string& string)
143{
144	if (!mActivePanel) return;
145
146	mFilterSubString = string;
147
148	if (string == "")
149	{
150		mActivePanel->setFilterSubString(LLStringUtil::null);
151	}
152
153	LLInventoryModelBackgroundFetch::instance().start();
154
155	if (mActivePanel->getFilterSubString().empty() && string.empty())
156	{
157		// current filter and new filter empty, do nothing
158		return;
159	}
160
161	// set new filter string
162	mActivePanel->setFilterSubString(string);
163}
164
165void LLPanelOutfitsInventory::onWearButtonClick()
166{
167	if (mMyOutfitsPanel->hasItemSelected())
168	{
169		mMyOutfitsPanel->wearSelectedItems();
170	}
171	else
172	{
173		mMyOutfitsPanel->performAction("replaceoutfit");
174	}
175}
176
177bool LLPanelOutfitsInventory::onSaveCommit(const LLSD& notification, const LLSD& response)
178{
179	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
180	if (0 == option)
181	{
182		std::string outfit_name = response["message"].asString();
183		LLStringUtil::trim(outfit_name);
184		if( !outfit_name.empty() )
185		{
186			LLUUID outfit_folder = LLAppearanceMgr::getInstance()->makeNewOutfitLinks(outfit_name);
187
188			LLSidepanelAppearance* panel_appearance = getAppearanceSP();
189			if (panel_appearance)
190			{
191				panel_appearance->showOutfitsInventoryPanel();
192			}
193
194			if (mAppearanceTabs)
195			{
196				mAppearanceTabs->selectTabByName(OUTFITS_TAB_NAME);
197			}	
198		}
199	}
200
201	return false;
202}
203
204void LLPanelOutfitsInventory::onSave()
205{
206	std::string outfit_name;
207
208	if (!LLAppearanceMgr::getInstance()->getBaseOutfitName(outfit_name))
209	{
210		outfit_name = LLViewerFolderType::lookupNewCategoryName(LLFolderType::FT_OUTFIT);
211	}
212
213	LLSD args;
214	args["DESC"] = outfit_name;
215
216	LLSD payload;
217	//payload["ids"].append(*it);
218	
219	LLNotificationsUtil::add("SaveOutfitAs", args, payload, boost::bind(&LLPanelOutfitsInventory::onSaveCommit, this, _1, _2));
220}
221
222//static
223LLPanelOutfitsInventory* LLPanelOutfitsInventory::findInstance()
224{
225	return dynamic_cast<LLPanelOutfitsInventory*>(LLFloaterSidePanelContainer::getPanel("appearance", "panel_outfits_inventory"));
226}
227
228//////////////////////////////////////////////////////////////////////////////////
229// List Commands                                                                //
230
231void LLPanelOutfitsInventory::initListCommandsHandlers()
232{
233	mListCommands = getChild<LLPanel>("bottom_panel");
234	mListCommands->childSetAction("wear_btn", boost::bind(&LLPanelOutfitsInventory::onWearButtonClick, this));
235	mMyOutfitsPanel->childSetAction("trash_btn", boost::bind(&LLPanelOutfitsInventory::onTrashButtonClick, this));
236}
237
238void LLPanelOutfitsInventory::updateListCommands()
239{
240	bool trash_enabled = isActionEnabled("delete");
241	bool wear_enabled =  isActionEnabled("wear");
242	bool wear_visible = !isCOFPanelActive();
243	bool make_outfit_enabled = isActionEnabled("save_outfit");
244
245	mMyOutfitsPanel->childSetEnabled("trash_btn", trash_enabled);
246	mListCommands->childSetEnabled("wear_btn", wear_enabled);
247	mListCommands->childSetVisible("wear_btn", wear_visible);
248	mSaveComboBtn->setMenuItemEnabled("save_outfit", make_outfit_enabled);
249	if (mMyOutfitsPanel->hasItemSelected())
250	{
251		mListCommands->childSetToolTip("wear_btn", getString("wear_items_tooltip"));
252	}
253	else
254	{
255		mListCommands->childSetToolTip("wear_btn", getString("wear_outfit_tooltip"));
256	}
257}
258
259void LLPanelOutfitsInventory::onTrashButtonClick()
260{
261	mMyOutfitsPanel->removeSelected();
262}
263
264bool LLPanelOutfitsInventory::isActionEnabled(const LLSD& userdata)
265{
266	return mActivePanel && mActivePanel->isActionEnabled(userdata);
267}
268// List Commands                                                                //
269//////////////////////////////////////////////////////////////////////////////////
270
271//////////////////////////////////////////////////////////////////////////////////
272// Tab panels                                                                   //
273
274void LLPanelOutfitsInventory::initTabPanels()
275{
276	mCurrentOutfitPanel = findChild<LLPanelWearing>(COF_TAB_NAME);
277	mCurrentOutfitPanel->setSelectionChangeCallback(boost::bind(&LLPanelOutfitsInventory::updateVerbs, this));
278
279	mMyOutfitsPanel = findChild<LLOutfitsList>(OUTFITS_TAB_NAME);
280	mMyOutfitsPanel->setSelectionChangeCallback(boost::bind(&LLPanelOutfitsInventory::updateVerbs, this));
281
282	mAppearanceTabs = getChild<LLTabContainer>("appearance_tabs");
283	mAppearanceTabs->setCommitCallback(boost::bind(&LLPanelOutfitsInventory::onTabChange, this));
284}
285
286void LLPanelOutfitsInventory::onTabChange()
287{
288	mActivePanel = dynamic_cast<LLPanelAppearanceTab*>(mAppearanceTabs->getCurrentPanel());
289	if (!mActivePanel) return;
290
291	mActivePanel->setFilterSubString(mFilterSubString);
292	mActivePanel->onOpen(LLSD());
293
294	updateVerbs();
295}
296
297bool LLPanelOutfitsInventory::isCOFPanelActive() const
298{
299	if (!mActivePanel) return false;
300
301	return mActivePanel->getName() == COF_TAB_NAME;
302}
303
304void LLPanelOutfitsInventory::setWearablesLoading(bool val)
305{
306	updateVerbs();
307}
308
309void LLPanelOutfitsInventory::onWearablesLoaded()
310{
311	setWearablesLoading(false);
312}
313
314void LLPanelOutfitsInventory::onWearablesLoading()
315{
316	setWearablesLoading(true);
317}
318
319// static
320LLSidepanelAppearance* LLPanelOutfitsInventory::getAppearanceSP()
321{
322	LLSidepanelAppearance* panel_appearance =
323		dynamic_cast<LLSidepanelAppearance*>(LLFloaterSidePanelContainer::getPanel("appearance"));
324	return panel_appearance;
325}