llfloaterclassified.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**
  2. * @file llfloaterclassified.cpp
  3. * @brief Classified information as shown in a floating window from
  4. * secondlife:// command handler.
  5. *
  6. * $LicenseInfo:firstyear=2002&license=viewergpl$
  7. *
  8. * Copyright (c) 2002-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #include "llviewerprecompiledheaders.h"
  34. #include "llfloaterclassified.h"
  35. #include "lluictrlfactory.h"
  36. #include "llagent.h"
  37. #include "llcommandhandler.h"
  38. #include "llfloateravatarinfo.h"
  39. #include "llpanelclassified.h"
  40. //static
  41. LLFloaterClassifiedInfo::instances_map_t LLFloaterClassifiedInfo::sInstances;
  42. class LLClassifiedHandler final : public LLCommandHandler
  43. {
  44. public:
  45. LLClassifiedHandler()
  46. : LLCommandHandler("classified", UNTRUSTED_THROTTLE)
  47. {
  48. }
  49. bool canHandleUntrusted(const LLSD& params, const LLSD&,
  50. LLMediaCtrl*, const std::string& nav_type) override
  51. {
  52. if (!params.size())
  53. {
  54. return true; // Do not block; it will fail later in handle()
  55. }
  56. if (nav_type == "clicked" || nav_type == "external")
  57. {
  58. return true;
  59. }
  60. return params[0].asString() != "create";
  61. }
  62. bool handle(const LLSD& tokens, const LLSD&, LLMediaCtrl*) override
  63. {
  64. if (tokens.size() == 1 && tokens[0].asString() == "create")
  65. {
  66. LLFloaterAvatarInfo::showFromObject(gAgentID, "Classified");
  67. return true;
  68. }
  69. if (tokens.size() < 2)
  70. {
  71. return false;
  72. }
  73. LLUUID classified_id;
  74. if (!classified_id.set(tokens[0], false))
  75. {
  76. return false;
  77. }
  78. if (tokens[1].asString() == "about")
  79. {
  80. LLFloaterClassifiedInfo::show(classified_id);
  81. return true;
  82. }
  83. return false;
  84. }
  85. };
  86. LLClassifiedHandler gClassifiedHandler;
  87. LLFloaterClassifiedInfo::LLFloaterClassifiedInfo(const std::string& name,
  88. const LLUUID& id)
  89. : LLFloater(name),
  90. mClassifiedID(id)
  91. {
  92. mFactoryMap["classified_details_panel"] = LLCallbackMap(LLFloaterClassifiedInfo::createClassifiedDetail,
  93. this);
  94. LLUICtrlFactory::getInstance()->buildFloater(this,
  95. "floater_preview_classified.xml",
  96. &getFactoryMap());
  97. sInstances[id] = this;
  98. }
  99. //virtual
  100. LLFloaterClassifiedInfo::~LLFloaterClassifiedInfo()
  101. {
  102. // child views automatically deleted
  103. sInstances.erase(mClassifiedID);
  104. }
  105. void LLFloaterClassifiedInfo::displayClassifiedInfo(const LLUUID& classified_id)
  106. {
  107. mClassifiedPanel->setClassifiedID(classified_id);
  108. mClassifiedPanel->sendClassifiedInfoRequest();
  109. this->setFrontmost(true);
  110. }
  111. //static
  112. void* LLFloaterClassifiedInfo::createClassifiedDetail(void* userdata)
  113. {
  114. LLFloaterClassifiedInfo* self = (LLFloaterClassifiedInfo*)userdata;
  115. self->mClassifiedPanel = new LLPanelClassified(true, true);
  116. #if 0
  117. self->mClassifiedPanel->childSetValue("classified_url",
  118. self->mClassifiedID);
  119. #endif
  120. return self->mClassifiedPanel;
  121. }
  122. //static
  123. LLFloaterClassifiedInfo* LLFloaterClassifiedInfo::show(const LLUUID& classified_id)
  124. {
  125. if (classified_id.isNull())
  126. {
  127. return NULL;
  128. }
  129. LLFloaterClassifiedInfo* floater;
  130. instances_map_t::iterator it = sInstances.find(classified_id);
  131. if (it != sInstances.end())
  132. {
  133. // ...bring that window to front
  134. floater = it->second;
  135. floater->open();
  136. floater->setFrontmost(true);
  137. }
  138. else
  139. {
  140. floater = new LLFloaterClassifiedInfo("classifiedinfo", classified_id);
  141. floater->center();
  142. floater->open();
  143. floater->displayClassifiedInfo(classified_id);
  144. floater->setFrontmost(true);
  145. }
  146. return floater;
  147. }