llfloatermute.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /**
  2. * @file llfloatermute.cpp
  3. * @brief Container for mute list
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, 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 "llfloatermute.h"
  34. #include "llbutton.h"
  35. #include "llcheckboxctrl.h"
  36. #include "llscrolllistctrl.h"
  37. #include "lluictrlfactory.h"
  38. #include "llagent.h"
  39. #include "llfloateravatarinfo.h"
  40. #include "llfloateravatarpicker.h"
  41. #include "llfloatergroupinfo.h"
  42. #include "llfloaterinspect.h"
  43. #include "llmutelist.h"
  44. #include "llviewerobjectlist.h"
  45. //-----------------------------------------------------------------------------
  46. // LLFloaterMuteObjectUI() - For handling mute object by name.
  47. //-----------------------------------------------------------------------------
  48. class LLFloaterMuteObjectUI final
  49. : public LLFloater,
  50. public LLFloaterSingleton<LLFloaterMuteObjectUI>
  51. {
  52. friend class LLUISingleton<LLFloaterMuteObjectUI,
  53. VisibilityPolicy<LLFloater> >;
  54. public:
  55. ~LLFloaterMuteObjectUI() override;
  56. typedef void (*callback_t)(const std::string&, void*);
  57. static LLFloaterMuteObjectUI* show(callback_t callback, void* userdata);
  58. bool postBuild() override;
  59. bool handleKeyHere(KEY key, MASK mask) override;
  60. private:
  61. // Open via show() only
  62. LLFloaterMuteObjectUI(const LLSD&);
  63. // UI Callbacks
  64. static void onBtnOk(void* data);
  65. static void onBtnCancel(void* data);
  66. void (*mCallback)(const std::string& objectName, void* userdata);
  67. void* mCallbackUserData;
  68. };
  69. //static
  70. LLFloaterMuteObjectUI* LLFloaterMuteObjectUI::show(callback_t callback,
  71. void* userdata)
  72. {
  73. // This will create a new instance if needed
  74. LLFloaterMuteObjectUI* self = getInstance();
  75. self->mCallback = callback;
  76. self->mCallbackUserData = userdata;
  77. self->open();
  78. return self;
  79. }
  80. LLFloaterMuteObjectUI::LLFloaterMuteObjectUI(const LLSD&)
  81. : mCallback(NULL),
  82. mCallbackUserData(NULL)
  83. {
  84. LLUICtrlFactory::getInstance()->buildFloater(this,
  85. "floater_mute_object.xml");
  86. }
  87. //virtual
  88. LLFloaterMuteObjectUI::~LLFloaterMuteObjectUI()
  89. {
  90. gFocusMgr.releaseFocusIfNeeded(this);
  91. }
  92. //virtual
  93. bool LLFloaterMuteObjectUI::postBuild()
  94. {
  95. childSetAction("OK", onBtnOk, this);
  96. childSetAction("Cancel", onBtnCancel, this);
  97. center();
  98. return true;
  99. }
  100. //virtual
  101. bool LLFloaterMuteObjectUI::handleKeyHere(KEY key, MASK mask)
  102. {
  103. if (key == KEY_RETURN && mask == MASK_NONE)
  104. {
  105. onBtnOk(this);
  106. return true;
  107. }
  108. else if (key == KEY_ESCAPE && mask == MASK_NONE)
  109. {
  110. onBtnCancel(this);
  111. return true;
  112. }
  113. return LLFloater::handleKeyHere(key, mask);
  114. }
  115. //static
  116. void LLFloaterMuteObjectUI::onBtnOk(void* userdata)
  117. {
  118. LLFloaterMuteObjectUI* self = (LLFloaterMuteObjectUI*)userdata;
  119. if (!self) return;
  120. if (self->mCallback)
  121. {
  122. const std::string& text = self->childGetValue("object_name").asString();
  123. self->mCallback(text, self->mCallbackUserData);
  124. }
  125. self->close();
  126. }
  127. //static
  128. void LLFloaterMuteObjectUI::onBtnCancel(void* userdata)
  129. {
  130. LLFloaterMuteObjectUI* self = (LLFloaterMuteObjectUI*)userdata;
  131. if (self)
  132. {
  133. self->close();
  134. }
  135. }
  136. //-----------------------------------------------------------------------------
  137. // LLFloaterMute()
  138. //-----------------------------------------------------------------------------
  139. LLFloaterMute::LLFloaterMute(const LLSD&)
  140. {
  141. LLUICtrlFactory::getInstance()->buildFloater(this, "floater_mute.xml");
  142. }
  143. //virtual
  144. LLFloaterMute::~LLFloaterMute()
  145. {
  146. LLMuteList::removeObserver(this);
  147. }
  148. //virtual
  149. bool LLFloaterMute::postBuild()
  150. {
  151. mMuteList = getChild<LLScrollListCtrl>("mutes");
  152. mMuteList->setCommitCallback(onSelectName);
  153. mMuteList->setDoubleClickCallback(onDoubleClickName);
  154. mMuteList->setCallbackUserData(this);
  155. mMuteList->setCommitOnSelectionChange(true);
  156. childSetAction("mute_resident", onClickPick, this);
  157. childSetAction("mute_by_name", onClickMuteByName, this);
  158. mUnmute = getChild<LLButton>("unmute");
  159. mUnmute->setClickedCallback(onClickRemove, this);
  160. mUpdateMutes = getChild<LLButton>("update_mutes");
  161. mUpdateMutes->setClickedCallback(onClickUpdateMutes, this);
  162. mMuteAll = getChild<LLCheckBoxCtrl>("mute_all");
  163. mMuteAll->setCommitCallback(onMuteAllToggled);
  164. mMuteAll->setCallbackUserData(this);
  165. mMuteChat = getChild<LLCheckBoxCtrl>("mute_chat");
  166. mMuteChat->setCommitCallback(onMuteTypeToggled);
  167. mMuteChat->setCallbackUserData(this);
  168. mMuteVoice = getChild<LLCheckBoxCtrl>("mute_voice");
  169. mMuteVoice->setCommitCallback(onMuteTypeToggled);
  170. mMuteVoice->setCallbackUserData(this);
  171. mMuteSound = getChild<LLCheckBoxCtrl>("mute_sounds");
  172. mMuteSound->setCommitCallback(onMuteTypeToggled);
  173. mMuteSound->setCallbackUserData(this);
  174. mMuteParticles = getChild<LLCheckBoxCtrl>("mute_particles");
  175. mMuteParticles->setCommitCallback(onMuteTypeToggled);
  176. mMuteParticles->setCallbackUserData(this);
  177. LLMuteList::addObserver(this);
  178. refreshMuteList();
  179. return true;
  180. }
  181. // LLMuteListObserver callback interface implementation.
  182. //virtual
  183. void LLFloaterMute::onChange()
  184. {
  185. refreshMuteList();
  186. }
  187. void LLFloaterMute::refreshMuteList()
  188. {
  189. // Remember any selected entry and the scroll position in the list
  190. S32 scrollpos = mMuteList->getScrollPos();
  191. LLScrollListItem* item = mMuteList->getFirstSelected();
  192. LLUUID selected_id;
  193. if (item)
  194. {
  195. selected_id = mMuteList->getValue().asUUID();
  196. }
  197. mMuteList->deleteAllItems();
  198. bool has_selected = false;
  199. std::string text;
  200. std::vector<LLMute> mutes = LLMuteList::getMutes();
  201. for (std::vector<LLMute>::iterator it = mutes.begin();
  202. it != mutes.end(); ++it)
  203. {
  204. text = it->getNameAndType();
  205. const LLUUID& id = it->mID;
  206. if (id == selected_id)
  207. {
  208. has_selected = true;
  209. }
  210. LLScrollListItem* item = mMuteList->addStringUUIDItem(text, id);
  211. if (item && gObjectList.findObject(id))
  212. {
  213. LLScrollListText* text_cell =
  214. dynamic_cast<LLScrollListText*>(item->getColumn(0));
  215. if (text_cell)
  216. {
  217. text_cell->setFontStyle(LLFontGL::BOLD);
  218. }
  219. }
  220. }
  221. // Restore any selected item and scroll position in list
  222. mMuteList->setScrollPos(scrollpos);
  223. if (has_selected && selected_id.notNull())
  224. {
  225. mMuteList->selectByID(selected_id);
  226. mMuteList->scrollToShowSelected();
  227. }
  228. updateButtons();
  229. }
  230. void LLFloaterMute::updateButtons()
  231. {
  232. bool selected = mMuteList->getFirstSelected() != NULL;
  233. bool enabled = selected;
  234. bool mute_all = false;
  235. U32 flags = 0;
  236. if (selected)
  237. {
  238. const LLUUID& id = mMuteList->getStringUUIDSelectedItem();
  239. std::vector<LLMute> mutes = LLMuteList::getMutes();
  240. std::vector<LLMute>::iterator it;
  241. for (it = mutes.begin(); it != mutes.end(); ++it)
  242. {
  243. if (it->mID == id)
  244. {
  245. break;
  246. }
  247. }
  248. if (it == mutes.end())
  249. {
  250. // Shoud never happen...
  251. enabled = false;
  252. }
  253. else
  254. {
  255. enabled = it->mType == LLMute::AGENT || it->mType == LLMute::GROUP;
  256. mute_all = it->mFlags == 0;
  257. if (!mute_all && enabled)
  258. {
  259. flags = ~(it->mFlags);
  260. }
  261. }
  262. }
  263. mUpdateMutes->setEnabled(false); // Mutes are up to date
  264. mUnmute->setEnabled(selected);
  265. mMuteAll->setEnabled(enabled && !mute_all);
  266. mMuteChat->setEnabled(enabled);
  267. mMuteVoice->setEnabled(enabled);
  268. mMuteSound->setEnabled(enabled);
  269. mMuteParticles->setEnabled(enabled);
  270. mMuteAll->setValue(mute_all);
  271. mMuteChat->setValue((flags & LLMute::flagTextChat) != 0);
  272. mMuteVoice->setValue((flags & LLMute::flagVoiceChat) != 0);
  273. mMuteSound->setValue((flags & LLMute::flagObjectSounds) != 0);
  274. mMuteParticles->setValue((flags & LLMute::flagParticles) != 0);
  275. }
  276. //static
  277. void LLFloaterMute::selectMute(const LLUUID& mute_id)
  278. {
  279. // This will create a new instance if needed:
  280. LLFloaterMute* self = getInstance();
  281. if (self) // Paranoia
  282. {
  283. self->mMuteList->selectByID(mute_id);
  284. self->mMuteList->scrollToShowSelected();
  285. self->updateButtons();
  286. self->open();
  287. }
  288. }
  289. //static
  290. void LLFloaterMute::selectMute(const std::string& name)
  291. {
  292. // This will create a new instance if needed:
  293. LLFloaterMute* self = getInstance();
  294. if (!self) return; // Paranoia
  295. std::vector<LLScrollListItem*> data = self->mMuteList->getAllData();
  296. std::string label;
  297. LLUUID id;
  298. for (S32 i = 0, count = data.size(); i < count; ++i)
  299. {
  300. LLScrollListItem* item = data[i];
  301. id = item->getUUID();
  302. LLMute mute(id);
  303. label = item->getColumn(0)->getValue().asString();
  304. mute.setFromDisplayName(label); // trims off the suffix from mute.mName
  305. if (mute.mName == name)
  306. {
  307. self->mMuteList->selectItem(item);
  308. self->mMuteList->scrollToShowSelected();
  309. break;
  310. }
  311. }
  312. self->updateButtons();
  313. self->open();
  314. }
  315. //static
  316. void LLFloaterMute::onDoubleClickName(void* data)
  317. {
  318. LLFloaterMute* self = (LLFloaterMute*)data;
  319. if (self)
  320. {
  321. const LLUUID& id = self->mMuteList->getStringUUIDSelectedItem();
  322. std::vector<LLMute> mutes = LLMuteList::getMutes();
  323. std::vector<LLMute>::iterator it;
  324. for (it = mutes.begin(); it != mutes.end(); ++it)
  325. {
  326. if (it->mID == id)
  327. {
  328. break;
  329. }
  330. }
  331. if (it != mutes.end())
  332. {
  333. if (it->mType == LLMute::AGENT)
  334. {
  335. LLFloaterAvatarInfo::show(id);
  336. }
  337. else if (it->mType == LLMute::GROUP)
  338. {
  339. LLFloaterGroupInfo::showFromUUID(id);
  340. }
  341. else if (it->mType == LLMute::OBJECT)
  342. {
  343. LLViewerObject* objectp = gObjectList.findObject(id);
  344. if (objectp)
  345. {
  346. LLFloaterInspect::show(objectp);
  347. }
  348. }
  349. }
  350. }
  351. }
  352. //static
  353. void LLFloaterMute::onSelectName(LLUICtrl* caller, void* data)
  354. {
  355. LLFloaterMute* self = (LLFloaterMute*)data;
  356. if (self)
  357. {
  358. self->updateButtons();
  359. }
  360. }
  361. //static
  362. void LLFloaterMute::onClickRemove(void* data)
  363. {
  364. LLFloaterMute* self = (LLFloaterMute*)data;
  365. if (!self) return;
  366. std::string name = self->mMuteList->getSelectedItemLabel();
  367. LLUUID id = self->mMuteList->getStringUUIDSelectedItem();
  368. LLMute mute(id);
  369. mute.setFromDisplayName(name); // Now mute.mName has the suffix trimmed off
  370. S32 last_selected = self->mMuteList->getFirstSelectedIndex();
  371. if (LLMuteList::remove(mute))
  372. {
  373. // Above removals may rebuild this dialog.
  374. if (last_selected == self->mMuteList->getItemCount())
  375. {
  376. // We were on the last item, so select the last item again
  377. self->mMuteList->selectNthItem(last_selected - 1);
  378. }
  379. else
  380. {
  381. // Else select the item after the last item previously selected
  382. self->mMuteList->selectNthItem(last_selected);
  383. }
  384. }
  385. self->updateButtons();
  386. self->mMuteList->deselectAllItems(true);
  387. }
  388. //static
  389. void LLFloaterMute::onClickPick(void* data)
  390. {
  391. LLFloaterMute* self = (LLFloaterMute*)data;
  392. if (self)
  393. {
  394. LLFloaterAvatarPicker* picker =
  395. // Not allowing multiple selection, with close on select
  396. LLFloaterAvatarPicker::show(onPickUser, data, false, true);
  397. self->addDependentFloater(picker);
  398. }
  399. }
  400. //static
  401. void LLFloaterMute::onPickUser(const std::vector<std::string>& names,
  402. const std::vector<LLUUID>& ids, void* data)
  403. {
  404. LLFloaterMute* self = (LLFloaterMute*)data;
  405. if (self && !names.empty() && !ids.empty())
  406. {
  407. LLMute mute(ids[0], names[0], LLMute::AGENT);
  408. LLMuteList::add(mute);
  409. self->updateButtons();
  410. }
  411. }
  412. //static
  413. void LLFloaterMute::onClickMuteByName(void* data)
  414. {
  415. LLFloaterMute* self = (LLFloaterMute*)data;
  416. if (self)
  417. {
  418. LLFloaterMuteObjectUI* picker;
  419. picker = LLFloaterMuteObjectUI::show(callbackMuteByName, data);
  420. if (picker)
  421. {
  422. self->addDependentFloater(picker);
  423. }
  424. }
  425. }
  426. //static
  427. void LLFloaterMute::callbackMuteByName(const std::string& text, void*)
  428. {
  429. if (!text.empty())
  430. {
  431. LLMute mute(LLUUID::null, text, LLMute::BY_NAME);
  432. LLMuteList::add(mute);
  433. }
  434. }
  435. //static
  436. void LLFloaterMute::onMuteAllToggled(LLUICtrl*, void* data)
  437. {
  438. LLFloaterMute* self = (LLFloaterMute*)data;
  439. if (self)
  440. {
  441. self->mMuteChat->setValue(false);
  442. self->mMuteVoice->setValue(false);
  443. self->mMuteSound->setValue(false);
  444. self->mMuteParticles->setValue(false);
  445. self->mUpdateMutes->setEnabled(true);
  446. }
  447. }
  448. //static
  449. void LLFloaterMute::onMuteTypeToggled(LLUICtrl* ctrl, void* data)
  450. {
  451. LLFloaterMute* self = (LLFloaterMute*)data;
  452. LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
  453. if (!self || !check) return;
  454. if (check->get())
  455. {
  456. self->mMuteAll->setValue(false);
  457. self->mMuteAll->setEnabled(true);
  458. }
  459. else
  460. {
  461. bool enabled = !(self->mMuteChat->get() || self->mMuteVoice->get() ||
  462. self->mMuteSound->get() ||
  463. self->mMuteParticles->get());
  464. self->mMuteAll->setValue(enabled);
  465. self->mMuteAll->setEnabled(!enabled);
  466. }
  467. self->mUpdateMutes->setEnabled(true);
  468. }
  469. //static
  470. void LLFloaterMute::onClickUpdateMutes(void* data)
  471. {
  472. LLFloaterMute* self = (LLFloaterMute*)data;
  473. if (!self) return;
  474. std::string name = self->mMuteList->getSelectedItemLabel();
  475. LLUUID id = self->mMuteList->getStringUUIDSelectedItem();
  476. LLMute mute(id);
  477. mute.setFromDisplayName(name); // now mute.mName has the suffix trimmed off
  478. U32 flags = 0;
  479. if (!self->mMuteAll->get())
  480. {
  481. if (self->mMuteChat->get())
  482. {
  483. flags |= LLMute::flagTextChat;
  484. }
  485. if (self->mMuteVoice->get())
  486. {
  487. flags |= LLMute::flagVoiceChat;
  488. }
  489. if (self->mMuteSound->get())
  490. {
  491. flags |= LLMute::flagObjectSounds;
  492. }
  493. if (self->mMuteParticles->get())
  494. {
  495. flags |= LLMute::flagParticles;
  496. }
  497. }
  498. // Refresh the mute entry by removing the mute then re-adding it.
  499. S32 last_selected = self->mMuteList->getFirstSelectedIndex();
  500. LLMuteList::remove(mute);
  501. LLMuteList::add(mute, flags);
  502. self->mMuteList->selectNthItem(last_selected);
  503. self->updateButtons();
  504. }