/* ============================================================ * rekonq * ============================================================ * SPDX-License-Identifier: GPL-3.0-only * Copyright (C) 2022 aqua * ============================================================ * Description: rekonq bookmarks model * ============================================================ */ #pragma once #include #include #include #include #include #include class BookmarksTreeItem { public: enum BookmarkAction { OPEN = 0, OPEN_IN_TAB, OPEN_IN_WINDOW, OPEN_FOLDER, BOOKMARK_PAGE, NEW_FOLDER, NEW_SEPARATOR, COPY, EDIT, #ifdef HAVE_NEPOMUK FANCYBOOKMARK, #endif DELETE, NUM_ACTIONS, SET_TOOLBAR_FOLDER, UNSET_TOOLBAR_FOLDER }; enum Types { Root, Folder, Bookmark, Separator, Alias }; constexpr static int TypesCount = 5; struct Attributes_t { QString title{}; QUrl href{}; QDateTime added{}; QDateTime visited{}; QDateTime modified{}; QString description{}; QString id{}; }; enum Attributes { Title = 0, Href = 1, Added = 2, Visited = 3, Modified = 4, Description = 5, Id = 6 }; constexpr static int AttributeCount = 7; explicit BookmarksTreeItem(Types type, Attributes_t &&args, BookmarksTreeItem *parent); ~BookmarksTreeItem(); [[nodiscard]] BookmarksTreeItem *parent() const { return m_parent; } /** * Add an item to the end of the children list, if the item can have children * @return true if the item was added, false otherwise */ bool appendChild(BookmarksTreeItem *childItem); bool insertChild(int position, BookmarksTreeItem *childItem); bool removeChildAt(int index, int count = 1); [[nodiscard]] BookmarksTreeItem *takeChild(int index) { return m_children.takeAt(index); } [[nodiscard]] BookmarksTreeItem *child(int index) const { return m_children.value(index); } [[nodiscard]] auto childCount() const { return m_children.count(); } [[nodiscard]] BookmarksTreeItem *findChild(const QString &id) { if (id.isEmpty()) return nullptr; if (m_data.id == id) return this; for (auto *child : qAsConst(m_children)) if (child->m_data.id == id) return child; for (auto *child : qAsConst(m_children)) if (auto *grandchild = child->findChild(id)) return grandchild; return nullptr; } [[nodiscard]] QVariant data(Attributes column) const { switch (column) { case Title: return m_data.title; case Href: return m_data.href; case Added: return m_data.added; case Visited: return m_data.visited; case Modified: return m_data.modified; case Description: return m_data.description; case Id: return m_data.id; } return {}; } bool setData(Attributes column, const QVariant &data); [[nodiscard]] auto icon() const { return m_icon; } [[nodiscard]] bool isExpanded() const { return m_isExpanded; } void setExpanded(bool expanded); [[nodiscard]] QString tooltip() const; [[nodiscard]] Types type() const { return m_type; } [[nodiscard]] int row() const; QStringList metadata; private: BookmarksTreeItem *m_parent; QVector m_children; const Types m_type; QIcon m_icon; bool m_isExpanded = false; Attributes_t m_data; };