Overte C++ Documentation
AvatarBookmarks.h
1 //
2 // AvatarBookmarks.h
3 // interface/src
4 //
5 // Created by Triplelexx on 23/03/17.
6 // Copyright 2017 High Fidelity, Inc.
7 // Copyright 2020 Vircadia contributors.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 //
12 
13 #ifndef hifi_AvatarBookmarks_h
14 #define hifi_AvatarBookmarks_h
15 
16 #include <DependencyManager.h>
17 #include "Bookmarks.h"
18 
19 /*@jsdoc
20  * The <code>AvatarBookmarks</code> API provides facilities for working with avatar bookmarks ("favorites" in the Avatar app).
21  * An avatar bookmark associates a name with an avatar model, scale, and avatar entities (wearables).
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 AvatarBookmarks
28  *
29  * @hifi-interface
30  * @hifi-client-entity
31  * @hifi-avatar
32  *
33  */
34 
35 class AvatarBookmarks: public Bookmarks, public Dependency {
36  Q_OBJECT
37  SINGLETON_DEPENDENCY
38 
39 public:
40  AvatarBookmarks();
41  void setupMenus(Menu* menubar, MenuWrapper* menu) override {};
42 
43  /*@jsdoc
44  * Gets the details of an avatar bookmark.
45  * @function AvatarBookmarks.getBookmark
46  * @param {string} bookmarkName - The name of the avatar bookmark (case sensitive).
47  * @returns {AvatarBookmarks.BookmarkData|{}} The bookmark data if the bookmark exists, <code>{}</code> if it doesn't.
48  */
49  Q_INVOKABLE QVariantMap getBookmark(const QString& bookmarkName);
50 
51 public slots:
52  /*@jsdoc
53  * Adds a new (or updates an existing) avatar bookmark with your current avatar model, scale, and avatar entities.
54  * @function AvatarBookmarks.addBookmark
55  * @param {string} bookmarkName - The name of the avatar bookmark (case sensitive).
56  * @example <caption>Add a new avatar bookmark and report the bookmark data.</caption>
57  * var bookmarkName = "New Bookmark";
58  * AvatarBookmarks.addBookmark(bookmarkName);
59  * var bookmarkData = AvatarBookmarks.getBookmark(bookmarkName);
60  * print("Bookmark data: " + JSON.stringify(bookmarkData));
61  */
62  void addBookmark(const QString& bookmarkName);
63 
64  /*@jsdoc
65  * Updates an existing bookmark with your current avatar model, scale, and wearables. No action is taken if the bookmark
66  * doesn't exist.
67  * @function AvatarBookmarks.saveBookmark
68  * @param {string} bookmarkName - The name of the avatar bookmark (case sensitive).
69  */
70  void saveBookmark(const QString& bookmarkName);
71 
72  /*@jsdoc
73  * Loads an avatar bookmark, setting your avatar model, scale, and avatar entities to those in the bookmark.
74  * @function AvatarBookmarks.loadBookmark
75  * @param {string} bookmarkName - The name of the avatar bookmark to load (case sensitive).
76  */
77  void loadBookmark(const QString& bookmarkName);
78 
79  /*@jsdoc
80  * Deletes an avatar bookmark.
81  * @function AvatarBookmarks.removeBookmark
82  * @param {string} bookmarkName - The name of the avatar bookmark to delete (case sensitive).
83  */
84  void removeBookmark(const QString& bookmarkName);
85 
86  /*@jsdoc
87  * Updates the avatar entities and their properties. Current avatar entities not included in the list provided are deleted.
88  * @function AvatarBookmarks.updateAvatarEntities
89  * @param {MyAvatar.AvatarEntityData[]} avatarEntities - The avatar entity IDs and properties.
90  * @deprecated This function is deprecated and will be removed. Use the {@link MyAvatar} API instead.
91  */
92  void updateAvatarEntities(const QVariantList& avatarEntities);
93 
94  /*@jsdoc
95  * Gets the details of all avatar bookmarks.
96  * @function AvatarBookmarks.getBookmarks
97  * @returns {Object<string,AvatarBookmarks.BookmarkData>} The current avatar bookmarks in an object where the keys are the
98  * bookmark names and the values are the bookmark details.
99  * @example <caption>List the names and URLs of all the avatar bookmarks.</caption>
100  * var bookmarks = AvatarBookmarks.getBookmarks();
101  * print("Avatar bookmarks:");
102  * for (var key in bookmarks) {
103  * print("- " + key + " " + bookmarks[key].avatarUrl);
104  * };
105  */
106  QVariantMap getBookmarks();
107 
108 signals:
109  /*@jsdoc
110  * Triggered when an avatar bookmark is loaded, setting your avatar model, scale, and avatar entities to those in the bookmark.
111  * @function AvatarBookmarks.bookmarkLoaded
112  * @param {string} bookmarkName - The name of the avatar bookmark loaded.
113  * @returns {Signal}
114  */
115  void bookmarkLoaded(const QString& bookmarkName);
116 
117  /*@jsdoc
118  * Triggered when an avatar bookmark is deleted.
119  * @function AvatarBookmarks.bookmarkDeleted
120  * @param {string} bookmarkName - The name of the avatar bookmark deleted.
121  * @returns {Signal}
122  * @example <caption>Report when a bookmark is deleted.</caption>
123  * AvatarBookmarks.bookmarkDeleted.connect(function (bookmarkName) {
124  * print("Bookmark deleted: " + bookmarkName);
125  * });
126  */
127  void bookmarkDeleted(const QString& bookmarkName);
128 
129  /*@jsdoc
130  * Triggered when a new avatar bookmark is added or an existing avatar bookmark is updated, using
131  * {@link AvatarBookmarks.addBookmark|addBookmark}.
132  * @function AvatarBookmarks.bookmarkAdded
133  * @param {string} bookmarkName - The name of the avatar bookmark added or updated.
134  * @returns {Signal}
135  */
136  void bookmarkAdded(const QString& bookmarkName);
137 
138 protected:
139  void addBookmarkToMenu(Menu* menubar, const QString& name, const QVariant& bookmark) override {};
140  void readFromFile() override;
141  QVariantMap getAvatarDataToBookmark();
142 
143 protected slots:
144  /*@jsdoc
145  * Performs no action.
146  * @function AvatarBookmarks.deleteBookmark
147  * @deprecated This function is deprecated and will be removed.
148  */
149  void deleteBookmark() override;
150 
151 private:
152  QVariantMap getBookmarkInternal(const QString &bookmarkName);
153  void addBookmarkInternal(const QString& bookmarkName);
154  void saveBookmarkInternal(const QString& bookmarkName);
155  void loadBookmarkInternal(const QString& bookmarkName);
156  void removeBookmarkInternal(const QString& bookmarkName);
157  const QString AVATARBOOKMARKS_FILENAME = "avatarbookmarks.json";
158  const QString ENTRY_AVATAR_URL = "avatarUrl";
159  const QString ENTRY_AVATAR_ICON = "avatarIcon";
160  const QString ENTRY_AVATAR_ENTITIES = "avatarEntites";
161  const QString ENTRY_AVATAR_SCALE = "avatarScale";
162  const QString ENTRY_VERSION = "version";
163 
164  const int AVATAR_BOOKMARK_VERSION = 3;
165 };
166 
167 #endif // hifi_AvatarBookmarks_h