llprefsnotifications.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /**
  2. * @file llprefsnotifications.cpp
  3. * @brief Notifications preferences panel
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Adapted by Henri Beauchamp from llpanelmsgs.cpp
  8. * Copyright (c) 2001-2009 Linden Research, Inc. (c) 2011 Henri Beauchamp
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #include "llviewerprecompiledheaders.h"
  34. #include "llprefsnotifications.h"
  35. #include "llbutton.h"
  36. #include "llnotifications.h"
  37. #include "llscrolllistctrl.h"
  38. #include "lluictrlfactory.h"
  39. #include "llfirstuse.h"
  40. #include "llviewercontrol.h"
  41. class LLPrefsNotificationsImpl final : public LLPanel
  42. {
  43. public:
  44. LLPrefsNotificationsImpl();
  45. ~LLPrefsNotificationsImpl() override
  46. {
  47. }
  48. void draw() override;
  49. void apply();
  50. void cancel();
  51. void buildLists();
  52. void resetAllIgnored();
  53. void setAllIgnored();
  54. void refreshValues();
  55. private:
  56. static void onClickEnablePopup(void* user_data);
  57. static void onClickDisablePopup(void* user_data);
  58. static void onClickResetDialogs(void* user_data);
  59. static void onClickSkipDialogs(void* user_data);
  60. private:
  61. LLButton* mEnablePopupBtn;
  62. LLButton* mDisablePopupBtn;
  63. LLScrollListCtrl* mEnabledPopupsList;
  64. LLScrollListCtrl* mDisabledPopupsList;
  65. U32 mLookAtNotifyDelay;
  66. bool mAutoAcceptNewInventory;
  67. bool mRejectNewInventoryWhenBusy;
  68. bool mShowNewInventory;
  69. bool mShowInInventory;
  70. bool mNotifyMoneyChange;
  71. bool mChatOnlineNotification;
  72. bool mHideNotificationsInChat;
  73. bool mScriptErrorsAsChat;
  74. bool mTeleportHistoryInChat;
  75. };
  76. //-----------------------------------------------------------------------------
  77. LLPrefsNotificationsImpl::LLPrefsNotificationsImpl()
  78. : LLPanel("Notifications Preferences Panel")
  79. {
  80. LLUICtrlFactory::getInstance()->buildPanel(this,
  81. "panel_preferences_notifications.xml");
  82. mEnablePopupBtn = getChild<LLButton>("enable_popup");
  83. mEnablePopupBtn->setClickedCallback(onClickEnablePopup, this);
  84. mDisablePopupBtn = getChild<LLButton>("disable_popup");
  85. mDisablePopupBtn->setClickedCallback(onClickDisablePopup, this);
  86. childSetAction("reset_dialogs_btn", onClickResetDialogs, this);
  87. childSetAction("skip_dialogs_btn", onClickSkipDialogs, this);
  88. mEnabledPopupsList = getChild<LLScrollListCtrl>("enabled_popups");
  89. mDisabledPopupsList = getChild<LLScrollListCtrl>("disabled_popups");
  90. refreshValues();
  91. buildLists();
  92. }
  93. void LLPrefsNotificationsImpl::refreshValues()
  94. {
  95. mLookAtNotifyDelay = gSavedSettings.getU32("LookAtNotifyDelay");
  96. mAutoAcceptNewInventory = gSavedSettings.getBool("AutoAcceptNewInventory");
  97. mRejectNewInventoryWhenBusy =
  98. gSavedSettings.getBool("RejectNewInventoryWhenBusy");
  99. mShowNewInventory = gSavedSettings.getBool("ShowNewInventory");
  100. mShowInInventory = gSavedSettings.getBool("ShowInInventory");
  101. mNotifyMoneyChange = gSavedSettings.getBool("NotifyMoneyChange");
  102. mChatOnlineNotification = gSavedSettings.getBool("ChatOnlineNotification");
  103. mHideNotificationsInChat = gSavedSettings.getBool("HideNotificationsInChat");
  104. mScriptErrorsAsChat = gSavedSettings.getBool("ScriptErrorsAsChat");
  105. mTeleportHistoryInChat = gSavedSettings.getBool("TeleportHistoryInChat");
  106. }
  107. void LLPrefsNotificationsImpl::buildLists()
  108. {
  109. mDisabledPopupsList->deleteAllItems();
  110. mEnabledPopupsList->deleteAllItems();
  111. std::string cname;
  112. for (LLNotifications::TemplateMap::const_iterator
  113. iter = gNotifications.templatesBegin(),
  114. end = gNotifications.templatesEnd();
  115. iter != end; ++iter)
  116. {
  117. LLNotificationTemplatePtr templatep = iter->second;
  118. LLNotificationFormPtr formp = templatep->mForm;
  119. LLNotificationForm::EIgnoreType ignore = formp->getIgnoreType();
  120. if (ignore == LLNotificationForm::IGNORE_NO) continue;
  121. LLSD row;
  122. row["columns"][0]["value"] = formp->getIgnoreMessage();
  123. row["columns"][0]["font"] = "SANSSERIF_SMALL";
  124. row["columns"][0]["width"] = 300;
  125. LLScrollListItem* item = NULL;
  126. bool show_popup = gSavedSettings.getWarning(templatep->mName);
  127. if (!show_popup)
  128. {
  129. if (ignore == LLNotificationForm::IGNORE_WITH_LAST_RESPONSE)
  130. {
  131. cname = "Default" + templatep->mName;
  132. LLSD last_response = LLUI::sConfigGroup->getLLSD(cname.c_str());
  133. if (!last_response.isUndefined())
  134. {
  135. for (LLSD::map_const_iterator it = last_response.beginMap();
  136. it != last_response.endMap(); ++it)
  137. {
  138. if (it->second.asBoolean())
  139. {
  140. row["columns"][1]["value"] =
  141. formp->getElement(it->first)["ignore"].asString();
  142. break;
  143. }
  144. }
  145. }
  146. row["columns"][1]["font"] = "SANSSERIF_SMALL";
  147. row["columns"][1]["width"] = 160;
  148. }
  149. item = mDisabledPopupsList->addElement(row, ADD_SORTED);
  150. }
  151. else
  152. {
  153. item = mEnabledPopupsList->addElement(row, ADD_SORTED);
  154. }
  155. if (item)
  156. {
  157. item->setUserdata((void*)&iter->first);
  158. }
  159. }
  160. }
  161. void LLPrefsNotificationsImpl::draw()
  162. {
  163. mEnablePopupBtn->setEnabled(mDisabledPopupsList->getFirstSelected() != NULL);
  164. mDisablePopupBtn->setEnabled(mEnabledPopupsList->getFirstSelected() != NULL);
  165. LLPanel::draw();
  166. }
  167. void LLPrefsNotificationsImpl::apply()
  168. {
  169. refreshValues();
  170. }
  171. void LLPrefsNotificationsImpl::cancel()
  172. {
  173. gSavedSettings.setU32("LookAtNotifyDelay", mLookAtNotifyDelay);
  174. gSavedSettings.setBool("AutoAcceptNewInventory", mAutoAcceptNewInventory);
  175. gSavedSettings.setBool("RejectNewInventoryWhenBusy",
  176. mRejectNewInventoryWhenBusy);
  177. gSavedSettings.setBool("ShowNewInventory", mShowNewInventory);
  178. gSavedSettings.setBool("ShowInInventory", mShowInInventory);
  179. gSavedSettings.setBool("NotifyMoneyChange", mNotifyMoneyChange);
  180. gSavedSettings.setBool("ChatOnlineNotification", mChatOnlineNotification);
  181. gSavedSettings.setBool("HideNotificationsInChat", mHideNotificationsInChat);
  182. gSavedSettings.setBool("ScriptErrorsAsChat", mScriptErrorsAsChat);
  183. gSavedSettings.setBool("TeleportHistoryInChat", mTeleportHistoryInChat);
  184. }
  185. void LLPrefsNotificationsImpl::resetAllIgnored()
  186. {
  187. LLNotifications::TemplateMap::const_iterator iter;
  188. for (LLNotifications::TemplateMap::const_iterator
  189. iter = gNotifications.templatesBegin(),
  190. end = gNotifications.templatesEnd();
  191. iter != end; ++iter)
  192. {
  193. if (iter->second->mForm->getIgnoreType() != LLNotificationForm::IGNORE_NO)
  194. {
  195. gSavedSettings.setWarning(iter->first, true);
  196. }
  197. }
  198. }
  199. void LLPrefsNotificationsImpl::setAllIgnored()
  200. {
  201. for (LLNotifications::TemplateMap::const_iterator
  202. iter = gNotifications.templatesBegin(),
  203. end = gNotifications.templatesEnd();
  204. iter != end; ++iter)
  205. {
  206. if (iter->second->mForm->getIgnoreType() != LLNotificationForm::IGNORE_NO)
  207. {
  208. gSavedSettings.setWarning(iter->first, false);
  209. }
  210. }
  211. }
  212. //static
  213. void LLPrefsNotificationsImpl::onClickEnablePopup(void* user_data)
  214. {
  215. LLPrefsNotificationsImpl* panelp = (LLPrefsNotificationsImpl*)user_data;
  216. if (!panelp) return;
  217. std::vector<LLScrollListItem*> items =
  218. panelp->mDisabledPopupsList->getAllSelected();
  219. std::vector<LLScrollListItem*>::iterator iter;
  220. for (iter = items.begin(); iter != items.end(); ++iter)
  221. {
  222. LLNotificationTemplatePtr templatep =
  223. gNotifications.getTemplate(*(std::string*)((*iter)->getUserdata()));
  224. if (templatep->mForm->getIgnoreType() != LLNotificationForm::IGNORE_NO)
  225. {
  226. gSavedSettings.setWarning(templatep->mName, true);
  227. }
  228. }
  229. panelp->buildLists();
  230. }
  231. //static
  232. void LLPrefsNotificationsImpl::onClickDisablePopup(void* user_data)
  233. {
  234. LLPrefsNotificationsImpl* panelp = (LLPrefsNotificationsImpl*)user_data;
  235. if (!panelp) return;
  236. std::vector<LLScrollListItem*> items =
  237. panelp->mDisabledPopupsList->getAllSelected();
  238. std::vector<LLScrollListItem*>::iterator iter;
  239. for (iter = items.begin(); iter != items.end(); ++iter)
  240. {
  241. LLNotificationTemplatePtr templatep =
  242. gNotifications.getTemplate(*(std::string*)((*iter)->getUserdata()));
  243. if (templatep->mForm->getIgnoreType() != LLNotificationForm::IGNORE_NO)
  244. {
  245. gSavedSettings.setWarning(templatep->mName, false);
  246. }
  247. }
  248. panelp->buildLists();
  249. }
  250. bool callback_reset_dialogs(const LLSD& notification, const LLSD& response,
  251. LLPrefsNotificationsImpl* panelp)
  252. {
  253. if (panelp &&
  254. LLNotification::getSelectedOption(notification, response) == 0)
  255. {
  256. panelp->resetAllIgnored();
  257. LLFirstUse::resetFirstUse();
  258. panelp->buildLists();
  259. }
  260. return false;
  261. }
  262. //static
  263. void LLPrefsNotificationsImpl::onClickResetDialogs(void* user_data)
  264. {
  265. gNotifications.add("ResetShowNextTimeDialogs", LLSD(), LLSD(),
  266. boost::bind(&callback_reset_dialogs, _1, _2,
  267. (LLPrefsNotificationsImpl*)user_data));
  268. }
  269. bool callback_skip_dialogs(const LLSD& notification, const LLSD& response,
  270. LLPrefsNotificationsImpl* panelp)
  271. {
  272. S32 option = LLNotification::getSelectedOption(notification, response);
  273. if (option == 0)
  274. {
  275. if (panelp)
  276. {
  277. panelp->setAllIgnored();
  278. LLFirstUse::disableFirstUse();
  279. panelp->buildLists();
  280. }
  281. }
  282. return false;
  283. }
  284. //static
  285. void LLPrefsNotificationsImpl::onClickSkipDialogs(void* user_data)
  286. {
  287. gNotifications.add("SkipShowNextTimeDialogs", LLSD(), LLSD(),
  288. boost::bind(&callback_skip_dialogs, _1, _2,
  289. (LLPrefsNotificationsImpl*)user_data));
  290. }
  291. //---------------------------------------------------------------------------
  292. LLPrefsNotifications::LLPrefsNotifications()
  293. : impl(*new LLPrefsNotificationsImpl())
  294. {
  295. }
  296. LLPrefsNotifications::~LLPrefsNotifications()
  297. {
  298. delete &impl;
  299. }
  300. void LLPrefsNotifications::draw()
  301. {
  302. impl.draw();
  303. }
  304. void LLPrefsNotifications::apply()
  305. {
  306. impl.apply();
  307. }
  308. void LLPrefsNotifications::cancel()
  309. {
  310. impl.cancel();
  311. }
  312. LLPanel* LLPrefsNotifications::getPanel()
  313. {
  314. return &impl;
  315. }