/indra/newview/llteleporthistory.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 239 lines · 56 code · 32 blank · 151 comment · 0 complexity · de44ab455443a6ce7374ee49f084b094 MD5 · raw file

  1. /**
  2. * @file llteleporthistory.h
  3. * @brief 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_LLTELEPORTHISTORY_H
  27. #define LL_LLTELEPORTHISTORY_H
  28. #include "llsingleton.h" // for LLSingleton
  29. #include <vector>
  30. #include <string>
  31. #include <boost/function.hpp>
  32. #include <boost/signals2.hpp>
  33. #include "llteleporthistorystorage.h"
  34. /**
  35. * An item of the teleport history.
  36. *
  37. * Contains the location's global coordinates and its title.
  38. */
  39. class LLTeleportHistoryItem
  40. {
  41. public:
  42. LLTeleportHistoryItem()
  43. {}
  44. LLTeleportHistoryItem(std::string title, LLVector3d global_pos)
  45. : mTitle(title), mGlobalPos(global_pos)
  46. {}
  47. /**
  48. * @return title formatted according to the current value of the
  49. * NavBarShowCoordinates setting.
  50. */
  51. const std::string& getTitle() const;
  52. std::string mTitle; // human-readable location title
  53. std::string mFullTitle; // human-readable location title including coordinates
  54. LLVector3d mGlobalPos; // global position
  55. LLUUID mRegionID; // region ID for getting the region info
  56. };
  57. /**
  58. * Teleport history.
  59. *
  60. * Along with the navigation bar "Back" and "Forward" buttons
  61. * implements web browser-like navigation functionality.
  62. *
  63. * @see LLNavigationBar
  64. */
  65. class LLTeleportHistory: public LLSingleton<LLTeleportHistory>
  66. {
  67. LOG_CLASS(LLTeleportHistory);
  68. public:
  69. typedef std::vector<LLTeleportHistoryItem> slurl_list_t;
  70. typedef boost::function<void()> history_callback_t;
  71. typedef boost::signals2::signal<void()> history_signal_t;
  72. LLTeleportHistory();
  73. ~LLTeleportHistory();
  74. /**
  75. * Go back in the history.
  76. */
  77. void goBack() { goToItem(getCurrentItemIndex() - 1); }
  78. /**
  79. * Go forward in the history.
  80. */
  81. void goForward() { goToItem(getCurrentItemIndex() + 1); }
  82. /**
  83. * Go to specific item in the history.
  84. *
  85. * The item is specified by its index (starting from 0).
  86. */
  87. void goToItem(int idx);
  88. /**
  89. * @return history items.
  90. */
  91. const slurl_list_t& getItems() const { return mItems; }
  92. void purgeItems();
  93. /**
  94. * Is the history empty?
  95. *
  96. * History containing single item is treated as empty
  97. * because the item points to the current location.
  98. */
  99. bool isEmpty() const { return mItems.size() <= 1; }
  100. /**
  101. * Get index of the current location in the history.
  102. */
  103. int getCurrentItemIndex() const { return mCurrentItem; }
  104. /**
  105. * Set a callback to be called upon history changes.
  106. *
  107. * Multiple callbacks can be set.
  108. */
  109. boost::signals2::connection setHistoryChangedCallback(history_callback_t cb);
  110. /**
  111. * Save history to a file so that we can restore it on startup.
  112. *
  113. * @see load()
  114. */
  115. void dump() const;
  116. /**
  117. * Process login complete event. Basically put current location into history
  118. */
  119. void handleLoginComplete();
  120. private:
  121. /**
  122. * Called by when a teleport fails.
  123. *
  124. * Called via callback set on the LLViewerParcelMgr "teleport failed" signal.
  125. *
  126. * @see mTeleportFailedConn
  127. */
  128. void onTeleportFailed();
  129. /**
  130. * Update current location.
  131. *
  132. * @param new_pos Current agent global position. After local teleports we
  133. * cannot rely on gAgent.getPositionGlobal(),
  134. * so the new position gets passed explicitly.
  135. *
  136. * Called when a teleport finishes.
  137. * Called via callback set on the LLViewerParcelMgr "teleport finished" signal.
  138. *
  139. * Takes mRequestedItem into consideration: if it's not -1
  140. * (i.e. user is teleporting to an arbitrary location, not to a history item)
  141. * we purge forward items and append a new one, making it current. Otherwise
  142. * we just modify mCurrentItem.
  143. *
  144. * @see mRequestedItem
  145. * @see mGotInitialUpdate
  146. */
  147. void updateCurrentLocation(const LLVector3d& new_pos);
  148. /**
  149. * Invokes the "history changed" callback(s).
  150. */
  151. void onHistoryChanged();
  152. /**
  153. * Format current agent location in a human-readable manner.
  154. *
  155. * @param full whether to include coordinates
  156. * @param local_pos_override hack: see description of updateCurrentLocation()
  157. * @return
  158. */
  159. static std::string getCurrentLocationTitle(bool full, const LLVector3& local_pos_override);
  160. /**
  161. * Actually, the teleport history.
  162. */
  163. slurl_list_t mItems;
  164. /**
  165. * Current position within the history.
  166. */
  167. int mCurrentItem;
  168. /**
  169. * Requested position within the history.
  170. *
  171. * When a teleport succeeds, this is checked by updateCurrentLocation() to tell
  172. * if this is a teleport within the history (mRequestedItem >=0) or not (-1).
  173. *
  174. * Set by goToItem(); reset by onTeleportFailed() (if teleport fails).
  175. *
  176. * @see goToItem()
  177. * @see updateCurrentLocation()
  178. */
  179. int mRequestedItem;
  180. /**
  181. * Have we received the initial location update?
  182. *
  183. * @see updateCurrentLocation()
  184. */
  185. bool mGotInitialUpdate;
  186. LLTeleportHistoryStorage* mTeleportHistoryStorage;
  187. /**
  188. * Signal emitted when the history gets changed.
  189. *
  190. * Invokes callbacks set with setHistoryChangedCallback().
  191. */
  192. history_signal_t mHistoryChangedSignal;
  193. /**
  194. * Teleport success notification connection.
  195. *
  196. * Using this connection we get notified when a teleport finishes
  197. * or initial location update occurs.
  198. */
  199. boost::signals2::connection mTeleportFinishedConn;
  200. /**
  201. * Teleport failure notification connection.
  202. *
  203. * Using this connection we get notified when a teleport fails.
  204. */
  205. boost::signals2::connection mTeleportFailedConn;
  206. };
  207. #endif