Browse Source

RSS code clean up

- Also drops support for Qt 4.5
adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
8e529fc179
  1. 2
      INSTALL
  2. 8
      configure
  3. 8
      qcm/qt4.qcm
  4. 2
      src/rss/rss_imp.cpp
  5. 53
      src/rss/rssarticle.cpp
  6. 38
      src/rss/rssdownloadrule.cpp
  7. 3
      src/rss/rssdownloadrule.h
  8. 71
      src/rss/rssdownloadrulelist.cpp
  9. 5
      src/rss/rssdownloadrulelist.h
  10. 2
      src/rss/rssfeed.cpp
  11. 2
      src/rss/rssfeed.h
  12. 10
      src/rss/rssmanager.cpp
  13. 4
      src/rss/rssmanager.h

2
INSTALL

@ -10,7 +10,7 @@ qBittorrent - A BitTorrent client in C++ / Qt4
will install and execute qBittorrent hopefully without any problems. will install and execute qBittorrent hopefully without any problems.
Dependencies: Dependencies:
- Qt >= 4.5.0 (libqtgui, libqtcore, libqtnetwork, libqtxml, libqtdbus/optional) - Qt >= 4.6.0 (libqtgui, libqtcore, libqtnetwork, libqtxml, libqtdbus/optional)
- pkg-config executable - pkg-config executable

8
configure vendored

