File indexing completed on 2024-05-12 16:21:32
0001 /** 0002 * SPDX-FileCopyrightText: 2021-2022 Bart De Vries <bart@mogwai.be> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #pragma once 0008 0009 #include <QNetworkAccessManager> 0010 #include <QNetworkReply> 0011 #include <QNetworkRequest> 0012 #include <QString> 0013 0014 #include <Syndication/Syndication> 0015 #include <ThreadWeaver/Job> 0016 0017 #include "enclosure.h" 0018 0019 class UpdateFeedJob : public QObject, public ThreadWeaver::Job 0020 { 0021 Q_OBJECT 0022 0023 public: 0024 explicit UpdateFeedJob(const QString &url, const QByteArray &data, QObject *parent = nullptr); 0025 ~UpdateFeedJob(); 0026 0027 void run(ThreadWeaver::JobPointer, ThreadWeaver::Thread *) override; 0028 void abort(); 0029 0030 struct EntryDetails { 0031 QString feed; 0032 QString id; 0033 QString title; 0034 QString content; 0035 int created; 0036 int updated; 0037 QString link; 0038 bool read; 0039 bool isNew; 0040 bool hasEnclosure; 0041 QString image; 0042 }; 0043 0044 struct AuthorDetails { 0045 QString feed; 0046 QString id; 0047 QString name; 0048 QString uri; 0049 QString email; 0050 }; 0051 0052 struct EnclosureDetails { 0053 QString feed; 0054 QString id; 0055 int duration; 0056 int size; 0057 QString title; 0058 QString type; 0059 QString url; 0060 int playPosition; 0061 Enclosure::Status downloaded; 0062 }; 0063 0064 struct ChapterDetails { 0065 QString feed; 0066 QString id; 0067 int start; 0068 QString title; 0069 QString link; 0070 QString image; 0071 }; 0072 0073 Q_SIGNALS: 0074 void feedDetailsUpdated(const QString &url, 0075 const QString &name, 0076 const QString &image, 0077 const QString &link, 0078 const QString &description, 0079 const QDateTime &lastUpdated, 0080 const QString &dirname); 0081 void feedUpdated(const QString &url); 0082 void entryAdded(const QString &feedurl, const QString &id); 0083 void entryUpdated(const QString &feedurl, const QString &id); 0084 void feedUpdateStatusChanged(const QString &url, bool status); 0085 void aborting(); 0086 void finished(); 0087 0088 private: 0089 void processFeed(Syndication::FeedPtr feed); 0090 bool processEntry(Syndication::ItemPtr entry); 0091 bool processAuthor(const QString &entryId, const QString &authorName, const QString &authorUri, const QString &authorEmail); 0092 bool processEnclosure(Syndication::EnclosurePtr enclosure, const EntryDetails &newEntry, const EntryDetails &oldEntry); 0093 bool processChapter(const QString &entryId, const int &start, const QString &chapterTitle, const QString &link, const QString &image); 0094 void writeToDatabase(); 0095 0096 QString generateFeedDirname(const QString &name) const; 0097 bool m_abort = false; 0098 0099 QString m_url; 0100 QString m_dirname; 0101 QByteArray m_data; 0102 0103 bool m_isNewFeed; 0104 bool m_markUnreadOnNewFeed; 0105 QVector<EntryDetails> m_entries, m_newEntries, m_updateEntries; 0106 QVector<AuthorDetails> m_authors, m_newAuthors, m_updateAuthors; 0107 QVector<EnclosureDetails> m_enclosures, m_newEnclosures, m_updateEnclosures; 0108 QVector<ChapterDetails> m_chapters, m_newChapters, m_updateChapters; 0109 };