llfloatergroupinfo.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /**
  2. * @file llfloatergroupinfo.cpp
  3. * @brief LLFloaterGroupInfo class implementation
  4. * Floater used both for display of group information and for
  5. * creating new groups.
  6. *
  7. * $LicenseInfo:firstyear=2002&license=viewergpl$
  8. *
  9. * Copyright (c) 2002-2009, Linden Research, Inc.
  10. *
  11. * Second Life Viewer Source Code
  12. * The source code in this file ("Source Code") is provided by Linden Lab
  13. * to you under the terms of the GNU General Public License, version 2.0
  14. * ("GPL"), unless you have obtained a separate licensing agreement
  15. * ("Other License"), formally executed by you and Linden Lab. Terms of
  16. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  17. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  18. *
  19. * There are special exceptions to the terms and conditions of the GPL as
  20. * it is applied to this Source Code. View the full text of the exception
  21. * in the file doc/FLOSS-exception.txt in this software distribution, or
  22. * online at
  23. * 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 "llfloatergroupinfo.h"
  36. #include "llcachename.h"
  37. #include "llagent.h"
  38. #include "llcommandhandler.h"
  39. #include "llfloaterchatterbox.h"
  40. #include "llfloatergroups.h"
  41. #include "llnotifications.h"
  42. #include "llpanelgroup.h"
  43. #include "llviewermessage.h" // For LLOfferInfo
  44. const char FLOATER_TITLE[] = "Group Information";
  45. //
  46. // Globals
  47. //
  48. LLFloaterGroupInfo::instances_map_t LLFloaterGroupInfo::sInstances;
  49. class LLGroupHandler final : public LLCommandHandler
  50. {
  51. public:
  52. LLGroupHandler()
  53. : LLCommandHandler("group", UNTRUSTED_THROTTLE)
  54. {
  55. }
  56. bool canHandleUntrusted(const LLSD& params, const LLSD&,
  57. LLMediaCtrl*, const std::string& nav_type) override
  58. {
  59. if (!params.size())
  60. {
  61. return true; // Do not block; it will fail later in handle()
  62. }
  63. if (nav_type == "clicked" || nav_type == "external")
  64. {
  65. return true;
  66. }
  67. return params[0].asString() != "create";
  68. }
  69. bool handle(const LLSD& tokens, const LLSD&, LLMediaCtrl*) override
  70. {
  71. if (tokens.size() < 1)
  72. {
  73. return false;
  74. }
  75. if (tokens[0].asString() == "create")
  76. {
  77. LLFloaterGroupInfo::showCreateGroup(NULL);
  78. return true;
  79. }
  80. if (tokens.size() < 2)
  81. {
  82. return false;
  83. }
  84. if (tokens[0].asString() == "list")
  85. {
  86. if (tokens[1].asString() == "show")
  87. {
  88. LLFloaterGroups::showInstance();
  89. return true;
  90. }
  91. return false;
  92. }
  93. LLUUID group_id;
  94. if (!group_id.set(tokens[0], false))
  95. {
  96. return false;
  97. }
  98. if (tokens[1].asString() == "about")
  99. {
  100. LLFloaterGroupInfo::showFromUUID(group_id);
  101. return true;
  102. }
  103. return false;
  104. }
  105. };
  106. LLGroupHandler gGroupHandler;
  107. //-----------------------------------------------------------------------------
  108. // LLFloaterGroupInfo class
  109. //-----------------------------------------------------------------------------
  110. LLFloaterGroupInfo::LLFloaterGroupInfo(const std::string& name,
  111. const std::string& rect_control,
  112. const std::string& title,
  113. const LLUUID& group_id,
  114. const std::string& tab_name)
  115. : LLFloater(name, rect_control, title),
  116. mGroupID(group_id)
  117. {
  118. // Construct the filename of the group panel xml definition file.
  119. mPanelGroupp = new LLPanelGroup("panel_group.xml", "PanelGroup", group_id,
  120. tab_name);
  121. addChild(mPanelGroupp);
  122. }
  123. // virtual
  124. LLFloaterGroupInfo::~LLFloaterGroupInfo()
  125. {
  126. sInstances.erase(mGroupID);
  127. }
  128. bool LLFloaterGroupInfo::canClose()
  129. {
  130. // Ask the panel if it is ok to close.
  131. if (mPanelGroupp)
  132. {
  133. return mPanelGroupp->canClose();
  134. }
  135. return true;
  136. }
  137. void LLFloaterGroupInfo::selectTabByName(std::string tab_name)
  138. {
  139. mPanelGroupp->selectTab(tab_name);
  140. }
  141. //static
  142. void LLFloaterGroupInfo::showMyGroupInfo(void*)
  143. {
  144. showFromUUID(gAgent.getGroupID());
  145. }
  146. //static
  147. void LLFloaterGroupInfo::showCreateGroup(void*)
  148. {
  149. showFromUUID(LLUUID::null, "general_tab");
  150. }
  151. //static
  152. void LLFloaterGroupInfo::closeGroup(const LLUUID& group_id)
  153. {
  154. LLFloaterGroupInfo* fgi = get_ptr_in_map(sInstances, group_id);
  155. if (fgi)
  156. {
  157. if (fgi->mPanelGroupp)
  158. {
  159. fgi->mPanelGroupp->close();
  160. }
  161. }
  162. }
  163. //static
  164. void LLFloaterGroupInfo::closeCreateGroup()
  165. {
  166. closeGroup(LLUUID::null);
  167. }
  168. //static
  169. void LLFloaterGroupInfo::refreshGroup(const LLUUID& group_id)
  170. {
  171. LLFloaterGroupInfo* fgi = get_ptr_in_map(sInstances, group_id);
  172. if (fgi)
  173. {
  174. if (fgi->mPanelGroupp)
  175. {
  176. fgi->mPanelGroupp->refreshData();
  177. }
  178. }
  179. }
  180. //static
  181. void LLFloaterGroupInfo::callbackLoadGroupName(const LLUUID& id,
  182. const std::string& name,
  183. bool is_group)
  184. {
  185. LLFloaterGroupInfo* fgi = get_ptr_in_map(sInstances, id);
  186. if (fgi)
  187. {
  188. // Build a new title including the group name.
  189. std::ostringstream title;
  190. title << name << " - " << FLOATER_TITLE;
  191. fgi->setTitle(title.str());
  192. }
  193. }
  194. //static
  195. void LLFloaterGroupInfo::showFromUUID(const LLUUID& group_id,
  196. const std::string& tab_name)
  197. {
  198. // If we don't have a floater for this group, create one.
  199. LLFloaterGroupInfo* fgi = get_ptr_in_map(sInstances, group_id);
  200. if (!fgi)
  201. {
  202. fgi = new LLFloaterGroupInfo("groupinfo", "FloaterGroupInfoRect",
  203. FLOATER_TITLE, group_id, tab_name);
  204. sInstances[group_id] = fgi;
  205. if (group_id.notNull() && gCacheNamep)
  206. {
  207. // Look up the group name.
  208. // The callback will insert it into the title.
  209. gCacheNamep->get(group_id, true, callbackLoadGroupName);
  210. }
  211. }
  212. fgi->selectTabByName(tab_name);
  213. fgi->open();
  214. }
  215. //static
  216. void LLFloaterGroupInfo::showNotice(const std::string& subject,
  217. const std::string& message,
  218. const LLUUID& group_id, bool has_inventory,
  219. const std::string& inventory_name,
  220. LLOfferInfo* inventory_offer)
  221. {
  222. if (group_id.isNull())
  223. {
  224. // We need to clean up that inventory offer.
  225. if (inventory_offer)
  226. {
  227. inventory_offer->forceResponse(IOR_DECLINE);
  228. }
  229. return;
  230. }
  231. // If we do not have a floater for this group, drop this packet on the
  232. // floor.
  233. LLFloaterGroupInfo* fgi = get_ptr_in_map(sInstances, group_id);
  234. if (!fgi)
  235. {
  236. // We need to clean up that inventory offer.
  237. if (inventory_offer)
  238. {
  239. inventory_offer->forceResponse(IOR_DECLINE);
  240. }
  241. return;
  242. }
  243. fgi->mPanelGroupp->showNotice(subject, message, has_inventory,
  244. inventory_name, inventory_offer);
  245. }