PageRenderTime 27ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llconfirmationmanager.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 112 lines | 66 code | 20 blank | 26 comment | 10 complexity | a02b9541c64492767592d2f0a0a40ce6 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llconfirmationmanager.cpp
  3. * @brief LLConfirmationManager class implementation
  4. *
  5. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llconfirmationmanager.h"
  28. #include "lluictrlfactory.h"
  29. // viewer includes
  30. #include "llnotificationsutil.h"
  31. #include "llstring.h"
  32. #include "llxmlnode.h"
  33. LLConfirmationManager::ListenerBase::~ListenerBase()
  34. {
  35. }
  36. static bool onConfirmAlert(const LLSD& notification, const LLSD& response, LLConfirmationManager::ListenerBase* listener)
  37. {
  38. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  39. if (option == 0)
  40. {
  41. listener->confirmed("");
  42. }
  43. delete listener;
  44. return false;
  45. }
  46. static bool onConfirmAlertPassword(const LLSD& notification, const LLSD& response, LLConfirmationManager::ListenerBase* listener)
  47. {
  48. std::string text = response["message"].asString();
  49. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  50. if (option == 0)
  51. {
  52. listener->confirmed(text);
  53. }
  54. delete listener;
  55. return false;
  56. }
  57. void LLConfirmationManager::confirm(Type type,
  58. const std::string& action,
  59. ListenerBase* listener)
  60. {
  61. LLSD args;
  62. args["ACTION"] = action;
  63. switch (type)
  64. {
  65. case TYPE_CLICK:
  66. LLNotificationsUtil::add("ConfirmPurchase", args, LLSD(), boost::bind(onConfirmAlert, _1, _2, listener));
  67. break;
  68. case TYPE_PASSWORD:
  69. LLNotificationsUtil::add("ConfirmPurchasePassword", args, LLSD(), boost::bind(onConfirmAlertPassword, _1, _2, listener));
  70. break;
  71. case TYPE_NONE:
  72. default:
  73. listener->confirmed("");
  74. break;
  75. }
  76. }
  77. void LLConfirmationManager::confirm(
  78. const std::string& type,
  79. const std::string& action,
  80. ListenerBase* listener)
  81. {
  82. Type decodedType = TYPE_NONE;
  83. if (type == "click")
  84. {
  85. decodedType = TYPE_CLICK;
  86. }
  87. else if (type == "password")
  88. {
  89. decodedType = TYPE_PASSWORD;
  90. }
  91. confirm(decodedType, action, listener);
  92. }