Warning, file /pim/akregator/src/folder.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     This file is part of Akregator.
0003 
0004     SPDX-FileCopyrightText: 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
0005         SPDX-FileCopyrightText: 2004-2005 Frank Osterfeld <osterfeld@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0008 */
0009 
0010 #pragma once
0011 
0012 #include "akregator_export.h"
0013 #include "treenode.h"
0014 
0015 class QDomDocument;
0016 class QDomElement;
0017 template<class T>
0018 class QList;
0019 
0020 namespace Akregator
0021 {
0022 class Article;
0023 class FetchQueue;
0024 class TreeNodeVisitor;
0025 
0026 /** Represents a folder (containing feeds and/or other folders)
0027  */
0028 class AKREGATOR_EXPORT Folder : public TreeNode
0029 {
0030     Q_OBJECT
0031 public:
0032     /** creates a feed group parsed from a XML dom element.
0033     Child nodes are not inserted or parsed.
0034     @param e the element representing the feed group
0035     @return a freshly created feed group */
0036     static Folder *fromOPML(const QDomElement &e);
0037 
0038     /** Creates a new folder with a given title
0039     @param title The title of the feed group
0040         */
0041     explicit Folder(const QString &title = QString());
0042 
0043     ~Folder() override;
0044 
0045     bool accept(TreeNodeVisitor *visitor) override;
0046 
0047     /** returns the number of unread articles in all children
0048     @return number of unread articles */
0049     [[nodiscard]] int unread() const override;
0050 
0051     /** returns the number of articles in all children
0052     @return number of articles */
0053     [[nodiscard]] int totalCount() const override;
0054 
0055     /** Helps the rest of the app to decide if node should be handled as group or not. */
0056     [[nodiscard]] bool isGroup() const override
0057     {
0058         return true;
0059     }
0060 
0061     // impl
0062     [[nodiscard]] bool isAggregation() const override
0063     {
0064         return true;
0065     }
0066 
0067     /** converts the feed group into OPML format for save and export and appends it to node @p parent in document @p document.
0068     Children are processed and appended recursively.
0069     @param parent The parent element
0070     @param document The DOM document
0071     @return The newly created element representing this feed group */
0072     QDomElement toOPML(QDomElement parent, QDomDocument document) const override;
0073 
0074     /** returns the (direct) children of this node.
0075     @return a list of pointers to the child nodes
0076         */
0077 
0078     [[nodiscard]] QList<const TreeNode *> children() const override;
0079 
0080     [[nodiscard]] QList<const TreeNode *> namedChildren(const QString &title) const;
0081     [[nodiscard]] QList<TreeNode *> namedChildren(const QString &title);
0082 
0083     [[nodiscard]] QList<TreeNode *> children() override;
0084 
0085     [[nodiscard]] QList<const Feed *> feeds() const override;
0086     [[nodiscard]] QList<Feed *> feeds() override;
0087     [[nodiscard]] QList<const Folder *> folders() const override;
0088     [[nodiscard]] QList<Folder *> folders() override;
0089 
0090     [[nodiscard]] int indexOf(const TreeNode *node) const;
0091 
0092     TreeNode *childAt(int pos) override;
0093 
0094     const TreeNode *childAt(int pos) const override;
0095 
0096     /** inserts @c node as child after child node @c after.
0097     if @c after is not a child of this group, @c node will be inserted as first child
0098     @param node the tree node to insert
0099     @param after the node after which @c node will be inserted */
0100     void insertChild(TreeNode *node, TreeNode *after);
0101 
0102     /** inserts @c node as first child
0103     @param node the tree node to insert */
0104     void prependChild(TreeNode *node);
0105 
0106     /** inserts @c node as last child
0107     @param node the tree node to insert */
0108     void appendChild(TreeNode *node);
0109 
0110     /** remove @c node from children. Note that @c node will not be deleted
0111     @param node the child node to remove  */
0112     void removeChild(TreeNode *node);
0113 
0114     /** returns the first child of the group, 0 if none exist */
0115     TreeNode *firstChild();
0116     const TreeNode *firstChild() const;
0117 
0118     /** returns the last child of the group, 0 if none exist */
0119     TreeNode *lastChild();
0120     const TreeNode *lastChild() const;
0121 
0122     /** returns whether the feed group is opened or not.
0123     Use only in \ref Folder . */
0124     [[nodiscard]] bool isOpen() const;
0125 
0126     /** open/close the feed group (display it as expanded/collapsed in the tree view). Use only in \ref Folder . */
0127     void setOpen(bool open);
0128 
0129     /** returns the next node in the tree.
0130     Calling next() unless it returns 0 iterates through the tree in pre-order
0131         */
0132     TreeNode *next() override;
0133     const TreeNode *next() const override;
0134 
0135     [[nodiscard]] QIcon icon() const override;
0136 
0137     /* returns whether @p node is among the direct or indirect children of this
0138      * folder
0139      */
0140     [[nodiscard]] bool subtreeContains(const Akregator::TreeNode *node) const;
0141 
0142     KJob *createMarkAsReadJob() override;
0143 
0144 Q_SIGNALS:
0145     /** emitted when a child was added */
0146     void signalChildAdded(Akregator::TreeNode *);
0147 
0148     /** emitted when a child was removed */
0149     void signalChildRemoved(Akregator::Folder *, Akregator::TreeNode *);
0150 
0151     void signalAboutToRemoveChild(Akregator::TreeNode *);
0152 
0153 public Q_SLOTS:
0154 
0155     /** Called when a child was modified.
0156     @param node the child that was changed
0157         */
0158     void slotChildChanged(Akregator::TreeNode *node);
0159 
0160     /** Called when a child was destroyed.
0161     @param node the child that was destroyed
0162     */
0163     void slotChildDestroyed(Akregator::TreeNode *node);
0164 
0165     /** enqueues children recursively for fetching
0166     @param queue a fetch queue
0167     @param intervalFetchesOnly determines whether to allow only interval fetches
0168     */
0169     void slotAddToFetchQueue(Akregator::FetchQueue *queue, bool intervalFetchesOnly = false) override;
0170 
0171 protected:
0172     /** inserts @c node as child on position @c index
0173     @param index the position where to insert
0174     @param node the tree node to insert */
0175     void insertChild(int index, TreeNode *node);
0176 
0177     void doArticleNotification() override;
0178 
0179 private:
0180     QList<Article> articles() override;
0181 
0182     void connectToNode(TreeNode *child);
0183     void disconnectFromNode(TreeNode *child);
0184 
0185     void updateUnreadCount() const;
0186     /** List of children */
0187     QList<TreeNode *> m_children;
0188     /** caching unread count of children */
0189     mutable int m_unread = 0;
0190     /** whether or not the folder is expanded */
0191     bool m_open = false;
0192 };
0193 } // namespace Akregator