File indexing completed on 2024-12-22 04:41:13
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #pragma once 0019 0020 #include "qmlbookmarktreenode.h" 0021 #include "mainapplication.h" 0022 0023 #include <QObject> 0024 0025 /** 0026 * @brief The class exposing the Bookmarks API to QML 0027 */ 0028 class QmlBookmarks : public QObject 0029 { 0030 Q_OBJECT 0031 0032 public: 0033 explicit QmlBookmarks(QObject *parent = nullptr); 0034 0035 /** 0036 * @brief Checks if the url is bookmarked 0037 * @param String representing the url to check 0038 * @return true if bookmarked, else false 0039 */ 0040 Q_INVOKABLE bool isBookmarked(const QString &url) const; 0041 /** 0042 * @brief Get the root bookmark item 0043 * @return Root boomkark item 0044 */ 0045 Q_INVOKABLE QmlBookmarkTreeNode *rootItem() const; 0046 /** 0047 * @brief Get the bookmarks toolbar 0048 * @return Bookmarks toolbar 0049 */ 0050 Q_INVOKABLE QmlBookmarkTreeNode *toolbarFolder() const; 0051 /** 0052 * @brief Get the bookmarks menu folder 0053 * @return Bookmarks menu folder 0054 */ 0055 Q_INVOKABLE QmlBookmarkTreeNode *menuFolder() const; 0056 /** 0057 * @brief Get the unsorted bookmarks folder 0058 * @return Unsorted bookmarks folder 0059 */ 0060 Q_INVOKABLE QmlBookmarkTreeNode *unsortedFolder() const; 0061 /** 0062 * @brief Get the last used bookmarks folder 0063 * @return Last used bookmarks folder 0064 */ 0065 Q_INVOKABLE QmlBookmarkTreeNode *lastUsedFolder() const; 0066 /** 0067 * @brief Creates a bookmark item 0068 * @param A JavaScript object containing 0069 * - parent: 0070 * Object of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode), representing 0071 * the parent of the new bookmark item. This is required field. 0072 * - title: 0073 * String representing the title of the new bookmark item. Defaults to empty string 0074 * - url: 0075 * String representing the url of the new bookmark item. Defaults to empty string 0076 * - description 0077 * String representing the description of the new bookmark item. Defaults to empty string 0078 * - type: 0079 * [Type](@ref QmlBookmarkTreeNode::Type) representing the type of the new bookmark item. 0080 * Defaults to [Url](@ref QmlBookmarkTreeNode::Url) if url is provided, else 0081 * [Folder](@ref QmlBookmarkTreeNode::Folder) if title is provided, else 0082 * [Invalid](@ref QmlBookmarkTreeNode::Invalid) 0083 * @return true if the bookmark it created, else false 0084 */ 0085 Q_INVOKABLE bool create(const QVariantMap &map) const; 0086 /** 0087 * @brief Removes a bookmark item 0088 * @param treeNode: 0089 * Object of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode) to be removed 0090 * @return true if the bookmark is removed, else false 0091 */ 0092 Q_INVOKABLE bool remove(QmlBookmarkTreeNode *treeNode) const; 0093 /** 0094 * @brief QmlBookmarks::search 0095 * @param A JavaScript object containing 0096 * - query: 0097 * String containing search query 0098 * - url: 0099 * String representing url to be search 0100 * @return List containing [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode). If both 0101 * query and url are not supplied then empty list is returned. 0102 */ 0103 Q_INVOKABLE QList<QObject*> search(const QVariantMap &map) const; 0104 /** 0105 * @brief Updates a bookmark item 0106 * @param Object of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode), representing the bookmark 0107 * to update 0108 * @param JavaScript object containing the values to be updated 0109 * - title: 0110 * String representing the new title of the bookmark item 0111 * - description: 0112 * String representing the new description of the bookmark item 0113 * - keyword: 0114 * String representing the new keyword of the bookmark item 0115 * @return true if the bookmark is updated, else false 0116 */ 0117 Q_INVOKABLE bool update(QObject *object, const QVariantMap &changes) const; 0118 /** 0119 * @brief Get the first matched bookmark item 0120 * @param String representing the query 0121 * @return Object of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode) if 0122 * the query is matched with a bookmark, else null 0123 */ 0124 Q_INVOKABLE QmlBookmarkTreeNode *get(const QString &string) const; 0125 /** 0126 * @brief Get children of the bookmark item 0127 * @param Object of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode), representing 0128 * the parent whose children are requested. 0129 * @return List containing the children, of type [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode) 0130 */ 0131 Q_INVOKABLE QList<QObject*> getChildren(QObject *object) const; 0132 0133 Q_SIGNALS: 0134 /** 0135 * @brief This signal is emitted when a new bookmark item is created 0136 * @param bookmark item, exposed to QML as [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode) 0137 */ 0138 void created(QmlBookmarkTreeNode *treeNode); 0139 0140 /** 0141 * @brief This signal is emitted when a bookmark item is edited 0142 * @param bookmark item, exposed to QML as [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode) 0143 */ 0144 void changed(QmlBookmarkTreeNode *treeNode); 0145 0146 /** 0147 * @brief This signal is emitted when a bookmark item is removed 0148 * @param bookmark item, exposed to QML as [QmlBookmarkTreeNode](@ref QmlBookmarkTreeNode) 0149 */ 0150 void removed(QmlBookmarkTreeNode *treeNode); 0151 0152 private: 0153 BookmarkItem *getBookmarkItem(QmlBookmarkTreeNode *treeNode) const; 0154 BookmarkItem *getBookmarkItem(QObject *object) const; 0155 };