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