/indra/newview/llpanelsnapshotoptions.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 120 lines · 73 code · 18 blank · 29 comment · 1 complexity · a041d8a0d4fb83134dfb10e447b89fe0 MD5 · raw file

  1. /**
  2. * @file llpanelsnapshotoptions.cpp
  3. * @brief Snapshot posting options panel.
  4. *
  5. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, 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 "lleconomy.h"
  28. #include "llpanel.h"
  29. #include "llsidetraypanelcontainer.h"
  30. #include "llfloatersnapshot.h" // FIXME: create a snapshot model
  31. /**
  32. * Provides several ways to save a snapshot.
  33. */
  34. class LLPanelSnapshotOptions
  35. : public LLPanel
  36. , public LLEconomyObserver
  37. {
  38. LOG_CLASS(LLPanelSnapshotOptions);
  39. public:
  40. LLPanelSnapshotOptions();
  41. ~LLPanelSnapshotOptions();
  42. /*virtual*/ void onOpen(const LLSD& key);
  43. /*virtual*/ void onEconomyDataChange() { updateUploadCost(); }
  44. private:
  45. void updateUploadCost();
  46. void openPanel(const std::string& panel_name);
  47. void onSaveToProfile();
  48. void onSaveToEmail();
  49. void onSaveToInventory();
  50. void onSaveToComputer();
  51. };
  52. static LLRegisterPanelClassWrapper<LLPanelSnapshotOptions> panel_class("llpanelsnapshotoptions");
  53. LLPanelSnapshotOptions::LLPanelSnapshotOptions()
  54. {
  55. mCommitCallbackRegistrar.add("Snapshot.SaveToProfile", boost::bind(&LLPanelSnapshotOptions::onSaveToProfile, this));
  56. mCommitCallbackRegistrar.add("Snapshot.SaveToEmail", boost::bind(&LLPanelSnapshotOptions::onSaveToEmail, this));
  57. mCommitCallbackRegistrar.add("Snapshot.SaveToInventory", boost::bind(&LLPanelSnapshotOptions::onSaveToInventory, this));
  58. mCommitCallbackRegistrar.add("Snapshot.SaveToComputer", boost::bind(&LLPanelSnapshotOptions::onSaveToComputer, this));
  59. LLGlobalEconomy::Singleton::getInstance()->addObserver(this);
  60. }
  61. LLPanelSnapshotOptions::~LLPanelSnapshotOptions()
  62. {
  63. LLGlobalEconomy::Singleton::getInstance()->removeObserver(this);
  64. }
  65. // virtual
  66. void LLPanelSnapshotOptions::onOpen(const LLSD& key)
  67. {
  68. updateUploadCost();
  69. }
  70. void LLPanelSnapshotOptions::updateUploadCost()
  71. {
  72. S32 upload_cost = LLGlobalEconomy::Singleton::getInstance()->getPriceUpload();
  73. getChild<LLUICtrl>("save_to_inventory_btn")->setLabelArg("[AMOUNT]", llformat("%d", upload_cost));
  74. }
  75. void LLPanelSnapshotOptions::openPanel(const std::string& panel_name)
  76. {
  77. LLSideTrayPanelContainer* parent = dynamic_cast<LLSideTrayPanelContainer*>(getParent());
  78. if (!parent)
  79. {
  80. llwarns << "Cannot find panel container" << llendl;
  81. return;
  82. }
  83. parent->openPanel(panel_name);
  84. parent->getCurrentPanel()->onOpen(LLSD());
  85. LLFloaterSnapshot::postPanelSwitch();
  86. }
  87. void LLPanelSnapshotOptions::onSaveToProfile()
  88. {
  89. openPanel("panel_snapshot_profile");
  90. }
  91. void LLPanelSnapshotOptions::onSaveToEmail()
  92. {
  93. openPanel("panel_snapshot_postcard");
  94. }
  95. void LLPanelSnapshotOptions::onSaveToInventory()
  96. {
  97. openPanel("panel_snapshot_inventory");
  98. }
  99. void LLPanelSnapshotOptions::onSaveToComputer()
  100. {
  101. openPanel("panel_snapshot_local");
  102. }