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