| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef FEEDSMODEL_H |
| 4 | #define FEEDSMODEL_H |
| 5 | |
| 6 | #include "services/abstract/rootitem.h" |
| 7 | |
| 8 | #include <QAbstractItemModel> |
| 9 | |
| 10 | class Category; |
| 11 | class Feed; |
| 12 | class ServiceRoot; |
| 13 | class ServiceEntryPoint; |
| 14 | class StandardServiceRoot; |
| 15 | |
| 16 | class RSSGUARD_DLLSPEC FeedsModel : public QAbstractItemModel { |
| 17 | Q_OBJECT |
| 18 | |
| 19 | public: |
| 20 | explicit FeedsModel(QObject* parent = nullptr); |
| 21 | virtual ~FeedsModel(); |
| 22 | |
| 23 | // Model implementation. |
| 24 | virtual QVariant data(const QModelIndex& index, int role) const; |
| 25 | |
| 26 | // Drag & drop. |
| 27 | virtual QMimeData* mimeData(const QModelIndexList& indexes) const; |
| 28 | virtual QStringList mimeTypes() const; |
| 29 | virtual Qt::DropActions supportedDropActions() const; |
| 30 | virtual Qt::ItemFlags flags(const QModelIndex& index) const; |
| 31 | |
| 32 | // Other subclassed methods. |
| 33 | virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
| 34 | virtual QModelIndex index(int row, int column, const QModelIndex& parent) const; |
| 35 | virtual QModelIndex parent(const QModelIndex& child) const; |
| 36 | virtual int columnCount(const QModelIndex& parent) const; |
| 37 | virtual int rowCount(const QModelIndex& parent) const; |
| 38 | |
| 39 | // Returns counts of ALL/UNREAD (non-deleted) messages for the model. |
| 40 | int countOfAllMessages() const; |
| 41 | int countOfUnreadMessages() const; |
| 42 | |
| 43 | // Returns all activated service roots. |
| 44 | // NOTE: Service root nodes are lying directly UNDER |
| 45 | // the model root item. |
| 46 | QList<ServiceRoot*> serviceRoots() const; |
| 47 | |
| 48 | // Returns the list of feeds which should be updated |
| 49 | // according to auto-update schedule. |
| 50 | // Variable "auto_update_now" is true, when global timeout |
| 51 | // for scheduled auto-update was met and global auto-update strategy is enabled |
| 52 | // so feeds with "default" auto-update strategy should be updated. |
| 53 | // |
| 54 | // This method might change some properties of some feeds. |
| 55 | QList<Feed*> feedsForScheduledUpdate(bool auto_update_now); |
| 56 | |
| 57 | // Returns ALL RECURSIVE CHILD feeds contained within single index. |
| 58 | QList<Feed*> feedsForIndex(const QModelIndex& index = QModelIndex()) const; |
| 59 | |
| 60 | // Returns feed/category which lies at the specified index or |
| 61 | // root item if index is invalid. |
| 62 | RootItem* itemForIndex(const QModelIndex& index) const; |
| 63 | |
| 64 | // Returns source QModelIndex on which lies given item. |
| 65 | // NOTE: This goes through all available indexes and |
| 66 | // checks their bound items manually, there is no |
| 67 | // other way to to this. |
| 68 | QModelIndex indexForItem(const RootItem* item) const; |
| 69 | |
| 70 | // Determines if any feed has any new messages. |
| 71 | bool hasAnyFeedNewMessages() const; |
| 72 | |
| 73 | // Access to root item. |
| 74 | RootItem* rootItem() const; |
| 75 | |
| 76 | void setupBehaviorDuringFetching(); |
| 77 | void setupFonts(); |
| 78 | void informAboutDatabaseCleanup(); |
| 79 | |
| 80 | public slots: |
| 81 | void loadActivatedServiceAccounts(); |
| 82 | |
| 83 | // Stops all accounts before exit. |
| 84 | void stopServiceAccounts(); |
| 85 | |
| 86 | // Reloads counts of all feeds/categories/whatever in the model. |
| 87 | void reloadCountsOfWholeModel(); |
| 88 | |
| 89 | // Checks if new parent node is different from one used by original node. |
| 90 | // If it is, then it reassigns original_node to new parent. |
| 91 | void reassignNodeToNewParent(RootItem* original_node, RootItem* new_parent); |
| 92 | |
| 93 | // Adds given service root account. |
| 94 | bool addServiceAccount(ServiceRoot* root, bool freshly_activated); |
| 95 | |
| 96 | // Removes item with given index. |
| 97 | // NOTE: Also deletes item from memory. |
| 98 | void removeItem(const QModelIndex& index); |
| 99 | void removeItem(RootItem* deleting_item); |
| 100 | |
| 101 | // Recycle bins operations. |
| 102 | bool restoreAllBins(); |
| 103 | bool emptyAllBins(); |
| 104 | |
| 105 | void changeSortOrder(RootItem* item, bool move_top, bool move_bottom, int new_sort_order = {}); |
| 106 | |
| 107 | // Takes direct descendants (but only categories or feeds) |
| 108 | // and rearranges them alphabetically. |
| 109 | void sortDirectDescendants(RootItem* item, RootItem::Kind kind_to_sort); |
| 110 | |
| 111 | // Feeds operations. |
| 112 | bool markItemRead(RootItem* item, RootItem::ReadStatus read); |
| 113 | bool markItemCleared(RootItem* item, bool clean_read_only); |
| 114 | bool purgeArticles(const QList<Feed *> &feeds); |
| 115 | |
| 116 | // Signals that properties (probably counts) |
| 117 | // of ALL items have changed. |
| 118 | void reloadWholeLayout(); |
| 119 | |
| 120 | // Signals that SOME data of this model need |
| 121 | // to be reloaded by ALL attached views. |
| 122 | // NOTE: This reloads all parent valid indexes too. |
| 123 | void reloadChangedLayout(QModelIndexList list); |
| 124 | |
| 125 | // Invalidates data under index for the item. |
| 126 | void reloadChangedItem(RootItem* item); |
| 127 | |
| 128 | // Notifies other components about messages |
| 129 | // counts. |
| 130 | void notifyWithCounts(); |
| 131 | |
| 132 | private slots: |
| 133 | void onItemDataChanged(const QList<RootItem*>& items); |
| 134 | |
| 135 | signals: |
| 136 | void messageCountsChanged(int unread_messages, bool any_feed_has_unread_messages); |
| 137 | |
| 138 | // Emitted if any item requested that any view should expand it. |
| 139 | void itemExpandRequested(QList<RootItem*> items, bool expand); |
| 140 | |
| 141 | // Emitted if any item requested that its expand states should be explicitly saved. |
| 142 | // NOTE: Normally expand states are saved when application quits. |
| 143 | void itemExpandStateSaveRequested(RootItem* subtree_root); |
| 144 | |
| 145 | // Emitted when there is a need of reloading of displayed messages. |
| 146 | void reloadMessageListRequested(bool mark_selected_messages_read); |
| 147 | |
| 148 | private: |
| 149 | bool m_updateDuringFetching; |
| 150 | QIcon m_updateItemIcon; |
| 151 | RootItem* m_rootItem; |
| 152 | QList<QString> m_headerData; |
| 153 | QList<QString> m_tooltipData; |
| 154 | QIcon m_countsIcon; |
| 155 | QFont m_normalFont; |
| 156 | QFont m_boldFont; |
| 157 | QFont m_normalStrikedFont; |
| 158 | QFont m_boldStrikedFont; |
| 159 | }; |
| 160 | |
| 161 | #endif // FEEDSMODEL_H |