llpanelgroupexperiences.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * @file llpanelgroupexperiences.cpp
  3. * @brief List of experiences owned by a group.
  4. *
  5. * $LicenseInfo:firstyear=2014&license=viewergpl$
  6. *
  7. * Copyright (c) 2014, 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 "llpanelgroupexperiences.h"
  34. #include "llexperiencecache.h"
  35. #include "llfloaterexperienceprofile.h"
  36. #include "llscrolllistctrl.h"
  37. #include "llagent.h"
  38. //static
  39. void* LLPanelGroupExperiences::createTab(void* data)
  40. {
  41. LLUUID* group_id = static_cast<LLUUID*>(data);
  42. return new LLPanelGroupExperiences("panel group experiences", *group_id);
  43. }
  44. LLPanelGroupExperiences::LLPanelGroupExperiences(const std::string& name,
  45. const LLUUID& group_id)
  46. : LLPanelGroupTab(name, group_id),
  47. mListEmpty(true)
  48. {
  49. }
  50. bool LLPanelGroupExperiences::postBuild()
  51. {
  52. mExperiencesList = getChild<LLScrollListCtrl>("experiences_list");
  53. mExperiencesList->addCommentText(getString("no_experiences_text"));
  54. mExperiencesList->setDoubleClickCallback(onDoubleClickProfile);
  55. mExperiencesList->setCallbackUserData(this);
  56. return LLPanelGroupTab::postBuild();
  57. }
  58. void LLPanelGroupExperiences::activate()
  59. {
  60. if (mGroupID.notNull() &&
  61. gAgent.hasRegionCapability("GroupExperiences"))
  62. {
  63. LLExperienceCache* exp = LLExperienceCache::getInstance();
  64. exp->getGroupExperiences(mGroupID,
  65. boost::bind(&LLPanelGroupExperiences::groupExperiencesResults,
  66. getDerivedHandle<LLPanelGroupExperiences>(),
  67. _1));
  68. }
  69. }
  70. //static
  71. void LLPanelGroupExperiences::groupExperiencesResults(LLHandle<LLPanelGroupExperiences> handle,
  72. const LLSD& experiences)
  73. {
  74. LLPanelGroupExperiences* self = handle.get();
  75. if (self)
  76. {
  77. self->setExperienceList(experiences);
  78. }
  79. }
  80. bool LLPanelGroupExperiences::isVisibleByAgent()
  81. {
  82. return mAllowEdit && gAgent.isInGroup(mGroupID) &&
  83. gAgent.hasRegionCapability("GroupExperiences");
  84. }
  85. //static
  86. void LLPanelGroupExperiences::cacheCallback(LLHandle<LLPanelGroupExperiences> handle,
  87. const LLSD& experience)
  88. {
  89. LLPanelGroupExperiences* self = handle.get();
  90. if (self && experience.has(LLExperienceCache::EXPERIENCE_ID))
  91. {
  92. if (self->mListEmpty)
  93. {
  94. // Remove the entry containing the "no experiences" comment
  95. self->mExperiencesList->deleteAllItems();
  96. self->mListEmpty = false;
  97. }
  98. const LLUUID& id = experience[LLExperienceCache::EXPERIENCE_ID];
  99. const LLSD& name = experience[LLExperienceCache::NAME];
  100. LLScrollListItem* item = self->mExperiencesList->getItem(id);
  101. if (item)
  102. {
  103. // Update the existing entry
  104. item->getColumn(0)->setValue(name);
  105. }
  106. else
  107. {
  108. // Create a new entry
  109. LLSD entry;
  110. entry["id"] = id;
  111. LLSD& columns = entry["columns"];
  112. columns[0]["column"] = "experience_name";
  113. columns[0]["value"] = name.asString();
  114. self->mExperiencesList->addElement(entry);
  115. }
  116. }
  117. }
  118. void LLPanelGroupExperiences::addExperience(const LLUUID& id)
  119. {
  120. if (!mExperiencesList->getItem(id))
  121. {
  122. LLExperienceCache* exp = LLExperienceCache::getInstance();
  123. exp->get(id,
  124. boost::bind(&LLPanelGroupExperiences::cacheCallback,
  125. getDerivedHandle<LLPanelGroupExperiences>(), _1));
  126. }
  127. }
  128. void LLPanelGroupExperiences::setExperienceList(const LLSD& experiences)
  129. {
  130. mExperiencesList->deleteAllItems();
  131. mListEmpty = true;
  132. mExperiencesList->addCommentText(getString("no_experiences_text"));
  133. for (LLSD::array_const_iterator it = experiences.beginArray(),
  134. end = experiences.endArray();
  135. it != end; ++it)
  136. {
  137. addExperience(it->asUUID());
  138. }
  139. }
  140. //static
  141. void LLPanelGroupExperiences::onDoubleClickProfile(void* data)
  142. {
  143. LLPanelGroupExperiences* self = (LLPanelGroupExperiences*)data;
  144. if (self)
  145. {
  146. LLScrollListItem* item = self->mExperiencesList->getFirstSelected();
  147. if (item)
  148. {
  149. LLFloaterExperienceProfile::show(item->getUUID());
  150. }
  151. }
  152. }