Skip to content

Commit 8e529fc

Browse files
author
Christophe Dumez
committed
RSS code clean up
- Also drops support for Qt 4.5
1 parent f344812 commit 8e529fc

13 files changed

Lines changed: 70 additions & 138 deletions

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ qBittorrent - A BitTorrent client in C++ / Qt4
1010
will install and execute qBittorrent hopefully without any problems.
1111

1212
Dependencies:
13-
- Qt >= 4.5.0 (libqtgui, libqtcore, libqtnetwork, libqtxml, libqtdbus/optional)
13+
- Qt >= 4.6.0 (libqtgui, libqtcore, libqtnetwork, libqtxml, libqtdbus/optional)
1414

1515
- pkg-config executable
1616

configure

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ cat >$1/modules.cpp <<EOT
325325
#line 1 "qt4.qcm"
326326
/*
327327
-----BEGIN QCMOD-----
328-
name: Qt >= 4.5
328+
name: Qt >= 4.6
329329
arg: enable-debug, Enable debug mode
330330
arg: disable-gui, Disable qBittorrent Graphical user interface for headless running
331331
-----END QCMOD-----
@@ -334,8 +334,8 @@ class qc_qt4 : public ConfObj
334334
{
335335
public:
336336
qc_qt4(Conf *c) : ConfObj(c) {}
337-
QString name() const { return "Qt >= 4.5"; }
338-
QString shortname() const { return "Qt 4.5"; }
337+
QString name() const { return "Qt >= 4.6"; }
338+
QString shortname() const { return "Qt 4.6"; }
339339
bool exec()
340340
{
341341
// NOX mode
@@ -356,7 +356,7 @@ public:
356356
#else
357357
conf->addExtra("MANPREFIX = \$\$PREFIX/share");
358358
#endif
359-
return(QT_VERSION >= 0x040500);
359+
return(QT_VERSION >= 0x040600);
360360
}
361361
};
362362
#line 1 "qt-dbus.qcm"

qcm/qt4.qcm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
-----BEGIN QCMOD-----
3-
name: Qt >= 4.5
3+
name: Qt >= 4.6
44
arg: enable-debug, Enable debug mode
55
arg: disable-gui, Disable qBittorrent Graphical user interface for headless running
66
-----END QCMOD-----
@@ -9,8 +9,8 @@ class qc_qt4 : public ConfObj
99
{
1010
public:
1111
qc_qt4(Conf *c) : ConfObj(c) {}
12-
QString name() const { return "Qt >= 4.5"; }
13-
QString shortname() const { return "Qt 4.5"; }
12+
QString name() const { return "Qt >= 4.6"; }
13+
QString shortname() const { return "Qt 4.6"; }
1414
bool exec()
1515
{
1616
// NOX mode
@@ -31,6 +31,6 @@ public:
3131
#else
3232
conf->addExtra("MANPREFIX = $$PREFIX/share");
3333
#endif
34-
return(QT_VERSION >= 0x040500);
34+
return(QT_VERSION >= 0x040600);
3535
}
3636
};

src/rss/rss_imp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ void RSSImp::refreshArticleList(QTreeWidgetItem* item) {
465465
else if (rss_item)
466466
news = rss_item->articleList();
467467
// Sort
468-
RssManager::sortNewsList(news);
468+
RssManager::sortArticleListByDateDesc(news);
469469
// Clear the list first
470470
textBrowser->clear();
471471
m_currentArticle = 0;

src/rss/rssarticle.cpp

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -220,39 +220,30 @@ RssArticlePtr xmlToRssArticle(RssFeed* parent, QXmlStreamReader& xml)
220220
QDateTime date;
221221
QString author;
222222

223-
while(!xml.atEnd()) {
224-
xml.readNext();
223+
Q_ASSERT(xml.isStartElement() && xml.name() == "item");
225224

226-
if (xml.isEndElement() && xml.name() == "item")
227-
break;
228-
229-
if (xml.isStartElement()) {
230-
if (xml.name() == "title") {
231-
title = xml.readElementText();
232-
}
233-
else if (xml.name() == "enclosure") {
234-
if (xml.attributes().value("type") == "application/x-bittorrent") {
235-
torrentUrl = xml.attributes().value("url").toString();
236-
}
237-
}
238-
else if (xml.name() == "link") {
239-
link = xml.readElementText();
240-
if (guid.isEmpty())
241-
guid = link;
242-
}
243-
else if (xml.name() == "description") {
244-
description = xml.readElementText();
245-
}
246-
else if (xml.name() == "pubDate") {
247-
date = RssArticle::parseDate(xml.readElementText());
248-
}
249-
else if (xml.name() == "author") {
250-
author = xml.readElementText();
251-
}
252-
else if (xml.name() == "guid") {
253-
guid = xml.readElementText();
254-
}
225+
while (xml.readNextStartElement()) {
226+
if (xml.name() == "title")
227+
title = xml.readElementText();
228+
else if (xml.name() == "enclosure") {
229+
if (xml.attributes().value("type") == "application/x-bittorrent")
230+
torrentUrl = xml.attributes().value("url").toString();
231+
}
232+
else if (xml.name() == "link") {
233+
link = xml.readElementText();
234+
if (guid.isEmpty())
235+
guid = link;
255236
}
237+
else if (xml.name() == "description")
238+
description = xml.readElementText();
239+
else if (xml.name() == "pubDate")
240+
date = RssArticle::parseDate(xml.readElementText());
241+
else if (xml.name() == "author")
242+
author = xml.readElementText();
243+
else if (xml.name() == "guid")
244+
guid = xml.readElementText();
245+
else
246+
xml.skipCurrentElement();
256247
}
257248

258249
if (guid.isEmpty())

src/rss/rssdownloadrule.cpp

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,20 @@ RssDownloadRule::RssDownloadRule(): m_enabled(false), m_useRegex(false)
4444
bool RssDownloadRule::matches(const QString &article_title) const
4545
{
4646
foreach (const QString& token, m_mustContain) {
47-
if (token.isEmpty() || token == "")
48-
continue;
49-
QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard);
50-
//reg.setMinimal(false);
51-
if (reg.indexIn(article_title) < 0) return false;
47+
if (!token.isEmpty()) {
48+
QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard);
49+
if (reg.indexIn(article_title) < 0)
50+
return false;
51+
}
5252
}
5353
qDebug("Checking not matching tokens");
5454
// Checking not matching
5555
foreach (const QString& token, m_mustNotContain) {
56-
if (token.isEmpty()) continue;
57-
QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard);
58-
if (reg.indexIn(article_title) > -1) return false;
56+
if (!token.isEmpty()) {
57+
QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard);
58+
if (reg.indexIn(article_title) > -1)
59+
return false;
60+
}
5961
}
6062
return true;
6163
}
@@ -76,25 +78,7 @@ void RssDownloadRule::setMustNotContain(const QString &tokens)
7678
m_mustNotContain = tokens.split(QRegExp("[\\s|]"));
7779
}
7880

79-
RssDownloadRulePtr RssDownloadRule::fromOldFormat(const QVariantHash &rule_hash, const QString &feed_url, const QString &rule_name)
80-
{
81-
qDebug() << Q_FUNC_INFO << feed_url << rule_name;
82-
RssDownloadRulePtr rule(new RssDownloadRule);
83-
rule->setName(rule_name);
84-
rule->setMustContain(rule_hash.value("matches", "").toString());
85-
rule->setMustNotContain(rule_hash.value("not", "").toString());
86-
if (!feed_url.isEmpty())
87-
rule->setRssFeeds(QStringList() << feed_url);
88-
rule->setSavePath(rule_hash.value("save_path", "").toString());
89-
// Is enabled?
90-
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
91-
const QHash<QString, QVariant> feeds_w_downloader = qBTRSS.value("downloader_on").toHash();
92-
rule->setEnabled(feeds_w_downloader.value(feed_url, true).toBool());
93-
// label was unsupported < 2.5.0
94-
return rule;
95-
}
96-
97-
RssDownloadRulePtr RssDownloadRule::fromNewFormat(const QVariantHash &rule_hash)
81+
RssDownloadRulePtr RssDownloadRule::fromVariantHash(const QVariantHash &rule_hash)
9882
{
9983
RssDownloadRulePtr rule(new RssDownloadRule);
10084
rule->setName(rule_hash.value("name").toString());

src/rss/rssdownloadrule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ class RssDownloadRule
4646

4747
public:
4848
explicit RssDownloadRule();
49-
static RssDownloadRulePtr fromOldFormat(const QVariantHash& rule_hash, const QString &feed_url, const QString &rule_name); // Before v2.5.0
50-
static RssDownloadRulePtr fromNewFormat(const QVariantHash &rule_hash);
49+
static RssDownloadRulePtr fromVariantHash(const QVariantHash &rule_hash);
5150
QVariantHash toVariantHash() const;
5251
bool matches(const QString &article_title) const;
5352
void setMustContain(const QString &tokens);

src/rss/rssdownloadrulelist.cpp

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -61,39 +61,9 @@ void RssDownloadRuleList::saveRulesToStorage()
6161
void RssDownloadRuleList::loadRulesFromStorage()
6262
{
6363
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
64-
if (qBTRSS.contains("feed_filters")) {
65-
importFeedsInOldFormat(qBTRSS.value("feed_filters").toHash());
66-
// Remove outdated rules
67-
qBTRSS.remove("feed_filters");
68-
// Save to new format
69-
saveRulesToStorage();
70-
return;
71-
}
72-
// Load from new format
7364
loadRulesFromVariantHash(qBTRSS.value("download_rules").toHash());
7465
}
7566

76-
void RssDownloadRuleList::importFeedsInOldFormat(const QHash<QString, QVariant> &rules)
77-
{
78-
foreach (const QString &feed_url, rules.keys()) {
79-
importFeedRulesInOldFormat(feed_url, rules.value(feed_url).toHash());
80-
}
81-
}
82-
83-
void RssDownloadRuleList::importFeedRulesInOldFormat(const QString &feed_url, const QHash<QString, QVariant> &rules)
84-
{
85-
foreach (const QString &rule_name, rules.keys()) {
86-
RssDownloadRulePtr rule = RssDownloadRule::fromOldFormat(rules.value(rule_name).toHash(), feed_url, rule_name);
87-
if (!rule) continue;
88-
// Check for rule name clash
89-
while(m_rules.contains(rule->name())) {
90-
rule->setName(rule->name()+"_");
91-
}
92-
// Add the rule to the list
93-
saveRule(rule);
94-
}
95-
}
96-
9767
QVariantHash RssDownloadRuleList::toVariantHash() const
9868
{
9969
QVariantHash ret;
@@ -105,11 +75,10 @@ QVariantHash RssDownloadRuleList::toVariantHash() const
10575

10676
void RssDownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h)
10777
{
108-
foreach (const QVariant& v, h.values()) {
109-
RssDownloadRulePtr rule = RssDownloadRule::fromNewFormat(v.toHash());
110-
if (rule && !rule->name().isEmpty()) {
78+
for (QVariantHash::ConstIterator it = h.begin(); it != h.end(); it++) {
79+
RssDownloadRulePtr rule = RssDownloadRule::fromVariantHash(it.value().toHash());
80+
if (rule && !rule->name().isEmpty())
11181
saveRule(rule);
112-
}
11382
}
11483
}
11584

@@ -182,30 +151,18 @@ bool RssDownloadRuleList::unserialize(const QString &path)
182151
QFile f(path);
183152
if (f.open(QIODevice::ReadOnly)) {
184153
QDataStream in(&f);
185-
if (path.endsWith(".filters", Qt::CaseInsensitive)) {
186-
// Old format (< 2.5.0)
187-
qDebug("Old serialization format detected, processing...");
188-
in.setVersion(QDataStream::Qt_4_3);
189-
QVariantHash tmp;
190-
in >> tmp;
191-
f.close();
192-
if (tmp.isEmpty()) return false;
193-
qDebug("Processing was successful!");
194-
// Unfortunately the feed_url is lost
195-
importFeedRulesInOldFormat("", tmp);
196-
} else {
197-
qDebug("New serialization format detected, processing...");
198-
in.setVersion(QDataStream::Qt_4_5);
199-
QVariantHash tmp;
200-
in >> tmp;
201-
f.close();
202-
if (tmp.isEmpty()) return false;
203-
qDebug("Processing was successful!");
204-
loadRulesFromVariantHash(tmp);
205-
}
154+
in.setVersion(QDataStream::Qt_4_5);
155+
QVariantHash tmp;
156+
in >> tmp;
157+
f.close();
158+
if (tmp.isEmpty())
159+
return false;
160+
qDebug("Processing was successful!");
161+
loadRulesFromVariantHash(tmp);
206162
return true;
163+
} else {
164+
qDebug("Error: could not open file at %s", qPrintable(path));
165+
return false;
207166
}
208-
qDebug("Error: could not open file at %s", qPrintable(path));
209-
return false;
210167
}
211168

src/rss/rssdownloadrulelist.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
#include <QHash>
3636
#include <QVariantHash>
3737
#include "rssdownloadrule.h"
38-
s
39-
// This class is not thread-safe (not required)
38+
4039
class RssDownloadRuleList
4140
{
4241
Q_DISABLE_COPY(RssDownloadRuleList)
@@ -56,8 +55,6 @@ class RssDownloadRuleList
5655

5756
private:
5857
void loadRulesFromStorage();
59-
void importFeedsInOldFormat(const QHash<QString, QVariant> &feedrules); // Before v2.5.0
60-
void importFeedRulesInOldFormat(const QString &feed_url, const QHash<QString, QVariant> &rules); // Before v2.5.0
6158
void loadRulesFromVariantHash(const QVariantHash& l);
6259
QVariantHash toVariantHash() const;
6360
void saveRulesToStorage();

src/rss/rssfeed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ void RssFeed::resizeList() {
319319
const uint nb_articles = m_articles.size();
320320
if (nb_articles > max_articles) {
321321
RssArticleList listItems = m_articles.values();
322-
RssManager::sortNewsList(listItems);
322+
RssManager::sortArticleListByDateDesc(listItems);
323323
const int excess = nb_articles - max_articles;
324324
for (uint i=nb_articles-excess; i<nb_articles; ++i) {
325325
m_articles.remove(listItems.at(i)->guid());

0 commit comments

Comments
 (0)