PageRenderTime 33ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLSEARCHHISTORY_H
  27. #define LL_LLSEARCHHISTORY_H
  28. #include "llsingleton.h"
  29. #include "llui.h"
  30. /**
  31. * Search history container able to save and load history from file.
  32. * History is stored in chronological order, most recent at the beginning.
  33. */
  34. class LLSearchHistory : public LLSingleton<LLSearchHistory>, private LLDestroyClass<LLSearchHistory>
  35. {
  36. friend class LLDestroyClass<LLSearchHistory>;
  37. public:
  38. // Forward declaration
  39. class LLSearchHistoryItem;
  40. // Search history container
  41. typedef std::list<LLSearchHistoryItem> search_history_list_t;
  42. /**
  43. * Saves search history to file
  44. */
  45. bool save();
  46. /**
  47. * loads search history from file
  48. */
  49. bool load();
  50. /**
  51. * Returns search history list
  52. */
  53. search_history_list_t& getSearchHistoryList() { return mSearchHistory; }
  54. /**
  55. * Deletes all search history queries from list.
  56. */
  57. void clearHistory() { mSearchHistory.clear(); }
  58. /**
  59. * Adds unique entry to front of search history list, case insensitive
  60. * If entry is already in list, it will be deleted and added to front.
  61. */
  62. void addEntry(const std::string& search_text);
  63. LLSearchHistory();
  64. /**
  65. * Class for storing data about single search request.
  66. */
  67. class LLSearchHistoryItem
  68. {
  69. public:
  70. LLSearchHistoryItem()
  71. {}
  72. LLSearchHistoryItem(const std::string& query)
  73. : search_query(query)
  74. {}
  75. LLSearchHistoryItem(const LLSD& item)
  76. {
  77. if(item.has(SEARCH_QUERY))
  78. search_query = item[SEARCH_QUERY].asString();
  79. }
  80. std::string search_query;
  81. /**
  82. * Allows std::list sorting
  83. */
  84. bool operator < (const LLSearchHistory::LLSearchHistoryItem& right);
  85. /**
  86. * Allows std::list sorting
  87. */
  88. bool operator > (const LLSearchHistory::LLSearchHistoryItem& right);
  89. bool operator==(const LLSearchHistoryItem& right);
  90. bool operator==(const std::string& right);
  91. /**
  92. * Serializes search history item to LLSD
  93. */
  94. LLSD toLLSD() const;
  95. };
  96. protected:
  97. /**
  98. * Returns path to search history file.
  99. */
  100. std::string getHistoryFilePath();
  101. static std::string SEARCH_HISTORY_FILE_NAME;
  102. static std::string SEARCH_QUERY;
  103. private:
  104. // Implementation of LLDestroyClass<LLSearchHistory>
  105. static void destroyClass()
  106. {
  107. LLSearchHistory::getInstance()->save();
  108. }
  109. search_history_list_t mSearchHistory;
  110. };
  111. class LLSearchComboBox;
  112. #endif //LL_LLSEARCHHISTORY_H