mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-18 14:11:50 +03:00
RSS code clean up
- Also drops support for Qt 4.5
This commit is contained in:
parent
f3448125c3
commit
8e529fc179
13 changed files with 70 additions and 138 deletions
2
INSTALL
2
INSTALL
|
@ -10,7 +10,7 @@ qBittorrent - A BitTorrent client in C++ / Qt4
|
|||
will install and execute qBittorrent hopefully without any problems.
|
||||
|
||||
Dependencies:
|
||||
- Qt >= 4.5.0 (libqtgui, libqtcore, libqtnetwork, libqtxml, libqtdbus/optional)
|
||||
- Qt >= 4.6.0 (libqtgui, libqtcore, libqtnetwork, libqtxml, libqtdbus/optional)
|
||||
|
||||
- pkg-config executable
|
||||
|
||||
|
|
8
configure
vendored
8
configure
vendored
|
@ -325,7 +325,7 @@ cat >$1/modules.cpp <<EOT
|
|||
#line 1 "qt4.qcm"
|
||||
/*
|
||||
-----BEGIN QCMOD-----
|
||||
name: Qt >= 4.5
|
||||
name: Qt >= 4.6
|
||||
arg: enable-debug, Enable debug mode
|
||||
arg: disable-gui, Disable qBittorrent Graphical user interface for headless running
|
||||
-----END QCMOD-----
|
||||
|
@ -334,8 +334,8 @@ class qc_qt4 : public ConfObj
|
|||
{
|
||||
public:
|
||||
qc_qt4(Conf *c) : ConfObj(c) {}
|
||||
QString name() const { return "Qt >= 4.5"; }
|
||||
QString shortname() const { return "Qt 4.5"; }
|
||||
QString name() const { return "Qt >= 4.6"; }
|
||||
QString shortname() const { return "Qt 4.6"; }
|
||||
bool exec()
|
||||
{
|
||||
// NOX mode
|
||||
|
@ -356,7 +356,7 @@ public:
|
|||
#else
|
||||
conf->addExtra("MANPREFIX = \$\$PREFIX/share");
|
||||
#endif
|
||||
return(QT_VERSION >= 0x040500);
|
||||
return(QT_VERSION >= 0x040600);
|
||||
}
|
||||
};
|
||||
#line 1 "qt-dbus.qcm"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
-----BEGIN QCMOD-----
|
||||
name: Qt >= 4.5
|
||||
name: Qt >= 4.6
|
||||
arg: enable-debug, Enable debug mode
|
||||
arg: disable-gui, Disable qBittorrent Graphical user interface for headless running
|
||||
-----END QCMOD-----
|
||||
|
@ -9,8 +9,8 @@ class qc_qt4 : public ConfObj
|
|||
{
|
||||
public:
|
||||
qc_qt4(Conf *c) : ConfObj(c) {}
|
||||
QString name() const { return "Qt >= 4.5"; }
|
||||
QString shortname() const { return "Qt 4.5"; }
|
||||
QString name() const { return "Qt >= 4.6"; }
|
||||
QString shortname() const { return "Qt 4.6"; }
|
||||
bool exec()
|
||||
{
|
||||
// NOX mode
|
||||
|
@ -31,6 +31,6 @@ public:
|
|||
#else
|
||||
conf->addExtra("MANPREFIX = $$PREFIX/share");
|
||||
#endif
|
||||
return(QT_VERSION >= 0x040500);
|
||||
return(QT_VERSION >= 0x040600);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -465,7 +465,7 @@ void RSSImp::refreshArticleList(QTreeWidgetItem* item) {
|
|||
else if (rss_item)
|
||||
news = rss_item->articleList();
|
||||
// Sort
|
||||
RssManager::sortNewsList(news);
|
||||
RssManager::sortArticleListByDateDesc(news);
|
||||
// Clear the list first
|
||||
textBrowser->clear();
|
||||
m_currentArticle = 0;
|
||||
|
|
|
@ -220,39 +220,30 @@ RssArticlePtr xmlToRssArticle(RssFeed* parent, QXmlStreamReader& xml)
|
|||
QDateTime date;
|
||||
QString author;
|
||||
|
||||
while(!xml.atEnd()) {
|
||||
xml.readNext();
|
||||
Q_ASSERT(xml.isStartElement() && xml.name() == "item");
|
||||
|
||||
if (xml.isEndElement() && xml.name() == "item")
|
||||
break;
|
||||
|
||||
if (xml.isStartElement()) {
|
||||
if (xml.name() == "title") {
|
||||
while (xml.readNextStartElement()) {
|
||||
if (xml.name() == "title")
|
||||
title = xml.readElementText();
|
||||
}
|
||||
else if (xml.name() == "enclosure") {
|
||||
if (xml.attributes().value("type") == "application/x-bittorrent") {
|
||||
if (xml.attributes().value("type") == "application/x-bittorrent")
|
||||
torrentUrl = xml.attributes().value("url").toString();
|
||||
}
|
||||
}
|
||||
else if (xml.name() == "link") {
|
||||
link = xml.readElementText();
|
||||
if (guid.isEmpty())
|
||||
guid = link;
|
||||
}
|
||||
else if (xml.name() == "description") {
|
||||
else if (xml.name() == "description")
|
||||
description = xml.readElementText();
|
||||
}
|
||||
else if (xml.name() == "pubDate") {
|
||||
else if (xml.name() == "pubDate")
|
||||
date = RssArticle::parseDate(xml.readElementText());
|
||||
}
|
||||
else if (xml.name() == "author") {
|
||||
else if (xml.name() == "author")
|
||||
author = xml.readElementText();
|
||||
}
|
||||
else if (xml.name() == "guid") {
|
||||
else if (xml.name() == "guid")
|
||||
guid = xml.readElementText();
|
||||
}
|
||||
}
|
||||
else
|
||||
xml.skipCurrentElement();
|
||||
}
|
||||
|
||||
if (guid.isEmpty())
|
||||
|
|
|
@ -44,18 +44,20 @@ RssDownloadRule::RssDownloadRule(): m_enabled(false), m_useRegex(false)
|
|||
bool RssDownloadRule::matches(const QString &article_title) const
|
||||
{
|
||||
foreach (const QString& token, m_mustContain) {
|
||||
if (token.isEmpty() || token == "")
|
||||
continue;
|
||||
if (!token.isEmpty()) {
|
||||
QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard);
|
||||
//reg.setMinimal(false);
|
||||
if (reg.indexIn(article_title) < 0) return false;
|
||||
if (reg.indexIn(article_title) < 0)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
qDebug("Checking not matching tokens");
|
||||
// Checking not matching
|
||||
foreach (const QString& token, m_mustNotContain) {
|
||||
if (token.isEmpty()) continue;
|
||||
if (!token.isEmpty()) {
|
||||
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;
|
||||
}
|
||||
|
@ -76,25 +78,7 @@ void RssDownloadRule::setMustNotContain(const QString &tokens)
|
|||
m_mustNotContain = tokens.split(QRegExp("[\\s|]"));
|
||||
}
|
||||
|
||||
RssDownloadRulePtr RssDownloadRule::fromOldFormat(const QVariantHash &rule_hash, const QString &feed_url, const QString &rule_name)
|
||||
{
|
||||
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 RssDownloadRule::fromVariantHash(const QVariantHash &rule_hash)
|
||||
{
|
||||
RssDownloadRulePtr rule(new RssDownloadRule);
|
||||
rule->setName(rule_hash.value("name").toString());
|
||||
|
|
|
@ -46,8 +46,7 @@ class RssDownloadRule
|
|||
|
||||
public:
|
||||
explicit RssDownloadRule();
|
||||
static RssDownloadRulePtr fromOldFormat(const QVariantHash& rule_hash, const QString &feed_url, const QString &rule_name); // Before v2.5.0
|
||||
static RssDownloadRulePtr fromNewFormat(const QVariantHash &rule_hash);
|
||||
static RssDownloadRulePtr fromVariantHash(const QVariantHash &rule_hash);
|
||||
QVariantHash toVariantHash() const;
|
||||
bool matches(const QString &article_title) const;
|
||||
void setMustContain(const QString &tokens);
|
||||
|
|
|
@ -61,39 +61,9 @@ void RssDownloadRuleList::saveRulesToStorage()
|
|||
void RssDownloadRuleList::loadRulesFromStorage()
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
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 ret;
|
||||
|
@ -105,12 +75,11 @@ QVariantHash RssDownloadRuleList::toVariantHash() const
|
|||
|
||||
void RssDownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h)
|
||||
{
|
||||
foreach (const QVariant& v, h.values()) {
|
||||
RssDownloadRulePtr rule = RssDownloadRule::fromNewFormat(v.toHash());
|
||||
if (rule && !rule->name().isEmpty()) {
|
||||
for (QVariantHash::ConstIterator it = h.begin(); it != h.end(); it++) {
|
||||
RssDownloadRulePtr rule = RssDownloadRule::fromVariantHash(it.value().toHash());
|
||||
if (rule && !rule->name().isEmpty())
|
||||
saveRule(rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RssDownloadRuleList::saveRule(const RssDownloadRulePtr &rule)
|
||||
|
@ -182,30 +151,18 @@ bool RssDownloadRuleList::unserialize(const QString &path)
|
|||
QFile f(path);
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
QDataStream in(&f);
|
||||
if (path.endsWith(".filters", Qt::CaseInsensitive)) {
|
||||
// Old format (< 2.5.0)
|
||||
qDebug("Old serialization format detected, processing...");
|
||||
in.setVersion(QDataStream::Qt_4_3);
|
||||
QVariantHash tmp;
|
||||
in >> tmp;
|
||||
f.close();
|
||||
if (tmp.isEmpty()) return false;
|
||||
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;
|
||||
if (tmp.isEmpty())
|
||||
return false;
|
||||
qDebug("Processing was successful!");
|
||||
loadRulesFromVariantHash(tmp);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
qDebug("Error: could not open file at %s", qPrintable(path));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,7 @@
|
|||
#include <QHash>
|
||||
#include <QVariantHash>
|
||||
#include "rssdownloadrule.h"
|
||||
s
|
||||
// This class is not thread-safe (not required)
|
||||
|
||||
class RssDownloadRuleList
|
||||
{
|
||||
Q_DISABLE_COPY(RssDownloadRuleList)
|
||||
|
@ -56,8 +55,6 @@ public:
|
|||
|
||||
private:
|
||||
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);
|
||||
QVariantHash toVariantHash() const;
|
||||
void saveRulesToStorage();
|
||||
|
|
|
@ -319,7 +319,7 @@ void RssFeed::resizeList() {
|
|||
const uint nb_articles = m_articles.size();
|
||||
if (nb_articles > max_articles) {
|
||||
RssArticleList listItems = m_articles.values();
|
||||
RssManager::sortNewsList(listItems);
|
||||
RssManager::sortArticleListByDateDesc(listItems);
|
||||
const int excess = nb_articles - max_articles;
|
||||
for (uint i=nb_articles-excess; i<nb_articles; ++i) {
|
||||
m_articles.remove(listItems.at(i)->guid());
|
||||
|
|
|
@ -41,7 +41,7 @@ class RssManager;
|
|||
|
||||
typedef QHash<QString, RssArticlePtr> RssArticleHash;
|
||||
typedef QSharedPointer<RssFeed> RssFeedPtr;
|
||||
typedef RssFeedList RssFeedList;
|
||||
typedef QList<RssFeedPtr> RssFeedList;
|
||||
|
||||
class RssFeed: public QObject, public RssFile {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -47,13 +47,17 @@ RssManager::RssManager():
|
|||
|
||||
RssManager::~RssManager() {
|
||||
qDebug("Deleting RSSManager...");
|
||||
delete m_rssDownloader;
|
||||
delete m_downloadRules;
|
||||
saveItemsToDisk();
|
||||
saveStreamList();
|
||||
qDebug("RSSManager deleted");
|
||||
}
|
||||
|
||||
DownloadThread *RssManager::rssDownloader() const
|
||||
{
|
||||
return m_rssDownloader;
|
||||
}
|
||||
|
||||
void RssManager::updateRefreshInterval(uint val) {
|
||||
if (m_refreshInterval != val) {
|
||||
m_refreshInterval = val;
|
||||
|
@ -86,7 +90,7 @@ void RssManager::loadStreamList() {
|
|||
// Create feed
|
||||
qDebug() << "Adding feed to parent folder";
|
||||
RssFeedPtr stream = feed_parent->addStream(this, feed_url);
|
||||
const QString alias = aliases.at(i);
|
||||
const QString& alias = aliases[i];
|
||||
if (!alias.isEmpty()) {
|
||||
stream->rename(alias);
|
||||
}
|
||||
|
@ -138,7 +142,7 @@ static bool laterItemDate(const RssArticlePtr& a, const RssArticlePtr& b)
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ public:
|
|||
RssManager();
|
||||
virtual ~RssManager();
|
||||
|
||||
inline DownloadThread* rssDownloader() const { return m_rssDownloader; }
|
||||
static void sortNewsList(RssArticleList& news_list);
|
||||
DownloadThread* rssDownloader() const;
|
||||
static void sortArticleListByDateDesc(RssArticleList& news_list);
|
||||
|
||||
RssDownloadRuleList* downloadRules() const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue