PageRenderTime 43ms CodeModel.GetById 15ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llinventory/lltransactionflags.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 167 lines | 125 code | 10 blank | 32 comment | 13 complexity | 265a91da1c15c6d989f61437c5bae7bd MD5 | raw file
  1/** 
  2 * @file lltransactionflags.cpp
  3 * @brief Some exported symbols and functions for dealing with
  4 * transaction flags.
  5 *
  6 * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#include "linden_common.h"
 29
 30#include "lluuid.h"
 31#include "lltransactionflags.h"
 32#include "lltransactiontypes.h"
 33 
 34const U8 TRANSACTION_FLAGS_NONE = 0;
 35const U8 TRANSACTION_FLAG_SOURCE_GROUP = 1;
 36const U8 TRANSACTION_FLAG_DEST_GROUP = 2;
 37const U8 TRANSACTION_FLAG_OWNER_GROUP = 4;
 38const U8 TRANSACTION_FLAG_SIMULTANEOUS_CONTRIBUTION = 8;
 39const U8 TRANSACTION_FLAG_SIMULTANEOUS_CONTRIBUTION_REMOVAL = 16;
 40
 41U8 pack_transaction_flags(BOOL is_source_group, BOOL is_dest_group)
 42{
 43	U8 rv = 0;
 44	if(is_source_group) rv |= TRANSACTION_FLAG_SOURCE_GROUP;
 45	if(is_dest_group) rv |= TRANSACTION_FLAG_DEST_GROUP;
 46	return rv;
 47}
 48
 49BOOL is_tf_source_group(TransactionFlags flags)
 50{
 51	return ((flags & TRANSACTION_FLAG_SOURCE_GROUP) == TRANSACTION_FLAG_SOURCE_GROUP);
 52}
 53
 54BOOL is_tf_dest_group(TransactionFlags flags)
 55{
 56	return ((flags & TRANSACTION_FLAG_DEST_GROUP) == TRANSACTION_FLAG_DEST_GROUP);
 57}
 58
 59BOOL is_tf_owner_group(TransactionFlags flags)
 60{
 61	return ((flags & TRANSACTION_FLAG_OWNER_GROUP) == TRANSACTION_FLAG_OWNER_GROUP);
 62}
 63
 64void append_reason(
 65	std::ostream& ostr,
 66	S32 transaction_type,
 67	const std::string& description)
 68{
 69	switch( transaction_type )
 70	{
 71	case TRANS_OBJECT_SALE:
 72	  ostr << " for " << (description.length() > 0 ? description : std::string("<unknown>"));
 73		break;
 74	case TRANS_LAND_SALE:
 75		ostr << " for a parcel of land";
 76		break;
 77	case TRANS_LAND_PASS_SALE:
 78		ostr << " for a land access pass";
 79		break;
 80	case TRANS_GROUP_LAND_DEED:
 81		ostr << " for deeding land";
 82	default:
 83		break;
 84	}
 85}
 86
 87std::string build_transfer_message_to_source(
 88	S32 amount,
 89	const LLUUID& source_id,
 90	const LLUUID& dest_id,
 91	const std::string& dest_name,
 92	S32 transaction_type,
 93	const std::string& description)
 94{
 95	lldebugs << "build_transfer_message_to_source: " << amount << " "
 96		<< source_id << " " << dest_id << " " << dest_name << " "
 97		<< transaction_type << " "
 98		<< (description.empty() ? "(no desc)" : description)
 99		<< llendl;
100	if(source_id.isNull())
101	{
102		return description;
103	}
104	if((0 == amount) && description.empty())
105	{
106		return description;
107	}
108	std::ostringstream ostr;
109	if(dest_id.isNull())
110	{
111		// *NOTE: Do not change these strings!  The viewer matches
112		// them in llviewermessage.cpp to perform localization.
113		// If you need to make changes, add a new, localizable message. JC
114		ostr << "You paid L$" << amount;
115		switch(transaction_type)
116		{
117		case TRANS_GROUP_CREATE:
118			ostr << " to create a group";
119			break;
120		case TRANS_GROUP_JOIN:
121			ostr << " to join a group";
122			break;
123		case TRANS_UPLOAD_CHARGE:
124			ostr << " to upload";
125			break;
126		default:
127			break;
128		}
129	}
130	else
131	{
132		ostr << "You paid " << dest_name << " L$" << amount;
133		append_reason(ostr, transaction_type, description);
134	}
135	ostr << ".";
136	return ostr.str();
137}
138
139std::string build_transfer_message_to_destination(
140	S32 amount,
141	const LLUUID& dest_id,
142	const LLUUID& source_id,
143	const std::string& source_name,
144	S32 transaction_type,
145	const std::string& description)
146{
147	lldebugs << "build_transfer_message_to_dest: " << amount << " "
148		<< dest_id << " " << source_id << " " << source_name << " "
149		<< transaction_type << " " << (description.empty() ? "(no desc)" : description)
150		<< llendl;
151	if(0 == amount)
152	{
153		return std::string();
154	}
155	if(dest_id.isNull())
156	{
157		return description;
158	}
159	std::ostringstream ostr;
160	// *NOTE: Do not change these strings!  The viewer matches
161	// them in llviewermessage.cpp to perform localization.
162	// If you need to make changes, add a new, localizable message. JC
163	ostr << source_name << " paid you L$" << amount;
164	append_reason(ostr, transaction_type, description);
165	ostr << ".";
166	return ostr.str();
167}