llfloatergroups.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /**
  2. * @file llfloatergroups.cpp
  3. * @brief LLFloaterGroups class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-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 "llfloatergroups.h"
  34. #include "llalertdialog.h"
  35. #include "llbutton.h"
  36. #include "lllineeditor.h"
  37. #include "llscrolllistctrl.h"
  38. #include "lltextbox.h"
  39. #include "lluictrlfactory.h"
  40. #include "llmessage.h"
  41. #include "roles_constants.h"
  42. #include "llagent.h"
  43. #include "llfloatergroupinfo.h"
  44. #include "hbfloatergrouptitles.h"
  45. #include "hbfloatersearch.h"
  46. #include "llimmgr.h"
  47. #include "llmutelist.h"
  48. //MK
  49. #include "mkrlinterface.h"
  50. //mk
  51. #include "llselectmgr.h"
  52. #include "llstartup.h"
  53. #include "llviewercontrol.h"
  54. using namespace LLOldEvents;
  55. //static
  56. LLFloaterGroupPicker::instances_list_t LLFloaterGroupPicker::sInstances;
  57. // Helper function used by the two LLFloaterGroupPicker and LLFloaterGroups
  58. // classes, to populate their groups list.
  59. void populate_groups_list(LLFloater* self, LLScrollListCtrl* group_list,
  60. const LLUUID& highlight_id, U64 powers_mask,
  61. bool with_checkboxes = false,
  62. const std::string& filter = LLStringUtil::null)
  63. {
  64. group_list->deleteAllItems();
  65. bool filter_groups = !filter.empty();
  66. for (U32 i = 0, count = gAgent.mGroups.size(); i < count; ++i)
  67. {
  68. const LLGroupData& group_data = gAgent.mGroups[i];
  69. const LLUUID& id = group_data.mID;
  70. if (filter_groups)
  71. {
  72. std::string name = group_data.mName;
  73. LLStringUtil::toLower(name);
  74. if (name.find(filter) == std::string::npos)
  75. {
  76. // Group name does not match the filter, skip this group. HB
  77. continue;
  78. }
  79. }
  80. if (powers_mask == GP_ALL_POWERS ||
  81. (group_data.mPowers & powers_mask) != 0)
  82. {
  83. std::string style = "NORMAL";
  84. if (highlight_id == id)
  85. {
  86. style = "BOLD";
  87. }
  88. LLSD element;
  89. element["id"] = id;
  90. LLSD& name_column = element["columns"][0];
  91. name_column["column"] = "name";
  92. name_column["value"] = group_data.mName;
  93. name_column["font"] = "SANSSERIF";
  94. name_column["font-style"] = style;
  95. if (with_checkboxes)
  96. {
  97. LLSD& profile_column = element["columns"][1];
  98. profile_column["column"] = "profile";
  99. profile_column["type"] = "checkbox";
  100. profile_column["value"] = group_data.mListInProfile;
  101. LLSD& chat_column = element["columns"][2];
  102. chat_column["column"] = "chat";
  103. chat_column["type"] = "checkbox";
  104. chat_column["value"] = !LLMuteList::isMuted(id, "",
  105. LLMute::flagTextChat);
  106. LLSD& notices_column = element["columns"][3];
  107. notices_column["column"] = "notices";
  108. notices_column["type"] = "checkbox";
  109. notices_column["value"] = group_data.mAcceptNotices;
  110. }
  111. group_list->addElement(element, ADD_SORTED);
  112. }
  113. }
  114. // Add "none" to list at top
  115. std::string style = "NORMAL";
  116. if (highlight_id.isNull())
  117. {
  118. style = "BOLD";
  119. }
  120. LLSD element;
  121. element["id"] = LLUUID::null;
  122. LLSD& name_column = element["columns"][0];
  123. name_column["column"] = "name";
  124. name_column["value"] = self->getString("none");
  125. name_column["font"] = "SANSSERIF";
  126. name_column["font-style"] = style;
  127. if (with_checkboxes)
  128. {
  129. LLSD& profile_column = element["columns"][1];
  130. profile_column["column"] = "profile";
  131. profile_column["value"] = "";
  132. LLSD& chat_column = element["columns"][2];
  133. chat_column["column"] = "chat";
  134. chat_column["value"] = "";
  135. LLSD& notices_column = element["columns"][3];
  136. notices_column["column"] = "notices";
  137. notices_column["value"] = "";
  138. }
  139. group_list->addElement(element, ADD_TOP);
  140. group_list->selectByValue(highlight_id);
  141. group_list->scrollToShowSelected();
  142. }
  143. //-----------------------------------------------------------------------------
  144. // LLFloaterGroupPicker class
  145. //-----------------------------------------------------------------------------
  146. //static
  147. LLFloaterGroupPicker* LLFloaterGroupPicker::show(LLFloaterGroupPicker::callback_t callback,
  148. void* userdata)
  149. {
  150. LLFloaterGroupPicker* self = NULL;
  151. for (instances_list_t::iterator it = sInstances.begin(),
  152. end = sInstances.end();
  153. it != end; ++it)
  154. {
  155. LLFloaterGroupPicker* instance = *it;
  156. if (instance && instance->mSelectCallback == callback &&
  157. instance->mCallbackUserdata == userdata)
  158. {
  159. self = instance;
  160. break;
  161. }
  162. }
  163. if (!self)
  164. {
  165. self = new LLFloaterGroupPicker(callback, userdata);
  166. }
  167. self->open();
  168. return self;
  169. }
  170. LLFloaterGroupPicker::LLFloaterGroupPicker(callback_t callback, void* userdata)
  171. : mSelectCallback(callback),
  172. mCallbackUserdata(userdata),
  173. mPowersMask(GP_ALL_POWERS)
  174. {
  175. sInstances.insert(this);
  176. LLUICtrlFactory::getInstance()->buildFloater(this,
  177. "floater_choose_group.xml");
  178. }
  179. //virtual
  180. LLFloaterGroupPicker::~LLFloaterGroupPicker()
  181. {
  182. sInstances.erase(this);
  183. }
  184. bool LLFloaterGroupPicker::postBuild()
  185. {
  186. mGroupsList = getChild<LLScrollListCtrl>("group list");
  187. mGroupsList->setDoubleClickCallback(onBtnOK);
  188. mGroupsList->setCallbackUserData(this);
  189. populate_groups_list(this, mGroupsList, gAgent.getGroupID(), mPowersMask);
  190. childSetAction("Cancel", onBtnCancel, this);
  191. childSetAction("OK", onBtnOK, this);
  192. setDefaultBtn("OK");
  193. return true;
  194. }
  195. void LLFloaterGroupPicker::setPowersMask(U64 powers_mask)
  196. {
  197. mPowersMask = powers_mask;
  198. populate_groups_list(this, mGroupsList, gAgent.getGroupID(), mPowersMask);
  199. }
  200. //static
  201. void LLFloaterGroupPicker::onBtnOK(void* userdata)
  202. {
  203. LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata;
  204. if (self)
  205. {
  206. if (self->mSelectCallback)
  207. {
  208. const LLUUID& group_id = self->mGroupsList->getCurrentID();
  209. self->mSelectCallback(group_id, self->mCallbackUserdata);
  210. }
  211. self->close();
  212. }
  213. }
  214. //static
  215. void LLFloaterGroupPicker::onBtnCancel(void* userdata)
  216. {
  217. LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata;
  218. if (self)
  219. {
  220. self->close();
  221. }
  222. }
  223. //-----------------------------------------------------------------------------
  224. // LLFloaterGroups class
  225. //-----------------------------------------------------------------------------
  226. LLFloaterGroups::LLFloaterGroups(const LLSD&)
  227. {
  228. LLUICtrlFactory::getInstance()->buildFloater(this, "floater_groups.xml");
  229. gAgent.addListener(this, "new group");
  230. gSavedSettings.setBool("ShowGroups", true);
  231. }
  232. //virtual
  233. LLFloaterGroups::~LLFloaterGroups()
  234. {
  235. gAgent.removeListener(this);
  236. gFocusMgr.releaseFocusIfNeeded(this);
  237. gSavedSettings.setBool("ShowGroups", false);
  238. }
  239. //virtual
  240. bool LLFloaterGroups::postBuild()
  241. {
  242. mGroupsList = getChild<LLScrollListCtrl>("group list");
  243. mGroupsList->setCommitCallback(onGroupList);
  244. mGroupsList->setDoubleClickCallback(onBtnIM);
  245. mGroupsList->setCallbackUserData(this);
  246. LLSearchEditor* editp = getChild<LLSearchEditor>("filter_search");
  247. editp->setSearchCallback(onSearchEdit, this);
  248. mActivateBtn = getChild<LLButton>("Activate");
  249. mActivateBtn->setClickedCallback(onBtnActivate, this);
  250. mInfoBtn = getChild<LLButton>("Info");
  251. mInfoBtn->setClickedCallback(onBtnInfo, this);
  252. mIMBtn = getChild<LLButton>("IM");
  253. mIMBtn->setClickedCallback(onBtnIM, this);
  254. mLeaveBtn = getChild<LLButton>("Leave");
  255. mLeaveBtn->setClickedCallback(onBtnLeave, this);
  256. mCreateBtn = getChild<LLButton>("Create");
  257. mCreateBtn->setClickedCallback(onBtnCreate, this);
  258. childSetAction("Search...", onBtnSearch, this);
  259. childSetAction("Titles...", onBtnTitles, this);
  260. childSetAction("OK", onBtnClose, this);
  261. setDefaultBtn("IM");
  262. reset();
  263. return true;
  264. }
  265. //virtual
  266. bool LLFloaterGroups::handleEvent(LLPointer<LLEvent> event, const LLSD&)
  267. {
  268. if (event->desc() == "new group")
  269. {
  270. reset();
  271. return true;
  272. }
  273. return false;
  274. }
  275. void LLFloaterGroups::reset()
  276. {
  277. childSetTextArg("groupcount", "[COUNT]",
  278. llformat("%d",gAgent.mGroups.size()));
  279. childSetTextArg("groupcount", "[MAX]", llformat("%d", gMaxAgentGroups));
  280. populate_groups_list(this, mGroupsList, gAgent.getGroupID(),
  281. GP_ALL_POWERS, true, mFilterString);
  282. enableButtons();
  283. }
  284. void LLFloaterGroups::enableButtons()
  285. {
  286. const LLUUID& group_id = mGroupsList->getCurrentID();
  287. mActivateBtn->setEnabled(group_id != gAgent.getGroupID());
  288. bool enable = group_id.notNull();
  289. mLeaveBtn->setEnabled(enable);
  290. mInfoBtn->setEnabled(enable);
  291. mIMBtn->setEnabled(enable &&
  292. !LLMuteList::isMuted(group_id, LLMute::flagTextChat));
  293. mCreateBtn->setEnabled((S32)gAgent.mGroups.size() < gMaxAgentGroups);
  294. }
  295. //static
  296. void LLFloaterGroups::onGroupList(LLUICtrl*, void* userdata)
  297. {
  298. LLFloaterGroups* self = (LLFloaterGroups*)userdata;
  299. if (!self)
  300. {
  301. return;
  302. }
  303. self->enableButtons();
  304. LLScrollListItem* item = self->mGroupsList->getFirstSelected();
  305. if (!item)
  306. {
  307. return;
  308. }
  309. const LLUUID group_id = item->getValue().asUUID();
  310. if (group_id.isNull())
  311. {
  312. return;
  313. }
  314. LLGroupData group_data;
  315. if (!gAgent.getGroupData(group_id, group_data))
  316. {
  317. return;
  318. }
  319. bool profile = item->getColumn(1)->getValue().asBoolean();
  320. bool chat = item->getColumn(2)->getValue().asBoolean();
  321. bool notices = item->getColumn(3)->getValue().asBoolean();
  322. bool update_floaters = false;
  323. bool muted = LLMuteList::isMuted(group_id, "", LLMute::flagTextChat);
  324. if (muted == chat)
  325. {
  326. LLMute mute(group_id, group_data.mName, LLMute::GROUP);
  327. if (chat)
  328. {
  329. if (muted)
  330. {
  331. LLMuteList::remove(mute, LLMute::flagTextChat);
  332. }
  333. }
  334. else
  335. {
  336. if (!muted)
  337. {
  338. LLMuteList::add(mute, LLMute::flagTextChat);
  339. }
  340. }
  341. update_floaters = true;
  342. }
  343. if (group_data.mListInProfile != profile ||
  344. group_data.mAcceptNotices != notices)
  345. {
  346. gAgent.setUserGroupFlags(group_id, notices, profile);
  347. // gAgent.setUserGroupFlags calls update_group_floaters()
  348. update_floaters = false;
  349. }
  350. if (update_floaters)
  351. {
  352. update_group_floaters(group_id);
  353. }
  354. }
  355. //static
  356. void LLFloaterGroups::onSearchEdit(const std::string& search_string,
  357. void* userdata)
  358. {
  359. LLFloaterGroups* self = (LLFloaterGroups*)userdata;
  360. if (self)
  361. {
  362. self->mFilterString = search_string;
  363. LLStringUtil::trim(self->mFilterString);
  364. LLStringUtil::toLower(self->mFilterString);
  365. self->reset();
  366. }
  367. }
  368. //static
  369. void LLFloaterGroups::onBtnCreate(void*)
  370. {
  371. LLFloaterGroupInfo::showCreateGroup(NULL);
  372. }
  373. //static
  374. void LLFloaterGroups::onBtnActivate(void* userdata)
  375. {
  376. LLFloaterGroups* self = (LLFloaterGroups*)userdata;
  377. if (self)
  378. {
  379. gAgent.setGroup(self->mGroupsList->getCurrentID());
  380. }
  381. }
  382. //static
  383. void LLFloaterGroups::onBtnInfo(void* userdata)
  384. {
  385. LLFloaterGroups* self = (LLFloaterGroups*)userdata;
  386. if (self)
  387. {
  388. const LLUUID& group_id = self->mGroupsList->getCurrentID();
  389. if (group_id.notNull())
  390. {
  391. LLFloaterGroupInfo::showFromUUID(group_id);
  392. }
  393. }
  394. }
  395. //static
  396. void LLFloaterGroups::onBtnIM(void* userdata)
  397. {
  398. LLFloaterGroups* self = (LLFloaterGroups*)userdata;
  399. if (self)
  400. {
  401. const LLUUID& group_id = self->mGroupsList->getCurrentID();
  402. if (gIMMgrp && group_id.notNull())
  403. {
  404. LLGroupData group_data;
  405. if (gAgent.getGroupData(group_id, group_data) &&
  406. !LLMuteList::isMuted(group_id, "", LLMute::flagTextChat))
  407. {
  408. gIMMgrp->setFloaterOpen(true);
  409. gIMMgrp->addSession(group_data.mName, IM_SESSION_GROUP_START,
  410. group_id);
  411. make_ui_sound("UISndStartIM");
  412. }
  413. else
  414. {
  415. // Muted group
  416. make_ui_sound("UISndInvalidOp");
  417. }
  418. }
  419. }
  420. }
  421. //static
  422. bool LLFloaterGroups::callbackLeaveGroup(const LLSD& notification,
  423. const LLSD& response)
  424. {
  425. if (LLNotification::getSelectedOption(notification, response) == 0)
  426. {
  427. const LLUUID& group_id = notification["payload"]["group_id"].asUUID();
  428. LLMessageSystem* msg = gMessageSystemp;
  429. msg->newMessageFast(_PREHASH_LeaveGroupRequest);
  430. msg->nextBlockFast(_PREHASH_AgentData);
  431. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  432. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  433. msg->nextBlockFast(_PREHASH_GroupData);
  434. msg->addUUIDFast(_PREHASH_GroupID, group_id);
  435. gAgent.sendReliableMessage();
  436. }
  437. return false;
  438. }
  439. //static
  440. void LLFloaterGroups::onBtnLeave(void* userdata)
  441. {
  442. LLFloaterGroups* self = (LLFloaterGroups*)userdata;
  443. if (self)
  444. {
  445. const LLUUID& group_id = self->mGroupsList->getCurrentID();
  446. if (group_id.notNull())
  447. {
  448. S32 count = gAgent.mGroups.size();
  449. S32 i;
  450. for (i = 0; i < count; ++i)
  451. {
  452. if (gAgent.mGroups[i].mID == group_id)
  453. {
  454. break;
  455. }
  456. }
  457. if (i < count)
  458. {
  459. LLSD args, payload;
  460. args["GROUP"] = gAgent.mGroups[i].mName;
  461. payload["group_id"] = group_id;
  462. gNotifications.add("GroupLeaveConfirmMember", args, payload,
  463. callbackLeaveGroup);
  464. }
  465. }
  466. }
  467. }
  468. //static
  469. void LLFloaterGroups::onBtnSearch(void*)
  470. {
  471. HBFloaterSearch::showGroups();
  472. }
  473. //static
  474. void LLFloaterGroups::onBtnTitles(void*)
  475. {
  476. HBFloaterGroupTitles::showInstance();
  477. }
  478. //static
  479. void LLFloaterGroups::onBtnClose(void* userdata)
  480. {
  481. LLFloaterGroups* self = (LLFloaterGroups*)userdata;
  482. if (self)
  483. {
  484. self->close();
  485. }
  486. }