PageRenderTime 261ms CodeModel.GetById 148ms app.highlight 10ms RepoModel.GetById 101ms app.codeStats 0ms

/indra/newview/lllocationhistory.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 141 lines | 94 code | 16 blank | 31 comment | 5 complexity | 2f7e7cc5c5f20f3051e673af28d32de0 MD5 | raw file
  1/** 
  2 * @file llocationhistory.h
  3 * @brief Typed locations 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_LLLOCATIONHISTORY_H
 28#define LL_LLLOCATIONHISTORY_H
 29
 30#include "llsingleton.h" // for LLSingleton
 31
 32#include <vector>
 33#include <string>
 34#include <map>
 35#include <boost/function.hpp>
 36#include <boost/signals2.hpp>
 37
 38class LLSD;
 39/**
 40 * This enum is responsible for identifying of history item.
 41 */
 42enum ELocationType {
 43	 TYPED_REGION_SLURL//item added after the user had typed a region name or slurl 
 44	,LANDMARK  // item has been loaded from landmark folder
 45	,TELEPORT_HISTORY // item from session teleport history
 46	};
 47class LLLocationHistoryItem {
 48			
 49public:
 50	LLLocationHistoryItem(){}
 51	LLLocationHistoryItem(std::string typed_location, 
 52			LLVector3d global_position, std::string tooltip,ELocationType type ):
 53		mLocation(typed_location),		
 54		mGlobalPos(global_position),
 55		mToolTip(tooltip),
 56		mType(type)
 57	{}
 58	LLLocationHistoryItem(const LLLocationHistoryItem& item):
 59		mGlobalPos(item.mGlobalPos),
 60		mToolTip(item.mToolTip),
 61		mLocation(item.mLocation),
 62		mType(item.mType)
 63	{}
 64	LLLocationHistoryItem(const LLSD& data):
 65	mLocation(data["location"]),
 66	mGlobalPos(data["global_pos"]),
 67	mToolTip(data["tooltip"]),
 68	mType(ELocationType(data["item_type"].asInteger()))
 69	{}
 70
 71	bool operator==(const LLLocationHistoryItem& item)
 72	{
 73		// do not compare  mGlobalPos, 
 74		// because of a rounding off , the history  can contain duplicates
 75		return mLocation == item.mLocation && (mType == item.mType); 
 76	}
 77	bool operator!=(const LLLocationHistoryItem& item)
 78	{
 79		return ! (*this == item);
 80	}
 81	LLSD toLLSD() const
 82	{
 83		LLSD val;
 84		val["location"]= mLocation;
 85		val["global_pos"]	= mGlobalPos.getValue();
 86		val["tooltip"]	= mToolTip;
 87		val["item_type"] = mType;
 88		return val;
 89	}
 90	const std::string& getLocation() const { return mLocation;	};
 91	const std::string& getToolTip() const { return mToolTip;	};
 92	//static bool equalByRegionParcel(const LLLocationHistoryItem& item1, const LLLocationHistoryItem& item2);
 93	static bool equalByLocation(const LLLocationHistoryItem& item1, const std::string& item_location)
 94	{
 95		return  item1.getLocation() == item_location;
 96	}
 97	
 98	LLVector3d	mGlobalPos; // global position
 99	std::string mToolTip;// SURL
100	std::string mLocation;// typed_location
101	ELocationType mType;
102};
103
104class LLLocationHistory: public LLSingleton<LLLocationHistory>
105{
106	LOG_CLASS(LLLocationHistory);
107
108public:
109	enum EChangeType
110	{
111		 ADD
112		,CLEAR
113		,LOAD
114	};
115	
116	typedef std::vector<LLLocationHistoryItem>	location_list_t;
117	typedef boost::function<void(EChangeType event)>			history_changed_callback_t;
118	typedef boost::signals2::signal<void(EChangeType event)>	history_changed_signal_t;
119	
120	LLLocationHistory();
121	
122	void					addItem(const LLLocationHistoryItem& item);
123	bool					touchItem(const LLLocationHistoryItem& item);
124	void                    removeItems();
125	size_t					getItemCount() const	{ return mItems.size(); }
126	const location_list_t&	getItems() const		{ return mItems; }
127	bool					getMatchingItems(const std::string& substring, location_list_t& result) const;
128	boost::signals2::connection	setChangedCallback(history_changed_callback_t cb) { return mChangedSignal.connect(cb); }
129	
130	void					save() const;
131	void					load();
132	void					dump() const;
133
134private:
135
136	location_list_t			mItems;
137	std::string							mFilename; /// File to store the history to.
138	history_changed_signal_t			mChangedSignal;
139};
140
141#endif