PageRenderTime 144ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llfloatergroups.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 394 lines | 277 code | 70 blank | 47 comment | 36 complexity | ac678ac5c1ce7bf6c51c11de31902c1d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloatergroups.cpp
  3. * @brief LLPanelGroups class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&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. * Shown from Edit -> Groups...
  28. * Shows the agent's groups and allows the edit window to be invoked.
  29. * Also overloaded to allow picking of a single group for assigning
  30. * objects and land to groups.
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloatergroups.h"
  34. #include "roles_constants.h"
  35. #include "llagent.h"
  36. #include "llbutton.h"
  37. #include "llgroupactions.h"
  38. #include "llscrolllistctrl.h"
  39. #include "llstartup.h"
  40. #include "lltextbox.h"
  41. #include "lluictrlfactory.h"
  42. #include "lltrans.h"
  43. using namespace LLOldEvents;
  44. // helper functions
  45. void init_group_list(LLScrollListCtrl* ctrl, const LLUUID& highlight_id, U64 powers_mask = GP_ALL_POWERS);
  46. ///----------------------------------------------------------------------------
  47. /// Class LLFloaterGroupPicker
  48. ///----------------------------------------------------------------------------
  49. LLFloaterGroupPicker::LLFloaterGroupPicker(const LLSD& seed)
  50. : LLFloater(seed),
  51. mPowersMask(GP_ALL_POWERS),
  52. mID(seed.asUUID())
  53. {
  54. // LLUICtrlFactory::getInstance()->buildFloater(this, "floater_choose_group.xml");
  55. }
  56. LLFloaterGroupPicker::~LLFloaterGroupPicker()
  57. {
  58. }
  59. void LLFloaterGroupPicker::setPowersMask(U64 powers_mask)
  60. {
  61. mPowersMask = powers_mask;
  62. init_group_list(getChild<LLScrollListCtrl>("group list"), gAgent.getGroupID(), mPowersMask);
  63. }
  64. BOOL LLFloaterGroupPicker::postBuild()
  65. {
  66. LLScrollListCtrl* list_ctrl = getChild<LLScrollListCtrl>("group list");
  67. if (list_ctrl)
  68. {
  69. init_group_list(list_ctrl, gAgent.getGroupID(), mPowersMask);
  70. list_ctrl->setDoubleClickCallback(onBtnOK, this);
  71. list_ctrl->setContextMenu(LLScrollListCtrl::MENU_GROUP);
  72. }
  73. childSetAction("OK", onBtnOK, this);
  74. childSetAction("Cancel", onBtnCancel, this);
  75. setDefaultBtn("OK");
  76. getChildView("OK")->setEnabled(TRUE);
  77. return TRUE;
  78. }
  79. void LLFloaterGroupPicker::removeNoneOption()
  80. {
  81. // Remove group "none" from list. Group "none" is added in init_group_list().
  82. // Some UI elements use group "none", we need to manually delete it here.
  83. // Group "none" ID is LLUUID:null.
  84. LLCtrlListInterface* group_list = getChild<LLScrollListCtrl>("group list")->getListInterface();
  85. if(group_list)
  86. {
  87. group_list->selectByValue(LLUUID::null);
  88. group_list->operateOnSelection(LLCtrlListInterface::OP_DELETE);
  89. }
  90. }
  91. void LLFloaterGroupPicker::onBtnOK(void* userdata)
  92. {
  93. LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata;
  94. if(self) self->ok();
  95. }
  96. void LLFloaterGroupPicker::onBtnCancel(void* userdata)
  97. {
  98. LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata;
  99. if(self) self->closeFloater();
  100. }
  101. void LLFloaterGroupPicker::ok()
  102. {
  103. LLCtrlListInterface *group_list = childGetListInterface("group list");
  104. LLUUID group_id;
  105. if (group_list)
  106. {
  107. group_id = group_list->getCurrentID();
  108. }
  109. mGroupSelectSignal(group_id);
  110. closeFloater();
  111. }
  112. ///----------------------------------------------------------------------------
  113. /// Class LLPanelGroups
  114. ///----------------------------------------------------------------------------
  115. //LLEventListener
  116. //virtual
  117. bool LLPanelGroups::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
  118. {
  119. if (event->desc() == "new group")
  120. {
  121. reset();
  122. return true;
  123. }
  124. return false;
  125. }
  126. // Default constructor
  127. LLPanelGroups::LLPanelGroups() :
  128. LLPanel()
  129. {
  130. gAgent.addListener(this, "new group");
  131. }
  132. LLPanelGroups::~LLPanelGroups()
  133. {
  134. gAgent.removeListener(this);
  135. }
  136. // clear the group list, and get a fresh set of info.
  137. void LLPanelGroups::reset()
  138. {
  139. LLCtrlListInterface *group_list = childGetListInterface("group list");
  140. if (group_list)
  141. {
  142. group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
  143. }
  144. getChild<LLUICtrl>("groupcount")->setTextArg("[COUNT]", llformat("%d",gAgent.mGroups.count()));
  145. getChild<LLUICtrl>("groupcount")->setTextArg("[MAX]", llformat("%d",gMaxAgentGroups));
  146. init_group_list(getChild<LLScrollListCtrl>("group list"), gAgent.getGroupID());
  147. enableButtons();
  148. }
  149. BOOL LLPanelGroups::postBuild()
  150. {
  151. childSetCommitCallback("group list", onGroupList, this);
  152. getChild<LLUICtrl>("groupcount")->setTextArg("[COUNT]", llformat("%d",gAgent.mGroups.count()));
  153. getChild<LLUICtrl>("groupcount")->setTextArg("[MAX]", llformat("%d",gMaxAgentGroups));
  154. LLScrollListCtrl *list = getChild<LLScrollListCtrl>("group list");
  155. if (list)
  156. {
  157. init_group_list(list, gAgent.getGroupID());
  158. list->setDoubleClickCallback(onBtnIM, this);
  159. list->setContextMenu(LLScrollListCtrl::MENU_GROUP);
  160. }
  161. childSetAction("Activate", onBtnActivate, this);
  162. childSetAction("Info", onBtnInfo, this);
  163. childSetAction("IM", onBtnIM, this);
  164. childSetAction("Leave", onBtnLeave, this);
  165. childSetAction("Create", onBtnCreate, this);
  166. childSetAction("Search...", onBtnSearch, this);
  167. setDefaultBtn("IM");
  168. reset();
  169. return TRUE;
  170. }
  171. void LLPanelGroups::enableButtons()
  172. {
  173. LLCtrlListInterface *group_list = childGetListInterface("group list");
  174. LLUUID group_id;
  175. if (group_list)
  176. {
  177. group_id = group_list->getCurrentID();
  178. }
  179. if(group_id != gAgent.getGroupID())
  180. {
  181. getChildView("Activate")->setEnabled(TRUE);
  182. }
  183. else
  184. {
  185. getChildView("Activate")->setEnabled(FALSE);
  186. }
  187. if (group_id.notNull())
  188. {
  189. getChildView("Info")->setEnabled(TRUE);
  190. getChildView("IM")->setEnabled(TRUE);
  191. getChildView("Leave")->setEnabled(TRUE);
  192. }
  193. else
  194. {
  195. getChildView("Info")->setEnabled(FALSE);
  196. getChildView("IM")->setEnabled(FALSE);
  197. getChildView("Leave")->setEnabled(FALSE);
  198. }
  199. getChildView("Create")->setEnabled(gAgent.canJoinGroups());
  200. }
  201. void LLPanelGroups::onBtnCreate(void* userdata)
  202. {
  203. LLPanelGroups* self = (LLPanelGroups*)userdata;
  204. if(self) self->create();
  205. }
  206. void LLPanelGroups::onBtnActivate(void* userdata)
  207. {
  208. LLPanelGroups* self = (LLPanelGroups*)userdata;
  209. if(self) self->activate();
  210. }
  211. void LLPanelGroups::onBtnInfo(void* userdata)
  212. {
  213. LLPanelGroups* self = (LLPanelGroups*)userdata;
  214. if(self) self->info();
  215. }
  216. void LLPanelGroups::onBtnIM(void* userdata)
  217. {
  218. LLPanelGroups* self = (LLPanelGroups*)userdata;
  219. if(self) self->startIM();
  220. }
  221. void LLPanelGroups::onBtnLeave(void* userdata)
  222. {
  223. LLPanelGroups* self = (LLPanelGroups*)userdata;
  224. if(self) self->leave();
  225. }
  226. void LLPanelGroups::onBtnSearch(void* userdata)
  227. {
  228. LLPanelGroups* self = (LLPanelGroups*)userdata;
  229. if(self) self->search();
  230. }
  231. void LLPanelGroups::create()
  232. {
  233. LLGroupActions::createGroup();
  234. }
  235. void LLPanelGroups::activate()
  236. {
  237. LLCtrlListInterface *group_list = childGetListInterface("group list");
  238. LLUUID group_id;
  239. if (group_list)
  240. {
  241. group_id = group_list->getCurrentID();
  242. }
  243. LLGroupActions::activate(group_id);
  244. }
  245. void LLPanelGroups::info()
  246. {
  247. LLCtrlListInterface *group_list = childGetListInterface("group list");
  248. LLUUID group_id;
  249. if (group_list && (group_id = group_list->getCurrentID()).notNull())
  250. {
  251. LLGroupActions::show(group_id);
  252. }
  253. }
  254. void LLPanelGroups::startIM()
  255. {
  256. LLCtrlListInterface *group_list = childGetListInterface("group list");
  257. LLUUID group_id;
  258. if (group_list && (group_id = group_list->getCurrentID()).notNull())
  259. {
  260. LLGroupActions::startIM(group_id);
  261. }
  262. }
  263. void LLPanelGroups::leave()
  264. {
  265. LLCtrlListInterface *group_list = childGetListInterface("group list");
  266. LLUUID group_id;
  267. if (group_list && (group_id = group_list->getCurrentID()).notNull())
  268. {
  269. LLGroupActions::leave(group_id);
  270. }
  271. }
  272. void LLPanelGroups::search()
  273. {
  274. LLGroupActions::search();
  275. }
  276. void LLPanelGroups::onGroupList(LLUICtrl* ctrl, void* userdata)
  277. {
  278. LLPanelGroups* self = (LLPanelGroups*)userdata;
  279. if(self) self->enableButtons();
  280. }
  281. void init_group_list(LLScrollListCtrl* group_list, const LLUUID& highlight_id, U64 powers_mask)
  282. {
  283. S32 count = gAgent.mGroups.count();
  284. LLUUID id;
  285. if (!group_list) return;
  286. group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
  287. for(S32 i = 0; i < count; ++i)
  288. {
  289. id = gAgent.mGroups.get(i).mID;
  290. LLGroupData* group_datap = &gAgent.mGroups.get(i);
  291. if ((powers_mask == GP_ALL_POWERS) || ((group_datap->mPowers & powers_mask) != 0))
  292. {
  293. std::string style = "NORMAL";
  294. if(highlight_id == id)
  295. {
  296. style = "BOLD";
  297. }
  298. LLSD element;
  299. element["id"] = id;
  300. element["columns"][0]["column"] = "name";
  301. element["columns"][0]["value"] = group_datap->mName;
  302. element["columns"][0]["font"]["name"] = "SANSSERIF";
  303. element["columns"][0]["font"]["style"] = style;
  304. group_list->addElement(element);
  305. }
  306. }
  307. group_list->sortOnce(0, TRUE);
  308. // add "none" to list at top
  309. {
  310. std::string style = "NORMAL";
  311. if (highlight_id.isNull())
  312. {
  313. style = "BOLD";
  314. }
  315. LLSD element;
  316. element["id"] = LLUUID::null;
  317. element["columns"][0]["column"] = "name";
  318. element["columns"][0]["value"] = LLTrans::getString("GroupsNone");
  319. element["columns"][0]["font"]["name"] = "SANSSERIF";
  320. element["columns"][0]["font"]["style"] = style;
  321. group_list->addElement(element, ADD_TOP);
  322. }
  323. group_list->selectByValue(highlight_id);
  324. }