llpaneldirevents.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /**
  2. * @file llpaneldirevents.cpp
  3. * @brief Events listing in the Find directory.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-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 <sstream>
  34. #include "llpaneldirevents.h"
  35. #include "llbutton.h"
  36. #include "llcheckboxctrl.h"
  37. #include "llnotifications.h"
  38. #include "llqueryflags.h"
  39. #include "llmessage.h"
  40. #include "llagent.h"
  41. #include "llappviewer.h"
  42. #include "llgridmanager.h"
  43. #include "llpaneldirbrowser.h"
  44. #include "llpanelevent.h"
  45. #include "llviewercontrol.h"
  46. bool gDisplayEventHack = false;
  47. // Helper function
  48. static std::string get_event_date(S32 relative_day)
  49. {
  50. // Get time UTC
  51. time_t utc_time = time_corrected();
  52. // Correct for offset
  53. constexpr S32 SECONDS_PER_DAY = 24 * 60 * 60;
  54. utc_time += relative_day * SECONDS_PER_DAY;
  55. return LLGridManager::getTimeStamp(utc_time, "%m-%d", false);
  56. }
  57. LLPanelDirEvents::LLPanelDirEvents(const std::string& name,
  58. HBFloaterSearch* floater)
  59. : LLPanelDirBrowser(name, floater),
  60. mDoneQuery(false),
  61. mDay(0)
  62. {
  63. // More results per page for this
  64. mResultsPerPage = 200;
  65. }
  66. //virtual
  67. bool LLPanelDirEvents::postBuild()
  68. {
  69. LLPanelDirBrowser::postBuild();
  70. childSetCommitCallback("date_mode", onDateModeCallback, this);
  71. childSetAction("<<", onBackBtn, this);
  72. childSetAction(">>", onForwardBtn, this);
  73. childSetAction("Today", onClickToday, this);
  74. childSetAction("search_btn", onClickSearchCore, this);
  75. setDefaultBtn("search_btn");
  76. mDeleteButton = getChild<LLButton>("Delete");
  77. mDeleteButton->setClickedCallback(onClickDelete, this);
  78. mDeleteButton->setEnabled(false);
  79. mDeleteButton->setVisible(false);
  80. onDateModeCallback(NULL, this);
  81. mCurrentSortColumn = "time";
  82. if (!gDisplayEventHack)
  83. {
  84. setDay(0); // For today
  85. }
  86. gDisplayEventHack = false;
  87. return true;
  88. }
  89. //virtual
  90. void LLPanelDirEvents::draw()
  91. {
  92. refresh();
  93. LLPanelDirBrowser::draw();
  94. }
  95. //virtual
  96. void LLPanelDirEvents::refresh()
  97. {
  98. bool godlike = gAgent.isGodlike();
  99. mDeleteButton->setEnabled(godlike);
  100. mDeleteButton->setVisible(godlike);
  101. updateMaturityCheckbox();
  102. }
  103. void LLPanelDirEvents::setDay(S32 day)
  104. {
  105. mDay = day;
  106. childSetValue("date_text", get_event_date(day));
  107. }
  108. //virtual
  109. void LLPanelDirEvents::performQuery()
  110. {
  111. // event_id 0 will perform no delete action.
  112. performQueryOrDelete(0);
  113. }
  114. void LLPanelDirEvents::performQueryOrDelete(U32 event_id)
  115. {
  116. childSetValue("date_text", get_event_date(mDay));
  117. mDoneQuery = true;
  118. bool inc_pg = !mIncPGCheck || mIncPGCheck->getValue().asBoolean();
  119. bool inc_mature = mIncMatureCheck &&
  120. mIncMatureCheck->getValue().asBoolean();
  121. bool inc_adult = mIncAdultCheck && mIncAdultCheck->getValue().asBoolean();
  122. U32 scope = DFQ_DATE_EVENTS;
  123. if (gAgent.wantsPGOnly()) scope |= DFQ_PG_SIMS_ONLY;
  124. if (inc_pg) scope |= DFQ_INC_PG;
  125. if (inc_mature) scope |= DFQ_INC_MATURE;
  126. if (inc_adult) scope |= DFQ_INC_ADULT;
  127. // Add old query flags in case we are talking to an old server
  128. if (inc_pg && !inc_mature)
  129. {
  130. scope |= DFQ_PG_EVENTS_ONLY;
  131. }
  132. if (!(scope & (DFQ_INC_PG | DFQ_INC_MATURE | DFQ_INC_ADULT)))
  133. {
  134. gNotifications.add("NoContentToSearch");
  135. return;
  136. }
  137. setupNewSearch();
  138. std::ostringstream params;
  139. // Date mode for the search
  140. if ("current" == childGetValue("date_mode").asString())
  141. {
  142. params << "u|";
  143. }
  144. else
  145. {
  146. params << mDay << "|";
  147. }
  148. // Categories are stored in the database in table indra.event_category
  149. // XML must match.
  150. U32 cat_id = childGetValue("category combo").asInteger();
  151. params << cat_id << "|";
  152. params << childGetValue("search_text").asString();
  153. // send the message
  154. LLMessageSystem* msg = gMessageSystemp;
  155. if (event_id == 0)
  156. {
  157. sendDirFindQuery(msg, mSearchID, params.str(), scope, mSearchStart);
  158. }
  159. else
  160. {
  161. // This delete will also perform a query.
  162. msg->newMessageFast(_PREHASH_EventGodDelete);
  163. msg->nextBlockFast(_PREHASH_AgentData);
  164. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  165. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  166. msg->nextBlockFast(_PREHASH_EventData);
  167. msg->addU32Fast(_PREHASH_EventID, event_id);
  168. msg->nextBlockFast(_PREHASH_QueryData);
  169. msg->addUUIDFast(_PREHASH_QueryID, mSearchID);
  170. msg->addStringFast(_PREHASH_QueryText, params.str());
  171. msg->addU32Fast(_PREHASH_QueryFlags, scope);
  172. msg->addS32Fast(_PREHASH_QueryStart, mSearchStart);
  173. gAgent.sendReliableMessage();
  174. }
  175. }
  176. //static
  177. void LLPanelDirEvents::onDateModeCallback(LLUICtrl* ctrl, void* data)
  178. {
  179. LLPanelDirEvents* self = (LLPanelDirEvents*)data;
  180. if (!self) return;
  181. if (self->childGetValue("date_mode").asString() == "date")
  182. {
  183. self->childEnable("Today");
  184. self->childEnable(">>");
  185. self->childEnable("<<");
  186. }
  187. else
  188. {
  189. self->childDisable("Today");
  190. self->childDisable(">>");
  191. self->childDisable("<<");
  192. }
  193. }
  194. //static
  195. void LLPanelDirEvents::onClickToday(void* data)
  196. {
  197. LLPanelDirEvents* self = (LLPanelDirEvents*)data;
  198. if (self)
  199. {
  200. self->resetSearchStart();
  201. self->setDay(0);
  202. self->performQuery();
  203. }
  204. }
  205. //static
  206. void LLPanelDirEvents::onBackBtn(void* data)
  207. {
  208. LLPanelDirEvents* self = (LLPanelDirEvents*)data;
  209. if (self)
  210. {
  211. self->resetSearchStart();
  212. self->setDay(self->mDay - 1);
  213. self->performQuery();
  214. }
  215. }
  216. //static
  217. void LLPanelDirEvents::onForwardBtn(void* data)
  218. {
  219. LLPanelDirEvents* self = (LLPanelDirEvents*)data;
  220. if (self)
  221. {
  222. self->resetSearchStart();
  223. self->setDay(self->mDay + 1);
  224. self->performQuery();
  225. }
  226. }
  227. //static
  228. void LLPanelDirEvents::onClickDelete(void* data)
  229. {
  230. LLPanelDirEvents* self = (LLPanelDirEvents*)data;
  231. if (self)
  232. {
  233. U32 event_id = self->getSelectedEventID();
  234. if (event_id)
  235. {
  236. self->performQueryOrDelete(event_id);
  237. }
  238. }
  239. }