llfloaterevent.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * @file llfloaterevent.cpp
  3. * @brief Event information as shown in a floating window from
  4. * secondlife:// command handler.
  5. *
  6. * $LicenseInfo:firstyear=2007&license=viewergpl$
  7. *
  8. * Copyright (c) 2007-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 "llfloaterevent.h"
  35. #include "lluictrlfactory.h"
  36. #include "llcommandhandler.h"
  37. #include "llpanelevent.h"
  38. ////////////////////////////////////////////////////////////////////////////
  39. // LLFloaterEventInfo
  40. //-----------------------------------------------------------------------------
  41. // Globals
  42. //-----------------------------------------------------------------------------
  43. LLFloaterEventInfo::instances_map_t LLFloaterEventInfo::sInstances;
  44. class LLEventHandler final : public LLCommandHandler
  45. {
  46. public:
  47. LLEventHandler()
  48. : LLCommandHandler("event", UNTRUSTED_THROTTLE)
  49. {
  50. }
  51. bool handle(const LLSD& tokens, const LLSD&, LLMediaCtrl*) override
  52. {
  53. if (tokens.size() < 2)
  54. {
  55. return false;
  56. }
  57. U32 event_id = tokens[0].asInteger();
  58. std::string info_type = tokens[1].asString();
  59. if (info_type == "about" || info_type == "details")
  60. {
  61. LLFloaterEventInfo::show(event_id);
  62. return true;
  63. }
  64. return false;
  65. }
  66. };
  67. LLEventHandler gEventHandler;
  68. LLFloaterEventInfo::LLFloaterEventInfo(const std::string& name, U32 event_id)
  69. : LLFloater(name),
  70. mEventID(event_id)
  71. {
  72. mFactoryMap["event_details_panel"] = LLCallbackMap(LLFloaterEventInfo::createEventDetail,
  73. this);
  74. LLUICtrlFactory::getInstance()->buildFloater(this,
  75. "floater_preview_event.xml",
  76. &getFactoryMap());
  77. sInstances[event_id] = this;
  78. }
  79. LLFloaterEventInfo::~LLFloaterEventInfo()
  80. {
  81. // child views automatically deleted
  82. sInstances.erase(mEventID);
  83. }
  84. void LLFloaterEventInfo::displayEventInfo(U32 event_id)
  85. {
  86. mPanelEventp->setEventID(event_id);
  87. this->setFrontmost(true);
  88. }
  89. // static
  90. void* LLFloaterEventInfo::createEventDetail(void* userdata)
  91. {
  92. LLFloaterEventInfo* self = (LLFloaterEventInfo*)userdata;
  93. if (!self) return NULL;
  94. self->mPanelEventp = new LLPanelEvent();
  95. LLUICtrlFactory::getInstance()->buildPanel(self->mPanelEventp,
  96. "panel_event.xml");
  97. return self->mPanelEventp;
  98. }
  99. // static
  100. LLFloaterEventInfo* LLFloaterEventInfo::show(U32 event_id)
  101. {
  102. LLFloaterEventInfo* floater;
  103. instances_map_t::iterator it = sInstances.find(event_id);
  104. if (it != sInstances.end())
  105. {
  106. // ...bring that window to front
  107. floater = it->second;
  108. floater->open();
  109. floater->setFrontmost(true);
  110. }
  111. else
  112. {
  113. floater = new LLFloaterEventInfo("eventinfo", event_id);
  114. floater->center();
  115. floater->open();
  116. floater->displayEventInfo(event_id);
  117. floater->setFrontmost(true);
  118. }
  119. return floater;
  120. }