Started work on the new RSS feed downloader (WIP)

This commit is contained in:
Christophe Dumez
2010-10-31 12:35:07 +00:00
parent a2c19302cb
commit 6b7af5b464
94 changed files with 8342 additions and 4909 deletions

View File

@@ -28,27 +28,32 @@
* Contact : chris@qbittorrent.org
*/
#include "automatedrssdownloader.h"
#include "ui_automatedrssdownloader.h"
#include "rssfilters.h"
#include "rsssettings.h"
#include "ui_rsssettings.h"
#include "preferences.h"
RssSettings::RssSettings(QWidget *parent) :
AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) :
QDialog(parent),
ui(new Ui::RssSettings)
ui(new Ui::AutomatedRssDownloader)
{
ui->setupUi(this);
// Load settings
ui->spinRSSRefresh->setValue(Preferences::getRSSRefreshInterval());
ui->spinRSSMaxArticlesPerFeed->setValue(Preferences::getRSSMaxArticlesPerFeed());
loadSettings();
//filters = RssFilters::getFeedFilters(feed_url);
}
RssSettings::~RssSettings()
AutomatedRssDownloader::~AutomatedRssDownloader()
{
delete ui;
saveSettings();
delete ui;
}
void RssSettings::on_buttonBox_accepted() {
// Save settings
Preferences::setRSSRefreshInterval(ui->spinRSSRefresh->value());
Preferences::setRSSMaxArticlesPerFeed(ui->spinRSSMaxArticlesPerFeed->value());
void AutomatedRssDownloader::loadSettings()
{
ui->checkEnableDownloader->setChecked(RssSettings::isRssDownloadingEnabled());
}
void AutomatedRssDownloader::saveSettings()
{
RssSettings::setRssDownloadingEnabled(ui->checkEnableDownloader->isChecked());
}

View File

@@ -0,0 +1,56 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2010 Christophe Dumez
*
* 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.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef AUTOMATEDRSSDOWNLOADER_H
#define AUTOMATEDRSSDOWNLOADER_H
#include <QDialog>
namespace Ui {
class AutomatedRssDownloader;
}
class AutomatedRssDownloader : public QDialog
{
Q_OBJECT
public:
explicit AutomatedRssDownloader(QWidget *parent = 0);
~AutomatedRssDownloader();
protected slots:
void loadSettings();
void saveSettings();
private:
Ui::AutomatedRssDownloader *ui;
};
#endif // AUTOMATEDRSSDOWNLOADER_H

View File

@@ -0,0 +1,310 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AutomatedRssDownloader</class>
<widget class="QDialog" name="AutomatedRssDownloader">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>816</width>
<height>494</height>
</rect>
</property>
<property name="windowTitle">
<string>Automated RSS Downloader</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="checkEnableDownloader">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Enable the automated RSS downloader</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Download rules</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="removeRuleBtn">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/list-remove.png</normaloff>:/Icons/oxygen/list-remove.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="addRuleBtn">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/list-add.png</normaloff>:/Icons/oxygen/list-add.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="listRules"/>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="ruleDefBox">
<property name="title">
<string>Rule definition</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Must contain:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineContains"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Must not contain:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineNotContains"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Save torrent to:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="lineSavePath"/>
</item>
<item>
<widget class="QToolButton" name="browseSP">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Assign label:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboLabel">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Apply rule to feeds:</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listFeeds"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Matching RSS articles</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listMatchingArticles">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../icons.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AutomatedRssDownloader</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AutomatedRssDownloader</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -1,7 +1,7 @@
INCLUDEPATH += $$PWD
HEADERS += $$PWD/rss_imp.h \
$$PWD/rsssettings.h \
HEADERS += $$PWD/rss_imp.h \
$$PWD/rsssettingsdlg.h \
$$PWD/feeddownloader.h \
$$PWD/feedlistwidget.h \
$$PWD/rssmanager.h \
@@ -9,19 +9,26 @@ HEADERS += $$PWD/rss_imp.h \
$$PWD/rssfolder.h \
$$PWD/rssfile.h \
$$PWD/rssarticle.h \
$$PWD/rssfilters.h
$$PWD/rssfilters.h \
$$PWD/automatedrssdownloader.h \
$$PWD/rsssettings.h \
$$PWD/rssdownloadrule.h \
$$PWD/rssdownloadrulelist.h
SOURCES += $$PWD/rss_imp.cpp \
$$PWD/rsssettings.cpp \
SOURCES += $$PWD/rss_imp.cpp \
$$PWD/rsssettingsdlg.cpp \
$$PWD/feedlistwidget.cpp \
$$PWD/rssmanager.cpp \
$$PWD/rssfeed.cpp \
$$PWD/rssfolder.cpp \
$$PWD/rssarticle.cpp \
$$PWD/feeddownloader.cpp \
$$PWD/rssfilters.cpp
FORMS += $$PWD/ui/rss.ui \
$$PWD/ui/feeddownloader.ui \
$$PWD/ui/rsssettings.ui
$$PWD/rssfilters.cpp \
$$PWD/automatedrssdownloader.cpp \
$$PWD/rssdownloadrule.cpp \
$$PWD/rssdownloadrulelist.cpp
FORMS += $$PWD/rss.ui \
$$PWD/feeddownloader.ui \
$$PWD/rsssettingsdlg.ui \
$$PWD/automatedrssdownloader.ui

View File

@@ -43,7 +43,7 @@
#include "qbtsession.h"
#include "cookiesdlg.h"
#include "preferences.h"
#include "rsssettings.h"
#include "rsssettingsdlg.h"
#include "rssmanager.h"
#include "rssfolder.h"
#include "rssarticle.h"
@@ -647,7 +647,7 @@ RSSImp::~RSSImp(){
void RSSImp::on_settingsButton_clicked() {
RssSettings rssSettingsDlg(this);
if(rssSettingsDlg.exec())
RssSettingsDlg dlg(this);
if(dlg.exec())
updateRefreshInterval(Preferences::getRefreshInterval());
}

View File

@@ -0,0 +1,87 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2010 Christophe Dumez
*
* 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.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#include <QRegExp>
#include "rssdownloadrule.h"
#include "qinisettings.h"
RssDownloadRule::RssDownloadRule()
{
}
bool RssDownloadRule::matches(const QString &article_title) const
{
foreach(const QString& token, m_mustContain) {
if(token.isEmpty() || token == "")
continue;
QRegExp reg(token, Qt::CaseInsensitive, QRegExp::Wildcard);
//reg.setMinimal(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;
QRegExp reg(token, Qt::CaseInsensitive, QRegExp::Wildcard);
if(reg.indexIn(article_title) > -1) return false;
}
return true;
}
void RssDownloadRule::setMustContain(const QString &tokens)
{
m_mustContain = tokens.split(" ");
}
void RssDownloadRule::setMustNotContain(const QString &tokens)
{
m_mustNotContain = tokens.split(QRegExp("[\\s|]"));
}
RssDownloadRule RssDownloadRule::fromOldFormat(const QHash<QString, QVariant> &rule_hash, const QString &feed_url, const QString &rule_name)
{
RssDownloadRule rule;
rule.setName(rule_name);
rule.setMustContain(rule_hash.value("matches", "").toString());
rule.setMustNotContain(rule_hash.value("not", "").toString());
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, false).toBool());
// label was unsupported < 2.5.0
return rule;
}
bool RssDownloadRule::operator==(const RssDownloadRule &other) {
return m_name == other.name();
}

