// For license of this file, see /LICENSE.md. #ifndef FEEDDOWNLOADER_H #define FEEDDOWNLOADER_H #include #include #include "core/message.h" #include "exceptions/applicationexception.h" #include "services/abstract/cacheforserviceroot.h" #include "services/abstract/feed.h" class MessageFilter; class QMutex; // Represents results of batch feed updates. class FeedDownloadResults { public: QList> updatedFeeds() const; QString overview(int how_many_feeds) const; void appendUpdatedFeed(const QPair& feed); void sort(); void clear(); private: // QString represents title if the feed, int represents count of newly downloaded messages. QList> m_updatedFeeds; }; // This class offers means to "update" feeds and "special" categories. // NOTE: This class is used within separate thread. class FeedDownloader : public QObject { Q_OBJECT public: explicit FeedDownloader(); virtual ~FeedDownloader(); bool isUpdateRunning() const; bool isCacheSynchronizationRunning() const; public slots: void synchronizeAccountCaches(const QList& caches, bool emit_signals); void updateFeeds(const QList& feeds); void stopRunningUpdate(); signals: void cachesSynchronized(); void updateStarted(); void updateFinished(FeedDownloadResults updated_feeds); void updateProgress(const Feed* feed, int current, int total); private: void skipFeedUpdateWithError(ServiceRoot* acc, Feed* feed, const ApplicationException& ex); void updateOneFeed(ServiceRoot* acc, Feed* feed, const QHash& stated_messages, const QHash& tagged_messages); void finalizeUpdate(); void removeDuplicateMessages(QList& messages); bool m_isCacheSynchronizationRunning; bool m_stopCacheSynchronization; QList m_feeds = {}; QMutex* m_mutex; FeedDownloadResults m_results; int m_feedsUpdated; int m_feedsOriginalCount; }; #endif // FEEDDOWNLOADER_H