PageRenderTime 33ms CodeModel.GetById 1ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llpanelblockedlist.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 278 lines | 174 code | 49 blank | 55 comment | 23 complexity | 39c921c2fd8ae620667f5d8f3291a808 MD5 | raw file
  1/** 
  2 * @file llpanelblockedlist.cpp
  3 * @brief Container for blocked Residents & Objects list
  4 *
  5 * $LicenseInfo:firstyear=2001&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 "llpanelblockedlist.h"
 30
 31// library include
 32#include "llavatarname.h"
 33#include "llfloater.h"
 34#include "llfloaterreg.h"
 35#include "llnotificationsutil.h"
 36#include "llscrolllistctrl.h"
 37
 38// project include
 39#include "llfloateravatarpicker.h"
 40#include "llfloatersidepanelcontainer.h"
 41#include "llsidetraypanelcontainer.h"
 42
 43static LLRegisterPanelClassWrapper<LLPanelBlockedList> t_panel_blocked_list("panel_block_list_sidetray");
 44
 45//
 46// Constants
 47//
 48const std::string BLOCKED_PARAM_NAME = "blocked_to_select";
 49
 50//-----------------------------------------------------------------------------
 51// LLPanelBlockedList()
 52//-----------------------------------------------------------------------------
 53
 54LLPanelBlockedList::LLPanelBlockedList()
 55:	LLPanel()
 56{
 57	mCommitCallbackRegistrar.add("Block.ClickPick",			boost::bind(&LLPanelBlockedList::onPickBtnClick, this));
 58	mCommitCallbackRegistrar.add("Block.ClickBlockByName",	boost::bind(&LLPanelBlockedList::onBlockByNameClick, this));
 59	mCommitCallbackRegistrar.add("Block.ClickRemove",		boost::bind(&LLPanelBlockedList::onRemoveBtnClick, this));
 60}
 61
 62LLPanelBlockedList::~LLPanelBlockedList()
 63{
 64	LLMuteList::getInstance()->removeObserver(this);
 65}
 66
 67BOOL LLPanelBlockedList::postBuild()
 68{
 69	mBlockedList = getChild<LLScrollListCtrl>("blocked");
 70	mBlockedList->setCommitOnSelectionChange(TRUE);
 71
 72	childSetCommitCallback("back", boost::bind(&LLPanelBlockedList::onBackBtnClick, this), NULL);
 73
 74	LLMuteList::getInstance()->addObserver(this);
 75	
 76	refreshBlockedList();
 77
 78	return LLPanel::postBuild();
 79}
 80
 81void LLPanelBlockedList::draw()
 82{
 83	updateButtons();
 84	LLPanel::draw();
 85}
 86
 87void LLPanelBlockedList::onOpen(const LLSD& key)
 88{
 89	if (key.has(BLOCKED_PARAM_NAME) && key[BLOCKED_PARAM_NAME].asUUID().notNull())
 90	{
 91		selectBlocked(key[BLOCKED_PARAM_NAME].asUUID());
 92	}
 93}
 94
 95void LLPanelBlockedList::selectBlocked(const LLUUID& mute_id)
 96{
 97	mBlockedList->selectByID(mute_id);
 98}
 99
100void LLPanelBlockedList::showPanelAndSelect(const LLUUID& idToSelect)
101{
102	LLFloaterSidePanelContainer::showPanel("people", "panel_block_list_sidetray", LLSD().with(BLOCKED_PARAM_NAME, idToSelect));
103}
104
105
106//////////////////////////////////////////////////////////////////////////
107// Private Section
108//////////////////////////////////////////////////////////////////////////
109void LLPanelBlockedList::refreshBlockedList()
110{
111	mBlockedList->deleteAllItems();
112
113	std::vector<LLMute> mutes = LLMuteList::getInstance()->getMutes();
114	std::vector<LLMute>::iterator it;
115	for (it = mutes.begin(); it != mutes.end(); ++it)
116	{
117		LLScrollListItem::Params item_p;
118		item_p.enabled(TRUE);
119		item_p.value(it->mID); // link UUID of blocked item with ScrollListItem
120		item_p.columns.add().column("item_name").value(it->mName);//.type("text");
121		item_p.columns.add().column("item_type").value(it->getDisplayType());//.type("text").width(111);
122
123		mBlockedList->addRow(item_p, ADD_BOTTOM);
124	}
125}
126
127void LLPanelBlockedList::updateButtons()
128{
129	bool hasSelected = NULL != mBlockedList->getFirstSelected();
130	getChildView("Unblock")->setEnabled(hasSelected);
131}
132
133
134
135void LLPanelBlockedList::onBackBtnClick()
136{
137	LLSideTrayPanelContainer* parent = dynamic_cast<LLSideTrayPanelContainer*>(getParent());
138	if(parent)
139	{
140		parent->openPreviousPanel();
141	}
142}
143
144void LLPanelBlockedList::onRemoveBtnClick()
145{
146	std::string name = mBlockedList->getSelectedItemLabel();
147	LLUUID id = mBlockedList->getStringUUIDSelectedItem();
148	LLMute mute(id, name);
149	
150	S32 last_selected = mBlockedList->getFirstSelectedIndex();
151	if (LLMuteList::getInstance()->remove(mute))
152	{
153		// Above removals may rebuild this dialog.
154		
155		if (last_selected == mBlockedList->getItemCount())
156		{
157			// we were on the last item, so select the last item again
158			mBlockedList->selectNthItem(last_selected - 1);
159		}
160		else
161		{
162			// else select the item after the last item previously selected
163			mBlockedList->selectNthItem(last_selected);
164		}
165	}
166}
167
168void LLPanelBlockedList::onPickBtnClick()
169{
170	const BOOL allow_multiple = FALSE;
171	const BOOL close_on_select = TRUE;
172	/*LLFloaterAvatarPicker* picker = */LLFloaterAvatarPicker::show(boost::bind(&LLPanelBlockedList::callbackBlockPicked, this, _1, _2), allow_multiple, close_on_select);
173
174	// *TODO: mantipov: should LLFloaterAvatarPicker be closed when panel is closed?
175	// old Floater dependency is not enable in panel
176	// addDependentFloater(picker);
177}
178
179void LLPanelBlockedList::onBlockByNameClick()
180{
181	LLFloaterGetBlockedObjectName::show(&LLPanelBlockedList::callbackBlockByName);
182}
183
184void LLPanelBlockedList::callbackBlockPicked(const uuid_vec_t& ids, const std::vector<LLAvatarName> names)
185{
186	if (names.empty() || ids.empty()) return;
187	LLMute mute(ids[0], names[0].getLegacyName(), LLMute::AGENT);
188	LLMuteList::getInstance()->add(mute);
189	showPanelAndSelect(mute.mID);
190}
191
192//static
193void LLPanelBlockedList::callbackBlockByName(const std::string& text)
194{
195	if (text.empty()) return;
196
197	LLMute mute(LLUUID::null, text, LLMute::BY_NAME);
198	BOOL success = LLMuteList::getInstance()->add(mute);
199	if (!success)
200	{
201		LLNotificationsUtil::add("MuteByNameFailed");
202	}
203}
204
205//////////////////////////////////////////////////////////////////////////
206//			LLFloaterGetBlockedObjectName
207//////////////////////////////////////////////////////////////////////////
208
209// Constructor/Destructor
210LLFloaterGetBlockedObjectName::LLFloaterGetBlockedObjectName(const LLSD& key)
211: LLFloater(key)
212, mGetObjectNameCallback(NULL)
213{
214}
215
216// Destroys the object
217LLFloaterGetBlockedObjectName::~LLFloaterGetBlockedObjectName()
218{
219	gFocusMgr.releaseFocusIfNeeded( this );
220}
221
222BOOL LLFloaterGetBlockedObjectName::postBuild()
223{
224	getChild<LLButton>("OK")->		setCommitCallback(boost::bind(&LLFloaterGetBlockedObjectName::applyBlocking, this));
225	getChild<LLButton>("Cancel")->	setCommitCallback(boost::bind(&LLFloaterGetBlockedObjectName::cancelBlocking, this));
226	center();
227
228	return LLFloater::postBuild();
229}
230
231BOOL LLFloaterGetBlockedObjectName::handleKeyHere(KEY key, MASK mask)
232{
233	if (key == KEY_RETURN && mask == MASK_NONE)
234	{
235		applyBlocking();
236		return TRUE;
237	}
238	else if (key == KEY_ESCAPE && mask == MASK_NONE)
239	{
240		cancelBlocking();
241		return TRUE;
242	}
243
244	return LLFloater::handleKeyHere(key, mask);
245}
246
247// static
248LLFloaterGetBlockedObjectName* LLFloaterGetBlockedObjectName::show(get_object_name_callback_t callback)
249{
250	LLFloaterGetBlockedObjectName* floater = LLFloaterReg::showTypedInstance<LLFloaterGetBlockedObjectName>("mute_object_by_name");
251
252	floater->mGetObjectNameCallback = callback;
253
254	// *TODO: mantipov: should LLFloaterGetBlockedObjectName be closed when panel is closed?
255	// old Floater dependency is not enable in panel
256	// addDependentFloater(floater);
257
258	return floater;
259}
260
261//////////////////////////////////////////////////////////////////////////
262// Private Section
263void LLFloaterGetBlockedObjectName::applyBlocking()
264{
265	if (mGetObjectNameCallback)
266	{
267		const std::string& text = getChild<LLUICtrl>("object_name")->getValue().asString();
268		mGetObjectNameCallback(text);
269	}
270	closeFloater();
271}
272
273void LLFloaterGetBlockedObjectName::cancelBlocking()
274{
275	closeFloater();
276}
277
278//EOF