Overte C++ Documentation
Bookmarks.h
1  //
2 // Bookmarks.h
3 // interface/src
4 //
5 // Created by David Rowe on 13 Jan 2015.
6 // Copyright 2015 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_Bookmarks_h
13 #define hifi_Bookmarks_h
14 
15 #include <QMap>
16 #include <QObject>
17 #include <QPointer>
18 
19 class QAction;
20 class QMenu;
21 class Menu;
22 class MenuWrapper;
23 
24 class Bookmarks: public QObject {
25  Q_OBJECT
26 
27 public:
28  Bookmarks();
29 
30  virtual void setupMenus(Menu* menubar, MenuWrapper* menu) = 0;
31  void insert(const QString& name, const QVariant& address); // Overwrites any existing entry with same name.
32  QString addressForBookmark(const QString& name) const;
33 
34 protected:
35  void deleteBookmark(const QString& bookmarkName);
36 
37  void addBookmarkToFile(const QString& bookmarkName, const QVariant& bookmark);
38  virtual void addBookmarkToMenu(Menu* menubar, const QString& name, const QVariant& bookmark) = 0;
39  void enableMenuItems(bool enabled);
40  virtual void readFromFile();
41  void sortActions(Menu* menubar, MenuWrapper* menu);
42  int getMenuItemLocation(QList<QAction*> actions, const QString& name) const;
43  void removeBookmarkFromMenu(Menu* menubar, const QString& name);
44  bool contains(const QString& name) const;
45  void remove(const QString& name);
46 
47  QVariantMap _bookmarks; // { name: url, ... }
48  QPointer<MenuWrapper> _bookmarksMenu;
49  QPointer<QAction> _deleteBookmarksAction;
50  QString _bookmarksFilename;
51  bool _isMenuSorted;
52 
53 protected slots:
54  /*@jsdoc
55  * Prompts the user to delete a bookmark. The user can select the bookmark to delete in the dialog that is opened.
56  * @function LocationBookmarks.deleteBookmark
57  */
58  virtual void deleteBookmark();
59 
60 private:
61  static bool sortOrder(QAction* a, QAction* b);
62 
63  void persistToFile();
64 };
65 
66 #endif // hifi_Bookmarks_h