PageRenderTime 45ms CodeModel.GetById 32ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lllogchat.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 121 lines | 53 code | 15 blank | 53 comment | 0 complexity | c78f90cdeb91c48d0748789985ba5f8b MD5 | raw file
  1/** 
  2 * @file lllogchat.h
  3 * @brief LLFloaterChat class definition
  4 *
  5 * $LicenseInfo:firstyear=2002&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#ifndef LL_LLLOGCHAT_H
 28#define LL_LLLOGCHAT_H
 29
 30class LLChat;
 31
 32class LLLogChat
 33{
 34public:
 35	// status values for callback function
 36	enum ELogLineType {
 37		LOG_EMPTY,
 38		LOG_LINE,
 39		LOG_LLSD,
 40		LOG_END
 41	};
 42	static std::string timestamp(bool withdate = false);
 43	static std::string makeLogFileName(std::string(filename));
 44	/**
 45	*Add functions to get old and non date stamped file names when needed
 46	*/
 47	static std::string oldLogFileName(std::string(filename));
 48	static void saveHistory(const std::string& filename,
 49				const std::string& from,
 50				const LLUUID& from_id,
 51				const std::string& line);
 52
 53	/** @deprecated @see loadAllHistory() */
 54	static void loadHistory(const std::string& filename, 
 55		                    void (*callback)(ELogLineType, const LLSD&, void*), 
 56							void* userdata);
 57
 58	static void loadAllHistory(const std::string& file_name, std::list<LLSD>& messages);
 59private:
 60	static std::string cleanFileName(std::string filename);
 61};
 62
 63/**
 64 * Formatter for the plain text chat log files
 65 */
 66class LLChatLogFormatter
 67{
 68public:
 69	LLChatLogFormatter(const LLSD& im) : mIM(im) {}
 70	virtual ~LLChatLogFormatter() {};
 71
 72	friend std::ostream& operator<<(std::ostream& str, const LLChatLogFormatter& formatter)
 73	{
 74		formatter.format(formatter.mIM, str);
 75		return str;
 76	}
 77
 78protected:
 79
 80	/**
 81	 * Format an instant message to a stream
 82	 * Timestamps and sender names are required
 83	 * New lines of multilined messages are prepended with a space
 84	 */
 85	void format(const LLSD& im, std::ostream& ostr) const;
 86
 87	LLSD mIM;
 88};
 89
 90/**
 91 * Parser for the plain text chat log files
 92 */
 93class LLChatLogParser
 94{
 95public:
 96
 97	 /**
 98	 * Parse a line from the plain text chat log file
 99	 * General plain text log format is like: "[timestamp]  [name]: [message]"
100	 * [timestamp] and [name] are optional
101	 * Examples of plain text chat log lines:
102	 * "[2009/11/20 2:53]  Igor ProductEngine: howdy"
103	 * "Igor ProductEngine: howdy"
104	 * "Dserduk ProductEngine is Online"
105	 *
106	 * @return false if failed to parse mandatory data - message text
107	 */
108	static bool parse(std::string& raw, LLSD& im);
109
110protected:
111	LLChatLogParser();
112	virtual ~LLChatLogParser() {};
113};
114
115// LLSD map lookup constants
116extern const std::string IM_TIME; //("time");
117extern const std::string IM_TEXT; //("message");
118extern const std::string IM_FROM; //("from");
119extern const std::string IM_FROM_ID; //("from_id");
120
121#endif