llpanelblockedlist.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:8k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llpanelblockedlist.cpp
  3.  * @brief Container for blocked Residents & Objects list
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llpanelblockedlist.h"
  34. // library include
  35. #include "llfloater.h"
  36. #include "llfloaterreg.h"
  37. #include "llnotificationsutil.h"
  38. #include "llscrolllistctrl.h"
  39. // project include
  40. #include "llfloateravatarpicker.h"
  41. #include "llsidetray.h"
  42. #include "llsidetraypanelcontainer.h"
  43. static LLRegisterPanelClassWrapper<LLPanelBlockedList> t_panel_blocked_list("panel_block_list_sidetray");
  44. //
  45. // Constants
  46. //
  47. const std::string BLOCKED_PARAM_NAME = "blocked_to_select";
  48. //-----------------------------------------------------------------------------
  49. // LLPanelBlockedList()
  50. //-----------------------------------------------------------------------------
  51. LLPanelBlockedList::LLPanelBlockedList()
  52. : LLPanel()
  53. {
  54. mCommitCallbackRegistrar.add("Block.ClickPick", boost::bind(&LLPanelBlockedList::onPickBtnClick, this));
  55. mCommitCallbackRegistrar.add("Block.ClickBlockByName", boost::bind(&LLPanelBlockedList::onBlockByNameClick, this));
  56. mCommitCallbackRegistrar.add("Block.ClickRemove", boost::bind(&LLPanelBlockedList::onRemoveBtnClick, this));
  57. }
  58. LLPanelBlockedList::~LLPanelBlockedList()
  59. {
  60. LLMuteList::getInstance()->removeObserver(this);
  61. }
  62. BOOL LLPanelBlockedList::postBuild()
  63. {
  64. mBlockedList = getChild<LLScrollListCtrl>("blocked");
  65. mBlockedList->setCommitOnSelectionChange(TRUE);
  66. childSetCommitCallback("back", boost::bind(&LLPanelBlockedList::onBackBtnClick, this), NULL);
  67. LLMuteList::getInstance()->addObserver(this);
  68. refreshBlockedList();
  69. return LLPanel::postBuild();
  70. }
  71. void LLPanelBlockedList::draw()
  72. {
  73. updateButtons();
  74. LLPanel::draw();
  75. }
  76. void LLPanelBlockedList::onOpen(const LLSD& key)
  77. {
  78. if (key.has(BLOCKED_PARAM_NAME) && key[BLOCKED_PARAM_NAME].asUUID().notNull())
  79. {
  80. selectBlocked(key[BLOCKED_PARAM_NAME].asUUID());
  81. }
  82. }
  83. void LLPanelBlockedList::selectBlocked(const LLUUID& mute_id)
  84. {
  85. mBlockedList->selectByID(mute_id);
  86. }
  87. void LLPanelBlockedList::showPanelAndSelect(const LLUUID& idToSelect)
  88. {
  89. LLSideTray::getInstance()->showPanel("panel_block_list_sidetray", LLSD().with(BLOCKED_PARAM_NAME, idToSelect));
  90. }
  91. //////////////////////////////////////////////////////////////////////////
  92. // Private Section
  93. //////////////////////////////////////////////////////////////////////////
  94. void LLPanelBlockedList::refreshBlockedList()
  95. {
  96. mBlockedList->deleteAllItems();
  97. std::vector<LLMute> mutes = LLMuteList::getInstance()->getMutes();
  98. std::vector<LLMute>::iterator it;
  99. for (it = mutes.begin(); it != mutes.end(); ++it)
  100. {
  101. std::string display_name = it->getDisplayName();
  102. mBlockedList->addStringUUIDItem(display_name, it->mID, ADD_BOTTOM, TRUE);
  103. }
  104. }
  105. void LLPanelBlockedList::updateButtons()
  106. {
  107. bool hasSelected = NULL != mBlockedList->getFirstSelected();
  108. childSetEnabled("Unblock", hasSelected);
  109. }
  110. void LLPanelBlockedList::onBackBtnClick()
  111. {
  112. LLSideTrayPanelContainer* parent = dynamic_cast<LLSideTrayPanelContainer*>(getParent());
  113. if(parent)
  114. {
  115. parent->openPreviousPanel();
  116. }
  117. }
  118. void LLPanelBlockedList::onRemoveBtnClick()
  119. {
  120. std::string name = mBlockedList->getSelectedItemLabel();
  121. LLUUID id = mBlockedList->getStringUUIDSelectedItem();
  122. LLMute mute(id);
  123. mute.setFromDisplayName(name);
  124. // now mute.mName has the suffix trimmed off
  125. S32 last_selected = mBlockedList->getFirstSelectedIndex();
  126. if (LLMuteList::getInstance()->remove(mute))
  127. {
  128. // Above removals may rebuild this dialog.
  129. if (last_selected == mBlockedList->getItemCount())
  130. {
  131. // we were on the last item, so select the last item again
  132. mBlockedList->selectNthItem(last_selected - 1);
  133. }
  134. else
  135. {
  136. // else select the item after the last item previously selected
  137. mBlockedList->selectNthItem(last_selected);
  138. }
  139. }
  140. }
  141. void LLPanelBlockedList::onPickBtnClick()
  142. {
  143. const BOOL allow_multiple = FALSE;
  144. const BOOL close_on_select = TRUE;
  145. /*LLFloaterAvatarPicker* picker = */LLFloaterAvatarPicker::show(boost::bind(&LLPanelBlockedList::callbackBlockPicked, this, _1, _2), allow_multiple, close_on_select);
  146. // *TODO: mantipov: should LLFloaterAvatarPicker be closed when panel is closed?
  147. // old Floater dependency is not enable in panel
  148. // addDependentFloater(picker);
  149. }
  150. void LLPanelBlockedList::onBlockByNameClick()
  151. {
  152. LLFloaterGetBlockedObjectName::show(&LLPanelBlockedList::callbackBlockByName);
  153. }
  154. void LLPanelBlockedList::callbackBlockPicked(const std::vector<std::string>& names, const std::vector<LLUUID>& ids)
  155. {
  156. if (names.empty() || ids.empty()) return;
  157. LLMute mute(ids[0], names[0], LLMute::AGENT);
  158. LLMuteList::getInstance()->add(mute);
  159. showPanelAndSelect(mute.mID);
  160. }
  161. //static
  162. void LLPanelBlockedList::callbackBlockByName(const std::string& text)
  163. {
  164. if (text.empty()) return;
  165. LLMute mute(LLUUID::null, text, LLMute::BY_NAME);
  166. BOOL success = LLMuteList::getInstance()->add(mute);
  167. if (!success)
  168. {
  169. LLNotificationsUtil::add("MuteByNameFailed");
  170. }
  171. }
  172. //////////////////////////////////////////////////////////////////////////
  173. // LLFloaterGetBlockedObjectName
  174. //////////////////////////////////////////////////////////////////////////
  175. // Constructor/Destructor
  176. LLFloaterGetBlockedObjectName::LLFloaterGetBlockedObjectName(const LLSD& key)
  177. : LLFloater(key)
  178. , mGetObjectNameCallback(NULL)
  179. {
  180. }
  181. // Destroys the object
  182. LLFloaterGetBlockedObjectName::~LLFloaterGetBlockedObjectName()
  183. {
  184. gFocusMgr.releaseFocusIfNeeded( this );
  185. }
  186. BOOL LLFloaterGetBlockedObjectName::postBuild()
  187. {
  188. getChild<LLButton>("OK")-> setCommitCallback(boost::bind(&LLFloaterGetBlockedObjectName::applyBlocking, this));
  189. getChild<LLButton>("Cancel")-> setCommitCallback(boost::bind(&LLFloaterGetBlockedObjectName::cancelBlocking, this));
  190. center();
  191. return LLFloater::postBuild();
  192. }
  193. BOOL LLFloaterGetBlockedObjectName::handleKeyHere(KEY key, MASK mask)
  194. {
  195. if (key == KEY_RETURN && mask == MASK_NONE)
  196. {
  197. applyBlocking();
  198. return TRUE;
  199. }
  200. else if (key == KEY_ESCAPE && mask == MASK_NONE)
  201. {
  202. cancelBlocking();
  203. return TRUE;
  204. }
  205. return LLFloater::handleKeyHere(key, mask);
  206. }
  207. // static
  208. LLFloaterGetBlockedObjectName* LLFloaterGetBlockedObjectName::show(get_object_name_callback_t callback)
  209. {
  210. LLFloaterGetBlockedObjectName* floater = LLFloaterReg::showTypedInstance<LLFloaterGetBlockedObjectName>("mute_object_by_name");
  211. floater->mGetObjectNameCallback = callback;
  212. // *TODO: mantipov: should LLFloaterGetBlockedObjectName be closed when panel is closed?
  213. // old Floater dependency is not enable in panel
  214. // addDependentFloater(floater);
  215. return floater;
  216. }
  217. //////////////////////////////////////////////////////////////////////////
  218. // Private Section
  219. void LLFloaterGetBlockedObjectName::applyBlocking()
  220. {
  221. if (mGetObjectNameCallback)
  222. {
  223. const std::string& text = childGetValue("object_name").asString();
  224. mGetObjectNameCallback(text);
  225. }
  226. closeFloater();
  227. }
  228. void LLFloaterGetBlockedObjectName::cancelBlocking()
  229. {
  230. closeFloater();
  231. }
  232. //EOF