Warning, file /pim/akregator/src/articlejobs.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 0009 #include "articlejobs.h" 0010 #include "article.h" 0011 #include "feed.h" 0012 #include "feedlist.h" 0013 #include "kernel.h" 0014 0015 #include "akregator_debug.h" 0016 #include <KLocalizedString> 0017 0018 #include <QTimer> 0019 0020 #include <vector> 0021 0022 #include <cassert> 0023 #include <chrono> 0024 0025 using namespace std::chrono_literals; 0026 0027 using namespace Akregator; 0028 0029 ArticleDeleteJob::ArticleDeleteJob(QObject *parent) 0030 : KJob(parent) 0031 , m_feedList(Kernel::self()->feedList()) 0032 { 0033 Q_ASSERT(m_feedList); 0034 } 0035 0036 void ArticleDeleteJob::appendArticleIds(const Akregator::ArticleIdList &ids) 0037 { 0038 m_ids += ids; 0039 } 0040 0041 void ArticleDeleteJob::appendArticleId(const ArticleId &id) 0042 { 0043 m_ids += id; 0044 } 0045 0046 void ArticleDeleteJob::start() 0047 { 0048 QTimer::singleShot(20ms, this, &ArticleDeleteJob::doStart); 0049 } 0050 0051 void ArticleDeleteJob::doStart() 0052 { 0053 if (!m_feedList) { 0054 qCWarning(AKREGATOR_LOG) << "Feedlist object was deleted, items not deleted"; 0055 emitResult(); 0056 return; 0057 } 0058 std::vector<Feed *> feeds; 0059 0060 for (const ArticleId &id : std::as_const(m_ids)) { 0061 Article article = m_feedList->findArticle(id.feedUrl, id.guid); 0062 if (article.isNull()) { 0063 continue; 0064 } 0065 0066 if (Feed *const feed = m_feedList->findByURL(id.feedUrl)) { 0067 feeds.push_back(feed); 0068 feed->setNotificationMode(false); 0069 } 0070 article.setDeleted(); 0071 } 0072 0073 for (Feed *const i : std::as_const(feeds)) { 0074 i->setNotificationMode(true); 0075 } 0076 0077 emitResult(); 0078 } 0079 0080 ArticleModifyJob::ArticleModifyJob(QObject *parent) 0081 : KJob(parent) 0082 , m_feedList(Kernel::self()->feedList()) 0083 { 0084 Q_ASSERT(m_feedList); 0085 } 0086 0087 void ArticleModifyJob::setStatus(const ArticleId &id, int status) 0088 { 0089 m_status[id] = status; 0090 } 0091 0092 void ArticleModifyJob::setKeep(const ArticleId &id, bool keep) 0093 { 0094 m_keepFlags[id] = keep; 0095 } 0096 0097 void ArticleModifyJob::start() 0098 { 0099 QTimer::singleShot(20ms, this, &ArticleModifyJob::doStart); 0100 } 0101 0102 void ArticleModifyJob::doStart() 0103 { 0104 if (!m_feedList) { 0105 qCWarning(AKREGATOR_LOG) << "Feedlist object was deleted, items not modified"; 0106 emitResult(); 0107 return; 0108 } 0109 std::vector<Feed *> feeds; 0110 0111 for (auto it = m_keepFlags.cbegin(), end = m_keepFlags.cend(); it != end; ++it) { 0112 const ArticleId &id = it.key(); 0113 Feed *feed = m_feedList->findByURL(id.feedUrl); 0114 if (!feed) { 0115 continue; 0116 } 0117 feed->setNotificationMode(false); 0118 feeds.push_back(feed); 0119 Article article = feed->findArticle(id.guid); 0120 if (!article.isNull()) { 0121 article.setKeep(it.value()); 0122 } 0123 } 0124 0125 for (auto it = m_status.cbegin(), end = m_status.cend(); it != end; ++it) { 0126 const ArticleId &id = it.key(); 0127 Feed *feed = m_feedList->findByURL(id.feedUrl); 0128 if (!feed) { 0129 continue; 0130 } 0131 feed->setNotificationMode(false); 0132 feeds.push_back(feed); 0133 Article article = feed->findArticle(id.guid); 0134 if (!article.isNull()) { 0135 article.setStatus(it.value()); 0136 } 0137 } 0138 0139 for (Feed *const i : std::as_const(feeds)) { 0140 i->setNotificationMode(true); 0141 } 0142 emitResult(); 0143 } 0144 0145 CompositeJob::CompositeJob(QObject *parent) 0146 : KCompositeJob(parent) 0147 { 0148 } 0149 0150 bool CompositeJob::addSubjob(KJob *job) 0151 { 0152 return KCompositeJob::addSubjob(job); 0153 } 0154 0155 void CompositeJob::start() 0156 { 0157 if (subjobs().isEmpty()) { 0158 emitResult(); 0159 return; 0160 } 0161 const auto jobs = subjobs(); 0162 for (KJob *const i : jobs) { 0163 i->start(); 0164 } 0165 } 0166 0167 ArticleListJob::ArticleListJob(TreeNode *p) 0168 : KJob(p) 0169 , m_node(p) 0170 { 0171 } 0172 0173 void ArticleListJob::start() 0174 { 0175 QTimer::singleShot(20ms, this, &ArticleListJob::doList); 0176 } 0177 0178 void ArticleListJob::doList() 0179 { 0180 if (m_node) { 0181 m_articles = m_node->articles(); 0182 } else { 0183 setError(ListingFailed); 0184 setErrorText(i18n("The feed to be listed was already removed.")); 0185 } 0186 emitResult(); 0187 } 0188 0189 TreeNode *ArticleListJob::node() const 0190 { 0191 return m_node; 0192 } 0193 0194 QList<Article> ArticleListJob::articles() const 0195 { 0196 return m_articles; 0197 } 0198 0199 #include "moc_articlejobs.cpp"