PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llpanelsnapshotpostcard.cpp

https://bitbucket.org/3das/3dasviewer
C++ | 270 lines | 177 code | 48 blank | 45 comment | 14 complexity | 1a6c43b61eaa08d4ff9087ff1d868907 MD5 | raw file
  1. /**
  2. * @file llpanelsnapshotpostcard.cpp
  3. * @brief Postcard sending 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 "llcombobox.h"
  28. #include "llnotificationsutil.h"
  29. #include "llsidetraypanelcontainer.h"
  30. #include "llsliderctrl.h"
  31. #include "llspinctrl.h"
  32. #include "lltexteditor.h"
  33. #include "llagent.h"
  34. #include "llagentui.h"
  35. #include "llfloatersnapshot.h" // FIXME: replace with a snapshot storage model
  36. #include "llpanelsnapshot.h"
  37. #include "llpostcard.h"
  38. #include "llviewercontrol.h" // gSavedSettings
  39. #include "llviewerwindow.h"
  40. #include <boost/regex.hpp>
  41. /**
  42. * Sends postcard via email.
  43. */
  44. class LLPanelSnapshotPostcard
  45. : public LLPanelSnapshot
  46. {
  47. LOG_CLASS(LLPanelSnapshotPostcard);
  48. public:
  49. LLPanelSnapshotPostcard();
  50. /*virtual*/ BOOL postBuild();
  51. /*virtual*/ void onOpen(const LLSD& key);
  52. /*virtual*/ S32 notify(const LLSD& info);
  53. private:
  54. /*virtual*/ std::string getWidthSpinnerName() const { return "postcard_snapshot_width"; }
  55. /*virtual*/ std::string getHeightSpinnerName() const { return "postcard_snapshot_height"; }
  56. /*virtual*/ std::string getAspectRatioCBName() const { return "postcard_keep_aspect_check"; }
  57. /*virtual*/ std::string getImageSizeComboName() const { return "postcard_size_combo"; }
  58. /*virtual*/ std::string getImageSizePanelName() const { return "postcard_image_size_lp"; }
  59. /*virtual*/ LLFloaterSnapshot::ESnapshotFormat getImageFormat() const { return LLFloaterSnapshot::SNAPSHOT_FORMAT_JPEG; }
  60. /*virtual*/ void updateControls(const LLSD& info);
  61. bool missingSubjMsgAlertCallback(const LLSD& notification, const LLSD& response);
  62. void sendPostcard();
  63. void onMsgFormFocusRecieved();
  64. void onFormatComboCommit(LLUICtrl* ctrl);
  65. void onQualitySliderCommit(LLUICtrl* ctrl);
  66. void onTabButtonPress(S32 btn_idx);
  67. void onSend();
  68. bool mHasFirstMsgFocus;
  69. std::string mAgentEmail;
  70. };
  71. static LLRegisterPanelClassWrapper<LLPanelSnapshotPostcard> panel_class("llpanelsnapshotpostcard");
  72. LLPanelSnapshotPostcard::LLPanelSnapshotPostcard()
  73. : mHasFirstMsgFocus(false)
  74. {
  75. mCommitCallbackRegistrar.add("Postcard.Send", boost::bind(&LLPanelSnapshotPostcard::onSend, this));
  76. mCommitCallbackRegistrar.add("Postcard.Cancel", boost::bind(&LLPanelSnapshotPostcard::cancel, this));
  77. mCommitCallbackRegistrar.add("Postcard.Message", boost::bind(&LLPanelSnapshotPostcard::onTabButtonPress, this, 0));
  78. mCommitCallbackRegistrar.add("Postcard.Settings", boost::bind(&LLPanelSnapshotPostcard::onTabButtonPress, this, 1));
  79. }
  80. // virtual
  81. BOOL LLPanelSnapshotPostcard::postBuild()
  82. {
  83. // pick up the user's up-to-date email address
  84. gAgent.sendAgentUserInfoRequest();
  85. std::string name_string;
  86. LLAgentUI::buildFullname(name_string);
  87. getChild<LLUICtrl>("name_form")->setValue(LLSD(name_string));
  88. // For the first time a user focuses to .the msg box, all text will be selected.
  89. getChild<LLUICtrl>("msg_form")->setFocusChangedCallback(boost::bind(&LLPanelSnapshotPostcard::onMsgFormFocusRecieved, this));
  90. getChild<LLUICtrl>("to_form")->setFocus(TRUE);
  91. getChild<LLUICtrl>("image_quality_slider")->setCommitCallback(boost::bind(&LLPanelSnapshotPostcard::onQualitySliderCommit, this, _1));
  92. getChild<LLButton>("message_btn")->setToggleState(TRUE);
  93. return LLPanelSnapshot::postBuild();
  94. }
  95. // virtual
  96. void LLPanelSnapshotPostcard::onOpen(const LLSD& key)
  97. {
  98. LLPanelSnapshot::onOpen(key);
  99. }
  100. // virtual
  101. S32 LLPanelSnapshotPostcard::notify(const LLSD& info)
  102. {
  103. if (!info.has("agent-email"))
  104. {
  105. llassert(info.has("agent-email"));
  106. return 0;
  107. }
  108. if (mAgentEmail.empty())
  109. {
  110. mAgentEmail = info["agent-email"].asString();
  111. }
  112. return 1;
  113. }
  114. // virtual
  115. void LLPanelSnapshotPostcard::updateControls(const LLSD& info)
  116. {
  117. getChild<LLUICtrl>("image_quality_slider")->setValue(gSavedSettings.getS32("SnapshotQuality"));
  118. updateImageQualityLevel();
  119. const bool have_snapshot = info.has("have-snapshot") ? info["have-snapshot"].asBoolean() : true;
  120. getChild<LLUICtrl>("send_btn")->setEnabled(have_snapshot);
  121. }
  122. bool LLPanelSnapshotPostcard::missingSubjMsgAlertCallback(const LLSD& notification, const LLSD& response)
  123. {
  124. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  125. if(0 == option)
  126. {
  127. // User clicked OK
  128. if((getChild<LLUICtrl>("subject_form")->getValue().asString()).empty())
  129. {
  130. // Stuff the subject back into the form.
  131. getChild<LLUICtrl>("subject_form")->setValue(getString("default_subject"));
  132. }
  133. if (!mHasFirstMsgFocus)
  134. {
  135. // The user never switched focus to the message window.
  136. // Using the default string.
  137. getChild<LLUICtrl>("msg_form")->setValue(getString("default_message"));
  138. }
  139. sendPostcard();
  140. }
  141. return false;
  142. }
  143. void LLPanelSnapshotPostcard::sendPostcard()
  144. {
  145. std::string to(getChild<LLUICtrl>("to_form")->getValue().asString());
  146. std::string subject(getChild<LLUICtrl>("subject_form")->getValue().asString());
  147. LLSD postcard = LLSD::emptyMap();
  148. postcard["pos-global"] = LLFloaterSnapshot::getPosTakenGlobal().getValue();
  149. postcard["to"] = to;
  150. postcard["from"] = mAgentEmail;
  151. postcard["name"] = getChild<LLUICtrl>("name_form")->getValue().asString();
  152. postcard["subject"] = subject;
  153. postcard["msg"] = getChild<LLUICtrl>("msg_form")->getValue().asString();
  154. LLPostCard::send(LLFloaterSnapshot::getImageData(), postcard);
  155. // Give user feedback of the event.
  156. gViewerWindow->playSnapshotAnimAndSound();
  157. LLFloaterSnapshot::postSave();
  158. }
  159. void LLPanelSnapshotPostcard::onMsgFormFocusRecieved()
  160. {
  161. LLTextEditor* msg_form = getChild<LLTextEditor>("msg_form");
  162. if (msg_form->hasFocus() && !mHasFirstMsgFocus)
  163. {
  164. mHasFirstMsgFocus = true;
  165. msg_form->setText(LLStringUtil::null);
  166. }
  167. }
  168. void LLPanelSnapshotPostcard::onFormatComboCommit(LLUICtrl* ctrl)
  169. {
  170. // will call updateControls()
  171. LLFloaterSnapshot::getInstance()->notify(LLSD().with("image-format-change", true));
  172. }
  173. void LLPanelSnapshotPostcard::onQualitySliderCommit(LLUICtrl* ctrl)
  174. {
  175. updateImageQualityLevel();
  176. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  177. S32 quality_val = llfloor((F32)slider->getValue().asReal());
  178. LLSD info;
  179. info["image-quality-change"] = quality_val;
  180. LLFloaterSnapshot::getInstance()->notify(info); // updates the "SnapshotQuality" setting
  181. }
  182. void LLPanelSnapshotPostcard::onTabButtonPress(S32 btn_idx)
  183. {
  184. LLButton* buttons[2] = {
  185. getChild<LLButton>("message_btn"),
  186. getChild<LLButton>("settings_btn"),
  187. };
  188. // Switch between Message and Settings tabs.
  189. LLButton* clicked_btn = buttons[btn_idx];
  190. LLButton* other_btn = buttons[!btn_idx];
  191. LLSideTrayPanelContainer* container =
  192. getChild<LLSideTrayPanelContainer>("postcard_panel_container");
  193. container->selectTab(clicked_btn->getToggleState() ? btn_idx : !btn_idx);
  194. //clicked_btn->setEnabled(FALSE);
  195. other_btn->toggleState();
  196. //other_btn->setEnabled(TRUE);
  197. lldebugs << "Button #" << btn_idx << " (" << clicked_btn->getName() << ") clicked" << llendl;
  198. }
  199. void LLPanelSnapshotPostcard::onSend()
  200. {
  201. // Validate input.
  202. std::string to(getChild<LLUICtrl>("to_form")->getValue().asString());
  203. boost::regex email_format("[A-Za-z0-9.%+-_]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}(,[ \t]*[A-Za-z0-9.%+-_]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,})*");
  204. if (to.empty() || !boost::regex_match(to, email_format))
  205. {
  206. LLNotificationsUtil::add("PromptRecipientEmail");
  207. return;
  208. }
  209. if (mAgentEmail.empty() || !boost::regex_match(mAgentEmail, email_format))
  210. {
  211. LLNotificationsUtil::add("PromptSelfEmail");
  212. return;
  213. }
  214. std::string subject(getChild<LLUICtrl>("subject_form")->getValue().asString());
  215. if(subject.empty() || !mHasFirstMsgFocus)
  216. {
  217. LLNotificationsUtil::add("PromptMissingSubjMsg", LLSD(), LLSD(), boost::bind(&LLPanelSnapshotPostcard::missingSubjMsgAlertCallback, this, _1, _2));
  218. return;
  219. }
  220. // Send postcard.
  221. sendPostcard();
  222. }