hbfloatergrouptitles.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /**
  2. * @file hbfloatergrouptitles.cpp
  3. * @brief HBFloaterGroupTitles class implementation
  4. *
  5. * This class implements a floater where all available group titles are
  6. * listed, allowing the user to activate any via simple double-click.
  7. *
  8. * $LicenseInfo:firstyear=2010&license=viewergpl$
  9. *
  10. * Copyright (c) 2010, Henri Beauchamp.
  11. *
  12. * Second Life Viewer Source Code
  13. * The source code in this file ("Source Code") is provided by Linden Lab
  14. * to you under the terms of the GNU General Public License, version 2.0
  15. * ("GPL"), unless you have obtained a separate licensing agreement
  16. * ("Other License"), formally executed by you and Linden Lab. Terms of
  17. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  18. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  19. *
  20. * There are special exceptions to the terms and conditions of the GPL as
  21. * it is applied to this Source Code. View the full text of the exception
  22. * in the file doc/FLOSS-exception.txt in this software distribution, or
  23. * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
  24. *
  25. * By copying, modifying or distributing this software, you acknowledge
  26. * that you have read and understood your obligations described above,
  27. * and agree to abide by those obligations.
  28. *
  29. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  30. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  31. * COMPLETENESS OR PERFORMANCE.
  32. * $/LicenseInfo$
  33. */
  34. #include "llviewerprecompiledheaders.h"
  35. #include "hbfloatergrouptitles.h"
  36. #include "llscrolllistctrl.h"
  37. #include "lluictrlfactory.h"
  38. #include "llmessage.h"
  39. #include "roles_constants.h"
  40. #include "llagent.h"
  41. using namespace LLOldEvents;
  42. // HBFloaterGroupTitlesObserver class
  43. HBFloaterGroupTitlesObserver::HBFloaterGroupTitlesObserver(HBFloaterGroupTitles* instance,
  44. const LLUUID& group_id)
  45. : LLGroupMgrObserver(group_id),
  46. mFloaterInstance(instance)
  47. {
  48. gGroupMgr.addObserver(this);
  49. }
  50. //virtual
  51. HBFloaterGroupTitlesObserver::~HBFloaterGroupTitlesObserver()
  52. {
  53. gGroupMgr.removeObserver(this);
  54. }
  55. //virtual
  56. void HBFloaterGroupTitlesObserver::changed(LLGroupChange gc)
  57. {
  58. if (gc != GC_PROPERTIES)
  59. {
  60. mFloaterInstance->setDirty();
  61. }
  62. }
  63. // HBFloaterGroupTitles class
  64. HBFloaterGroupTitles::HBFloaterGroupTitles(const LLSD&)
  65. : mIsDirty(true)
  66. {
  67. LLUICtrlFactory::getInstance()->buildFloater(this,
  68. "floater_group_titles.xml");
  69. gAgent.addListener(this, "new group");
  70. }
  71. //virtual
  72. HBFloaterGroupTitles::~HBFloaterGroupTitles()
  73. {
  74. gAgent.removeListener(this);
  75. observers_map_t::iterator it;
  76. while (!mObservers.empty())
  77. {
  78. it = mObservers.begin();
  79. delete it->second;
  80. mObservers.hmap_erase(it);
  81. }
  82. }
  83. //virtual
  84. bool HBFloaterGroupTitles::postBuild()
  85. {
  86. mTitlesList = getChild<LLScrollListCtrl>("titles_list");
  87. mTitlesList->setDoubleClickCallback(onActivate);
  88. mTitlesList->setCallbackUserData(this);
  89. childSetAction("close", onCloseButtonPressed, this);
  90. childSetAction("refresh", onRefreshButtonPressed, this);
  91. childSetAction("activate", onActivate, this);
  92. return true;
  93. }
  94. //virtual
  95. void HBFloaterGroupTitles::draw()
  96. {
  97. if (mIsDirty)
  98. {
  99. const LLUUID& current_group_id = gAgent.getGroupID();
  100. LLUUID highlight_id;
  101. std::string style;
  102. LLSD element;
  103. S32 scrollpos = mTitlesList->getScrollPos();
  104. mTitlesList->deleteAllItems();
  105. for (S32 i = 0, count = gAgent.mGroups.size(); i < count; ++i)
  106. {
  107. LLGroupData* gdatap = &gAgent.mGroups[i];
  108. if (!gdatap) continue; // Paranoia
  109. const LLUUID& id = gdatap->mID;
  110. // Add an observer for this group if there is none so far.
  111. if (mObservers.find(id) == mObservers.end())
  112. {
  113. HBFloaterGroupTitlesObserver* obs =
  114. new HBFloaterGroupTitlesObserver(this, id);
  115. mObservers.emplace(id, obs);
  116. }
  117. LLGroupMgrGroupData* mgrdatap = gGroupMgr.getGroupData(id);
  118. if (!mgrdatap)
  119. {
  120. gGroupMgr.sendGroupTitlesRequest(id);
  121. continue;
  122. }
  123. for (S32 j = 0, count2 = mgrdatap->mTitles.size(); j < count2; ++j)
  124. {
  125. const LLGroupTitle& title = mgrdatap->mTitles[j];
  126. style = "NORMAL";
  127. if (current_group_id == id && title.mSelected)
  128. {
  129. style = "BOLD";
  130. highlight_id = title.mRoleID;
  131. }
  132. element["id"] = title.mRoleID;
  133. element["columns"][LIST_TITLE]["column"] = "title";
  134. element["columns"][LIST_TITLE]["value"] = title.mTitle;
  135. element["columns"][LIST_TITLE]["font-style"] = style;
  136. element["columns"][LIST_GROUP_NAME]["column"] = "group_name";
  137. // NOTE/FIXME: mgrdatap->mName is apparently always empty !
  138. element["columns"][LIST_GROUP_NAME]["value"] = gdatap->mName;
  139. element["columns"][LIST_GROUP_NAME]["font-style"] = style;
  140. element["columns"][LIST_GROUP_ID]["column"] = "group_id";
  141. element["columns"][LIST_GROUP_ID]["value"] = id;
  142. mTitlesList->addElement(element, ADD_SORTED);
  143. }
  144. }
  145. // Add "none" at top of list
  146. style = "NORMAL";
  147. if (current_group_id.isNull())
  148. {
  149. style = "BOLD";
  150. }
  151. element["id"] = LLUUID::null;
  152. element["columns"][LIST_TITLE]["column"] = "title";
  153. element["columns"][LIST_TITLE]["value"] = "none";
  154. element["columns"][LIST_TITLE]["font-style"] = style;
  155. element["columns"][LIST_GROUP_NAME]["column"] = "group_name";
  156. element["columns"][LIST_GROUP_NAME]["value"] = "none";
  157. element["columns"][LIST_GROUP_NAME]["font-style"] = style;
  158. element["columns"][LIST_GROUP_ID]["column"] = "group_id";
  159. element["columns"][LIST_GROUP_ID]["value"] = LLUUID::null;
  160. mTitlesList->addElement(element, ADD_TOP);
  161. mTitlesList->setScrollPos(scrollpos);
  162. mTitlesList->selectByValue(highlight_id);
  163. mIsDirty = false;
  164. }
  165. LLFloater::draw();
  166. }
  167. //static
  168. void HBFloaterGroupTitles::onCloseButtonPressed(void* userdata)
  169. {
  170. HBFloaterGroupTitles* self = (HBFloaterGroupTitles*)userdata;
  171. if (self)
  172. {
  173. self->close();
  174. }
  175. }
  176. //static
  177. void HBFloaterGroupTitles::onRefreshButtonPressed(void* userdata)
  178. {
  179. HBFloaterGroupTitles* self = (HBFloaterGroupTitles*)userdata;
  180. if (!self) return;
  181. observers_map_t::iterator it;
  182. while (!self->mObservers.empty())
  183. {
  184. it = self->mObservers.begin();
  185. delete it->second;
  186. self->mObservers.hmap_erase(it);
  187. }
  188. LLGroupMgr::debugClearAllGroups(NULL);
  189. self->setDirty();
  190. }
  191. //static
  192. void HBFloaterGroupTitles::onActivate(void* userdata)
  193. {
  194. HBFloaterGroupTitles* self = (HBFloaterGroupTitles*)userdata;
  195. if (!self) return;
  196. LLScrollListItem* item = self->mTitlesList->getFirstSelected();
  197. if (!item) return;
  198. // Get the group id
  199. LLUUID group_id = item->getColumn(LIST_GROUP_ID)->getValue().asUUID();
  200. // Set the title for this group
  201. gGroupMgr.sendGroupTitleUpdate(group_id, item->getUUID());
  202. // Set the group if needed.
  203. const LLUUID& old_group_id = gAgent.getGroupID();
  204. if (group_id != old_group_id)
  205. {
  206. gAgent.setGroup(group_id);
  207. }
  208. else
  209. {
  210. // Force a refresh via the observer
  211. if (group_id.isNull())
  212. {
  213. group_id = old_group_id;
  214. }
  215. gGroupMgr.sendGroupTitlesRequest(group_id);
  216. }
  217. }
  218. // LLSimpleListener
  219. //virtual
  220. bool HBFloaterGroupTitles::handleEvent(LLPointer<LLEvent> event,
  221. const LLSD& userdata)
  222. {
  223. if (event.notNull() && event->desc() == "new group")
  224. {
  225. setDirty();
  226. return true;
  227. }
  228. return false;
  229. }