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 #include "bookmarkitem.h"
0020 
0021 #include <QObject>
0022 
0023 /**
0024  * @brief The class exposing the bookmark item to QML
0025  */
0026 class QmlBookmarkTreeNode : public QObject
0027 {
0028     Q_OBJECT
0029 
0030     /**
0031      * @brief type of bookmark tree node.
0032      */
0033     Q_PROPERTY(Type type READ type CONSTANT)
0034 
0035     /**
0036      * @brief title of bookmark tree node.
0037      */
0038     Q_PROPERTY(QString title READ title CONSTANT)
0039 
0040     /**
0041      * @brief url of bookmark tree node.
0042      */
0043     Q_PROPERTY(QString url READ url CONSTANT)
0044 
0045     /**
0046      * @brief description of bookmark tree node.
0047      */
0048     Q_PROPERTY(QString description READ description CONSTANT)
0049 
0050     /**
0051      * @brief keyword of bookmark tree node.
0052      */
0053     Q_PROPERTY(QString keyword READ keyword CONSTANT)
0054 
0055     /**
0056      * @brief visit count of bookmark tree node.
0057      */
0058     Q_PROPERTY(int visitCount READ visitCount CONSTANT)
0059 
0060     /**
0061      * @brief parent of bookmark tree node.
0062      */
0063     Q_PROPERTY(QmlBookmarkTreeNode* parent READ parent CONSTANT)
0064 
0065     /**
0066      * @brief checks if bookmark tree node is unmodifiable.
0067      */
0068     Q_PROPERTY(bool unmodifiable READ unmodifiable CONSTANT)
0069 
0070     /**
0071      * @brief gets children of bookmark tree node.
0072      */
0073     Q_PROPERTY(QList<QObject*> children READ children CONSTANT)
0074 
0075 public:
0076     /**
0077      * @brief The Type enum
0078      *
0079      * Contains the information of the type of the bookmark item,
0080      */
0081     enum Type {
0082         Root = BookmarkItem::Root,           //!< Represents the root bookmark item
0083         Url = BookmarkItem::Url,             //!< Represents the single bookmark item of type url
0084         Folder = BookmarkItem::Folder,       //!< Represents the bookmark folder
0085         Separator = BookmarkItem::Separator, //!< Represents the bookmark separator
0086         Invalid = BookmarkItem::Invalid      //!< Represents invalid bookmark item
0087     };
0088     Q_ENUM(Type)
0089 
0090     explicit QmlBookmarkTreeNode(BookmarkItem *item = nullptr);
0091 
0092     BookmarkItem *item();
0093     Type type() const;
0094     QString title() const;
0095     QString url() const;
0096     QString description() const;
0097     QString keyword() const;
0098 
0099 private:
0100     BookmarkItem *m_item = nullptr;
0101 
0102     int visitCount() const;
0103     QmlBookmarkTreeNode *parent() const;
0104     bool unmodifiable() const;
0105     QList<QObject*> children() const;
0106 };