69
src/rss/rssdownloadrule.h Normal file
View File

@@ -0,0 +1,69 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2010 Christophe Dumez
*
* 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.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef RSSDOWNLOADRULE_H
#define RSSDOWNLOADRULE_H
#include <QStringList>
#include <QHash>
class RssDownloadRule
{
public:
explicit RssDownloadRule();
static RssDownloadRule fromOldFormat(const QHash<QString, QVariant>& rule_hash, const QString &feed_url, const QString &rule_name); // Before v2.5.0
bool matches(const QString &article_title) const;
void setMustContain(const QString &tokens);
void setMustNotContain(const QString &tokens);
inline QStringList rssFeeds() const { return m_rssFeeds; }
inline void setRssFeeds(const QStringList& rss_feeds) { m_rssFeeds = rss_feeds; }
inline QString name() const { return m_name; }
inline void setName(const QString &name) { m_name = name; }
inline QString savePath() const { return m_savePath; }
inline void setSavePath(const QString &save_path) { m_savePath = save_path; }
inline QString label() const { return m_label; }
inline void setLabel(const QString &_label) { m_label = _label; }
inline bool isEnabled() const { return m_enabled; }
inline void setEnabled(bool enable) { m_enabled = enable; }
// Operators
bool operator==(const RssDownloadRule &other);
private:
QString m_name;
QStringList m_mustContain;
QStringList m_mustNotContain;
QString m_savePath;
QString m_label;
bool m_enabled;
QStringList m_rssFeeds;
};
#endif // RSSDOWNLOADRULE_H

