llpanelexperiencelog.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /**
  2. * @file llpanelexperiencelog.cpp
  3. * @brief LLPanelExperienceLog class
  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 "llpanelexperiencelog.h"
  34. #include "llbutton.h"
  35. #include "llcheckboxctrl.h"
  36. #include "llcombobox.h"
  37. #include "llexperiencecache.h"
  38. #include "llscrolllistctrl.h"
  39. #include "llspinctrl.h"
  40. #include "lluictrlfactory.h"
  41. #include "llexperiencelog.h"
  42. #include "llfloaterexperienceprofile.h"
  43. #include "llfloaterreporter.h"
  44. LLPanelExperienceLog::LLPanelExperienceLog()
  45. : mPageSize(25),
  46. mCurrentPage(0)
  47. {
  48. LLUICtrlFactory::getInstance()->buildPanel(this,
  49. "panel_experience_log.xml");
  50. }
  51. bool LLPanelExperienceLog::postBuild()
  52. {
  53. mEventList = getChild<LLScrollListCtrl>("experience_log_list");
  54. mEventList->setCommitCallback(onSelectionChanged);
  55. mEventList->setDoubleClickCallback(onProfileExperience);
  56. mEventList->setCallbackUserData(this);
  57. mClearBtn = getChild<LLButton>("btn_clear");
  58. mClearBtn->setClickedCallback(onClear, this);
  59. mProfileBtn = getChild<LLButton>("btn_profile_xp");
  60. mProfileBtn->setClickedCallback(onProfileExperience, this);
  61. mReportBtn = getChild<LLButton>("btn_report_xp");
  62. mReportBtn->setClickedCallback(onReportExperience, this);
  63. mNotifyBtn = getChild<LLButton>("btn_notify");
  64. mNotifyBtn->setClickedCallback(onNotify, this);
  65. mNextBtn = getChild<LLButton>("btn_next");
  66. mNextBtn->setClickedCallback(onNext, this);
  67. mPrevBtn = getChild<LLButton>("btn_prev");
  68. mPrevBtn->setClickedCallback(onPrev, this);
  69. LLExperienceLog* log = LLExperienceLog::getInstance();
  70. mNotifyAllCheck = getChild<LLCheckBoxCtrl>("notify_all");
  71. mNotifyAllCheck->set(log->getNotifyNewEvent());
  72. mNotifyAllCheck->setCommitCallback(onNotifyChanged);
  73. mNotifyAllCheck->setCallbackUserData(this);
  74. mLogSizeSpin = getChild<LLSpinCtrl>("logsizespinner");
  75. mLogSizeSpin->set(log->getMaxDays());
  76. mLogSizeSpin->setCommitCallback(onLogSizeChanged);
  77. mLogSizeSpin->setCallbackUserData(this);
  78. mPageSize = log->getPageSize();
  79. mNewEvent = log->addUpdateSignal(boost::bind(&LLPanelExperienceLog::refresh,
  80. this));
  81. refresh();
  82. return true;
  83. }
  84. LLPanelExperienceLog* LLPanelExperienceLog::create()
  85. {
  86. return new LLPanelExperienceLog();
  87. }
  88. void LLPanelExperienceLog::refresh()
  89. {
  90. S32 selected = mEventList->getFirstSelectedIndex();
  91. mEventList->deleteAllItems();
  92. LLExperienceLog* log = LLExperienceLog::getInstance();
  93. const LLSD events = log->getEvents();
  94. if (events.size() == 0)
  95. {
  96. mEventList->addCommentText(getString("no_events"));
  97. return;
  98. }
  99. setAllChildrenEnabled(false);
  100. LLSD item;
  101. bool waiting = false;
  102. LLUUID waiting_id;
  103. S32 to_skip = mPageSize * mCurrentPage;
  104. S32 items = 0;
  105. bool more_items = false;
  106. LLSD events_to_save = events;
  107. LLExperienceCache* expcache = LLExperienceCache::getInstance();
  108. if (events.size() && events.isMap())
  109. {
  110. LLSD::map_const_iterator day = events.endMap();
  111. do
  112. {
  113. --day;
  114. const LLSD& day_array = day->second;
  115. std::string date = day->first;
  116. if (!log->isNotExpired(date))
  117. {
  118. events_to_save.erase(day->first);
  119. continue;
  120. }
  121. S32 size = day_array.size();
  122. if (to_skip > size)
  123. {
  124. to_skip -= size;
  125. continue;
  126. }
  127. if (items >= mPageSize && size > 0)
  128. {
  129. more_items = true;
  130. break;
  131. }
  132. for (S32 i = day_array.size() - to_skip - 1; i >= 0; --i)
  133. {
  134. if (items >= mPageSize)
  135. {
  136. more_items = true;
  137. break;
  138. }
  139. LLSD event = day_array[i];
  140. LLUUID id = event[LLExperienceCache::EXPERIENCE_ID].asUUID();
  141. const LLSD& experience = expcache->get(id);
  142. if (experience.isUndefined())
  143. {
  144. waiting = true;
  145. waiting_id = id;
  146. }
  147. if (!waiting)
  148. {
  149. std::string name = experience[LLExperienceCache::NAME].asString();
  150. if (!name.empty())
  151. {
  152. event["ExpName"] = name;
  153. }
  154. item["id"] = event;
  155. LLSD& columns = item["columns"];
  156. columns[0]["column"] = "time";
  157. columns[0]["value"] = day->first +
  158. event["Time"].asString();
  159. columns[1]["column"] = "event";
  160. columns[1]["value"] = LLExperienceLog::getPermissionString(event,
  161. "ExperiencePermissionShort");
  162. columns[2]["column"] = "experience_name";
  163. columns[2]["value"] = name;
  164. columns[3]["column"] = "object_name";
  165. columns[3]["value"] = event["ObjectName"].asString();
  166. mEventList->addElement(item);
  167. }
  168. ++items;
  169. }
  170. }
  171. while (day != events.beginMap());
  172. }
  173. log->setEventsToSave(events_to_save);
  174. if (waiting)
  175. {
  176. mEventList->deleteAllItems();
  177. mEventList->addCommentText(getString("no_events"));
  178. expcache->get(waiting_id,
  179. boost::bind(&LLPanelExperienceLog::refresh, this));
  180. }
  181. else
  182. {
  183. setAllChildrenEnabled(true);
  184. mEventList->setEnabled(true);
  185. mNextBtn->setEnabled(more_items);
  186. mPrevBtn->setEnabled(mCurrentPage > 0);
  187. mClearBtn->setEnabled(mEventList->getItemCount() > 0);
  188. if (selected < 0)
  189. {
  190. selected = 0;
  191. }
  192. mEventList->selectNthItem(selected);
  193. onSelectionChanged(mEventList, this);
  194. }
  195. }
  196. LLSD LLPanelExperienceLog::getSelectedEvent()
  197. {
  198. LLScrollListItem* item = mEventList->getFirstSelected();
  199. if (item)
  200. {
  201. return item->getValue();
  202. }
  203. return LLSD();
  204. }
  205. //static
  206. void LLPanelExperienceLog::onProfileExperience(void* data)
  207. {
  208. LLPanelExperienceLog* self = (LLPanelExperienceLog*)data;
  209. if (self)
  210. {
  211. LLSD event = self->getSelectedEvent();
  212. if (event.isDefined())
  213. {
  214. const LLUUID& id = event[LLExperienceCache::EXPERIENCE_ID].asUUID();
  215. LLFloaterExperienceProfile::show(id);
  216. }
  217. }
  218. }
  219. //static
  220. void LLPanelExperienceLog::onClear(void* data)
  221. {
  222. LLPanelExperienceLog* self = (LLPanelExperienceLog*)data;
  223. if (self)
  224. {
  225. LLExperienceLog::getInstance()->clear();
  226. self->refresh();
  227. }
  228. }
  229. //static
  230. void LLPanelExperienceLog::onReportExperience(void* data)
  231. {
  232. LLPanelExperienceLog* self = (LLPanelExperienceLog*)data;
  233. if (self)
  234. {
  235. LLSD event = self->getSelectedEvent();
  236. if (event.isDefined())
  237. {
  238. const LLUUID& id = event[LLExperienceCache::EXPERIENCE_ID].asUUID();
  239. LLFloaterReporter::showFromExperience(id);
  240. }
  241. }
  242. }
  243. //static
  244. void LLPanelExperienceLog::onNotify(void* data)
  245. {
  246. LLPanelExperienceLog* self = (LLPanelExperienceLog*)data;
  247. if (self)
  248. {
  249. LLSD event = self->getSelectedEvent();
  250. if (event.isDefined())
  251. {
  252. LLExperienceLog::getInstance()->notify(event);
  253. }
  254. }
  255. }
  256. //static
  257. void LLPanelExperienceLog::onNext(void* data)
  258. {
  259. LLPanelExperienceLog* self = (LLPanelExperienceLog*)data;
  260. if (self)
  261. {
  262. self->mCurrentPage++;
  263. self->refresh();
  264. }
  265. }
  266. //static
  267. void LLPanelExperienceLog::onPrev(void* data)
  268. {
  269. LLPanelExperienceLog* self = (LLPanelExperienceLog*)data;
  270. if (self)
  271. {
  272. self->mCurrentPage--;
  273. self->refresh();
  274. }
  275. }
  276. //static
  277. void LLPanelExperienceLog::onNotifyChanged(LLUICtrl* ctrl, void* data)
  278. {
  279. LLPanelExperienceLog* self = (LLPanelExperienceLog*)data;
  280. if (self)
  281. {
  282. bool notify = self->mNotifyAllCheck->get();
  283. LLExperienceLog::getInstance()->setNotifyNewEvent(notify);
  284. }
  285. }
  286. //static
  287. void LLPanelExperienceLog::onLogSizeChanged(LLUICtrl* ctrl, void* data)
  288. {
  289. LLPanelExperienceLog* self = (LLPanelExperienceLog*)data;
  290. if (self)
  291. {
  292. U32 value = (U32)self->mLogSizeSpin->get();
  293. LLExperienceLog::getInstance()->setMaxDays(value);
  294. self->refresh();
  295. }
  296. }
  297. //static
  298. void LLPanelExperienceLog::onSelectionChanged(LLUICtrl* ctrl, void* data)
  299. {
  300. LLPanelExperienceLog* self = (LLPanelExperienceLog*)data;
  301. if (self)
  302. {
  303. bool enabled = self->mEventList->getNumSelected() == 1;
  304. self->mReportBtn->setEnabled(enabled);
  305. self->mProfileBtn->setEnabled(enabled);
  306. self->mNotifyBtn->setEnabled(enabled);
  307. }
  308. }