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