View File

@@ -0,0 +1,88 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2010 Christophe Dumez
*
* 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.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#include "rssdownloadrulelist.h"
#include "qinisettings.h"
RssDownloadRuleList* RssDownloadRuleList::m_instance = 0;
RssDownloadRuleList::RssDownloadRuleList(){
loadRulesFromStorage();
}
RssDownloadRuleList* RssDownloadRuleList::instance()
{
if(!m_instance)
m_instance = new RssDownloadRuleList;
return m_instance;
}
void RssDownloadRuleList::drop()
{
if(m_instance)
delete m_instance;
}
const RssDownloadRule * RssDownloadRuleList::findMatchingRule(const QString &feed_url, const QString &article_title) const
{
const QList<RssDownloadRule*> rules = feedRules(feed_url);
foreach(const RssDownloadRule* rule, rules) {
if(rule->matches(article_title)) return rule;
}
return 0;
}
void RssDownloadRuleList::loadRulesFromStorage()
{
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
if(qBTRSS.contains("feed_filters")) {
importRulesInOldFormat(qBTRSS.value("feed_filters").toHash());
}
}
void RssDownloadRuleList::importRulesInOldFormat(const QHash<QString, QVariant> &rules)
{
foreach(const QString &feed_url, rules.keys()) {
const QHash<QString, QVariant> feed_rules = rules.value(feed_url).toHash();
foreach(const QString &rule_name, feed_rules.keys()) {
const RssDownloadRule rule = RssDownloadRule::fromOldFormat(feed_rules.value(rule_name).toHash(), feed_url, rule_name);
append(rule);
}
}
}
void RssDownloadRuleList::append(const RssDownloadRule &rule)
{
Q_ASSERT(!contains(rule));
QList<RssDownloadRule>::append(rule);
foreach(const QString &feed_url, rule.rssFeeds()) {
m_feedRules[feed_url].append(&last());
}
}

View File

@@ -0,0 +1,64 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2010 Christophe Dumez
*
* 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.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef RSSDOWNLOADRULELIST_H
#define RSSDOWNLOADRULELIST_H
#include <QList>
#include <QHash>
#include "rssdownloadrule.h"
// This class is not thread-safe (not required)
class RssDownloadRuleList : public QList<RssDownloadRule>
{
Q_DISABLE_COPY(RssDownloadRuleList)
private:
explicit RssDownloadRuleList();
static RssDownloadRuleList* m_instance;
public:
static RssDownloadRuleList* instance();
static void drop();
const RssDownloadRule* findMatchingRule(const QString &feed_url, const QString &article_title) const;
inline QList<RssDownloadRule*> feedRules(const QString &feed_url) const { return m_feedRules.value(feed_url); }
void append(const RssDownloadRule& rule);
private:
void loadRulesFromStorage();
void importRulesInOldFormat(const QHash<QString, QVariant> &rules); // Before v2.5.0
private:
QHash<QString, QList<RssDownloadRule*> > m_feedRules;
};
#endif // RSSDOWNLOADFILTERLIST_H

View File

