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 #include "qmlbookmarktreenode.h" 0019 #include "mainapplication.h" 0020 #include "bookmarks.h" 0021 #include "qml/qmlstaticdata.h" 0022 #include <QQmlEngine> 0023 0024 QmlBookmarkTreeNode::QmlBookmarkTreeNode(BookmarkItem *item) 0025 : m_item(item) 0026 { 0027 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); 0028 } 0029 0030 BookmarkItem *QmlBookmarkTreeNode::item() 0031 { 0032 return m_item; 0033 } 0034 0035 QmlBookmarkTreeNode::Type QmlBookmarkTreeNode::type() const 0036 { 0037 if (!m_item) { 0038 return Invalid; 0039 } 0040 0041 switch (m_item->type()) { 0042 case BookmarkItem::Root: 0043 return Root; 0044 0045 case BookmarkItem::Url: 0046 return Url; 0047 0048 case BookmarkItem::Folder: 0049 return Folder; 0050 0051 case BookmarkItem::Separator: 0052 return Separator; 0053 0054 case BookmarkItem::Invalid: 0055 return Invalid; 0056 } 0057 0058 return Invalid; 0059 } 0060 0061 QString QmlBookmarkTreeNode::title() const 0062 { 0063 if (!m_item) { 0064 return {}; 0065 } 0066 0067 return m_item->title(); 0068 } 0069 0070 QString QmlBookmarkTreeNode::url() const 0071 { 0072 if (!m_item) { 0073 return {}; 0074 } 0075 0076 return m_item->urlString(); 0077 } 0078 0079 QString QmlBookmarkTreeNode::description() const 0080 { 0081 if (!m_item) { 0082 return {}; 0083 } 0084 0085 return m_item->description(); 0086 } 0087 0088 QString QmlBookmarkTreeNode::keyword() const 0089 { 0090 if (!m_item) { 0091 return {}; 0092 } 0093 0094 return m_item->keyword(); 0095 } 0096 0097 int QmlBookmarkTreeNode::visitCount() const 0098 { 0099 if (!m_item) { 0100 return 0; 0101 } 0102 0103 return m_item->visitCount(); 0104 } 0105 0106 QmlBookmarkTreeNode *QmlBookmarkTreeNode::parent() const 0107 { 0108 if (!m_item) { 0109 return nullptr; 0110 } 0111 0112 return QmlStaticData::instance().getBookmarkTreeNode(m_item->parent()); 0113 } 0114 0115 bool QmlBookmarkTreeNode::unmodifiable() const 0116 { 0117 return !mApp->bookmarks()->canBeModified(m_item); 0118 } 0119 0120 QList<QObject*> QmlBookmarkTreeNode::children() const 0121 { 0122 const QList<BookmarkItem*> items = m_item->children(); 0123 QList<QObject*> ret; 0124 ret.reserve(items.size()); 0125 for (BookmarkItem *item : items) { 0126 ret.append(QmlStaticData::instance().getBookmarkTreeNode(item)); 0127 } 0128 return ret; 0129 }