PageRenderTime 35ms CodeModel.GetById 9ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lltoastgroupnotifypanel.cpp

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