llpanelevent.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /**
  2. * @file llpanelevent.cpp
  3. * @brief Display for events in the finder
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright (c) 2004-2009, 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 "llpanelevent.h"
  34. #include "llbutton.h"
  35. #include "llcachename.h"
  36. #include "llfloater.h"
  37. #include "lltextbox.h"
  38. #include "lluictrlfactory.h"
  39. #include "llmessage.h"
  40. #include "llagent.h"
  41. #include "lleventnotifier.h"
  42. #include "llfloaterworldmap.h"
  43. #include "llgridmanager.h"
  44. #include "llinventorymodel.h"
  45. #include "llviewercontrol.h"
  46. #include "llviewertexteditor.h"
  47. #include "llweb.h"
  48. #include "llworldmap.h"
  49. //static
  50. std::list<LLPanelEvent*> LLPanelEvent::sInstances;
  51. LLPanelEvent::LLPanelEvent()
  52. : LLPanel("Event Panel")
  53. {
  54. sInstances.push_back(this);
  55. }
  56. //virtual
  57. LLPanelEvent::~LLPanelEvent()
  58. {
  59. sInstances.remove(this);
  60. }
  61. //virtual
  62. bool LLPanelEvent::postBuild()
  63. {
  64. mTBName = getChild<LLTextBox>("event_name");
  65. mTBCategory = getChild<LLTextBox>("event_category");
  66. mTBDate = getChild<LLTextBox>("event_date");
  67. mTBDuration = getChild<LLTextBox>("event_duration");
  68. mTBDesc = getChild<LLTextEditor>("event_desc");
  69. mTBDesc->setWordWrap(true);
  70. mTBDesc->setEnabled(false);
  71. mTBRunBy = getChild<LLTextBox>("event_runby");
  72. mTBLocation = getChild<LLTextBox>("event_location");
  73. mTBCover = getChild<LLTextBox>("event_cover");
  74. mTeleportBtn = getChild<LLButton>( "teleport_btn");
  75. mTeleportBtn->setClickedCallback(onClickTeleport);
  76. mTeleportBtn->setCallbackUserData(this);
  77. mMapBtn = getChild<LLButton>( "map_btn");
  78. mMapBtn->setClickedCallback(onClickMap);
  79. mMapBtn->setCallbackUserData(this);
  80. mNotifyBtn = getChild<LLButton>( "notify_btn");
  81. mNotifyBtn->setClickedCallback(onClickNotify);
  82. mNotifyBtn->setCallbackUserData(this);
  83. mCreateEventBtn = getChild<LLButton>( "create_event_btn");
  84. mCreateEventBtn->setClickedCallback(onClickCreateEvent);
  85. mCreateEventBtn->setCallbackUserData(this);
  86. return true;
  87. }
  88. void LLPanelEvent::setEventID(U32 event_id)
  89. {
  90. mEventID = event_id;
  91. // Should reset all of the panel state here
  92. resetInfo();
  93. if (event_id != 0)
  94. {
  95. sendEventInfoRequest();
  96. }
  97. }
  98. void LLPanelEvent::sendEventInfoRequest()
  99. {
  100. LLMessageSystem* msg = gMessageSystemp;
  101. msg->newMessageFast(_PREHASH_EventInfoRequest);
  102. msg->nextBlockFast(_PREHASH_AgentData);
  103. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  104. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  105. msg->nextBlockFast(_PREHASH_EventData);
  106. msg->addU32Fast(_PREHASH_EventID, mEventID);
  107. gAgent.sendReliableMessage();
  108. }
  109. //static
  110. void LLPanelEvent::processEventInfoReply(LLMessageSystem* msg, void**)
  111. {
  112. // extract the agent id
  113. LLUUID agent_id;
  114. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id );
  115. U32 event_id;
  116. msg->getU32("EventData", "EventID", event_id);
  117. // look up all panels which have this avatar
  118. for (panel_list_t::iterator iter = sInstances.begin();
  119. iter != sInstances.end(); ++iter)
  120. {
  121. LLPanelEvent* self = *iter;
  122. // Skip updating panels which aren't for this event
  123. if (self->mEventID != event_id)
  124. {
  125. continue;
  126. }
  127. self->mEventInfo.unpack(msg);
  128. self->mTBName->setText(self->mEventInfo.mName);
  129. self->mTBCategory->setText(self->mEventInfo.mCategoryStr);
  130. self->mTBDate->setText(self->mEventInfo.mTimeStr);
  131. self->mTBDesc->setText(self->mEventInfo.mDesc);
  132. self->mTBDuration->setText(llformat("%d:%.2d",
  133. self->mEventInfo.mDuration / 60,
  134. self->mEventInfo.mDuration % 60));
  135. if (!self->mEventInfo.mHasCover)
  136. {
  137. self->mTBCover->setText(self->getString("none"));
  138. }
  139. else
  140. {
  141. self->mTBCover->setText(llformat("%d", self->mEventInfo.mCover));
  142. }
  143. F32 global_x = (F32)self->mEventInfo.mPosGlobal.mdV[VX];
  144. F32 global_y = (F32)self->mEventInfo.mPosGlobal.mdV[VY];
  145. S32 region_x = ll_roundp(global_x) % REGION_WIDTH_UNITS;
  146. S32 region_y = ll_roundp(global_y) % REGION_WIDTH_UNITS;
  147. S32 region_z = ll_roundp((F32)self->mEventInfo.mPosGlobal.mdV[VZ]);
  148. std::string desc = self->mEventInfo.mSimName +
  149. llformat(" (%d, %d, %d)", region_x, region_y,
  150. region_z);
  151. self->mTBLocation->setText(desc);
  152. if (self->mEventInfo.mEventFlags & EVENT_FLAG_MATURE)
  153. {
  154. self->childSetVisible("event_mature_yes", true);
  155. self->childSetVisible("event_mature_no", false);
  156. }
  157. else
  158. {
  159. self->childSetVisible("event_mature_yes", false);
  160. self->childSetVisible("event_mature_no", true);
  161. }
  162. if (self->mEventInfo.mUnixTime < time_corrected())
  163. {
  164. self->mNotifyBtn->setEnabled(false);
  165. }
  166. else
  167. {
  168. self->mNotifyBtn->setEnabled(true);
  169. }
  170. if (gEventNotifier.hasNotification(self->mEventInfo.mID))
  171. {
  172. self->mNotifyBtn->setLabel(self->getString("dont_notify"));
  173. }
  174. else
  175. {
  176. self->mNotifyBtn->setLabel(self->getString("notify"));
  177. }
  178. }
  179. }
  180. //virtual
  181. void LLPanelEvent::draw()
  182. {
  183. if (mLastOwnerId != mEventInfo.mRunByID && gCacheNamep)
  184. {
  185. mLastOwnerId = mEventInfo.mRunByID;
  186. std::string name;
  187. gCacheNamep->getFullName(mLastOwnerId, name);
  188. mTBRunBy->setText(name);
  189. }
  190. LLPanel::draw();
  191. }
  192. void LLPanelEvent::resetInfo()
  193. {
  194. // Clear all of the text fields.
  195. }
  196. //static
  197. void LLPanelEvent::onClickTeleport(void* data)
  198. {
  199. LLPanelEvent* self = (LLPanelEvent*)data;
  200. if (!self->mEventInfo.mPosGlobal.isExactlyZero())
  201. {
  202. gAgent.teleportViaLocation(self->mEventInfo.mPosGlobal);
  203. if (gFloaterWorldMapp)
  204. {
  205. gFloaterWorldMapp->trackLocation(self->mEventInfo.mPosGlobal);
  206. }
  207. }
  208. }
  209. //static
  210. void LLPanelEvent::onClickMap(void* data)
  211. {
  212. LLPanelEvent* self = (LLPanelEvent*)data;
  213. if (!self->mEventInfo.mPosGlobal.isExactlyZero() && gFloaterWorldMapp)
  214. {
  215. gFloaterWorldMapp->trackLocation(self->mEventInfo.mPosGlobal);
  216. LLFloaterWorldMap::show(NULL, true);
  217. }
  218. }
  219. #if 0
  220. //static
  221. void LLPanelEvent::onClickLandmark(void* data)
  222. {
  223. LLPanelEvent* self = (LLPanelEvent*)data;
  224. # if 0
  225. create_landmark(self->mTBName->getText(), "", self->mEventInfo.mPosGlobal);
  226. # endif
  227. LLMessageSystem* msg = gMessageSystemp;
  228. msg->newMessage("CreateLandmarkForEvent");
  229. msg->nextBlockFast(_PREHASH_AgentData);
  230. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  231. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  232. msg->nextBlockFast(_PREHASH_EventData);
  233. msg->addU32Fast(_PREHASH_EventID, self->mEventID);
  234. msg->nextBlockFast(_PREHASH_InventoryBlock);
  235. LLUUID folder_id;
  236. folder_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_LANDMARK);
  237. msg->addUUIDFast(_PREHASH_FolderID, folder_id);
  238. msg->addStringFast(_PREHASH_Name, self->mTBName->getText());
  239. gAgent.sendReliableMessage();
  240. }
  241. #endif
  242. //static
  243. void LLPanelEvent::onClickCreateEvent(void* data)
  244. {
  245. gNotifications.add("PromptGoToEventsPage", LLSD(), LLSD(),
  246. callbackCreateEventWebPage);
  247. }
  248. //static
  249. void LLPanelEvent::onClickNotify(void *data)
  250. {
  251. LLPanelEvent* self = (LLPanelEvent*)data;
  252. if (!gEventNotifier.hasNotification(self->mEventID))
  253. {
  254. gEventNotifier.add(self->mEventInfo);
  255. self->mNotifyBtn->setLabel(self->getString("dont_notify"));
  256. }
  257. else
  258. {
  259. gEventNotifier.remove(self->mEventInfo.mID);
  260. self->mNotifyBtn->setLabel(self->getString("notify"));
  261. }
  262. }
  263. //static
  264. bool LLPanelEvent::callbackCreateEventWebPage(const LLSD& notification,
  265. const LLSD& response)
  266. {
  267. if (LLNotification::getSelectedOption(notification, response) == 0)
  268. {
  269. llinfos << "Loading events page " << EVENTS_URL << llendl;
  270. LLWeb::loadURL(EVENTS_URL);
  271. }
  272. return false;
  273. }