PageRenderTime 66ms CodeModel.GetById 21ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLTELEPORTHISTORYSTORAGE_H
  27. #define LL_LLTELEPORTHISTORYSTORAGE_H
  28. #include <vector>
  29. #include "llsingleton.h"
  30. #include "lldate.h"
  31. #include "v3dmath.h"
  32. class LLSD;
  33. /**
  34. * An item of the teleport history, stored in file
  35. *
  36. * Contains the location's global coordinates, title and date.
  37. */
  38. class LLTeleportHistoryPersistentItem
  39. {
  40. public:
  41. LLTeleportHistoryPersistentItem()
  42. {}
  43. LLTeleportHistoryPersistentItem(const std::string title, const LLVector3d& global_pos)
  44. : mTitle(title), mGlobalPos(global_pos), mDate(LLDate::now())
  45. {}
  46. LLTeleportHistoryPersistentItem(const std::string title, const LLVector3d& global_pos, const LLDate& date)
  47. : mTitle(title), mGlobalPos(global_pos), mDate(date)
  48. {}
  49. LLTeleportHistoryPersistentItem(const LLSD& val);
  50. LLSD toLLSD() const;
  51. std::string mTitle;
  52. LLVector3d mGlobalPos;
  53. LLDate mDate;
  54. };
  55. /**
  56. * Persistent teleport history.
  57. *
  58. */
  59. class LLTeleportHistoryStorage: public LLSingleton<LLTeleportHistoryStorage>
  60. {
  61. LOG_CLASS(LLTeleportHistoryStorage);
  62. public:
  63. typedef std::vector<LLTeleportHistoryPersistentItem> slurl_list_t;
  64. // removed_index is index of removed item, which replaced by more recent
  65. typedef boost::function<void(S32 removed_index)> history_callback_t;
  66. typedef boost::signals2::signal<void(S32 removed_index)> history_signal_t;
  67. LLTeleportHistoryStorage();
  68. ~LLTeleportHistoryStorage();
  69. /**
  70. * @return history items.
  71. */
  72. const slurl_list_t& getItems() const { return mItems; }
  73. void purgeItems();
  74. void addItem(const std::string title, const LLVector3d& global_pos);
  75. void addItem(const std::string title, const LLVector3d& global_pos, const LLDate& date);
  76. void removeItem(S32 idx);
  77. void save();
  78. /**
  79. * Set a callback to be called upon history changes.
  80. *
  81. * Multiple callbacks can be set.
  82. */
  83. boost::signals2::connection setHistoryChangedCallback(history_callback_t cb);
  84. /**
  85. * Go to specific item in the history.
  86. *
  87. * The item is specified by its index (starting from 0).
  88. */
  89. void goToItem(S32 idx);
  90. private:
  91. void load();
  92. void dump() const;
  93. void onTeleportHistoryChange();
  94. bool compareByTitleAndGlobalPos(const LLTeleportHistoryPersistentItem& a, const LLTeleportHistoryPersistentItem& b);
  95. slurl_list_t mItems;
  96. std::string mFilename;
  97. /**
  98. * Signal emitted when the history gets changed.
  99. *
  100. * Invokes callbacks set with setHistoryChangedCallback().
  101. */
  102. history_signal_t mHistoryChangedSignal;
  103. };
  104. #endif //LL_LLTELEPORTHISTORYSTORAGE_H