llfloaternotificationsconsole.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:10k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llnotificationsconsole.cpp
  3.  * @brief Debugging console for unified notifications.
  4.  *
  5.  * $LicenseInfo:firstyear=2003&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2003-2010, 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 "llfloaternotificationsconsole.h"
  34. #include "llnotifications.h"
  35. #include "lluictrlfactory.h"
  36. #include "llbutton.h"
  37. #include "llscrolllistctrl.h"
  38. #include "llscrolllistitem.h"
  39. #include "llpanel.h"
  40. #include "llcombobox.h"
  41. const S32 NOTIFICATION_PANEL_HEADER_HEIGHT = 20;
  42. const S32 HEADER_PADDING = 38;
  43. class LLNotificationChannelPanel : public LLPanel
  44. {
  45. public:
  46. LLNotificationChannelPanel(const std::string& channel_name);
  47. BOOL postBuild();
  48. private:
  49. bool update(const LLSD& payload, bool passed_filter);
  50. static void toggleClick(void* user_data);
  51. static void onClickNotification(void* user_data);
  52. static void onClickNotificationReject(void* user_data);
  53. LLNotificationChannelPtr mChannelPtr;
  54. LLNotificationChannelPtr mChannelRejectsPtr;
  55. };
  56. LLNotificationChannelPanel::LLNotificationChannelPanel(const std::string& channel_name) 
  57. : LLPanel()
  58. {
  59. mChannelPtr = LLNotifications::instance().getChannel(channel_name);
  60. mChannelRejectsPtr = LLNotificationChannelPtr(
  61. LLNotificationChannel::buildChannel(channel_name + "rejects", mChannelPtr->getParentChannelName(),
  62. !boost::bind(mChannelPtr->getFilter(), _1)));
  63. LLUICtrlFactory::instance().buildPanel(this, "panel_notifications_channel.xml");
  64. }
  65. BOOL LLNotificationChannelPanel::postBuild()
  66. {
  67. LLButton* header_button = getChild<LLButton>("header");
  68. header_button->setLabel(mChannelPtr->getName());
  69. header_button->setClickedCallback(toggleClick, this);
  70. mChannelPtr->connectChanged(boost::bind(&LLNotificationChannelPanel::update, this, _1, true));
  71. mChannelRejectsPtr->connectChanged(boost::bind(&LLNotificationChannelPanel::update, this, _1, false));
  72. LLScrollListCtrl* scroll = getChild<LLScrollListCtrl>("notifications_list");
  73. scroll->setDoubleClickCallback(onClickNotification, this);
  74. scroll->setRect(LLRect( getRect().mLeft, getRect().mTop, getRect().mRight, 0));
  75. scroll = getChild<LLScrollListCtrl>("notification_rejects_list");
  76. scroll->setDoubleClickCallback(onClickNotificationReject, this);
  77. scroll->setRect(LLRect( getRect().mLeft, getRect().mTop, getRect().mRight, 0));
  78. return TRUE;
  79. }
  80. //static
  81. void LLNotificationChannelPanel::toggleClick(void *user_data)
  82. {
  83. LLNotificationChannelPanel* self = (LLNotificationChannelPanel*)user_data;
  84. if (!self) return;
  85. LLButton* header_button = self->getChild<LLButton>("header");
  86. LLLayoutStack* stack = dynamic_cast<LLLayoutStack*>(self->getParent());
  87. if (stack)
  88. {
  89. stack->collapsePanel(self, header_button->getToggleState());
  90. }
  91. // turn off tab stop for collapsed panel
  92. self->getChild<LLScrollListCtrl>("notifications_list")->setTabStop(!header_button->getToggleState());
  93. self->getChild<LLScrollListCtrl>("notifications_list")->setVisible(!header_button->getToggleState());
  94. self->getChild<LLScrollListCtrl>("notification_rejects_list")->setTabStop(!header_button->getToggleState());
  95. self->getChild<LLScrollListCtrl>("notification_rejects_list")->setVisible(!header_button->getToggleState());
  96. }
  97. /*static*/
  98. void LLNotificationChannelPanel::onClickNotification(void* user_data)
  99. {
  100. LLNotificationChannelPanel* self = (LLNotificationChannelPanel*)user_data;
  101. if (!self) return;
  102. LLScrollListItem* firstselected = self->getChild<LLScrollListCtrl>("notifications_list")->getFirstSelected();
  103. llassert(firstselected);
  104. if (firstselected)
  105. {
  106. void* data = firstselected->getUserdata();
  107. if (data)
  108. {
  109. gFloaterView->getParentFloater(self)->addDependentFloater(new LLFloaterNotification((LLNotification*)data), TRUE);
  110. }
  111. }
  112. }
  113. /*static*/
  114. void LLNotificationChannelPanel::onClickNotificationReject(void* user_data)
  115. {
  116. LLNotificationChannelPanel* self = (LLNotificationChannelPanel*)user_data;
  117. if (!self) return;
  118. LLScrollListItem* firstselected = self->getChild<LLScrollListCtrl>("notification_rejects_list")->getFirstSelected();
  119. llassert(firstselected);
  120. if (firstselected)
  121. {
  122. void* data = firstselected->getUserdata();
  123. if (data)
  124. {
  125. gFloaterView->getParentFloater(self)->addDependentFloater(new LLFloaterNotification((LLNotification*)data), TRUE);
  126. }
  127. }
  128. }
  129. bool LLNotificationChannelPanel::update(const LLSD& payload, bool passed_filter)
  130. {
  131. LLNotificationPtr notification = LLNotifications::instance().find(payload["id"].asUUID());
  132. if (notification)
  133. {
  134. LLSD row;
  135. row["columns"][0]["value"] = notification->getName();
  136. row["columns"][0]["column"] = "name";
  137. row["columns"][1]["value"] = notification->getMessage();
  138. row["columns"][1]["column"] = "content";
  139. row["columns"][2]["value"] = notification->getDate();
  140. row["columns"][2]["column"] = "date";
  141. row["columns"][2]["type"] = "date";
  142. LLScrollListItem* sli = passed_filter ? 
  143. getChild<LLScrollListCtrl>("notifications_list")->addElement(row) :
  144. getChild<LLScrollListCtrl>("notification_rejects_list")->addElement(row);
  145. sli->setUserdata(&(*notification));
  146. }
  147. return false;
  148. }
  149. //
  150. // LLFloaterNotificationConsole
  151. //
  152. LLFloaterNotificationConsole::LLFloaterNotificationConsole(const LLSD& key)
  153. : LLFloater(key)
  154. {
  155. mCommitCallbackRegistrar.add("ClickAdd",     boost::bind(&LLFloaterNotificationConsole::onClickAdd, this));
  156. //LLUICtrlFactory::instance().buildFloater(this, "floater_notifications_console.xml");
  157. }
  158. BOOL LLFloaterNotificationConsole::postBuild()
  159. {
  160. // these are in the order of processing
  161. addChannel("Unexpired");
  162. addChannel("Ignore");
  163. addChannel("Visible", true);
  164. // all the ones below attach to the Visible channel
  165. addChannel("History");
  166. addChannel("Alerts");
  167. addChannel("AlertModal");
  168. addChannel("Group Notifications");
  169. addChannel("Notifications");
  170. addChannel("NotificationTips");
  171. // getChild<LLButton>("add_notification")->setClickedCallback(onClickAdd, this);
  172. LLComboBox* notifications = getChild<LLComboBox>("notification_types");
  173. LLNotifications::TemplateNames names = LLNotifications::instance().getTemplateNames();
  174. for (LLNotifications::TemplateNames::iterator template_it = names.begin();
  175. template_it != names.end();
  176. ++template_it)
  177. {
  178. notifications->add(*template_it);
  179. }
  180. notifications->sortByName();
  181. return TRUE;
  182. }
  183. void LLFloaterNotificationConsole::addChannel(const std::string& name, bool open)
  184. {
  185. LLLayoutStack& stack = getChildRef<LLLayoutStack>("notification_channels");
  186. LLNotificationChannelPanel* panelp = new LLNotificationChannelPanel(name);
  187. stack.addPanel(panelp, 0, NOTIFICATION_PANEL_HEADER_HEIGHT, TRUE, TRUE, LLLayoutStack::ANIMATE);
  188. LLButton& header_button = panelp->getChildRef<LLButton>("header");
  189. header_button.setToggleState(!open);
  190. stack.collapsePanel(panelp, !open);
  191. updateResizeLimits();
  192. }
  193. void LLFloaterNotificationConsole::removeChannel(const std::string& name)
  194. {
  195. LLPanel* panelp = getChild<LLPanel>(name);
  196. getChildRef<LLLayoutStack>("notification_channels").removePanel(panelp);
  197. delete panelp;
  198. updateResizeLimits();
  199. }
  200. //static 
  201. void LLFloaterNotificationConsole::updateResizeLimits()
  202. {
  203. const LLFloater::Params& floater_params = LLFloater::getDefaultParams();
  204. S32 floater_header_size = floater_params.header_height;
  205. LLLayoutStack& stack = getChildRef<LLLayoutStack>("notification_channels");
  206. setResizeLimits(getMinWidth(), floater_header_size + HEADER_PADDING + ((NOTIFICATION_PANEL_HEADER_HEIGHT + 3) * stack.getNumPanels()));
  207. }
  208. void LLFloaterNotificationConsole::onClickAdd()
  209. {
  210. std::string message_name = getChild<LLComboBox>("notification_types")->getValue().asString();
  211. if (!message_name.empty())
  212. {
  213. LLNotifications::instance().add(message_name, LLSD(), LLSD());
  214. }
  215. }
  216. //=============== LLFloaterNotification ================
  217. LLFloaterNotification::LLFloaterNotification(LLNotification* note) 
  218. : LLFloater(LLSD()),
  219. mNote(note)
  220. {
  221. LLUICtrlFactory::instance().buildFloater(this, "floater_notification.xml", NULL);
  222. }
  223. BOOL LLFloaterNotification::postBuild()
  224. {
  225. setTitle(mNote->getName());
  226. getChild<LLUICtrl>("payload")->setValue(mNote->getMessage());
  227. LLComboBox* responses_combo = getChild<LLComboBox>("response");
  228. LLCtrlListInterface* response_list = responses_combo->getListInterface();
  229. LLNotificationFormPtr form(mNote->getForm());
  230. if(!form)
  231. {
  232. return TRUE;
  233. }
  234. responses_combo->setCommitCallback(onCommitResponse, this);
  235. LLSD form_sd = form->asLLSD();
  236. for (LLSD::array_const_iterator form_item = form_sd.beginArray(); form_item != form_sd.endArray(); ++form_item)
  237. {
  238. if ( (*form_item)["type"].asString() != "button") continue;
  239. std::string text = (*form_item)["text"].asString();
  240. response_list->addSimpleElement(text);
  241. }
  242. return TRUE;
  243. }
  244. void LLFloaterNotification::respond()
  245. {
  246. LLComboBox* responses_combo = getChild<LLComboBox>("response");
  247. LLCtrlListInterface* response_list = responses_combo->getListInterface();
  248. const std::string& trigger = response_list->getSelectedValue().asString();
  249. //llinfos << trigger << llendl;
  250. LLSD response = mNote->getResponseTemplate();
  251. response[trigger] = true;
  252. mNote->respond(response);
  253. }