PageRenderTime 212ms CodeModel.GetById 80ms app.highlight 6ms RepoModel.GetById 125ms app.codeStats 0ms

/indra/newview/llsearchhistory.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 141 lines | 49 code | 29 blank | 63 comment | 1 complexity | e3fca5d9fe4dd43cc02ae1e78ccd32fd MD5 | raw file
  1/** 
  2 * @file llsearchhistory.h
  3 * @brief Search history container definition
  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_LLSEARCHHISTORY_H
 28#define LL_LLSEARCHHISTORY_H
 29
 30#include "llsingleton.h"
 31#include "llui.h"
 32
 33/**
 34 * Search history container able to save and load history from file.
 35 * History is stored in chronological order, most recent at the beginning.
 36 */
 37class LLSearchHistory : public LLSingleton<LLSearchHistory>, private LLDestroyClass<LLSearchHistory>
 38{
 39	friend class LLDestroyClass<LLSearchHistory>;
 40public:
 41
 42	// Forward declaration
 43	class LLSearchHistoryItem;
 44
 45	// Search history container
 46	typedef std::list<LLSearchHistoryItem>	search_history_list_t;
 47
 48	/**
 49	 * Saves search history to file
 50	 */
 51	bool save();
 52
 53	/**
 54	 * loads search history from file
 55	 */
 56	bool load();
 57
 58	/**
 59	 * Returns search history list
 60	 */
 61	search_history_list_t& getSearchHistoryList() { return mSearchHistory; }
 62
 63	/**
 64	 * Deletes all search history queries from list.
 65	 */
 66	void clearHistory() { mSearchHistory.clear(); }
 67
 68	/**
 69	 * Adds unique entry to front of search history list, case insensitive
 70	 * If entry is already in list, it will be deleted and added to front.
 71	 */
 72	void addEntry(const std::string& search_text);
 73
 74	LLSearchHistory();
 75
 76	/**
 77	 * Class for storing data about single search request.
 78	 */
 79	class LLSearchHistoryItem
 80	{
 81	public:
 82
 83		LLSearchHistoryItem()
 84		{}
 85
 86		LLSearchHistoryItem(const std::string& query)
 87			: search_query(query)
 88		{}
 89
 90		LLSearchHistoryItem(const LLSD& item)
 91		{
 92			if(item.has(SEARCH_QUERY))
 93				search_query = item[SEARCH_QUERY].asString();
 94		}
 95
 96		std::string search_query;
 97
 98		/**
 99		 * Allows std::list sorting
100		 */
101		bool operator < (const LLSearchHistory::LLSearchHistoryItem& right);
102
103		/**
104		 * Allows std::list sorting
105		 */
106		bool operator > (const LLSearchHistory::LLSearchHistoryItem& right);
107
108		bool operator==(const LLSearchHistoryItem& right);
109
110		bool operator==(const std::string& right);
111
112		/**
113		 * Serializes search history item to LLSD
114		 */
115		LLSD toLLSD() const;
116	};
117
118protected:
119
120	/**
121	 * Returns path to search history file.
122	 */
123	std::string getHistoryFilePath();
124
125	static std::string SEARCH_HISTORY_FILE_NAME;
126	static std::string SEARCH_QUERY;
127
128private:
129
130	// Implementation of LLDestroyClass<LLSearchHistory>
131	static void destroyClass()
132	{
133		LLSearchHistory::getInstance()->save();
134	}
135
136	search_history_list_t mSearchHistory;
137};
138
139class LLSearchComboBox;
140
141#endif //LL_LLSEARCHHISTORY_H