Overte C++ Documentation
LocationBookmarks.h
1 //
2 // LocationBookmarks.h
3 // interface/src
4 //
5 // Created by Triplelexx on 23/03/17.
6 // Copyright 2017 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_LocationBookmarks_h
13 #define hifi_LocationBookmarks_h
14 
15 #include <DependencyManager.h>
16 
17 #include "Bookmarks.h"
18 
19 /*@jsdoc
20  * The <code>LocationBookmarks</code> API provides facilities for working with location bookmarks. A location bookmark
21  * associates a name with a directory services address.
22  *
23  * <p><strong>Note:</strong> This is a protected API and it is only available
24  * to scripts with the appropriate permissions. Without them, the functions in
25  * this namespace won't do anything and will return empty values.</p>
26  *
27  * @namespace LocationBookmarks
28  *
29  * @hifi-client-entity
30  * @hifi-interface
31  * @hifi-avatar
32  */
33 
34 class LocationBookmarks : public Bookmarks, public Dependency {
35  Q_OBJECT
36  SINGLETON_DEPENDENCY
37 
38 public:
39  LocationBookmarks();
40 
41  void setupMenus(Menu* menubar, MenuWrapper* menu) override;
42  static const QString HOME_BOOKMARK;
43 
44  /*@jsdoc
45  * Gets the directory services address associated with a bookmark.
46  * @function LocationBookmarks.getAddress
47  * @param {string} bookmarkName - Name of the bookmark to get the directory services address for (case sensitive).
48  * @returns {string} The directory services address for the bookmark. If the bookmark does not exist, <code>""</code> is returned.
49  * @example <caption>Report the "Home" bookmark's directory services address.</caption>
50  * print("Home bookmark's address: " + LocationBookmarks.getAddress("Home"));
51  */
52  Q_INVOKABLE QString getAddress(const QString& bookmarkName);
53 
54 public slots:
55 
56  /*@jsdoc
57  * Prompts the user to bookmark their current location. The user can specify the name of the bookmark in the dialog that is
58  * opened.
59  * @function LocationBookmarks.addBookmark
60  */
61  void addBookmark();
62 
63  /*@jsdoc
64  * Sets the directory services address associated with the "Home" bookmark.
65  * @function LocationBookmarks.setHomeLocationToAddress
66  * @param {string} address - The directory services address to set the "Home" bookmark to.
67  */
68  void setHomeLocationToAddress(const QVariant& address);
69 
70  /*@jsdoc
71  * Gets the directory services address associated with the "Home" bookmark.
72  * @function LocationBookmarks.getHomeLocationAddress
73  * @returns {string} The directory services address for the "Home" bookmark.
74  */
75  QString getHomeLocationAddress();
76 
77  /*@jsdoc
78  * Gets the details of all bookmarks.
79  * @function LocationBookmarks.getBookmarks
80  * @returns {object} The current bookmarks in an object where the keys
81  * are the bookmark names and the values are the bookmark URLs.
82  * @example <caption>List the names and URLs of all the bookmarks.</caption>
83  * var bookmarks = LocationBookmarks.getBookmarks();
84  * print("Location bookmarks:");
85  * for (const [name, url] of Object.entries(bookmarks)) {
86  * print(`- ${name} ${url}`);
87  * }
88  */
89  QVariantMap getBookmarks();
90 
91  /*@jsdoc
92  * Adds a new bookmark or replaces an existing one.
93  * @function LocationBookmarks.addBookmark
94  * @param {string} name - The name of the bookmark.
95  * @param {string} url - The bookmark's URL.
96  */
97  void addBookmark(const QString& name, const QString& url);
98 
99 
100  /*@jsdoc
101  * Deletes a bookmark, if it exists.
102  * @function LocationBookmarks.removeBookmark
103  * @param {string} name - The name of the bookmark.
104  */
105  void removeBookmark(const QString& name);
106 
107 protected:
108  void addBookmarkToMenu(Menu* menubar, const QString& name, const QVariant& address) override;
109 
110 private:
111  const QString LOCATIONBOOKMARKS_FILENAME = "bookmarks.json";
112 
113 private slots:
114  void setHomeLocation();
115  void teleportToBookmark();
116 };
117 
118 #endif // hifi_LocationBookmarks_h