/indra/newview/lltoastgroupnotifypanel.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 220 lines · 146 code · 34 blank · 40 comment · 12 complexity · 03298409b0b675084535fa02b935679c MD5 · raw file

  1. /**
  2. * @file lltoastgroupnotifypanel.cpp
  3. * @brief Panel for group notify toasts.
  4. *
  5. * $LicenseInfo:firstyear=2001&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 "lltoastgroupnotifypanel.h"
  28. #include "llfocusmgr.h"
  29. #include "llbutton.h"
  30. #include "lliconctrl.h"
  31. #include "llinventoryfunctions.h"
  32. #include "llnotifications.h"
  33. #include "llviewertexteditor.h"
  34. #include "llavatarnamecache.h"
  35. #include "lluiconstants.h"
  36. #include "llui.h"
  37. #include "llviewercontrol.h"
  38. #include "lltrans.h"
  39. #include "llstyle.h"
  40. #include "llglheaders.h"
  41. #include "llagent.h"
  42. #include "llavatariconctrl.h"
  43. #include "llfloaterinventory.h"
  44. #include "llinventorytype.h"
  45. const S32 LLToastGroupNotifyPanel::DEFAULT_MESSAGE_MAX_LINE_COUNT = 7;
  46. LLToastGroupNotifyPanel::LLToastGroupNotifyPanel(LLNotificationPtr& notification)
  47. : LLToastPanel(notification),
  48. mInventoryOffer(NULL)
  49. {
  50. buildFromFile( "panel_group_notify.xml");
  51. const LLSD& payload = notification->getPayload();
  52. LLGroupData groupData;
  53. if (!gAgent.getGroupData(payload["group_id"].asUUID(),groupData))
  54. {
  55. llwarns << "Group notice for unknown group: " << payload["group_id"].asUUID() << llendl;
  56. }
  57. //group icon
  58. LLIconCtrl* pGroupIcon = getChild<LLIconCtrl>("group_icon", TRUE);
  59. pGroupIcon->setValue(groupData.mInsigniaID);
  60. //header title
  61. std::string from_name = payload["sender_name"].asString();
  62. if (LLAvatarNameCache::useDisplayNames())
  63. {
  64. from_name = LLCacheName::buildUsername(from_name);
  65. }
  66. std::stringstream from;
  67. from << from_name << "/" << groupData.mName;
  68. LLTextBox* pTitleText = getChild<LLTextBox>("title");
  69. pTitleText->setValue(from.str());
  70. pTitleText->setToolTip(from.str());
  71. //message subject
  72. const std::string& subject = payload["subject"].asString();
  73. //message body
  74. const std::string& message = payload["message"].asString();
  75. std::string timeStr = "["+LLTrans::getString("UTCTimeWeek")+"],["
  76. +LLTrans::getString("UTCTimeDay")+"] ["
  77. +LLTrans::getString("UTCTimeMth")+"] ["
  78. +LLTrans::getString("UTCTimeYr")+"] ["
  79. +LLTrans::getString("UTCTimeHr")+"]:["
  80. +LLTrans::getString("UTCTimeMin")+"]:["
  81. +LLTrans::getString("UTCTimeSec")+"] ["
  82. +LLTrans::getString("UTCTimeTimezone")+"]";
  83. const LLDate timeStamp = notification->getDate();
  84. LLDate notice_date = timeStamp.notNull() ? timeStamp : LLDate::now();
  85. LLSD substitution;
  86. substitution["datetime"] = (S32) notice_date.secondsSinceEpoch();
  87. LLStringUtil::format(timeStr, substitution);
  88. LLViewerTextEditor* pMessageText = getChild<LLViewerTextEditor>("message");
  89. pMessageText->clear();
  90. LLStyle::Params style;
  91. LLFontGL* subject_font = LLFontGL::getFontByName(getString("subject_font"));
  92. if (subject_font)
  93. style.font = subject_font;
  94. pMessageText->appendText(subject, FALSE, style);
  95. LLFontGL* date_font = LLFontGL::getFontByName(getString("date_font"));
  96. if (date_font)
  97. style.font = date_font;
  98. pMessageText->appendText(timeStr + "\n", TRUE, style);
  99. style.font = pMessageText->getDefaultFont();
  100. pMessageText->appendText(message, TRUE, style);
  101. //attachment
  102. BOOL hasInventory = payload["inventory_offer"].isDefined();
  103. //attachment text
  104. LLTextBox * pAttachLink = getChild<LLTextBox>("attachment");
  105. //attachment icon
  106. LLIconCtrl* pAttachIcon = getChild<LLIconCtrl>("attachment_icon", TRUE);
  107. //If attachment is empty let it be invisible and not take place at the panel
  108. pAttachLink->setVisible(hasInventory);
  109. pAttachIcon->setVisible(hasInventory);
  110. if (hasInventory) {
  111. pAttachLink->setValue(payload["inventory_name"]);
  112. mInventoryOffer = new LLOfferInfo(payload["inventory_offer"]);
  113. getChild<LLTextBox>("attachment")->setClickedCallback(boost::bind(
  114. &LLToastGroupNotifyPanel::onClickAttachment, this));
  115. LLUIImagePtr attachIconImg = LLInventoryIcon::getIcon(mInventoryOffer->mType,
  116. LLInventoryType::IT_TEXTURE);
  117. pAttachIcon->setValue(attachIconImg->getName());
  118. }
  119. //ok button
  120. LLButton* pOkBtn = getChild<LLButton>("btn_ok");
  121. pOkBtn->setClickedCallback((boost::bind(&LLToastGroupNotifyPanel::onClickOk, this)));
  122. setDefaultBtn(pOkBtn);
  123. S32 maxLinesCount;
  124. std::istringstream ss( getString("message_max_lines_count") );
  125. if (!(ss >> maxLinesCount))
  126. {
  127. maxLinesCount = DEFAULT_MESSAGE_MAX_LINE_COUNT;
  128. }
  129. snapToMessageHeight(pMessageText, maxLinesCount);
  130. }
  131. // virtual
  132. LLToastGroupNotifyPanel::~LLToastGroupNotifyPanel()
  133. {
  134. }
  135. void LLToastGroupNotifyPanel::close()
  136. {
  137. // The group notice dialog may be an inventory offer.
  138. // If it has an inventory save button and that button is still enabled
  139. // Then we need to send the inventory declined message
  140. if(mInventoryOffer != NULL)
  141. {
  142. mInventoryOffer->forceResponse(IOR_DECLINE);
  143. mInventoryOffer = NULL;
  144. }
  145. die();
  146. }
  147. void LLToastGroupNotifyPanel::onClickOk()
  148. {
  149. LLSD response = mNotification->getResponseTemplate();
  150. mNotification->respond(response);
  151. close();
  152. }
  153. void LLToastGroupNotifyPanel::onClickAttachment()
  154. {
  155. if (mInventoryOffer != NULL) {
  156. mInventoryOffer->forceResponse(IOR_ACCEPT);
  157. LLTextBox * pAttachLink = getChild<LLTextBox> ("attachment");
  158. static const LLUIColor textColor = LLUIColorTable::instance().getColor(
  159. "GroupNotifyDimmedTextColor");
  160. pAttachLink->setColor(textColor);
  161. LLIconCtrl* pAttachIcon =
  162. getChild<LLIconCtrl> ("attachment_icon", TRUE);
  163. pAttachIcon->setEnabled(FALSE);
  164. //if attachment isn't openable - notify about saving
  165. if (!isAttachmentOpenable(mInventoryOffer->mType)) {
  166. LLNotifications::instance().add("AttachmentSaved", LLSD(), LLSD());
  167. }
  168. mInventoryOffer = NULL;
  169. }
  170. }
  171. //static
  172. bool LLToastGroupNotifyPanel::isAttachmentOpenable(LLAssetType::EType type)
  173. {
  174. switch(type)
  175. {
  176. case LLAssetType::AT_LANDMARK:
  177. case LLAssetType::AT_NOTECARD:
  178. case LLAssetType::AT_IMAGE_JPEG:
  179. case LLAssetType::AT_IMAGE_TGA:
  180. case LLAssetType::AT_TEXTURE:
  181. case LLAssetType::AT_TEXTURE_TGA:
  182. return true;
  183. default:
  184. return false;
  185. }
  186. }