lltoastgroupnotifypanel.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:7k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /**
  2.  * @file lltoastgroupnotifypanel.cpp
  3.  * @brief Panel for group notify toasts.
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "lltoastgroupnotifypanel.h"
  34. #include "llfocusmgr.h"
  35. #include "llbutton.h"
  36. #include "lliconctrl.h"
  37. #include "llinventoryfunctions.h"
  38. #include "llnotifications.h"
  39. #include "llviewertexteditor.h"
  40. #include "lluiconstants.h"
  41. #include "llui.h"
  42. #include "llviewercontrol.h"
  43. #include "lltrans.h"
  44. #include "llstyle.h"
  45. #include "llglheaders.h"
  46. #include "llagent.h"
  47. #include "llavatariconctrl.h"
  48. #include "llfloaterinventory.h"
  49. #include "llinventorytype.h"
  50. const S32 LLToastGroupNotifyPanel::DEFAULT_MESSAGE_MAX_LINE_COUNT = 7;
  51. LLToastGroupNotifyPanel::LLToastGroupNotifyPanel(LLNotificationPtr& notification)
  52. : LLToastPanel(notification),
  53. mInventoryOffer(NULL)
  54. {
  55. LLUICtrlFactory::getInstance()->buildPanel(this, "panel_group_notify.xml");
  56. const LLSD& payload = notification->getPayload();
  57. LLGroupData groupData;
  58. if (!gAgent.getGroupData(payload["group_id"].asUUID(),groupData))
  59. {
  60. llwarns << "Group notice for unkown group: " << payload["group_id"].asUUID() << llendl;
  61. }
  62. //group icon
  63. LLIconCtrl* pGroupIcon = getChild<LLIconCtrl>("group_icon", TRUE);
  64. pGroupIcon->setValue(groupData.mInsigniaID);
  65. //header title
  66. const std::string& from_name = payload["sender_name"].asString();
  67. std::stringstream from;
  68. from << from_name << "/" << groupData.mName;
  69. LLTextBox* pTitleText = getChild<LLTextBox>("title");
  70. pTitleText->setValue(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. childSetActionTextbox("attachment", boost::bind(
  114. &LLToastGroupNotifyPanel::onClickAttachment, this));
  115. LLUIImagePtr attachIconImg = get_item_icon(mInventoryOffer->mType,
  116. LLInventoryType::IT_TEXTURE,
  117. 0, FALSE);
  118. pAttachIcon->setValue(attachIconImg->getName());
  119. }
  120. //ok button
  121. LLButton* pOkBtn = getChild<LLButton>("btn_ok");
  122. pOkBtn->setClickedCallback((boost::bind(&LLToastGroupNotifyPanel::onClickOk, this)));
  123. setDefaultBtn(pOkBtn);
  124. S32 maxLinesCount;
  125. std::istringstream ss( getString("message_max_lines_count") );
  126. if (!(ss >> maxLinesCount))
  127. {
  128. maxLinesCount = DEFAULT_MESSAGE_MAX_LINE_COUNT;
  129. }
  130. snapToMessageHeight(pMessageText, maxLinesCount);
  131. }
  132. // virtual
  133. LLToastGroupNotifyPanel::~LLToastGroupNotifyPanel()
  134. {
  135. }
  136. void LLToastGroupNotifyPanel::close()
  137. {
  138. // The group notice dialog may be an inventory offer.
  139. // If it has an inventory save button and that button is still enabled
  140. // Then we need to send the inventory declined message
  141. if(mInventoryOffer != NULL)
  142. {
  143. mInventoryOffer->forceResponse(IOR_DECLINE);
  144. mInventoryOffer = NULL;
  145. }
  146. die();
  147. }
  148. void LLToastGroupNotifyPanel::onClickOk()
  149. {
  150. LLSD response = mNotification->getResponseTemplate();
  151. mNotification->respond(response);
  152. close();
  153. }
  154. void LLToastGroupNotifyPanel::onClickAttachment()
  155. {
  156. if (mInventoryOffer != NULL) {
  157. mInventoryOffer->forceResponse(IOR_ACCEPT);
  158. LLTextBox * pAttachLink = getChild<LLTextBox> ("attachment");
  159. static const LLUIColor textColor = LLUIColorTable::instance().getColor(
  160. "GroupNotifyDimmedTextColor");
  161. pAttachLink->setColor(textColor);
  162. LLIconCtrl* pAttachIcon =
  163. getChild<LLIconCtrl> ("attachment_icon", TRUE);
  164. pAttachIcon->setEnabled(FALSE);
  165. //if attachment isn't openable - notify about saving
  166. if (!isAttachmentOpenable(mInventoryOffer->mType)) {
  167. LLNotifications::instance().add("AttachmentSaved", LLSD(), LLSD());
  168. }
  169. mInventoryOffer = NULL;
  170. }
  171. }
  172. //static
  173. bool LLToastGroupNotifyPanel::isAttachmentOpenable(LLAssetType::EType type)
  174. {
  175. switch(type)
  176. {
  177. case LLAssetType::AT_LANDMARK:
  178. case LLAssetType::AT_NOTECARD:
  179. case LLAssetType::AT_IMAGE_JPEG:
  180. case LLAssetType::AT_IMAGE_TGA:
  181. case LLAssetType::AT_TEXTURE:
  182. case LLAssetType::AT_TEXTURE_TGA:
  183. return true;
  184. default:
  185. return false;
  186. }
  187. }