@ -325,7 +325,7 @@ cat >$1/modules.cpp <<EOT
#line 1 "qt4.qcm" #line 1 "qt4.qcm"
/* /*
-----BEGIN QCMOD----- -----BEGIN QCMOD-----
name: Qt >= 4.5 name: Qt >= 4.6
arg: enable-debug, Enable debug mode arg: enable-debug, Enable debug mode
arg: disable-gui, Disable qBittorrent Graphical user interface for headless running arg: disable-gui, Disable qBittorrent Graphical user interface for headless running
-----END QCMOD----- -----END QCMOD-----
@ -334,8 +334,8 @@ class qc_qt4 : public ConfObj
{ {
public: public:
qc_qt4(Conf *c) : ConfObj(c) {} qc_qt4(Conf *c) : ConfObj(c) {}
QString name() const { return "Qt >= 4.5"; } QString name() const { return "Qt >= 4.6"; }
QString shortname() const { return "Qt 4.5"; } QString shortname() const { return "Qt 4.6"; }
bool exec() bool exec()
{ {
// NOX mode // NOX mode
@ -356,7 +356,7 @@ public:
#else #else
conf->addExtra("MANPREFIX = \$\$PREFIX/share"); conf->addExtra("MANPREFIX = \$\$PREFIX/share");
#endif #endif
return(QT_VERSION >= 0x040500); return(QT_VERSION >= 0x040600);
} }
}; };
#line 1 "qt-dbus.qcm" #line 1 "qt-dbus.qcm"

8
qcm/qt4.qcm

@ -1,6 +1,6 @@
/* /*
-----BEGIN QCMOD----- -----BEGIN QCMOD-----
name: Qt >= 4.5 name: Qt >= 4.6
arg: enable-debug, Enable debug mode arg: enable-debug, Enable debug mode
arg: disable-gui, Disable qBittorrent Graphical user interface for headless running arg: disable-gui, Disable qBittorrent Graphical user interface for headless running
-----END QCMOD----- -----END QCMOD-----
@ -9,8 +9,8 @@ class qc_qt4 : public ConfObj
{ {
public: public:
qc_qt4(Conf *c) : ConfObj(c) {} qc_qt4(Conf *c) : ConfObj(c) {}
QString name() const { return "Qt >= 4.5"; } QString name() const { return "Qt >= 4.6"; }
QString shortname() const { return "Qt 4.5"; } QString shortname() const { return "Qt 4.6"; }
bool exec() bool exec()
{ {
// NOX mode // NOX mode
@ -31,6 +31,6 @@ public:
#else #else
conf->addExtra("MANPREFIX = $$PREFIX/share"); conf->addExtra("MANPREFIX = $$PREFIX/share");
#endif #endif
return(QT_VERSION >= 0x040500); return(QT_VERSION >= 0x040600);
} }
}; };

2
src/rss/rss_imp.cpp

@ -465,7 +465,7 @@ void RSSImp::refreshArticleList(QTreeWidgetItem* item) {
else if (rss_item) else if (rss_item)
news = rss_item->articleList(); news = rss_item->articleList();
// Sort // Sort
RssManager::sortNewsList(news); RssManager::sortArticleListByDateDesc(news);
// Clear the list first // Clear the list first
textBrowser->clear(); textBrowser->clear();
m_currentArticle = 0; m_currentArticle = 0;

53
src/rss/rssarticle.cpp

@ -220,39 +220,30 @@ RssArticlePtr xmlToRssArticle(RssFeed* parent, QXmlStreamReader& xml)
QDateTime date; QDateTime date;
QString author; QString author;
while(!xml.atEnd()) { Q_ASSERT(xml.isStartElement() && xml.name() == "item");
xml.readNext();
if (xml.isEndElement() && xml.name() == "item") while (xml.readNextStartElement()) {
break; if (xml.name() == "title")
title = xml.readElementText();
if (xml.isStartElement()) { else if (xml.name() == "enclosure") {
if (xml.name() == "title") { if (xml.attributes().value("type") == "application/x-bittorrent")
title = xml.readElementText(); torrentUrl = xml.attributes().value("url").toString();
} }
else if (xml.name() == "enclosure") { else if (xml.name() == "link") {
if (xml.attributes().value("type") == "application/x-bittorrent") { link = xml.readElementText();
torrentUrl = xml.attributes().value("url").toString(); if (guid.isEmpty())
} guid = link;
}
else if (xml.name() == "link") {
link = xml.readElementText();
if (guid.isEmpty())
guid = link;
}
else if (xml.name() == "description") {
description = xml.readElementText();
}
else if (xml.name() == "pubDate") {
date = RssArticle::parseDate(xml.readElementText());
}
else if (xml.name() == "author") {
author = xml.readElementText();
}
else if (xml.name() == "guid") {
guid = xml.readElementText();
}
} }
else if (xml.name() == "description")
description = xml.readElementText();
else if (xml.name() == "pubDate")
date = RssArticle::parseDate(xml.readElementText());
else if (xml.name() == "author")
author = xml.readElementText();
else if (xml.name() == "guid")
guid = xml.readElementText();
else
xml.skipCurrentElement();
} }
if (guid.isEmpty()) if (guid.isEmpty())

38
src/rss/rssdownloadrule.cpp

@ -44,18 +44,20 @@ RssDownloadRule::RssDownloadRule(): m_enabled(false), m_useRegex(false)
bool RssDownloadRule::matches(const QString &article_title) const bool RssDownloadRule::matches(const QString &article_title) const
{ {
foreach (const QString& token, m_mustContain) { foreach (const QString& token, m_mustContain) {
if (token.isEmpty() || token == "") if (!token.isEmpty()) {
continue; QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard);
QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard); if (reg.indexIn(article_title) < 0)
//reg.setMinimal(false); return false;
if (reg.indexIn(article_title) < 0) return false; }
} }
qDebug("Checking not matching tokens"); qDebug("Checking not matching tokens");
// Checking not matching // Checking not matching
foreach (const QString& token, m_mustNotContain) { foreach (const QString& token, m_mustNotContain) {
if (token.isEmpty()) continue; if (!token.isEmpty()) {
QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard); QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard);
if (reg.indexIn(article_title) > -1) return false; if (reg.indexIn(article_title) > -1)
return false;
}
} }
return true; return true;
} }
@ -76,25 +78,7 @@ void RssDownloadRule::setMustNotContain(const QString &tokens)
m_mustNotContain = tokens.split(QRegExp("[\\s|]")); m_mustNotContain = tokens.split(QRegExp("[\\s|]"));
} }
RssDownloadRulePtr RssDownloadRule::fromOldFormat(const QVariantHash &rule_hash, const QString &feed_url, const QString &rule_name) RssDownloadRulePtr RssDownloadRule::fromVariantHash(const QVariantHash &rule_hash)
{
qDebug() << Q_FUNC_INFO << feed_url << rule_name;
RssDownloadRulePtr rule(new RssDownloadRule);
rule->setName(rule_name);
rule->setMustContain(rule_hash.value("matches", "").toString());
rule->setMustNotContain(rule_hash.value("not", "").toString());
if (!feed_url.isEmpty())
rule->setRssFeeds(QStringList() << feed_url);
rule->setSavePath(rule_hash.value("save_path", "").toString());
// Is enabled?
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
const QHash<QString, QVariant> feeds_w_downloader = qBTRSS.value("downloader_on").toHash();
rule->setEnabled(feeds_w_downloader.value(feed_url, true).toBool());
// label was unsupported < 2.5.0
return rule;
}
RssDownloadRulePtr RssDownloadRule::fromNewFormat(const QVariantHash &rule_hash)
{ {
RssDownloadRulePtr rule(new RssDownloadRule); RssDownloadRulePtr rule(new RssDownloadRule);
rule->setName(rule_hash.value("name").toString()); rule->setName(rule_hash.value("name").toString());

3
src/rss/rssdownloadrule.h

@ -46,8 +46,7 @@ class RssDownloadRule
public: public:
explicit RssDownloadRule(); explicit RssDownloadRule();
static RssDownloadRulePtr fromOldFormat(const QVariantHash& rule_hash, const QString &feed_url, const QString &rule_name); // Before v2.5.0 static RssDownloadRulePtr fromVariantHash(const QVariantHash &rule_hash);
static RssDownloadRulePtr fromNewFormat(const QVariantHash &rule_hash);
QVariantHash toVariantHash() const; QVariantHash toVariantHash() const;
bool matches(const QString &article_title) const; bool matches(const QString &article_title) const;
void setMustContain(const QString &tokens); void setMustContain(const QString &tokens);

71
src/rss/rssdownloadrulelist.cpp

@ -61,39 +61,9 @@ void RssDownloadRuleList::saveRulesToStorage()
void RssDownloadRuleList::loadRulesFromStorage() void RssDownloadRuleList::loadRulesFromStorage()
{ {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
if (qBTRSS.contains("feed_filters")) {
importFeedsInOldFormat(qBTRSS.value("feed_filters").toHash());
// Remove outdated rules
qBTRSS.remove("feed_filters");
// Save to new format
saveRulesToStorage();
return;
}
// Load from new format
loadRulesFromVariantHash(qBTRSS.value("download_rules").toHash()); loadRulesFromVariantHash(qBTRSS.value("download_rules").toHash());
} }
void RssDownloadRuleList::importFeedsInOldFormat(const QHash<QString, QVariant> &rules)
{
foreach (const QString &feed_url, rules.keys()) {
importFeedRulesInOldFormat(feed_url, rules.value(feed_url).toHash());
}
}
void RssDownloadRuleList::importFeedRulesInOldFormat(const QString &feed_url, const QHash<QString, QVariant> &rules)
{
foreach (const QString &rule_name, rules.keys()) {
RssDownloadRulePtr rule = RssDownloadRule::fromOldFormat(rules.value(rule_name).toHash(), feed_url, rule_name);
if (!rule) continue;
// Check for rule name clash
while(m_rules.contains(rule->name())) {
rule->setName(rule->name()+"_");
}
// Add the rule to the list
saveRule(rule);
}
}
QVariantHash RssDownloadRuleList::toVariantHash() const QVariantHash RssDownloadRuleList::toVariantHash() const
{ {
QVariantHash ret; QVariantHash ret;
@ -105,11 +75,10 @@ QVariantHash RssDownloadRuleList::toVariantHash() const
void RssDownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h) void RssDownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h)
{ {
foreach (const QVariant& v, h.values()) { for (QVariantHash::ConstIterator it = h.begin(); it != h.end(); it++) {
RssDownloadRulePtr rule = RssDownloadRule::fromNewFormat(v.toHash()); RssDownloadRulePtr rule = RssDownloadRule::fromVariantHash(it.value().toHash());
if (rule && !rule->name().isEmpty()) { if (rule && !rule->name().isEmpty())
saveRule(rule); saveRule(rule);
}
} }
} }
@ -182,30 +151,18 @@ bool RssDownloadRuleList::unserialize(const QString &path)
QFile f(path); QFile f(path);
if (f.open(QIODevice::ReadOnly)) { if (f.open(QIODevice::ReadOnly)) {
QDataStream in(&f); QDataStream in(&f);
if (path.endsWith(".filters", Qt::CaseInsensitive)) { in.setVersion(QDataStream::Qt_4_5);
// Old format (< 2.5.0) QVariantHash tmp;
qDebug("Old serialization format detected, processing..."); in >> tmp;
in.setVersion(QDataStream::Qt_4_3); f.close();
QVariantHash tmp; if (tmp.isEmpty())
in >> tmp; return false;
f.close(); qDebug("Processing was successful!");
if (tmp.isEmpty()) return false; loadRulesFromVariantHash(tmp);
qDebug("Processing was successful!");
// Unfortunately the feed_url is lost
importFeedRulesInOldFormat("", tmp);
} else {
qDebug("New serialization format detected, processing...");
in.setVersion(QDataStream::Qt_4_5);
QVariantHash tmp;
in >> tmp;
f.close();
if (tmp.isEmpty()) return false;
qDebug("Processing was successful!");
loadRulesFromVariantHash(tmp);
}
return true; return true;
} else {
qDebug("Error: could not open file at %s", qPrintable(path));
return false;
} }
qDebug("Error: could not open file at %s", qPrintable(path));
return false;
} }

5
src/rss/rssdownloadrulelist.h

@ -35,8 +35,7 @@
#include <QHash> #include <QHash>
#include <QVariantHash> #include <QVariantHash>
#include "rssdownloadrule.h" #include "rssdownloadrule.h"
s
// This class is not thread-safe (not required)
class RssDownloadRuleList class RssDownloadRuleList
{ {
Q_DISABLE_COPY(RssDownloadRuleList) Q_DISABLE_COPY(RssDownloadRuleList)
@ -56,8 +55,6 @@ public:
private: private:
void loadRulesFromStorage(); void loadRulesFromStorage();
void importFeedsInOldFormat(const QHash<QString, QVariant> &feedrules); // Before v2.5.0
void importFeedRulesInOldFormat(const QString &feed_url, const QHash<QString, QVariant> &rules); // Before v2.5.0
void loadRulesFromVariantHash(const QVariantHash& l); void loadRulesFromVariantHash(const QVariantHash& l);
QVariantHash toVariantHash() const; QVariantHash toVariantHash() const;
void saveRulesToStorage(); void saveRulesToStorage();

2
src/rss/rssfeed.cpp

@ -319,7 +319,7 @@ void RssFeed::resizeList() {
const uint nb_articles = m_articles.size(); const uint nb_articles = m_articles.size();
if (nb_articles > max_articles) { if (nb_articles > max_articles) {
RssArticleList listItems = m_articles.values(); RssArticleList listItems = m_articles.values();
RssManager::sortNewsList(listItems); RssManager::sortArticleListByDateDesc(listItems);
const int excess = nb_articles - max_articles; const int excess = nb_articles - max_articles;
for (uint i=nb_articles-excess; i<nb_articles; ++i) { for (uint i=nb_articles-excess; i<nb_articles; ++i) {
m_articles.remove(listItems.at(i)->guid()); m_articles.remove(listItems.at(i)->guid());

2
src/rss/rssfeed.h

@ -41,7 +41,7 @@ class RssManager;
typedef QHash<QString, RssArticlePtr> RssArticleHash; typedef QHash<QString, RssArticlePtr> RssArticleHash;
typedef QSharedPointer<RssFeed> RssFeedPtr; typedef QSharedPointer<RssFeed> RssFeedPtr;
typedef RssFeedList RssFeedList; typedef QList<RssFeedPtr> RssFeedList;
class RssFeed: public QObject, public RssFile { class RssFeed: public QObject, public RssFile {
Q_OBJECT Q_OBJECT

10
src/rss/rssmanager.cpp

@ -47,13 +47,17 @@ RssManager::RssManager():
RssManager::~RssManager() { RssManager::~RssManager() {
qDebug("Deleting RSSManager..."); qDebug("Deleting RSSManager...");
delete m_rssDownloader;
delete m_downloadRules; delete m_downloadRules;
saveItemsToDisk(); saveItemsToDisk();
saveStreamList(); saveStreamList();
qDebug("RSSManager deleted"); qDebug("RSSManager deleted");
} }
DownloadThread *RssManager::rssDownloader() const
{
return m_rssDownloader;
}
void RssManager::updateRefreshInterval(uint val) { void RssManager::updateRefreshInterval(uint val) {
if (m_refreshInterval != val) { if (m_refreshInterval != val) {
m_refreshInterval = val; m_refreshInterval = val;
@ -86,7 +90,7 @@ void RssManager::loadStreamList() {
// Create feed // Create feed
qDebug() << "Adding feed to parent folder"; qDebug() << "Adding feed to parent folder";
RssFeedPtr stream = feed_parent->addStream(this, feed_url); RssFeedPtr stream = feed_parent->addStream(this, feed_url);
const QString alias = aliases.at(i); const QString& alias = aliases[i];
if (!alias.isEmpty()) { if (!alias.isEmpty()) {
stream->rename(alias); stream->rename(alias);
} }
@ -138,7 +142,7 @@ static bool laterItemDate(const RssArticlePtr& a, const RssArticlePtr& b)
return (a->date() > b->date()); return (a->date() > b->date());
} }
void RssManager::sortNewsList(RssArticleList& news_list) { void RssManager::sortArticleListByDateDesc(RssArticleList& news_list) {
qSort(news_list.begin(), news_list.end(), laterItemDate); qSort(news_list.begin(), news_list.end(), laterItemDate);
} }

4
src/rss/rssmanager.h

@ -49,8 +49,8 @@ public:
RssManager(); RssManager();
virtual ~RssManager(); virtual ~RssManager();
inline DownloadThread* rssDownloader() const { return m_rssDownloader; } DownloadThread* rssDownloader() const;
static void sortNewsList(RssArticleList& news_list); static void sortArticleListByDateDesc(RssArticleList& news_list);
RssDownloadRuleList* downloadRules() const; RssDownloadRuleList* downloadRules() const;

Loading…
Cancel
Save