File indexing completed on 2024-05-05 05:13:11
0001 /* 0002 This file is part of Akregator. 0003 0004 SPDX-FileCopyrightText: 2007 Frank Osterfeld <osterfeld@kde.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0007 */ 0008 #pragma once 0009 0010 #include "akregatorpart_export.h" 0011 0012 #include <QAbstractItemModel> 0013 #include <QSet> 0014 #include <QSortFilterProxyModel> 0015 0016 #include <QColor> 0017 #include <QSharedPointer> 0018 0019 namespace Akregator 0020 { 0021 class Feed; 0022 class FeedList; 0023 class Folder; 0024 class TreeNode; 0025 0026 /** 0027 * Filters feeds with unread counts. 0028 */ 0029 class FilterUnreadProxyModel : public QSortFilterProxyModel 0030 { 0031 Q_OBJECT 0032 public: 0033 explicit FilterUnreadProxyModel(QObject *parent = nullptr); 0034 0035 [[nodiscard]] bool doFilter() const; 0036 0037 void setDoFilter(bool v); 0038 0039 void setSourceModel(QAbstractItemModel *src) override; 0040 0041 public Q_SLOTS: 0042 void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); 0043 void clearCache(); 0044 0045 private: 0046 [[nodiscard]] bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; 0047 0048 using SelectionHierarchy = QSet<QModelIndex>; 0049 0050 bool m_doFilter = false; 0051 SelectionHierarchy m_selectedHierarchy; 0052 }; 0053 0054 class AKREGATORPART_EXPORT SubscriptionListModel : public QAbstractItemModel 0055 { 0056 Q_OBJECT 0057 public: 0058 enum Role { SubscriptionIdRole = Qt::UserRole, IsFetchableRole, IsGroupRole, IsAggregationRole, LinkRole, IdRole, IsOpenRole, HasUnreadRole }; 0059 0060 enum Column { 0061 TitleColumn = 0, 0062 UnreadCountColumn = 1, 0063 TotalCountColumn = 2, 0064 ColumnCount = 3, 0065 }; 0066 0067 explicit SubscriptionListModel(const QSharedPointer<const FeedList> &feedList, QObject *parent = nullptr); 0068 0069 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0070 0071 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0072 0073 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0074 0075 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0076 0077 QModelIndex parent(const QModelIndex &index) const override; 0078 0079 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0080 0081 Qt::ItemFlags flags(const QModelIndex &index) const override; 0082 0083 QStringList mimeTypes() const override; 0084 0085 QMimeData *mimeData(const QModelIndexList &indexes) const override; 0086 0087 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 0088 0089 bool setData(const QModelIndex &idx, const QVariant &value, int role = Qt::EditRole) override; 0090 0091 private: 0092 QModelIndex indexForNode(const TreeNode *node) const; 0093 0094 private Q_SLOTS: 0095 0096 void subscriptionAdded(Akregator::TreeNode *); 0097 0098 void aboutToRemoveSubscription(Akregator::TreeNode *); 0099 0100 void subscriptionRemoved(Akregator::TreeNode *); 0101 0102 void subscriptionChanged(Akregator::TreeNode *); 0103 0104 void fetchStarted(Akregator::Feed *); 0105 0106 void fetched(Akregator::Feed *); 0107 0108 void fetchError(Akregator::Feed *); 0109 0110 void fetchAborted(Akregator::Feed *); 0111 0112 private: 0113 QSharedPointer<const FeedList> m_feedList; 0114 bool m_beganRemoval; 0115 0116 QColor m_errorColor; 0117 }; 0118 } 0119 0120 namespace Akregator 0121 { 0122 class AKREGATORPART_EXPORT FolderExpansionHandler : public QObject 0123 { 0124 Q_OBJECT 0125 0126 public: 0127 explicit FolderExpansionHandler(QObject *parent = nullptr); 0128 0129 void setFeedList(const QSharedPointer<FeedList> &feedList); 0130 void setModel(QAbstractItemModel *model); 0131 0132 public Q_SLOTS: 0133 void itemExpanded(const QModelIndex &index); 0134 void itemCollapsed(const QModelIndex &index); 0135 0136 private: 0137 void setExpanded(const QModelIndex &index, bool expanded); 0138 0139 private: 0140 QSharedPointer<FeedList> m_feedList; 0141 QAbstractItemModel *m_model = nullptr; 0142 }; 0143 } // namespace Akregator