1 // For license of this file, see <project-root-folder>/LICENSE.md. 2 3 #ifndef FEEDDOWNLOADER_H 4 #define FEEDDOWNLOADER_H 5 6 #include <QObject> 7 8 #include <QPair> 9 10 #include "core/message.h" 11 #include "services/abstract/cacheforserviceroot.h" 12 #include "services/abstract/feed.h" 13 14 class MessageFilter; 15 class QMutex; 16 17 // Represents results of batch feed updates. 18 class FeedDownloadResults { 19 public: 20 QList<QPair<QString, int>> updatedFeeds() const; 21 QString overview(int how_many_feeds) const; 22 23 void appendUpdatedFeed(const QPair<QString, int>& feed); 24 void sort(); FeedDownloader()25 void clear(); 26 27 private: 28 29 // QString represents title if the feed, int represents count of newly downloaded messages. ~FeedDownloader()30 QList<QPair<QString, int>> m_updatedFeeds; 31 }; 32 33 // This class offers means to "update" feeds and "special" categories. 34 // NOTE: This class is used within separate thread. 35 class FeedDownloader : public QObject { 36 Q_OBJECT isUpdateRunning() const37 38 public: 39 explicit FeedDownloader(); 40 virtual ~FeedDownloader(); synchronizeAccountCaches(const QList<CacheForServiceRoot * > & caches,bool emit_signals)41 42 bool isUpdateRunning() const; 43 bool isCacheSynchronizationRunning() const; 44 45 public slots: 46 void synchronizeAccountCaches(const QList<CacheForServiceRoot*>& caches, bool emit_signals); 47 void updateFeeds(const QList<Feed*>& feeds); 48 void stopRunningUpdate(); 49 50 signals: 51 void cachesSynchronized(); 52 void updateStarted(); 53 void updateFinished(FeedDownloadResults updated_feeds); 54 void updateProgress(const Feed* feed, int current, int total); 55 56 private: 57 void updateOneFeed(ServiceRoot* acc, 58 Feed* feed, 59 const QHash<ServiceRoot::BagOfMessages, QStringList>& stated_messages, 60 const QHash<QString, QStringList>& tagged_messages); 61 void finalizeUpdate(); 62 63 bool m_isCacheSynchronizationRunning; 64 bool m_stopCacheSynchronization; updateFeeds(const QList<Feed * > & feeds)65 QList<Feed*> m_feeds = {}; 66 QMutex* m_mutex; 67 FeedDownloadResults m_results; 68 int m_feedsUpdated; 69 int m_feedsOriginalCount; 70 }; 71 72 #endif // FEEDDOWNLOADER_H 73