llfloaternotificationsconsole.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /**
  2. * @file llnotificationsconsole.cpp
  3. * @brief Debugging console for unified notifications.
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Copyright (c) 2003-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. // Work-around for a spurious and bogus "LLNotificationChannelPtr( ... _1) may
  34. // be used uninitialized" warning with new GCC versions (v11+ at least). HB
  35. #if LL_GNUC
  36. # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
  37. #endif
  38. #include "llfloaternotificationsconsole.h"
  39. #include "llbutton.h"
  40. #include "llcombobox.h"
  41. #include "llnotifications.h"
  42. #include "llpanel.h"
  43. #include "llscrolllistctrl.h"
  44. #include "lluictrlfactory.h"
  45. #include "llviewertexteditor.h"
  46. constexpr S32 NOTIFICATION_PANEL_HEADER_HEIGHT = 20;
  47. constexpr S32 HEADER_PADDING = 38;
  48. ///////////////////////////////////////////////////////////////////////////////
  49. // LLNotificationChannelPanel class
  50. ///////////////////////////////////////////////////////////////////////////////
  51. class LLNotificationChannelPanel : public LLPanel
  52. {
  53. public:
  54. LLNotificationChannelPanel(const std::string& channel_name);
  55. ~LLNotificationChannelPanel();
  56. bool postBuild();
  57. private:
  58. bool update(const LLSD& payload, bool passed_filter);
  59. static void toggleClick(void* user_data);
  60. static void onClickNotification(void* user_data);
  61. static void onClickNotificationReject(void* user_data);
  62. private:
  63. LLNotificationChannelPtr mChannelPtr;
  64. LLNotificationChannelPtr mChannelRejectsPtr;
  65. LLScrollListCtrl* mNotifList;
  66. LLScrollListCtrl* mNotifRejectsList;
  67. };
  68. LLNotificationChannelPanel::LLNotificationChannelPanel(const std::string& channel_name)
  69. : LLPanel(channel_name),
  70. mNotifList(NULL),
  71. mNotifRejectsList(NULL)
  72. {
  73. mChannelPtr = gNotifications.getChannel(channel_name);
  74. mChannelRejectsPtr =
  75. LLNotificationChannelPtr(LLNotificationChannel::buildChannel(channel_name + "rejects",
  76. mChannelPtr->getParentChannelName(),
  77. !boost::bind(mChannelPtr->getFilter(),
  78. _1)));
  79. LLUICtrlFactory::getInstance()->buildPanel(this,
  80. "panel_notifications_channel.xml");
  81. }
  82. LLNotificationChannelPanel::~LLNotificationChannelPanel()
  83. {
  84. // Userdata for all records is a LLNotification* we need to clean up
  85. std::vector<LLScrollListItem*> data_list = mNotifList->getAllData();
  86. for (std::vector<LLScrollListItem*>::iterator it = data_list.begin(),
  87. end = data_list.end();
  88. it != end; ++it)
  89. {
  90. LLScrollListItem* item = *it;
  91. LLNotification* notif = (LLNotification*)item->getUserdata();
  92. delete notif;
  93. notif = NULL;
  94. }
  95. }
  96. bool LLNotificationChannelPanel::postBuild()
  97. {
  98. LLButton* header_button = getChild<LLButton>("header");
  99. header_button->setLabel(mChannelPtr->getName());
  100. header_button->setClickedCallback(toggleClick, this);
  101. mChannelPtr->connectChanged(boost::bind(&LLNotificationChannelPanel::update,
  102. this, _1, true));
  103. mChannelRejectsPtr->connectChanged(boost::bind(&LLNotificationChannelPanel::update,
  104. this, _1, false));
  105. mNotifList = getChild<LLScrollListCtrl>("notifications_list");
  106. mNotifList->setDoubleClickCallback(onClickNotification);
  107. mNotifList->setCallbackUserData(this);
  108. mNotifRejectsList = getChild<LLScrollListCtrl>("notification_rejects_list");
  109. mNotifRejectsList->setDoubleClickCallback(onClickNotificationReject);
  110. mNotifRejectsList->setCallbackUserData(this);
  111. return true;
  112. }
  113. //static
  114. void LLNotificationChannelPanel::toggleClick(void* user_data)
  115. {
  116. LLNotificationChannelPanel* self = (LLNotificationChannelPanel*)user_data;
  117. if (!self) return;
  118. LLButton* buttonp = self->getChild<LLButton>("header");
  119. bool state = buttonp->getToggleState();
  120. LLLayoutStack* stackp = dynamic_cast<LLLayoutStack*>(self->getParent());
  121. if (stackp)
  122. {
  123. stackp->collapsePanel(self, state);
  124. }
  125. // Turn off tab stop for collapsed panel
  126. self->mNotifList->setTabStop(!state);
  127. self->mNotifList->setVisible(!state);
  128. self->mNotifRejectsList->setTabStop(!state);
  129. self->mNotifRejectsList->setVisible(!state);
  130. }
  131. //static
  132. void LLNotificationChannelPanel::onClickNotification(void* user_data)
  133. {
  134. LLNotificationChannelPanel* self = (LLNotificationChannelPanel*)user_data;
  135. if (!self || !gFloaterViewp) return;
  136. LLScrollListCtrl* listp = self->mNotifList;
  137. if (!listp || !listp->getFirstSelected()) return;
  138. LLNotification* notifp =
  139. (LLNotification*)listp->getFirstSelected()->getUserdata();
  140. if (!notifp) return;
  141. LLFloaterNotification* childp = new LLFloaterNotification(notifp);
  142. if (childp)
  143. {
  144. LLFloater* parentp = gFloaterViewp->getParentFloater(self);
  145. if (parentp)
  146. {
  147. parentp->addDependentFloater(childp);
  148. }
  149. }
  150. }
  151. //static
  152. void LLNotificationChannelPanel::onClickNotificationReject(void* user_data)
  153. {
  154. LLNotificationChannelPanel* self = (LLNotificationChannelPanel*)user_data;
  155. if (!self) return;
  156. LLScrollListCtrl* list = self->mNotifRejectsList;
  157. if (!list || !list->getFirstSelected()) return;
  158. void* data = list->getFirstSelected()->getUserdata();
  159. if (!data) return;
  160. LLFloaterNotification* childp;
  161. childp = new LLFloaterNotification((LLNotification*)data);
  162. if (childp && gFloaterViewp)
  163. {
  164. LLFloater* parentp = gFloaterViewp->getParentFloater(self);
  165. if (parentp)
  166. {
  167. parentp->addDependentFloater(childp);
  168. }
  169. }
  170. }
  171. bool LLNotificationChannelPanel::update(const LLSD& payload,
  172. bool passed_filter)
  173. {
  174. LLNotificationPtr notification = gNotifications.find(payload["id"].asUUID());
  175. if (notification)
  176. {
  177. LLSD row;
  178. row["columns"][0]["value"] = notification->getName();
  179. row["columns"][0]["column"] = "name";
  180. row["columns"][1]["value"] = notification->getMessage();
  181. row["columns"][1]["column"] = "content";
  182. row["columns"][2]["value"] = notification->getDate();
  183. row["columns"][2]["column"] = "date";
  184. row["columns"][2]["type"] = "date";
  185. LLScrollListItem* sli = passed_filter ?
  186. getChild<LLScrollListCtrl>("notifications_list")->addElement(row) :
  187. getChild<LLScrollListCtrl>("notification_rejects_list")->addElement(row);
  188. sli->setUserdata(new LLNotification(notification->asLLSD()));
  189. }
  190. return false;
  191. }
  192. ///////////////////////////////////////////////////////////////////////////////
  193. // LLFloaterNotificationConsole class
  194. ///////////////////////////////////////////////////////////////////////////////
  195. LLFloaterNotificationConsole::LLFloaterNotificationConsole(const LLSD& key)
  196. {
  197. LLUICtrlFactory::getInstance()->buildFloater(this,
  198. "floater_notifications_console.xml");
  199. }
  200. void LLFloaterNotificationConsole::onClose(bool app_quitting)
  201. {
  202. setVisible(false);
  203. }
  204. bool LLFloaterNotificationConsole::postBuild()
  205. {
  206. mLayoutStack = getChild<LLLayoutStack>("notification_channels");
  207. // These are in the order of processing
  208. addChannel("Unexpired");
  209. addChannel("Ignore");
  210. addChannel("Visible", true);
  211. // All the ones below attach to the Visible channel
  212. addChannel("History");
  213. addChannel("Alerts");
  214. addChannel("AlertModal");
  215. addChannel("Group Notifications");
  216. addChannel("Notifications");
  217. addChannel("NotificationTips");
  218. LLButton* buttonp = getChild<LLButton>("add_notification");
  219. buttonp->setClickedCallback(onClickAdd, this);
  220. mNotifTypesCombo = getChild<LLComboBox>("notification_types");
  221. LLNotifications::TemplateNames names = gNotifications.getTemplateNames();
  222. for (LLNotifications::TemplateNames::iterator it = names.begin(),
  223. end = names.end();
  224. it != end; ++it)
  225. {
  226. mNotifTypesCombo->add(*it);
  227. }
  228. mNotifTypesCombo->sortByName();
  229. return true;
  230. }
  231. void LLFloaterNotificationConsole::addChannel(const std::string& name,
  232. bool open)
  233. {
  234. LLNotificationChannelPanel* panelp = new LLNotificationChannelPanel(name);
  235. mLayoutStack->addPanel(panelp, 0, NOTIFICATION_PANEL_HEADER_HEIGHT, true,
  236. true, LLLayoutStack::ANIMATE);
  237. LLButton* buttonp = panelp->getChild<LLButton>("header");
  238. buttonp->setToggleState(!open);
  239. mLayoutStack->collapsePanel(panelp, !open);
  240. updateResizeLimits();
  241. }
  242. void LLFloaterNotificationConsole::removeChannel(const std::string& name)
  243. {
  244. LLPanel* panelp = getChild<LLPanel>(name.c_str(), true, false);
  245. if (panelp)
  246. {
  247. mLayoutStack->removePanel(panelp);
  248. delete panelp;
  249. }
  250. updateResizeLimits();
  251. }
  252. void LLFloaterNotificationConsole::updateResizeLimits()
  253. {
  254. setResizeLimits(getMinWidth(),
  255. LLFLOATER_HEADER_SIZE + HEADER_PADDING +
  256. (NOTIFICATION_PANEL_HEADER_HEIGHT + 3) *
  257. mLayoutStack->getNumPanels());
  258. }
  259. //static
  260. void LLFloaterNotificationConsole::onClickAdd(void* data)
  261. {
  262. LLFloaterNotificationConsole* self = (LLFloaterNotificationConsole*)data;
  263. if (!self) return;
  264. std::string message_name = self->mNotifTypesCombo->getValue().asString();
  265. if (!message_name.empty())
  266. {
  267. gNotifications.add(message_name, LLSD());
  268. }
  269. }
  270. ///////////////////////////////////////////////////////////////////////////////
  271. // LLFloaterNotification class
  272. ///////////////////////////////////////////////////////////////////////////////
  273. LLFloaterNotification::LLFloaterNotification(LLNotification* notifp)
  274. // Do not store the pointer on the notification, but its Id ! HB
  275. : mNotificationId(notifp->getID())
  276. {
  277. LLUICtrlFactory::getInstance()->buildFloater(this,
  278. "floater_notification.xml");
  279. setTitle(notifp->getName());
  280. getChild<LLViewerTextEditor>("payload")->setText(notifp->getMessage());
  281. mResponsesCombo = getChild<LLComboBox>("response");
  282. LLNotificationFormPtr formp = notifp->getForm();
  283. if (!formp)
  284. {
  285. mResponsesCombo->setEnabled(false);
  286. return;
  287. }
  288. mResponsesCombo->setCommitCallback(onCommitResponse);
  289. mResponsesCombo->setCallbackUserData(this);
  290. std::string text;
  291. LLSD form_sd = formp->asLLSD();
  292. for (LLSD::array_const_iterator form_item = form_sd.beginArray();
  293. form_item != form_sd.endArray(); ++form_item)
  294. {
  295. if ((*form_item)["type"].asString() == "button")
  296. {
  297. text = (*form_item)["text"].asString();
  298. mResponsesCombo->addSimpleElement(text);
  299. }
  300. }
  301. mResponsesCombo->setEnabled(mResponsesCombo->getItemCount() > 0);
  302. }
  303. void LLFloaterNotification::respond()
  304. {
  305. LLNotificationPtr notifp = gNotifications.find(mNotificationId);
  306. if (notifp) // NULL *will* happen after the notification is gone ! HB
  307. {
  308. LLSD response = notifp->getResponseTemplate();
  309. response[mResponsesCombo->getSelectedValue().asString()] = true;
  310. notifp->respond(response);
  311. }
  312. }
  313. //static
  314. void LLFloaterNotification::onCommitResponse(LLUICtrl*, void* userdata)
  315. {
  316. LLFloaterNotification* self = (LLFloaterNotification*)userdata;
  317. if (self)
  318. {
  319. self->respond();
  320. }
  321. }