summaryrefslogtreecommitdiff
path: root/kde-apps/akregator/files/akregator-18.04.3-syndication.patch
blob: f20f8fffa93e45438e837fcc4b2878ef43e2c79b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
From d2797fe48b6d4429cd30163fd75003118400511f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Vr=C3=A1til?= <dvratil@kde.org>
Date: Sun, 22 Apr 2018 09:13:45 +0200
Subject: Port away from remove Syndication API

---
 src/CMakeLists.txt         |  1 +
 src/akregator_part.cpp     | 10 ------
 src/feed/feed.cpp          |  3 +-
 src/feed/feedretriever.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++
 src/feed/feedretriever.h   | 54 ++++++++++++++++++++++++++++++++
 5 files changed, 135 insertions(+), 11 deletions(-)
 create mode 100644 src/feed/feedretriever.cpp
 create mode 100644 src/feed/feedretriever.h

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 86af10e..312daee 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -86,6 +86,7 @@ set(akregatorprivate_LIB_SRCS
     article.cpp
     feed/feed.cpp
     feed/feedlist.cpp
+    feed/feedretriever.cpp
     treenode.cpp
     treenodevisitor.cpp
     utils.cpp
diff --git a/src/akregator_part.cpp b/src/akregator_part.cpp
index 74acfab..afde53f 100644
--- a/src/akregator_part.cpp
+++ b/src/akregator_part.cpp
@@ -259,14 +259,6 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &)
     connect(m_autosaveTimer, &QTimer::timeout, this, &Part::slotSaveFeedList);
     m_autosaveTimer->start(5 * 60 * 1000); // 5 minutes
 
-    QString useragent = QStringLiteral("Akregator/%1; syndication").arg(QStringLiteral(AKREGATOR_VERSION));
-
-    if (!Settings::customUserAgent().isEmpty()) {
-        useragent = Settings::customUserAgent();
-    }
-
-    Syndication::FileRetriever::setUserAgent(useragent);
-
     loadPlugins(QStringLiteral("extension"));   // FIXME: also unload them!
     if (mCentralWidget->previousSessionCrashed()) {
         mCentralWidget->needToRestoreCrashedSession();
@@ -361,8 +353,6 @@ void Part::slotSettingsChanged()
         m_actionManager->setTrayIcon(nullptr);
     }
 
-    Syndication::FileRetriever::setUseCache(Settings::useHTMLCache());
-
     const QStringList fonts {
         Settings::standardFont(),
         Settings::fixedFont(),
diff --git a/src/feed/feed.cpp b/src/feed/feed.cpp
index 87ba473..774f506 100644
--- a/src/feed/feed.cpp
+++ b/src/feed/feed.cpp
@@ -36,6 +36,7 @@
 #include "treenodevisitor.h"
 #include "types.h"
 #include "utils.h"
+#include "feedretriever.h"
 
 #include <Syndication/Syndication>
 
@@ -681,7 +682,7 @@ void Akregator::Feed::tryFetch()
     d->loader = Syndication::Loader::create(this, SLOT(fetchCompleted(Syndication::Loader *,
                                                                       Syndication::FeedPtr,
                                                                       Syndication::ErrorCode)));
-    d->loader->loadFrom(QUrl(d->xmlUrl));
+    d->loader->loadFrom(QUrl(d->xmlUrl), new FeedRetriever());
 }
 
 void Akregator::Feed::slotImageFetched(const QPixmap &image)
diff --git a/src/feed/feedretriever.cpp b/src/feed/feedretriever.cpp
new file mode 100644
index 0000000..62526c4
--- /dev/null
+++ b/src/feed/feedretriever.cpp
@@ -0,0 +1,78 @@
+/*
+    This file is part of Akregator.
+
+    Copyright (C) 2018 Daniel Vrátil <dvratil@kde.org>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+    As a special exception, permission is given to link this program
+    with any edition of Qt, and distribute the resulting executable,
+    without including the source code for Qt in the source distribution.
+*/
+
+#include "feedretriever.h"
+#include "akregatorconfig.h"
+#include "akregator-version.h"
+
+#include <KIO/StoredTransferJob>
+
+#include <QUrl>
+
+using namespace Akregator;
+
+FeedRetriever::FeedRetriever()
+    : Syndication::DataRetriever()
+{
+}
+
+void FeedRetriever::retrieveData(const QUrl &url)
+{
+    QString userAgent = QStringLiteral("Akregator/%1; syndication").arg(QStringLiteral(AKREGATOR_VERSION));
+    if (!Settings::customUserAgent().isEmpty()) {
+        userAgent = Settings::customUserAgent();
+    }
+    bool useCache = Settings::useHTMLCache();
+
+    auto job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo);
+    job->addMetaData(QStringLiteral("UserAgent"), userAgent);
+    job->addMetaData(QStringLiteral("cache"), useCache ? QStringLiteral("refresh") : QStringLiteral("reload"));
+    connect(job, &KJob::result, this, &FeedRetriever::getFinished);
+    mJob = job;
+    mJob->start();
+}
+
+int FeedRetriever::errorCode() const
+{
+    return mError;
+}
+
+void FeedRetriever::abort()
+{
+    if (mJob) {
+        mJob->kill();
+        mJob = nullptr;
+    }
+}
+
+void FeedRetriever::getFinished(KJob *job)
+{
+    if (job->error()) {
+        mError = job->error();
+        Q_EMIT dataRetrieved({}, false);
+        return;
+    }
+
+    Q_EMIT dataRetrieved(static_cast<KIO::StoredTransferJob*>(job)->data(), true);
+}
diff --git a/src/feed/feedretriever.h b/src/feed/feedretriever.h
new file mode 100644
index 0000000..3a0ff3d
--- /dev/null
+++ b/src/feed/feedretriever.h
@@ -0,0 +1,54 @@
+/*
+    This file is part of Akregator.
+
+    Copyright (C) 2018 Daniel Vrátil <dvratil@kde.org>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+    As a special exception, permission is given to link this program
+    with any edition of Qt, and distribute the resulting executable,
+    without including the source code for Qt in the source distribution.
+*/
+
+#ifndef FEEDRETRIEVER_H_
+#define FEEDRETRIEVER_H_
+
+#include <syndication/dataretriever.h>
+
+class KJob;
+
+namespace Akregator {
+
+class FeedRetriever : public Syndication::DataRetriever
+{
+    Q_OBJECT
+public:
+    explicit FeedRetriever();
+
+    void retrieveData(const QUrl &url) override;
+    void abort() override;
+    int errorCode() const override;
+
+private Q_SLOTS:
+    void getFinished(KJob *job);
+
+private:
+    KJob *mJob = nullptr;
+    int mError = 0;
+};
+
+}
+
+#endif
-- 
cgit v0.11.2