@@ -32,9 +32,11 @@
#include "rssmanager.h"
#include "qbtsession.h"
#include "rssfolder.h"
#include "preferences.h"
#include "rsssettings.h"
#include "rssarticle.h"
#include "feeddownloader.h"
#include "misc.h"
#include "rssdownloadrulelist.h"
RssFeed::RssFeed(RssFolder* parent, RssManager *rssmanager, QBtSession *BTSession, QString _url): parent(parent), rssmanager(rssmanager), BTSession(BTSession), alias(""), iconPath(":/Icons/rss16.png"), refreshed(false), downloadFailure(false), currently_loading(false) {
qDebug("RSSStream constructed");
@@ -321,7 +323,7 @@ short RssFeed::readDoc(QIODevice* device) {
}
void RssFeed::resizeList() {
unsigned int max_articles = Preferences::getRSSMaxArticlesPerFeed();
unsigned int max_articles = RssSettings::getRSSMaxArticlesPerFeed();
unsigned int nb_articles = this->size();
if(nb_articles > max_articles) {
QList<RssArticle*> listItem = RssManager::sortNewsList(this->values());

View File

@@ -29,7 +29,7 @@
*/
#include "rssmanager.h"
#include "preferences.h"
#include "rsssettings.h"
#include "qbtsession.h"
#include "rssfeed.h"
#include "rssarticle.h"
@@ -37,7 +37,7 @@
RssManager::RssManager(QBtSession *BTSession): RssFolder(0, this, BTSession, QString::null) {
loadStreamList();
connect(&newsRefresher, SIGNAL(timeout()), this, SLOT(refreshAll()));
refreshInterval = Preferences::getRSSRefreshInterval();
refreshInterval = RssSettings::getRSSRefreshInterval();
newsRefresher.start(refreshInterval*60000);
}

View File

@@ -31,25 +31,50 @@
#ifndef RSSSETTINGS_H
#define RSSSETTINGS_H
#include <QDialog>
namespace Ui {
class RssSettings;
}
class RssSettings : public QDialog
{
Q_OBJECT
#include "qinisettings.h"
class RssSettings {
public:
explicit RssSettings(QWidget *parent = 0);
~RssSettings();
protected slots:
void on_buttonBox_accepted();
static bool isRSSEnabled() {
QIniSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/RSS/RSSEnabled"), false).toBool();
}
private:
Ui::RssSettings *ui;
static void setRSSEnabled(bool enabled) {
QIniSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/RSS/RSSEnabled"), enabled);
}
static unsigned int getRSSRefreshInterval() {
QIniSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/RSS/RSSRefresh"), 5).toUInt();
}
static void setRSSRefreshInterval(uint interval) {
QIniSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/RSS/RSSRefresh"), interval);
}
static int getRSSMaxArticlesPerFeed() {
QIniSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), 50).toInt();
}
static void setRSSMaxArticlesPerFeed(int nb) {
QIniSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), nb);
}
static bool isRssDownloadingEnabled() {
QIniSettings settings("qBittorrent", "qBittorrent");
return settings.value("Preferences/RSS/RssDownloading", false).toBool();
}
static void setRssDownloadingEnabled(bool b) {
QIniSettings settings("qBittorrent", "qBittorrent");
settings.setValue("Preferences/RSS/RssDownloading", b);
}
};

View File

@@ -0,0 +1,55 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2010 Christophe Dumez
*
* 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.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#include "rsssettingsdlg.h"
#include "ui_rsssettingsdlg.h"
#include "rsssettings.h"
RssSettingsDlg::RssSettingsDlg(QWidget *parent) :
QDialog(parent),
ui(new Ui::RssSettingsDlg)
{
ui->setupUi(this);
// Load settings
ui->spinRSSRefresh->setValue(RssSettings::getRSSRefreshInterval());
ui->spinRSSMaxArticlesPerFeed->setValue(RssSettings::getRSSMaxArticlesPerFeed());
}
RssSettingsDlg::~RssSettingsDlg()
{
qDebug("Deleting the RSS settings dialog");
delete ui;
}
void RssSettingsDlg::on_buttonBox_accepted() {
// Save settings
RssSettings::setRSSRefreshInterval(ui->spinRSSRefresh->value());
RssSettings::setRSSMaxArticlesPerFeed(ui->spinRSSMaxArticlesPerFeed->value());
}

56
src/rss/rsssettingsdlg.h Normal file
View File

@@ -0,0 +1,56 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2010 Christophe Dumez
*
* 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.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef RSSSETTINGSDLG_H
#define RSSSETTINGSDLG_H
#include <QDialog>
namespace Ui {
class RssSettingsDlg;
}
class RssSettingsDlg : public QDialog
{
Q_OBJECT
public:
explicit RssSettingsDlg(QWidget *parent = 0);
~RssSettingsDlg();
protected slots:
void on_buttonBox_accepted();
private:
Ui::RssSettingsDlg *ui;
};
#endif // RSSSETTINGS_H

View File

@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RssSettings</class>
<widget class="QDialog" name="RssSettings">
<class>RssSettingsDlg</class>
<widget class="QDialog" name="RssSettingsDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>468</width>
<width>502</width>
<height>137</height>
</rect>
</property>
@@ -125,7 +125,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>RssSettings</receiver>
<receiver>RssSettingsDlg</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@@ -141,7 +141,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>RssSettings</receiver>
<receiver>RssSettingsDlg</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">