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

/indra/newview/llteleporthistorystorage.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 130 lines | 51 code | 26 blank | 53 comment | 0 complexity | 14b4f32c1d3c9c4572341e27bc4f225c MD5 | raw file
  1/**
  2 * @file llteleporthistorystorage.h
  3 * @brief Saving/restoring of teleport history.
  4 *
  5 * $LicenseInfo:firstyear=2009&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_LLTELEPORTHISTORYSTORAGE_H
 28#define LL_LLTELEPORTHISTORYSTORAGE_H
 29
 30#include <vector>
 31
 32#include "llsingleton.h"
 33#include "lldate.h"
 34#include "v3dmath.h"
 35
 36class LLSD;
 37
 38/**
 39 * An item of the teleport history, stored in file
 40 *
 41 * Contains the location's global coordinates, title and date.
 42 */
 43class LLTeleportHistoryPersistentItem
 44{
 45public:
 46	LLTeleportHistoryPersistentItem()
 47	{}
 48
 49	LLTeleportHistoryPersistentItem(const std::string title, const LLVector3d& global_pos)
 50		: mTitle(title), mGlobalPos(global_pos), mDate(LLDate::now())
 51	{}
 52
 53	LLTeleportHistoryPersistentItem(const std::string title, const LLVector3d& global_pos, const LLDate& date)
 54		: mTitle(title), mGlobalPos(global_pos), mDate(date)
 55	{}
 56
 57	LLTeleportHistoryPersistentItem(const LLSD& val);
 58	LLSD toLLSD() const;
 59
 60	std::string	mTitle;
 61	LLVector3d	mGlobalPos;
 62	LLDate		mDate;
 63};
 64
 65/**
 66 * Persistent teleport history.
 67 *
 68 */
 69class LLTeleportHistoryStorage: public LLSingleton<LLTeleportHistoryStorage>
 70{
 71	LOG_CLASS(LLTeleportHistoryStorage);
 72
 73public:
 74
 75	typedef std::vector<LLTeleportHistoryPersistentItem> slurl_list_t;
 76
 77	// removed_index is index of removed item, which replaced by more recent
 78	typedef boost::function<void(S32 removed_index)>		history_callback_t;
 79	typedef boost::signals2::signal<void(S32 removed_index)>	history_signal_t;
 80
 81	LLTeleportHistoryStorage();
 82	~LLTeleportHistoryStorage();
 83
 84	/**
 85	 * @return history items.
 86	 */
 87	const slurl_list_t& getItems() const { return mItems; }
 88	void			purgeItems();
 89
 90	void addItem(const std::string title, const LLVector3d& global_pos);
 91	void addItem(const std::string title, const LLVector3d& global_pos, const LLDate& date);
 92
 93	void removeItem(S32 idx);
 94
 95	void save();
 96
 97	/**
 98	 * Set a callback to be called upon history changes.
 99	 * 
100	 * Multiple callbacks can be set.
101	 */
102	boost::signals2::connection	setHistoryChangedCallback(history_callback_t cb);
103
104	/**
105	 * Go to specific item in the history.
106	 * 
107	 * The item is specified by its index (starting from 0).
108	 */
109	void					goToItem(S32 idx);
110
111private:
112
113	void load();
114	void dump() const;
115	
116	void onTeleportHistoryChange();
117	bool compareByTitleAndGlobalPos(const LLTeleportHistoryPersistentItem& a, const LLTeleportHistoryPersistentItem& b);
118
119	slurl_list_t	mItems;
120	std::string	mFilename;
121
122	/**
123	 * Signal emitted when the history gets changed.
124	 * 
125	 * Invokes callbacks set with setHistoryChangedCallback().
126	 */
127	history_signal_t		mHistoryChangedSignal;
128};
129
130#endif //LL_LLTELEPORTHISTORYSTORAGE_H