File indexing completed on 2024-04-28 05:11:03

0001 /*
0002     This file is part of Akregator.
0003 
0004     SPDX-FileCopyrightText: 2004 Frank Osterfeld <osterfeld@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0007 */
0008 
0009 #include "treenode.h"
0010 #include "article.h"
0011 #include "articlejobs.h"
0012 #include "folder.h"
0013 
0014 #include <QString>
0015 
0016 using namespace Akregator;
0017 
0018 TreeNode::TreeNode()
0019     : QObject(nullptr)
0020 {
0021 }
0022 
0023 void TreeNode::emitSignalDestroyed()
0024 {
0025     if (!m_signalDestroyedEmitted) {
0026         if (parent()) {
0027             parent()->removeChild(this);
0028         }
0029         Q_EMIT signalDestroyed(this);
0030         m_signalDestroyedEmitted = true;
0031     }
0032 }
0033 
0034 TreeNode::~TreeNode()
0035 {
0036     Q_ASSERT(m_signalDestroyedEmitted || !"TreeNode subclasses must call emitSignalDestroyed in their destructor");
0037 }
0038 
0039 QString TreeNode::title() const
0040 {
0041     return m_title;
0042 }
0043 
0044 void TreeNode::setTitle(const QString &title)
0045 {
0046     if (m_title != title) {
0047         m_title = title;
0048         nodeModified();
0049     }
0050 }
0051 
0052 TreeNode *TreeNode::nextSibling()
0053 {
0054     if (!m_parent) {
0055         return nullptr;
0056     }
0057     const QList<TreeNode *> children = parent()->children();
0058     const int idx = children.indexOf(this);
0059 
0060     return (idx + 1 < children.size()) ? children.at(idx + 1) : nullptr;
0061 }
0062 
0063 const TreeNode *TreeNode::nextSibling() const
0064 {
0065     if (!m_parent) {
0066         return nullptr;
0067     }
0068     const QList<const TreeNode *> children = parent()->children();
0069     const int idx = children.indexOf(this);
0070 
0071     return (idx + 1 < children.size()) ? children.at(idx + 1) : nullptr;
0072 }
0073 
0074 TreeNode *TreeNode::prevSibling()
0075 {
0076     if (!m_parent) {
0077         return nullptr;
0078     }
0079     const QList<TreeNode *> children = parent()->children();
0080 
0081     const int idx = children.indexOf(this);
0082     return (idx > 0) ? children.at(idx - 1) : nullptr;
0083 }
0084 
0085 const TreeNode *TreeNode::prevSibling() const
0086 {
0087     if (!m_parent) {
0088         return nullptr;
0089     }
0090     const QList<const TreeNode *> children = parent()->children();
0091     const int idx = children.indexOf(this);
0092     return (idx > 0) ? children.at(idx - 1) : nullptr;
0093 }
0094 
0095 const Folder *TreeNode::parent() const
0096 {
0097     return m_parent;
0098 }
0099 
0100 Folder *TreeNode::parent()
0101 {
0102     return m_parent;
0103 }
0104 
0105 QList<const TreeNode *> TreeNode::children() const
0106 {
0107     return {};
0108 }
0109 
0110 QList<TreeNode *> TreeNode::children()
0111 {
0112     return {};
0113 }
0114 
0115 const TreeNode *TreeNode::childAt(int pos) const
0116 {
0117     Q_UNUSED(pos)
0118     return nullptr;
0119 }
0120 
0121 TreeNode *TreeNode::childAt(int pos)
0122 {
0123     Q_UNUSED(pos)
0124     return nullptr;
0125 }
0126 
0127 void TreeNode::setParent(Folder *parent)
0128 {
0129     m_parent = parent;
0130 }
0131 
0132 void TreeNode::setNotificationMode(bool doNotify)
0133 {
0134     if (doNotify && !m_doNotify) { // turned on
0135         m_doNotify = true;
0136         if (m_nodeChangeOccurred) {
0137             Q_EMIT signalChanged(this);
0138         }
0139         if (m_articleChangeOccurred) {
0140             doArticleNotification();
0141         }
0142         m_nodeChangeOccurred = false;
0143         m_articleChangeOccurred = false;
0144     } else if (!doNotify && m_doNotify) { // turned off
0145         m_nodeChangeOccurred = false;
0146         m_articleChangeOccurred = false;
0147         m_doNotify = false;
0148     }
0149 }
0150 
0151 uint TreeNode::id() const
0152 {
0153     return m_id;
0154 }
0155 
0156 void TreeNode::setId(uint id)
0157 {
0158     m_id = id;
0159 }
0160 
0161 void TreeNode::nodeModified()
0162 {
0163     if (m_doNotify) {
0164         Q_EMIT signalChanged(this);
0165     } else {
0166         m_nodeChangeOccurred = true;
0167     }
0168 }
0169 
0170 void TreeNode::articlesModified()
0171 {
0172     if (m_doNotify) {
0173         doArticleNotification();
0174     } else {
0175         m_articleChangeOccurred = true;
0176     }
0177 }
0178 
0179 void TreeNode::doArticleNotification()
0180 {
0181 }
0182 
0183 QPoint TreeNode::listViewScrollBarPositions() const
0184 {
0185     return m_scrollBarPositions;
0186 }
0187 
0188 void TreeNode::setListViewScrollBarPositions(const QPoint &pos)
0189 {
0190     m_scrollBarPositions = pos;
0191 }
0192 
0193 ArticleListJob *TreeNode::createListJob()
0194 {
0195     return new ArticleListJob(this);
0196 }
0197 
0198 #include "moc_treenode.cpp"