Browse Source

RSS: Use SharedPtr everywhere

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
50a3e4e776
  1. 111
      src/rss/automatedrssdownloader.cpp
  2. 9
      src/rss/automatedrssdownloader.h
  3. 54
      src/rss/feedlistwidget.cpp
  4. 20
      src/rss/feedlistwidget.h
  5. 67
      src/rss/rss_imp.cpp
  6. 8
      src/rss/rss_imp.h
  7. 38
      src/rss/rssdownloadrule.cpp
  8. 12
      src/rss/rssdownloadrule.h
  9. 60
      src/rss/rssdownloadrulelist.cpp
  10. 8
      src/rss/rssdownloadrulelist.h
  11. 39
      src/rss/rssfeed.cpp
  12. 14
      src/rss/rssfeed.h
  13. 2
      src/rss/rssfile.cpp
  14. 22
      src/rss/rssfile.h
  15. 86
      src/rss/rssfolder.cpp
  16. 31
      src/rss/rssfolder.h
  17. 31
      src/rss/rssmanager.cpp
  18. 17
      src/rss/rssmanager.h

111
src/rss/automatedrssdownloader.cpp

@ -45,10 +45,10 @@ @@ -45,10 +45,10 @@
#include "rssfeed.h"
#include "iconprovider.h"
AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) :
AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<RssManager>& manager, QWidget *parent) :
QDialog(parent),
ui(new Ui::AutomatedRssDownloader),
m_editedRule(0)
m_manager(manager), m_editedRule(0)
{
ui->setupUi(this);
// Icons
@ -129,7 +129,7 @@ void AutomatedRssDownloader::loadRulesList() @@ -129,7 +129,7 @@ void AutomatedRssDownloader::loadRulesList()
foreach (const QString &rule_name, m_ruleList->ruleNames()) {
QListWidgetItem *item = new QListWidgetItem(rule_name, ui->listRules);
item->setFlags(item->flags()|Qt::ItemIsUserCheckable);
if(m_ruleList->getRule(rule_name).isEnabled())
if(m_ruleList->getRule(rule_name)->isEnabled())
item->setCheckState(Qt::Checked);
else
item->setCheckState(Qt::Unchecked);
@ -164,17 +164,17 @@ void AutomatedRssDownloader::updateFeedList() @@ -164,17 +164,17 @@ void AutomatedRssDownloader::updateFeedList()
const QString feed_url = item->data(Qt::UserRole).toString();
bool all_enabled = false;
foreach(const QListWidgetItem *ruleItem, ui->listRules->selectedItems()) {
RssDownloadRule rule = m_ruleList->getRule(ruleItem->text());
if(!rule.isValid()) continue;
qDebug() << "Rule" << rule.name() << "affects" << rule.rssFeeds().size() << "feeds.";
foreach(QString test, rule.rssFeeds()) {
RssDownloadRulePtr rule = m_ruleList->getRule(ruleItem->text());
if(!rule) continue;
qDebug() << "Rule" << rule->name() << "affects" << rule->rssFeeds().size() << "feeds.";
foreach(QString test, rule->rssFeeds()) {
qDebug() << "Feed is " << test;
}
if(rule.rssFeeds().contains(feed_url)) {
qDebug() << "Rule " << rule.name() << " affects feed " << feed_url;
if(rule->rssFeeds().contains(feed_url)) {
qDebug() << "Rule " << rule->name() << " affects feed " << feed_url;
all_enabled = true;
} else {
qDebug() << "Rule " << rule.name() << " does NOT affect feed " << feed_url;
qDebug() << "Rule " << rule->name() << " does NOT affect feed " << feed_url;
all_enabled = false;
break;
}
@ -203,18 +203,18 @@ void AutomatedRssDownloader::updateRuleDefinitionBox() @@ -203,18 +203,18 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
const QList<QListWidgetItem*> selection = ui->listRules->selectedItems();
if(selection.count() == 1) {
m_editedRule = selection.first();
RssDownloadRule rule = getCurrentRule();
if(rule.isValid()) {
ui->lineContains->setText(rule.mustContain());
ui->lineNotContains->setText(rule.mustNotContain());
ui->saveDiffDir_check->setChecked(!rule.savePath().isEmpty());
ui->lineSavePath->setText(rule.savePath());
ui->checkRegex->setChecked(rule.useRegex());
if(rule.label().isEmpty()) {
RssDownloadRulePtr rule = getCurrentRule();
if (rule) {
ui->lineContains->setText(rule->mustContain());
ui->lineNotContains->setText(rule->mustNotContain());
ui->saveDiffDir_check->setChecked(!rule->savePath().isEmpty());
ui->lineSavePath->setText(rule->savePath());
ui->checkRegex->setChecked(rule->useRegex());
if (rule->label().isEmpty()) {
ui->comboLabel->setCurrentIndex(-1);
ui->comboLabel->clearEditText();
} else {
ui->comboLabel->setCurrentIndex(ui->comboLabel->findText(rule.label()));
ui->comboLabel->setCurrentIndex(ui->comboLabel->findText(rule->label()));
}
updateMustLineValidity();
updateMustNotLineValidity();
@ -247,12 +247,12 @@ void AutomatedRssDownloader::clearRuleDefinitionBox() @@ -247,12 +247,12 @@ void AutomatedRssDownloader::clearRuleDefinitionBox()
updateMustNotLineValidity();
}
RssDownloadRule AutomatedRssDownloader::getCurrentRule() const
RssDownloadRulePtr AutomatedRssDownloader::getCurrentRule() const
{
QListWidgetItem * current_item = ui->listRules->currentItem();
if(current_item)
return m_ruleList->getRule(current_item->text());
return RssDownloadRule();
return RssDownloadRulePtr();
}
void AutomatedRssDownloader::initLabelCombobox()
@ -273,26 +273,26 @@ void AutomatedRssDownloader::saveEditedRule() @@ -273,26 +273,26 @@ void AutomatedRssDownloader::saveEditedRule()
qDebug() << "Probably removed the item, no need to save it";
return;
}
RssDownloadRule rule = m_ruleList->getRule(m_editedRule->text());
if(!rule.isValid()) {
rule.setName(m_editedRule->text());
RssDownloadRulePtr rule = m_ruleList->getRule(m_editedRule->text());
if (!rule) {
rule->setName(m_editedRule->text());
}
if(m_editedRule->checkState() == Qt::Unchecked)
rule.setEnabled(false);
if (m_editedRule->checkState() == Qt::Unchecked)
rule->setEnabled(false);
else
rule.setEnabled(true);
rule.setUseRegex(ui->checkRegex->isChecked());
rule.setMustContain(ui->lineContains->text());
rule.setMustNotContain(ui->lineNotContains->text());
rule->setEnabled(true);
rule->setUseRegex(ui->checkRegex->isChecked());
rule->setMustContain(ui->lineContains->text());
rule->setMustNotContain(ui->lineNotContains->text());
if(ui->saveDiffDir_check->isChecked())
rule.setSavePath(ui->lineSavePath->text());
rule->setSavePath(ui->lineSavePath->text());
else
rule.setSavePath("");
rule.setLabel(ui->comboLabel->currentText());
rule->setSavePath("");
rule->setLabel(ui->comboLabel->currentText());
// Save new label
if(!rule.label().isEmpty())
Preferences().addTorrentLabel(rule.label());
//rule.setRssFeeds(getSelectedFeeds());
if(!rule->label().isEmpty())
Preferences().addTorrentLabel(rule->label());
//rule->setRssFeeds(getSelectedFeeds());
// Save it
m_ruleList->saveRule(rule);
}
@ -301,15 +301,15 @@ void AutomatedRssDownloader::saveEditedRule() @@ -301,15 +301,15 @@ void AutomatedRssDownloader::saveEditedRule()
void AutomatedRssDownloader::on_addRuleBtn_clicked()
{
// Ask for a rule name
const QString rule = QInputDialog::getText(this, tr("New rule name"), tr("Please type the name of the new download rule."));
if(rule.isEmpty()) return;
const QString rule_name = QInputDialog::getText(this, tr("New rule name"), tr("Please type the name of the new download rule->"));
if(rule_name.isEmpty()) return;
// Check if this rule name already exists
if(m_ruleList->getRule(rule).isValid()) {
if(m_ruleList->getRule(rule_name)) {
QMessageBox::warning(this, tr("Rule name conflict"), tr("A rule with this name already exists, please choose another name."));
return;
}
// Add the new rule to the list
QListWidgetItem * item = new QListWidgetItem(rule, ui->listRules);
QListWidgetItem * item = new QListWidgetItem(rule_name, ui->listRules);
item->setFlags(item->flags()|Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Checked); // Enable as a default
ui->listRules->clearSelection();
@ -382,7 +382,7 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos) @@ -382,7 +382,7 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos)
{
Q_UNUSED(pos);
QMenu menu;
QAction *addAct = menu.addAction(IconProvider::instance()->getIcon("list-add"), tr("Add new rule..."));
QAction *addAct = menu.addAction(IconProvider::instance()->getIcon("list-add"), tr("Add new rule->.."));
QAction *delAct = 0;
QAction *renameAct = 0;
const QList<QListWidgetItem*> selection = ui->listRules->selectedItems();
@ -390,7 +390,7 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos) @@ -390,7 +390,7 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos)
if(selection.count() == 1) {
delAct = menu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Delete rule"));
menu.addSeparator();
renameAct = menu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Rename rule..."));
renameAct = menu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Rename rule->.."));
} else {
delAct = menu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Delete selected rules"));
}
@ -438,9 +438,9 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it @@ -438,9 +438,9 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it
}
const QString feed_url = feed_item->data(Qt::UserRole).toString();
foreach (QListWidgetItem* rule_item, ui->listRules->selectedItems()) {
RssDownloadRule rule = m_ruleList->getRule(rule_item->text());
Q_ASSERT(rule.isValid());
QStringList affected_feeds = rule.rssFeeds();
RssDownloadRulePtr rule = m_ruleList->getRule(rule_item->text());
Q_ASSERT(rule);
QStringList affected_feeds = rule->rssFeeds();
if(feed_item->checkState() == Qt::Checked) {
if(!affected_feeds.contains(feed_url))
affected_feeds << feed_url;
@ -449,8 +449,8 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it @@ -449,8 +449,8 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it
affected_feeds.removeOne(feed_url);
}
// Save the updated rule
if(affected_feeds.size() != rule.rssFeeds().size()) {
rule.setRssFeeds(affected_feeds);
if(affected_feeds.size() != rule->rssFeeds().size()) {
rule->setRssFeeds(affected_feeds);
m_ruleList->saveRule(rule);
}
}
@ -464,26 +464,29 @@ void AutomatedRssDownloader::updateMatchingArticles() @@ -464,26 +464,29 @@ void AutomatedRssDownloader::updateMatchingArticles()
if(ui->ruleDefBox->isEnabled()) {
saveEditedRule();
}
const QHash<QString, RssFeed*> all_feeds = RssManager::instance()->getAllFeedsAsHash();
RssManagerPtr manager = m_manager.toStrongRef();
if (!manager)
return;
const QHash<QString, RssFeedPtr> all_feeds = manager->getAllFeedsAsHash();
foreach(const QListWidgetItem *rule_item, ui->listRules->selectedItems()) {
RssDownloadRule rule = m_ruleList->getRule(rule_item->text());
if(!rule.isValid()) continue;
foreach(const QString &feed_url, rule.rssFeeds()) {
RssDownloadRulePtr rule = m_ruleList->getRule(rule_item->text());
if(!rule) continue;
foreach(const QString &feed_url, rule->rssFeeds()) {
qDebug() << Q_FUNC_INFO << feed_url;
Q_ASSERT(all_feeds.contains(feed_url));
if(!all_feeds.contains(feed_url)) continue;
const RssFeed *feed = all_feeds.value(feed_url);
RssFeedPtr feed = all_feeds.value(feed_url);
Q_ASSERT(feed);
if(!feed) continue;
const QStringList matching_articles = rule.findMatchingArticles(feed);
const QStringList matching_articles = rule->findMatchingArticles(feed);
if(!matching_articles.isEmpty())
addFeedArticlesToTree(feed, matching_articles);
}
}
}
void AutomatedRssDownloader::addFeedArticlesToTree(const RssFeed *feed, const QStringList &articles)
void AutomatedRssDownloader::addFeedArticlesToTree(const RssFeedPtr& feed, const QStringList &articles)
{
// Check if this feed is already in the tree
QTreeWidgetItem *treeFeedItem = 0;

9
src/rss/automatedrssdownloader.h

@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
#define AUTOMATEDRSSDOWNLOADER_H
#include <QDialog>
#include <QWeakPointer>
#include "rssdownloadrule.h"
QT_BEGIN_NAMESPACE
@ -41,6 +42,7 @@ class AutomatedRssDownloader; @@ -41,6 +42,7 @@ class AutomatedRssDownloader;
QT_END_NAMESPACE
class RssDownloadRuleList;
class RssManager;
QT_BEGIN_NAMESPACE
class QListWidgetItem;
@ -51,7 +53,7 @@ class AutomatedRssDownloader : public QDialog @@ -51,7 +53,7 @@ class AutomatedRssDownloader : public QDialog
Q_OBJECT
public:
explicit AutomatedRssDownloader(QWidget *parent = 0);
explicit AutomatedRssDownloader(const QWeakPointer<RssManager>& manager, QWidget *parent = 0);
~AutomatedRssDownloader();
bool isRssDownloaderEnabled() const;
@ -80,12 +82,13 @@ private slots: @@ -80,12 +82,13 @@ private slots:
void updateMustNotLineValidity();
private:
RssDownloadRule getCurrentRule() const;
RssDownloadRulePtr getCurrentRule() const;
void initLabelCombobox();
void addFeedArticlesToTree(const RssFeed *feed, const QStringList& articles);
void addFeedArticlesToTree(const RssFeedPtr& feed, const QStringList& articles);
private:
Ui::AutomatedRssDownloader *ui;
QWeakPointer<RssManager> m_manager;
QListWidgetItem* m_editedRule;
RssDownloadRuleList *m_ruleList;
};

54
src/rss/feedlistwidget.cpp

@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
#include "rssfeed.h"
#include "iconprovider.h"
FeedListWidget::FeedListWidget(QWidget *parent, RssManager *rssmanager): QTreeWidget(parent), m_rssManager(rssmanager) {
FeedListWidget::FeedListWidget(QWidget *parent, const RssManagerPtr& rssmanager): QTreeWidget(parent), m_rssManager(rssmanager) {
setContextMenuPolicy(Qt::CustomContextMenu);
setDragDropMode(QAbstractItemView::InternalMove);
setSelectionMode(QAbstractItemView::ExtendedSelection);
@ -51,20 +51,20 @@ FeedListWidget::~FeedListWidget() { @@ -51,20 +51,20 @@ FeedListWidget::~FeedListWidget() {
delete m_unreadStickyItem;
}
void FeedListWidget::itemAdded(QTreeWidgetItem *item, IRssFile* file) {
void FeedListWidget::itemAdded(QTreeWidgetItem *item, const RssFilePtr& file) {
m_rssMapping[item] = file;
if(file->type() == IRssFile::FEED) {
m_feedsItems[file->id()] = item;
if (RssFeedPtr feed = qSharedPointerDynamicCast<RssFeed>(file)) {
m_feedsItems[feed->id()] = item;
}
}
void FeedListWidget::itemAboutToBeRemoved(QTreeWidgetItem *item) {
IRssFile* file = m_rssMapping.take(item);
if(file->type() == IRssFile::FEED) {
m_feedsItems.remove(file->id());
} else {
QList<RssFeed*> feeds = ((RssFolder*)file)->getAllFeeds();
foreach(RssFeed* feed, feeds) {
RssFilePtr file = m_rssMapping.take(item);
if (RssFeedPtr feed = qSharedPointerDynamicCast<RssFeed>(file)) {
m_feedsItems.remove(feed->id());
} if (RssFolderPtr folder = qSharedPointerDynamicCast<RssFolder>(file)) {
RssFeedList feeds = folder->getAllFeeds();
foreach(const RssFeedPtr& feed, feeds) {
m_feedsItems.remove(feed->id());
}
}
@ -105,7 +105,7 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllOpenFolders(QTreeWidgetItem *paren @@ -105,7 +105,7 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllOpenFolders(QTreeWidgetItem *paren
item = parent->child(i);
else
item = topLevelItem(i);
if(getItemType(item) == IRssFile::FOLDER && item->isExpanded()) {
if(isFolder(item) && item->isExpanded()) {
QList<QTreeWidgetItem*> open_subfolders = getAllOpenFolders(item);
if(!open_subfolders.empty()) {
open_folders << open_subfolders;
@ -122,7 +122,7 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllFeedItems(QTreeWidgetItem* folder) @@ -122,7 +122,7 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllFeedItems(QTreeWidgetItem* folder)
const int nbChildren = folder->childCount();
for(int i=0; i<nbChildren; ++i) {
QTreeWidgetItem *item = folder->child(i);
if(getItemType(item) == IRssFile::FEED) {
if(isFeed(item)) {
feeds << item;
} else {
feeds << getAllFeedItems(item);
@ -131,12 +131,18 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllFeedItems(QTreeWidgetItem* folder) @@ -131,12 +131,18 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllFeedItems(QTreeWidgetItem* folder)
return feeds;
}
IRssFile* FeedListWidget::getRSSItem(QTreeWidgetItem *item) const {
return m_rssMapping.value(item, 0);
RssFilePtr FeedListWidget::getRSSItem(QTreeWidgetItem *item) const {
return m_rssMapping.value(item, RssFilePtr());
}
bool FeedListWidget::isFeed(QTreeWidgetItem *item) const
{
return (qSharedPointerDynamicCast<RssFeed>(m_rssMapping.value(item)) != NULL);
}
IRssFile::FileType FeedListWidget::getItemType(QTreeWidgetItem *item) const {
return m_rssMapping.value(item)->type();
bool FeedListWidget::isFolder(QTreeWidgetItem *item) const
{
return (qSharedPointerDynamicCast<RssFolder>(m_rssMapping.value(item)) != NULL);
}
QString FeedListWidget::getItemID(QTreeWidgetItem *item) const {
@ -147,8 +153,8 @@ QTreeWidgetItem* FeedListWidget::getTreeItemFromUrl(const QString &url) const{ @@ -147,8 +153,8 @@ QTreeWidgetItem* FeedListWidget::getTreeItemFromUrl(const QString &url) const{
return m_feedsItems.value(url, 0);
}
RssFeed* FeedListWidget::getRSSItemFromUrl(const QString &url) const {
return dynamic_cast<RssFeed*>(getRSSItem(getTreeItemFromUrl(url)));
RssFeedPtr FeedListWidget::getRSSItemFromUrl(const QString &url) const {
return qSharedPointerDynamicCast<RssFeed>(getRSSItem(getTreeItemFromUrl(url)));
}
QTreeWidgetItem* FeedListWidget::currentItem() const {
@ -162,7 +168,7 @@ QTreeWidgetItem* FeedListWidget::currentFeed() const { @@ -162,7 +168,7 @@ QTreeWidgetItem* FeedListWidget::currentFeed() const {
void FeedListWidget::updateCurrentFeed(QTreeWidgetItem* new_item) {
if(!new_item) return;
if(!m_rssMapping.contains(new_item)) return;
if((getItemType(new_item) == IRssFile::FEED) || new_item == m_unreadStickyItem)
if(isFeed(new_item) || new_item == m_unreadStickyItem)
m_currentFeed = new_item;
}
@ -171,7 +177,7 @@ void FeedListWidget::dragMoveEvent(QDragMoveEvent * event) { @@ -171,7 +177,7 @@ void FeedListWidget::dragMoveEvent(QDragMoveEvent * event) {
if(item == m_unreadStickyItem) {
event->ignore();
} else {
if(item && getItemType(item) != IRssFile::FOLDER)
if(item && isFolder(item))
event->ignore();
else {
if(selectedItems().contains(m_unreadStickyItem)) {
@ -187,9 +193,9 @@ void FeedListWidget::dropEvent(QDropEvent *event) { @@ -187,9 +193,9 @@ void FeedListWidget::dropEvent(QDropEvent *event) {
qDebug("dropEvent");
QList<QTreeWidgetItem*> folders_altered;
QTreeWidgetItem *dest_folder_item = itemAt(event->pos());
RssFolder *dest_folder;
RssFolderPtr dest_folder;
if(dest_folder_item) {
dest_folder = (RssFolder*)getRSSItem(dest_folder_item);
dest_folder = qSharedPointerCast<RssFolder>(getRSSItem(dest_folder_item));
folders_altered << dest_folder_item;
} else {
dest_folder = m_rssManager;
@ -197,7 +203,7 @@ void FeedListWidget::dropEvent(QDropEvent *event) { @@ -197,7 +203,7 @@ void FeedListWidget::dropEvent(QDropEvent *event) {
QList<QTreeWidgetItem *> src_items = selectedItems();
// Check if there is not going to overwrite another file
foreach(QTreeWidgetItem *src_item, src_items) {
IRssFile *file = getRSSItem(src_item);
RssFilePtr file = getRSSItem(src_item);
if(dest_folder->hasChild(file->id())) {
emit overwriteAttempt(file->id());
return;
@ -209,7 +215,7 @@ void FeedListWidget::dropEvent(QDropEvent *event) { @@ -209,7 +215,7 @@ void FeedListWidget::dropEvent(QDropEvent *event) {
if(parent_folder && !folders_altered.contains(parent_folder))
folders_altered << parent_folder;
// Actually move the file
IRssFile *file = getRSSItem(src_item);
RssFilePtr file = getRSSItem(src_item);
m_rssManager->moveFile(file, dest_folder);
}
QTreeWidget::dropEvent(event);

20
src/rss/feedlistwidget.h

@ -40,15 +40,14 @@ @@ -40,15 +40,14 @@
#include <QUrl>
#include "rssfile.h"
class RssManager;
class RssFeed;
#include "rssfeed.h"
#include "rssmanager.h"
class FeedListWidget: public QTreeWidget {
Q_OBJECT
public:
FeedListWidget(QWidget *parent, RssManager *m_rssManager);
FeedListWidget(QWidget *parent, const RssManagerPtr& rssManager);
~FeedListWidget();
bool hasFeed(const QString &url) const;
@ -57,16 +56,17 @@ public: @@ -57,16 +56,17 @@ public:
QStringList getItemPath(QTreeWidgetItem* item) const;
QList<QTreeWidgetItem*> getAllOpenFolders(QTreeWidgetItem *parent=0) const;
QList<QTreeWidgetItem*> getAllFeedItems(QTreeWidgetItem* folder);
IRssFile* getRSSItem(QTreeWidgetItem *item) const;
IRssFile::FileType getItemType(QTreeWidgetItem *item) const;
RssFilePtr getRSSItem(QTreeWidgetItem *item) const;
bool isFeed(QTreeWidgetItem *item) const;
bool isFolder(QTreeWidgetItem *item) const;
QString getItemID(QTreeWidgetItem *item) const;
QTreeWidgetItem* getTreeItemFromUrl(const QString &url) const;
RssFeed* getRSSItemFromUrl(const QString &url) const;
RssFeedPtr getRSSItemFromUrl(const QString &url) const;
QTreeWidgetItem* currentItem() const;
QTreeWidgetItem* currentFeed() const;
public slots:
void itemAdded(QTreeWidgetItem *item, IRssFile* file);
void itemAdded(QTreeWidgetItem *item, const RssFilePtr& file);
void itemAboutToBeRemoved(QTreeWidgetItem *item);
signals:
@ -81,8 +81,8 @@ protected: @@ -81,8 +81,8 @@ protected:
void dropEvent(QDropEvent *event);
private:
RssManager *m_rssManager;
QHash<QTreeWidgetItem*, IRssFile*> m_rssMapping;
RssManagerPtr m_rssManager;
QHash<QTreeWidgetItem*, RssFilePtr> m_rssMapping;
QHash<QString, QTreeWidgetItem*> m_feedsItems;
QTreeWidgetItem* m_currentFeed;
QTreeWidgetItem *m_unreadStickyItem;

67
src/rss/rss_imp.cpp

@ -78,7 +78,7 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){ @@ -78,7 +78,7 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){
myRSSListMenu.addAction(actionRename);
myRSSListMenu.addAction(actionDelete);
myRSSListMenu.addSeparator();
if(m_feedList->getItemType(selectedItems.first()) == IRssFile::FOLDER) {
if(m_feedList->isFolder(selectedItems.first())) {
myRSSListMenu.addAction(actionNew_folder);
} else {
myRSSListMenu.addAction(actionManage_cookies);
@ -86,7 +86,7 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){ @@ -86,7 +86,7 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){
}
}
myRSSListMenu.addAction(actionNew_subscription);
if(m_feedList->getItemType(selectedItems.first()) == IRssFile::FEED) {
if(m_feedList->isFeed(selectedItems.first())) {
myRSSListMenu.addSeparator();
myRSSListMenu.addAction(actionCopy_feed_URL);
}
@ -137,18 +137,18 @@ void RSSImp::on_actionManage_cookies_triggered() { @@ -137,18 +137,18 @@ void RSSImp::on_actionManage_cookies_triggered() {
void RSSImp::askNewFolder() {
QTreeWidgetItem *parent_item = 0;
RssFolder *rss_parent;
RssFolderPtr rss_parent;
if(m_feedList->selectedItems().size() > 0) {
parent_item = m_feedList->selectedItems().at(0);
rss_parent = dynamic_cast<RssFolder*>(m_feedList->getRSSItem(parent_item));
Q_ASSERT(rss_parent->type() == IRssFile::FOLDER);
rss_parent = qSharedPointerDynamicCast<RssFolder>(m_feedList->getRSSItem(parent_item));
Q_ASSERT(rss_parent);
} else {
rss_parent = m_rssManager;
}
bool ok;
QString new_name = QInputDialog::getText(this, tr("Please choose a folder name"), tr("Folder name:"), QLineEdit::Normal, tr("New folder"), &ok);
if(ok) {
RssFolder* new_folder = rss_parent->addFolder(new_name);
RssFolderPtr new_folder = rss_parent->addFolder(new_name);
QTreeWidgetItem* folder_item;
if(parent_item)
folder_item = new QTreeWidgetItem(parent_item);
@ -183,13 +183,13 @@ void RSSImp::on_newFeedButton_clicked() { @@ -183,13 +183,13 @@ void RSSImp::on_newFeedButton_clicked() {
if(parent_item == m_feedList->stickyUnreadItem()) {
parent_item = 0;
} else {
if(m_feedList->getItemType(parent_item) != IRssFile::FOLDER)
if(m_feedList->isFolder(parent_item))
parent_item = parent_item->parent();
}
}
RssFolder *rss_parent;
RssFolderPtr rss_parent;
if(parent_item) {
rss_parent = (RssFolder*)m_feedList->getRSSItem(parent_item);
rss_parent = qSharedPointerCast<RssFolder>(m_feedList->getRSSItem(parent_item));
} else {
rss_parent = m_rssManager;
}
@ -210,7 +210,7 @@ void RSSImp::on_newFeedButton_clicked() { @@ -210,7 +210,7 @@ void RSSImp::on_newFeedButton_clicked() {
QMessageBox::Ok);
return;
}
RssFeed *stream = rss_parent->addStream(newUrl);
RssFeedPtr stream = rss_parent->addStream(m_rssManager.data(), newUrl);
// Create TreeWidget item
QTreeWidgetItem* item;
if(parent_item)
@ -248,7 +248,7 @@ void RSSImp::deleteSelectedItems() { @@ -248,7 +248,7 @@ void RSSImp::deleteSelectedItems() {
m_currentArticle = 0;
listArticles->clear();
}
IRssFile *rss_item = m_feedList->getRSSItem(item);
RssFilePtr rss_item = m_feedList->getRSSItem(item);
QTreeWidgetItem * parent = item->parent();
// Notify TreeWidget
m_feedList->itemAboutToBeRemoved(item);
@ -350,7 +350,7 @@ void RSSImp::renameFiles() { @@ -350,7 +350,7 @@ void RSSImp::renameFiles() {
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
Q_ASSERT(selectedItems.size() == 1);
QTreeWidgetItem *item = selectedItems.at(0);
IRssFile *rss_item = m_feedList->getRSSItem(item);
RssFilePtr rss_item = m_feedList->getRSSItem(item);
bool ok;
QString newName;
do {
@ -375,7 +375,7 @@ void RSSImp::renameFiles() { @@ -375,7 +375,7 @@ void RSSImp::renameFiles() {
void RSSImp::refreshSelectedItems() {
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
foreach(QTreeWidgetItem* item, selectedItems){
IRssFile* file = m_feedList->getRSSItem(item);
RssFilePtr file = m_feedList->getRSSItem(item);
// Update icons
if(item == m_feedList->stickyUnreadItem()) {
foreach(QTreeWidgetItem *feed, m_feedList->getAllFeedItems()) {
@ -384,9 +384,9 @@ void RSSImp::refreshSelectedItems() { @@ -384,9 +384,9 @@ void RSSImp::refreshSelectedItems() {
file->refresh();
break;
} else {
if(file->type() == IRssFile::FEED) {
if (qSharedPointerDynamicCast<RssFeed>(file)) {
item->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
} else {
} else if (qSharedPointerDynamicCast<RssFolder>(file)) {
// Update feeds in the folder
foreach(QTreeWidgetItem *feed, m_feedList->getAllFeedItems(item)) {
feed->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
@ -403,7 +403,7 @@ void RSSImp::copySelectedFeedsURL() { @@ -403,7 +403,7 @@ void RSSImp::copySelectedFeedsURL() {
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
QTreeWidgetItem* item;
foreach(item, selectedItems){
if(m_feedList->getItemType(item) == IRssFile::FEED)
if(m_feedList->isFeed(item))
URLs << m_feedList->getItemID(item);
}
qApp->clipboard()->setText(URLs.join("\n"));
@ -413,7 +413,7 @@ void RSSImp::on_markReadButton_clicked() { @@ -413,7 +413,7 @@ void RSSImp::on_markReadButton_clicked() {
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
QTreeWidgetItem* item;
foreach(item, selectedItems){
IRssFile *rss_item = m_feedList->getRSSItem(item);
RssFilePtr rss_item = m_feedList->getRSSItem(item);
rss_item->markAsRead();
updateItemInfos(item);
}
@ -421,14 +421,14 @@ void RSSImp::on_markReadButton_clicked() { @@ -421,14 +421,14 @@ void RSSImp::on_markReadButton_clicked() {
refreshArticleList(m_feedList->currentItem());
}
void RSSImp::fillFeedsList(QTreeWidgetItem *parent, RssFolder *rss_parent) {
QList<IRssFile*> children;
void RSSImp::fillFeedsList(QTreeWidgetItem *parent, const RssFolderPtr& rss_parent) {
QList<RssFilePtr> children;
if(parent) {
children = rss_parent->getContent();
} else {
children = m_rssManager->getContent();
}
foreach(IRssFile* rss_child, children){
foreach (const RssFilePtr& rss_child, children){
QTreeWidgetItem* item;
if(!parent)
item = new QTreeWidgetItem(m_feedList);
@ -438,12 +438,12 @@ void RSSImp::fillFeedsList(QTreeWidgetItem *parent, RssFolder *rss_parent) { @@ -438,12 +438,12 @@ void RSSImp::fillFeedsList(QTreeWidgetItem *parent, RssFolder *rss_parent) {
// Notify TreeWidget of item addition
m_feedList->itemAdded(item, rss_child);
// Set Icon
if(rss_child->type() == IRssFile::FEED) {
if(qSharedPointerDynamicCast<RssFeed>(rss_child)) {
item->setData(0,Qt::DecorationRole, QVariant(QIcon(QString::fromUtf8(":/Icons/loading.png"))));
} else {
} else if (RssFolderPtr folder = qSharedPointerDynamicCast<RssFolder>(rss_child)) {
item->setData(0,Qt::DecorationRole, QVariant(IconProvider::instance()->getIcon("inode-directory")));
// Recurvive call to load sub folders/files
fillFeedsList(item, (RssFolder*)rss_child);
fillFeedsList(item, folder);
}
}
}
@ -455,11 +455,11 @@ void RSSImp::refreshArticleList(QTreeWidgetItem* item) { @@ -455,11 +455,11 @@ void RSSImp::refreshArticleList(QTreeWidgetItem* item) {
return;
}
IRssFile *rss_item = m_feedList->getRSSItem(item);
RssFilePtr rss_item = m_feedList->getRSSItem(item);
if(!rss_item) return;
qDebug("Getting the list of news");
QList<RssArticlePtr> news;
RssArticleList news;
if(rss_item == m_rssManager)
news = rss_item->unreadArticleList();
else if(rss_item)
@ -507,7 +507,7 @@ void RSSImp::refreshTextBrowser() { @@ -507,7 +507,7 @@ void RSSImp::refreshTextBrowser() {
}
m_currentArticle = item;
}
RssFeed *stream = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString());
RssFeedPtr stream = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString());
RssArticlePtr article = stream->getItem(item->data(Article::IdRole).toString());
QString html;
html += "<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>";
@ -556,7 +556,7 @@ void RSSImp::updateItemsInfos(const QList<QTreeWidgetItem *> &items) { @@ -556,7 +556,7 @@ void RSSImp::updateItemsInfos(const QList<QTreeWidgetItem *> &items) {
}
void RSSImp::updateItemInfos(QTreeWidgetItem *item) {
IRssFile *rss_item = m_feedList->getRSSItem(item);
RssFilePtr rss_item = m_feedList->getRSSItem(item);
if (!rss_item)
return;
@ -579,7 +579,7 @@ void RSSImp::updateFeedIcon(const QString &url, const QString &icon_path){ @@ -579,7 +579,7 @@ void RSSImp::updateFeedIcon(const QString &url, const QString &icon_path){
void RSSImp::updateFeedInfos(const QString &url, const QString &display_name, uint nbUnread){
qDebug() << Q_FUNC_INFO << display_name;
QTreeWidgetItem *item = m_feedList->getTreeItemFromUrl(url);
RssFeed *stream = (RssFeed*)m_feedList->getRSSItem(item);
RssFeedPtr stream = qSharedPointerCast<RssFeed>(m_feedList->getRSSItem(item));
item->setText(0, display_name + QString::fromUtf8(" (") + QString::number(nbUnread, 10)+ QString(")"));
if(!stream->isLoading())
item->setData(0,Qt::DecorationRole, QVariant(QIcon(stream->icon())));
@ -603,7 +603,7 @@ void RSSImp::updateRefreshInterval(uint val) { @@ -603,7 +603,7 @@ void RSSImp::updateRefreshInterval(uint val) {
m_rssManager->updateRefreshInterval(val);
}
RSSImp::RSSImp(QWidget *parent) : QWidget(parent) {
RSSImp::RSSImp(QWidget *parent) : QWidget(parent), m_rssManager(new RssManager) {
setupUi(this);
// Icons
actionCopy_feed_URL->setIcon(IconProvider::instance()->getIcon("edit-copy"));
@ -623,8 +623,6 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) { @@ -623,8 +623,6 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) {
rssDownloaderBtn->setIcon(IconProvider::instance()->getIcon("download"));
settingsButton->setIcon(IconProvider::instance()->getIcon("preferences-system"));
m_rssManager = RssManager::instance();
m_feedList = new FeedListWidget(splitter_h, m_rssManager);
splitter_h->insertWidget(0, m_feedList);
listArticles->setSelectionBehavior(QAbstractItemView::SelectItems);
@ -635,8 +633,8 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) { @@ -635,8 +633,8 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) {
refreshArticleList(m_feedList->currentItem());
loadFoldersOpenState();
connect(m_rssManager, SIGNAL(feedInfosChanged(QString, QString, unsigned int)), this, SLOT(updateFeedInfos(QString, QString, unsigned int)));
connect(m_rssManager, SIGNAL(feedIconChanged(QString, QString)), this, SLOT(updateFeedIcon(QString, QString)));
connect(m_rssManager.data(), SIGNAL(feedInfosChanged(QString, QString, unsigned int)), this, SLOT(updateFeedInfos(QString, QString, unsigned int)));
connect(m_rssManager.data(), SIGNAL(feedIconChanged(QString, QString)), this, SLOT(updateFeedIcon(QString, QString)));
connect(m_feedList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRSSListMenu(const QPoint&)));
connect(listArticles, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayItemsListMenu(const QPoint&)));
@ -676,7 +674,6 @@ RSSImp::~RSSImp(){ @@ -676,7 +674,6 @@ RSSImp::~RSSImp(){
qDebug("Deleting RSSImp...");
saveFoldersOpenState();
delete m_feedList;
RssManager::drop();
qDebug("RSSImp deleted");
}
@ -689,7 +686,7 @@ void RSSImp::on_settingsButton_clicked() { @@ -689,7 +686,7 @@ void RSSImp::on_settingsButton_clicked() {
void RSSImp::on_rssDownloaderBtn_clicked()
{
AutomatedRssDownloader dlg(this);
AutomatedRssDownloader dlg(m_rssManager, this);
dlg.exec();
if(dlg.isRssDownloaderEnabled())
on_updateAllButton_clicked();

8
src/rss/rss_imp.h

@ -35,10 +35,10 @@ @@ -35,10 +35,10 @@
#include <QPointer>
#include "ui_rss.h"
#include "rssfolder.h"
#include "rssmanager.h"
class FeedListWidget;
class RssFolder;
class RssManager;
QT_BEGIN_NAMESPACE
class QTreeWidgetItem;
@ -72,7 +72,7 @@ private slots: @@ -72,7 +72,7 @@ private slots:
void updateItemInfos(QTreeWidgetItem *item);
void openNewsUrl();
void downloadTorrent();
void fillFeedsList(QTreeWidgetItem *parent=0, RssFolder *rss_parent=0);
void fillFeedsList(QTreeWidgetItem *parent=0, const RssFolderPtr& rss_parent = RssFolderPtr());
void saveSlidersPosition();
void restoreSlidersPosition();
void askNewFolder();
@ -84,7 +84,7 @@ private slots: @@ -84,7 +84,7 @@ private slots:
void on_rssDownloaderBtn_clicked();
private:
RssManager *m_rssManager;
RssManagerPtr m_rssManager;
FeedListWidget *m_feedList;
QListWidgetItem* m_currentArticle;

38
src/rss/rssdownloadrule.cpp

@ -76,35 +76,35 @@ void RssDownloadRule::setMustNotContain(const QString &tokens) @@ -76,35 +76,35 @@ void RssDownloadRule::setMustNotContain(const QString &tokens)
m_mustNotContain = tokens.split(QRegExp("[\\s|]"));
}
RssDownloadRule RssDownloadRule::fromOldFormat(const QVariantHash &rule_hash, const QString &feed_url, const QString &rule_name)
RssDownloadRulePtr RssDownloadRule::fromOldFormat(const QVariantHash &rule_hash, const QString &feed_url, const QString &rule_name)
{
qDebug() << Q_FUNC_INFO << feed_url << rule_name;
RssDownloadRule rule;
rule.setName(rule_name);
rule.setMustContain(rule_hash.value("matches", "").toString());
rule.setMustNotContain(rule_hash.value("not", "").toString());
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());
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());
rule->setEnabled(feeds_w_downloader.value(feed_url, true).toBool());
// label was unsupported < 2.5.0
return rule;
}
RssDownloadRule RssDownloadRule::fromNewFormat(const QVariantHash &rule_hash)
RssDownloadRulePtr RssDownloadRule::fromNewFormat(const QVariantHash &rule_hash)
{
RssDownloadRule rule;
rule.setName(rule_hash.value("name").toString());
rule.setMustContain(rule_hash.value("must_contain").toString());
rule.setMustNotContain(rule_hash.value("must_not_contain").toString());
rule.setRssFeeds(rule_hash.value("affected_feeds").toStringList());
rule.setEnabled(rule_hash.value("enabled", false).toBool());
rule.setSavePath(rule_hash.value("save_path").toString());
rule.setLabel(rule_hash.value("label_assigned").toString());
rule.setUseRegex(rule_hash.value("use_regex", false).toBool());
RssDownloadRulePtr rule(new RssDownloadRule);
rule->setName(rule_hash.value("name").toString());
rule->setMustContain(rule_hash.value("must_contain").toString());
rule->setMustNotContain(rule_hash.value("must_not_contain").toString());
rule->setRssFeeds(rule_hash.value("affected_feeds").toStringList());
rule->setEnabled(rule_hash.value("enabled", false).toBool());
rule->setSavePath(rule_hash.value("save_path").toString());
rule->setLabel(rule_hash.value("label_assigned").toString());
rule->setUseRegex(rule_hash.value("use_regex", false).toBool());
return rule;
}
@ -134,7 +134,7 @@ void RssDownloadRule::setSavePath(const QString &save_path) @@ -134,7 +134,7 @@ void RssDownloadRule::setSavePath(const QString &save_path)
m_savePath = QString();
}
QStringList RssDownloadRule::findMatchingArticles(const RssFeed *feed) const
QStringList RssDownloadRule::findMatchingArticles(const RssFeedPtr& feed) const
{
QStringList ret;
const RssArticleHash& feed_articles = feed->articleHash();

12
src/rss/rssdownloadrule.h

@ -33,16 +33,21 @@ @@ -33,16 +33,21 @@
#include <QStringList>
#include <QVariantHash>
#include <QSharedPointer>
class RssFeed;
typedef QSharedPointer<RssFeed> RssFeedPtr;
class RssDownloadRule;
typedef QSharedPointer<RssDownloadRule> RssDownloadRulePtr;
class RssDownloadRule
{
public:
explicit RssDownloadRule();
static RssDownloadRule fromOldFormat(const QVariantHash& rule_hash, const QString &feed_url, const QString &rule_name); // Before v2.5.0
static RssDownloadRule fromNewFormat(const QVariantHash &rule_hash);
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);
QVariantHash toVariantHash() const;
bool matches(const QString &article_title) const;
void setMustContain(const QString &tokens);
@ -57,12 +62,11 @@ public: @@ -57,12 +62,11 @@ public:
inline void setLabel(const QString &_label) { m_label = _label; }
inline bool isEnabled() const { return m_enabled; }
inline void setEnabled(bool enable) { m_enabled = enable; }
inline bool isValid() const { return !m_name.isEmpty(); }
inline QString mustContain() const { return m_mustContain.join(" "); }
inline QString mustNotContain() const { return m_mustNotContain.join(" "); }
inline bool useRegex() const { return m_useRegex; }
inline void setUseRegex(bool enabled) { m_useRegex = enabled; }
QStringList findMatchingArticles(const RssFeed* feed) const;
QStringList findMatchingArticles(const RssFeedPtr& feed) const;
// Operators
bool operator==(const RssDownloadRule &other);

60
src/rss/rssdownloadrulelist.cpp

@ -51,19 +51,21 @@ RssDownloadRuleList* RssDownloadRuleList::instance() @@ -51,19 +51,21 @@ RssDownloadRuleList* RssDownloadRuleList::instance()
void RssDownloadRuleList::drop()
{
if(m_instance)
if (m_instance) {
delete m_instance;
m_instance = 0;
}
}
RssDownloadRule RssDownloadRuleList::findMatchingRule(const QString &feed_url, const QString &article_title) const
RssDownloadRulePtr RssDownloadRuleList::findMatchingRule(const QString &feed_url, const QString &article_title) const
{
Q_ASSERT(RssSettings().isRssDownloadingEnabled());
const QStringList rule_names = m_feedRules.value(feed_url);
QStringList rule_names = m_feedRules.value(feed_url);
foreach(const QString &rule_name, rule_names) {
const RssDownloadRule &rule = m_rules[rule_name];
if(rule.isEnabled() && rule.matches(article_title)) return rule;
RssDownloadRulePtr rule = m_rules[rule_name];
if(rule->isEnabled() && rule->matches(article_title)) return rule;
}
return RssDownloadRule();
return RssDownloadRulePtr();
}
void RssDownloadRuleList::saveRulesToStorage()
@ -97,11 +99,11 @@ void RssDownloadRuleList::importFeedsInOldFormat(const QHash<QString, QVariant> @@ -97,11 +99,11 @@ void RssDownloadRuleList::importFeedsInOldFormat(const QHash<QString, QVariant>
void RssDownloadRuleList::importFeedRulesInOldFormat(const QString &feed_url, const QHash<QString, QVariant> &rules)
{
foreach(const QString &rule_name, rules.keys()) {
RssDownloadRule rule = RssDownloadRule::fromOldFormat(rules.value(rule_name).toHash(), feed_url, rule_name);
if(!rule.isValid()) continue;
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()+"_");
while(m_rules.contains(rule->name())) {
rule->setName(rule->name()+"_");
}
// Add the rule to the list
saveRule(rule);
@ -111,8 +113,8 @@ void RssDownloadRuleList::importFeedRulesInOldFormat(const QString &feed_url, co @@ -111,8 +113,8 @@ void RssDownloadRuleList::importFeedRulesInOldFormat(const QString &feed_url, co
QVariantHash RssDownloadRuleList::toVariantHash() const
{
QVariantHash ret;
foreach(const RssDownloadRule &rule, m_rules.values()) {
ret.insert(rule.name(), rule.toVariantHash());
foreach(const RssDownloadRulePtr &rule, m_rules.values()) {
ret.insert(rule->name(), rule->toVariantHash());
}
return ret;
}
@ -120,25 +122,25 @@ QVariantHash RssDownloadRuleList::toVariantHash() const @@ -120,25 +122,25 @@ QVariantHash RssDownloadRuleList::toVariantHash() const
void RssDownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h)
{
foreach(const QVariant& v, h.values()) {
RssDownloadRule rule = RssDownloadRule::fromNewFormat(v.toHash());
if(!rule.name().isEmpty()) {
RssDownloadRulePtr rule = RssDownloadRule::fromNewFormat(v.toHash());
if(rule && !rule->name().isEmpty()) {
saveRule(rule);
}
}
}
void RssDownloadRuleList::saveRule(const RssDownloadRule &rule)
void RssDownloadRuleList::saveRule(const RssDownloadRulePtr &rule)
{
qDebug() << Q_FUNC_INFO << rule.name();
Q_ASSERT(rule.isValid());
if(m_rules.contains(rule.name())) {
qDebug() << Q_FUNC_INFO << rule->name();
Q_ASSERT(rule);
if(m_rules.contains(rule->name())) {
qDebug("This is an update, removing old rule first");
removeRule(rule.name());
removeRule(rule->name());
}
m_rules.insert(rule.name(), rule);
m_rules.insert(rule->name(), rule);
// Update feedRules hashtable
foreach(const QString &feed_url, rule.rssFeeds()) {
m_feedRules[feed_url].append(rule.name());
foreach(const QString &feed_url, rule->rssFeeds()) {
m_feedRules[feed_url].append(rule->name());
}
// Save rules
saveRulesToStorage();
@ -149,10 +151,10 @@ void RssDownloadRuleList::removeRule(const QString &name) @@ -149,10 +151,10 @@ void RssDownloadRuleList::removeRule(const QString &name)
{
qDebug() << Q_FUNC_INFO << name;
if(!m_rules.contains(name)) return;
const RssDownloadRule rule = m_rules.take(name);
RssDownloadRulePtr rule = m_rules.take(name);
// Update feedRules hashtable
foreach(const QString &feed_url, rule.rssFeeds()) {
m_feedRules[feed_url].removeOne(rule.name());
foreach(const QString &feed_url, rule->rssFeeds()) {
m_feedRules[feed_url].removeOne(rule->name());
}
// Save rules
saveRulesToStorage();
@ -161,18 +163,18 @@ void RssDownloadRuleList::removeRule(const QString &name) @@ -161,18 +163,18 @@ void RssDownloadRuleList::removeRule(const QString &name)
void RssDownloadRuleList::renameRule(const QString &old_name, const QString &new_name)
{
if(!m_rules.contains(old_name)) return;
RssDownloadRule rule = m_rules.take(old_name);
rule.setName(new_name);
RssDownloadRulePtr rule = m_rules.take(old_name);
rule->setName(new_name);
m_rules.insert(new_name, rule);
// Update feedRules hashtable
foreach(const QString &feed_url, rule.rssFeeds()) {
foreach(const QString &feed_url, rule->rssFeeds()) {
m_feedRules[feed_url].replace(m_feedRules[feed_url].indexOf(old_name), new_name);
}
// Save rules
saveRulesToStorage();
}
const RssDownloadRule RssDownloadRuleList::getRule(const QString &name) const
RssDownloadRulePtr RssDownloadRuleList::getRule(const QString &name) const
{
return m_rules.value(name);
}

8
src/rss/rssdownloadrulelist.h

@ -49,12 +49,12 @@ private: @@ -49,12 +49,12 @@ private:
public:
static RssDownloadRuleList* instance();
static void drop();
RssDownloadRule findMatchingRule(const QString &feed_url, const QString &article_title) const;
RssDownloadRulePtr findMatchingRule(const QString &feed_url, const QString &article_title) const;
// Operators
void saveRule(const RssDownloadRule &rule);
void saveRule(const RssDownloadRulePtr &rule);
void removeRule(const QString &name);
void renameRule(const QString &old_name, const QString &new_name);
const RssDownloadRule getRule(const QString &name) const;
RssDownloadRulePtr getRule(const QString &name) const;
inline QStringList ruleNames() const { return m_rules.keys(); }
inline bool isEmpty() const { return m_rules.isEmpty(); }
bool serialize(const QString& path);
@ -69,7 +69,7 @@ private: @@ -69,7 +69,7 @@ private:
void saveRulesToStorage();
private:
QHash<QString, RssDownloadRule> m_rules;
QHash<QString, RssDownloadRulePtr> m_rules;
QHash<QString, QStringList> m_feedRules;
};

39
src/rss/rssfeed.cpp

@ -39,16 +39,17 @@ @@ -39,16 +39,17 @@
#include "rssdownloadrulelist.h"
#include "downloadthread.h"
RssFeed::RssFeed(RssFolder* parent, const QString &url): m_parent(parent), m_icon(":/Icons/oxygen/application-rss+xml.png"),
RssFeed::RssFeed(RssManager* manager, RssFolder* parent, const QString &url):
m_manager(manager), m_parent(parent), m_icon(":/Icons/oxygen/application-rss+xml.png"),
m_refreshed(false), m_downloadFailure(false), m_loading(false) {
qDebug() << Q_FUNC_INFO << url;
m_url = QUrl::fromEncoded(url.toUtf8()).toString();
// Listen for new RSS downloads
connect(RssManager::instance()->rssDownloader(), SIGNAL(downloadFinished(QString,QString)), SLOT(handleFinishedDownload(QString,QString)));
connect(RssManager::instance()->rssDownloader(), SIGNAL(downloadFailure(QString,QString)), SLOT(handleDownloadFailure(QString,QString)));
connect(manager->rssDownloader(), SIGNAL(downloadFinished(QString,QString)), SLOT(handleFinishedDownload(QString,QString)));
connect(manager->rssDownloader(), SIGNAL(downloadFailure(QString,QString)), SLOT(handleDownloadFailure(QString,QString)));
// Download the RSS Feed icon
m_iconUrl = iconUrl();
RssManager::instance()->rssDownloader()->downloadUrl(m_iconUrl);
manager->rssDownloader()->downloadUrl(m_iconUrl);
// Load old RSS articles
loadItemsFromDisk();
@ -90,10 +91,6 @@ void RssFeed::loadItemsFromDisk() { @@ -90,10 +91,6 @@ void RssFeed::loadItemsFromDisk() {
}
}
IRssFile::FileType RssFeed::type() const {
return IRssFile::FEED;
}
void RssFeed::refresh() {
if(m_loading) {
qWarning() << Q_FUNC_INFO << "Feed" << this->displayName() << "is already being refreshed, ignoring request";
@ -101,7 +98,7 @@ void RssFeed::refresh() { @@ -101,7 +98,7 @@ void RssFeed::refresh() {
}
m_loading = true;
// Download the RSS again
RssManager::instance()->rssDownloader()->downloadUrl(m_url);
m_manager->rssDownloader()->downloadUrl(m_url);
}
void RssFeed::removeAllSettings() {
@ -189,7 +186,7 @@ void RssFeed::markAsRead() { @@ -189,7 +186,7 @@ void RssFeed::markAsRead() {
for (RssArticleHash::ConstIterator it=m_articles.begin(); it != m_articles.end(); it++) {
it.value()->markAsRead();
}
RssManager::instance()->forwardFeedInfosChanged(m_url, displayName(), 0);
m_manager->forwardFeedInfosChanged(m_url, displayName(), 0);
}
uint RssFeed::unreadCount() const{
@ -201,12 +198,12 @@ uint RssFeed::unreadCount() const{ @@ -201,12 +198,12 @@ uint RssFeed::unreadCount() const{
return nbUnread;
}
const QList<RssArticlePtr> RssFeed::articleList() const{
const RssArticleList RssFeed::articleList() const{
return m_articles.values();
}
const QList<RssArticlePtr> RssFeed::unreadArticleList() const {
QList<RssArticlePtr> unread_news;
const RssArticleList RssFeed::unreadArticleList() const {
RssArticleList unread_news;
for (RssArticleHash::ConstIterator it = m_articles.begin(); it != m_articles.end(); it++) {
if(!it.value()->isRead())
unread_news << it.value();
@ -270,7 +267,7 @@ bool RssFeed::parseRSS(QIODevice* device) { @@ -270,7 +267,7 @@ bool RssFeed::parseRSS(QIODevice* device) {
QString icon_path = xml.attributes().value("url").toString();
if(!icon_path.isEmpty()) {
m_iconUrl = icon_path;
RssManager::instance()->rssDownloader()->downloadUrl(m_iconUrl);
m_manager->rssDownloader()->downloadUrl(m_iconUrl);
}
}
else if(xml.name() == "item") {
@ -305,13 +302,13 @@ void RssFeed::downloadMatchingArticleTorrents() { @@ -305,13 +302,13 @@ void RssFeed::downloadMatchingArticleTorrents() {
else
torrent_url = item->link();
// Check if the item should be automatically downloaded
const RssDownloadRule matching_rule = RssDownloadRuleList::instance()->findMatchingRule(m_url, item->title());
if(matching_rule.isValid()) {
RssDownloadRulePtr matching_rule = RssDownloadRuleList::instance()->findMatchingRule(m_url, item->title());
if(matching_rule) {
// Item was downloaded, consider it as Read
item->markAsRead();
// Download the torrent
QBtSession::instance()->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(item->title()).arg(displayName()));
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule.savePath(), matching_rule.label());
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule->savePath(), matching_rule->label());
}
}
}
@ -320,7 +317,7 @@ void RssFeed::resizeList() { @@ -320,7 +317,7 @@ void RssFeed::resizeList() {
const uint max_articles = RssSettings().getRSSMaxArticlesPerFeed();
const uint nb_articles = m_articles.size();
if(nb_articles > max_articles) {
QList<RssArticlePtr> listItems = m_articles.values();
RssArticleList listItems = m_articles.values();
RssManager::sortNewsList(listItems);
const int excess = nb_articles - max_articles;
for(uint i=nb_articles-excess; i<nb_articles; ++i){
@ -358,14 +355,14 @@ void RssFeed::handleFinishedDownload(const QString& url, const QString &file_pat @@ -358,14 +355,14 @@ void RssFeed::handleFinishedDownload(const QString& url, const QString &file_pat
// Parse the download RSS
if(parseXmlFile(file_path)) {
m_refreshed = true;
RssManager::instance()->forwardFeedInfosChanged(m_url, displayName(), unreadCount()); // XXX: Ugly
m_manager->forwardFeedInfosChanged(m_url, displayName(), unreadCount()); // XXX: Ugly
qDebug() << Q_FUNC_INFO << "Feed parsed successfuly";
}
}
else if(url == m_iconUrl) {
m_icon = file_path;
qDebug() << Q_FUNC_INFO << "icon path:" << m_icon;
RssManager::instance()->forwardFeedIconChanged(m_url, m_icon); // XXX: Ugly
m_manager->forwardFeedIconChanged(m_url, m_icon); // XXX: Ugly
}
}
@ -373,7 +370,7 @@ void RssFeed::handleDownloadFailure(const QString &url, const QString& error) { @@ -373,7 +370,7 @@ void RssFeed::handleDownloadFailure(const QString &url, const QString& error) {
if(url != m_url) return;
m_downloadFailure = true;
m_loading = false;
RssManager::instance()->forwardFeedInfosChanged(m_url, displayName(), unreadCount()); // XXX: Ugly
m_manager->forwardFeedInfosChanged(m_url, displayName(), unreadCount()); // XXX: Ugly
qWarning() << "Failed to download RSS feed at" << url;
qWarning() << "Reason:" << error;
}

14
src/rss/rssfeed.h

@ -32,22 +32,25 @@ @@ -32,22 +32,25 @@
#define RSSFEED_H
#include <QHash>
#include <QSharedPointer>
#include "rssfile.h"
class RssFeed;
class RssManager;
typedef QHash<QString, RssArticlePtr> RssArticleHash;
typedef QSharedPointer<RssFeed> RssFeedPtr;
typedef QList<RssFeedPtr> RssFeedList;
class RssFeed: public QObject, public IRssFile {
class RssFeed: public QObject, public RssFile {
Q_OBJECT
public:
RssFeed(RssFolder* m_parent, const QString &url);
RssFeed(RssManager* manager, RssFolder* m_parent, const QString &url);
virtual ~RssFeed();
inline RssFolder* parent() const { return m_parent; }
void setParent(RssFolder* parent) { m_parent = parent; }
FileType type() const;
void refresh();
QString id() const { return m_url; }
void removeAllSettings();
@ -65,9 +68,9 @@ public: @@ -65,9 +68,9 @@ public:
uint count() const;
void markAsRead();
uint unreadCount() const;
const QList<RssArticlePtr> articleList() const;
const RssArticleList articleList() const;
const RssArticleHash& articleHash() const { return m_articles; }
const QList<RssArticlePtr> unreadArticleList() const;
const RssArticleList unreadArticleList() const;
private slots:
void handleFinishedDownload(const QString& url, const QString &file_path);
@ -83,6 +86,7 @@ private: @@ -83,6 +86,7 @@ private:
void loadItemsFromDisk();
private:
RssManager* m_manager;
RssArticleHash m_articles;
RssFolder *m_parent;
QString m_title;

2
src/rss/rssfile.cpp

@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
#include "rssfile.h"
#include "rssfolder.h"
QStringList IRssFile::pathHierarchy() const {
QStringList RssFile::pathHierarchy() const {
QStringList path;
if(parent())
path << parent()->pathHierarchy();

22
src/rss/rssfile.h

@ -33,19 +33,25 @@ @@ -33,19 +33,25 @@
#include <QList>
#include <QStringList>
#include "rssarticle.h"
#include <QSharedPointer>
class RssFolder;
class RssFile;
class RssArticle;
class IRssFile {
typedef QSharedPointer<RssFile> RssFilePtr;
typedef QSharedPointer<RssArticle> RssArticlePtr;
typedef QList<RssArticlePtr> RssArticleList;
typedef QList<RssFilePtr> RssFileList;
/**
* Parent interface for RssFolder and RssFeed.
*/
class RssFile {
public:
enum FileType {FEED, FOLDER};
virtual ~IRssFile() {}
virtual ~RssFile() {}
virtual uint unreadCount() const = 0;
virtual FileType type() const = 0;
virtual QString displayName() const = 0;
virtual QString id() const = 0;
virtual void rename(const QString &new_name) = 0;
@ -54,8 +60,8 @@ public: @@ -54,8 +60,8 @@ public:
virtual void setParent(RssFolder* parent) = 0;
virtual void refresh() = 0;
virtual void removeAllSettings() = 0;
virtual const QList<RssArticlePtr> articleList() const = 0;
virtual const QList<RssArticlePtr> unreadArticleList() const = 0;
virtual const RssArticleList articleList() const = 0;
virtual const RssArticleList unreadArticleList() const = 0;
QStringList pathHierarchy() const;
};

86
src/rss/rssfolder.cpp

@ -40,8 +40,6 @@ RssFolder::RssFolder(RssFolder *parent, const QString &name): m_parent(parent), @@ -40,8 +40,6 @@ RssFolder::RssFolder(RssFolder *parent, const QString &name): m_parent(parent),
}
RssFolder::~RssFolder() {
qDebug("Deleting a RSS folder, removing elements");
qDeleteAll(m_children.values());
}
unsigned int RssFolder::unreadCount() const {
@ -52,31 +50,26 @@ unsigned int RssFolder::unreadCount() const { @@ -52,31 +50,26 @@ unsigned int RssFolder::unreadCount() const {
return nb_unread;
}
IRssFile::FileType RssFolder::type() const {
return IRssFile::FOLDER;
}
void RssFolder::removeChild(const QString &childId) {
if (m_children.contains(childId)) {
IRssFile* child = m_children.take(childId);
RssFilePtr child = m_children.take(childId);
child->removeAllSettings();
delete child;
}
}
RssFolder* RssFolder::addFolder(const QString &name) {
RssFolder *subfolder;
RssFolderPtr RssFolder::addFolder(const QString &name) {
RssFolderPtr subfolder;
if (!m_children.contains(name)) {
subfolder = new RssFolder(this, name);
subfolder = RssFolderPtr(new RssFolder(this, name));
m_children[name] = subfolder;
} else {
subfolder = dynamic_cast<RssFolder*>(m_children.value(name));
subfolder = qSharedPointerDynamicCast<RssFolder>(m_children.value(name));
}
return subfolder;
}
RssFeed* RssFolder::addStream(const QString &url) {
RssFeed* stream = new RssFeed(this, url);
RssFeedPtr RssFolder::addStream(RssManager* manager, const QString &url) {
RssFeedPtr stream(new RssFeed(manager, this, url));
Q_ASSERT(!m_children.contains(stream->url()));
m_children[stream->url()] = stream;
stream->refresh();
@ -90,33 +83,33 @@ void RssFolder::refresh() { @@ -90,33 +83,33 @@ void RssFolder::refresh() {
}
}
const QList<RssArticlePtr> RssFolder::articleList() const {
QList<RssArticlePtr> news;
const RssArticleList RssFolder::articleList() const {
RssArticleList news;
for (RssFileHash::ConstIterator it = m_children.begin(); it != m_children.end(); it++) {
news << it.value()->articleList();
}
return news;
}
const QList<RssArticlePtr> RssFolder::unreadArticleList() const {
QList<RssArticlePtr> unread_news;
const RssArticleList RssFolder::unreadArticleList() const {
RssArticleList unread_news;
for (RssFileHash::ConstIterator it = m_children.begin(); it != m_children.end(); it++) {
unread_news << it.value()->unreadArticleList();
}
return unread_news;
}
QList<IRssFile*> RssFolder::getContent() const {
RssFileList RssFolder::getContent() const {
return m_children.values();
}
unsigned int RssFolder::getNbFeeds() const {
uint nbFeeds = 0;
for (RssFileHash::ConstIterator it = m_children.begin(); it != m_children.end(); it++) {
if (it.value()->type() == IRssFile::FOLDER)
nbFeeds += ((RssFolder*)*it)->getNbFeeds();
if (RssFolderPtr folder = qSharedPointerDynamicCast<RssFolder>(it.value()))
nbFeeds += folder->getNbFeeds();
else
nbFeeds += 1;
++nbFeeds; // Feed
}
return nbFeeds;
}
@ -142,51 +135,46 @@ void RssFolder::markAsRead() { @@ -142,51 +135,46 @@ void RssFolder::markAsRead() {
}
}
QList<RssFeed*> RssFolder::getAllFeeds() const {
QList<RssFeed*> streams;
RssFeedList RssFolder::getAllFeeds() const {
RssFeedList streams;
for (RssFileHash::ConstIterator it = m_children.begin(); it != m_children.end(); it++) {
if (it.value()->type() == IRssFile::FEED) {
streams << static_cast<RssFeed*>(it.value());
} else {
streams << static_cast<RssFolder*>(it.value())->getAllFeeds();
if (RssFeedPtr feed = qSharedPointerDynamicCast<RssFeed>(it.value())) {
streams << feed;
} else if (RssFolderPtr folder = qSharedPointerDynamicCast<RssFolder>(it.value())) {
streams << folder->getAllFeeds();
}
}
return streams;
}
QHash<QString, RssFeed*> RssFolder::getAllFeedsAsHash() const {
QHash<QString, RssFeed*> ret;
QHash<QString, RssFeedPtr> RssFolder::getAllFeedsAsHash() const {
QHash<QString, RssFeedPtr> ret;
for (RssFileHash::ConstIterator it = m_children.begin(); it != m_children.end(); it++) {
if (it.value()->type() == IRssFile::FEED) {
RssFeed* feed = dynamic_cast<RssFeed*>(it.value());
Q_ASSERT(feed);
if (RssFeedPtr feed = qSharedPointerDynamicCast<RssFeed>(it.value())) {
qDebug() << Q_FUNC_INFO << feed->url();
ret[feed->url()] = feed;
} else {
ret.unite(static_cast<RssFolder*>(it.value())->getAllFeedsAsHash());
} else if (RssFolderPtr folder = qSharedPointerDynamicCast<RssFolder>(it.value())) {
ret.unite(folder->getAllFeedsAsHash());
}
}
return ret;
}
void RssFolder::addFile(IRssFile * item) {
if (item->type() == IRssFile::FEED) {
RssFeed* feedItem = dynamic_cast<RssFeed*>(item);
Q_ASSERT(!m_children.contains(feedItem->url()));
m_children[feedItem->url()] = item;
qDebug("Added feed %s to folder ./%s", qPrintable(feedItem->url()), qPrintable(m_name));
} else {
RssFolder* folderItem = dynamic_cast<RssFolder*>(item);
Q_ASSERT(!m_children.contains(folderItem->displayName()));
m_children[folderItem->displayName()] = item;
qDebug("Added folder %s to folder ./%s", qPrintable(folderItem->displayName()), qPrintable(m_name));
void RssFolder::addFile(const RssFilePtr& item) {
if (RssFeedPtr feed = qSharedPointerDynamicCast<RssFeed>(item)) {
Q_ASSERT(!m_children.contains(feed->url()));
m_children[feed->url()] = item;
qDebug("Added feed %s to folder ./%s", qPrintable(feed->url()), qPrintable(m_name));
} else if (RssFolderPtr folder = qSharedPointerDynamicCast<RssFolder>(item)) {
Q_ASSERT(!m_children.contains(folder->displayName()));
m_children[folder->displayName()] = item;
qDebug("Added folder %s to folder ./%s", qPrintable(folder->displayName()), qPrintable(m_name));
}
// Update parent
item->setParent(this);
}
void RssFolder::removeAllItems() {
qDeleteAll(m_children.values());
m_children.clear();
}
@ -207,11 +195,11 @@ bool RssFolder::hasChild(const QString &childId) { @@ -207,11 +195,11 @@ bool RssFolder::hasChild(const QString &childId) {
void RssFolder::renameChildFolder(const QString &old_name, const QString &new_name)
{
Q_ASSERT(m_children.contains(old_name));
IRssFile *folder = m_children.take(old_name);
RssFilePtr folder = m_children.take(old_name);
m_children[new_name] = folder;
}
IRssFile * RssFolder::takeChild(const QString &childId)
RssFilePtr RssFolder::takeChild(const QString &childId)
{
return m_children.take(childId);
}

31
src/rss/rssfolder.h

@ -32,15 +32,19 @@ @@ -32,15 +32,19 @@
#define RSSFOLDER_H
#include <QHash>
#include <QSharedPointer>
#include "rssfile.h"
class RssArticle;
class RssFolder;
class RssFeed;
class RssManager;
typedef QHash<QString, IRssFile*> RssFileHash;
typedef QHash<QString, RssFilePtr> RssFileHash;
typedef QSharedPointer<RssFeed> RssFeedPtr;
typedef QSharedPointer<RssFolder> RssFolderPtr;
typedef QList<RssFeedPtr> RssFeedList;
class RssFolder: public QObject, public IRssFile {
class RssFolder: public QObject, public RssFile {
Q_OBJECT
public:
@ -49,26 +53,25 @@ public: @@ -49,26 +53,25 @@ public:
inline RssFolder* parent() const { return m_parent; }
void setParent(RssFolder* parent) { m_parent = parent; }
unsigned int unreadCount() const;
FileType type() const;
RssFeed* addStream(const QString &url);
RssFolder* addFolder(const QString &name);
RssFeedPtr addStream(RssManager* manager, const QString &url);
RssFolderPtr addFolder(const QString &name);
unsigned int getNbFeeds() const;
QList<IRssFile*> getContent() const;
QList<RssFeed*> getAllFeeds() const;
QHash<QString, RssFeed*> getAllFeedsAsHash() const;
RssFileList getContent() const;
RssFeedList getAllFeeds() const;
QHash<QString, RssFeedPtr> getAllFeedsAsHash() const;
QString displayName() const;
QString id() const;
bool hasChild(const QString &childId);
const QList<RssArticlePtr> articleList() const;
const QList<RssArticlePtr> unreadArticleList() const;
const RssArticleList articleList() const;
const RssArticleList unreadArticleList() const;
void removeAllSettings();
void removeAllItems();
void renameChildFolder(const QString &old_name, const QString &new_name);
IRssFile *takeChild(const QString &childId);
RssFilePtr takeChild(const QString &childId);
public slots:
void refresh();
void addFile(IRssFile * item);
void addFile(const RssFilePtr& item);
void removeChild(const QString &childId);
void rename(const QString &new_name);
void markAsRead();

31
src/rss/rssmanager.cpp

@ -37,8 +37,6 @@ @@ -37,8 +37,6 @@
#include "rssdownloadrulelist.h"
#include "downloadthread.h"
RssManager* RssManager::m_instance = 0;
RssManager::RssManager(): m_rssDownloader(new DownloadThread(this)) {
connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
m_refreshInterval = RssSettings().getRSSRefreshInterval();
@ -78,14 +76,14 @@ void RssManager::loadStreamList() { @@ -78,14 +76,14 @@ void RssManager::loadStreamList() {
const QString feed_url = path.takeLast();
qDebug() << "Feed URL:" << feed_url;
// Create feed path (if it does not exists)
RssFolder * feed_parent = this;
RssFolder* feed_parent = this;
foreach(const QString &folder_name, path) {
qDebug() << "Adding parent folder:" << folder_name;
feed_parent = feed_parent->addFolder(folder_name);
feed_parent = feed_parent->addFolder(folder_name).data();
}
// Create feed
qDebug() << "Adding feed to parent folder";
RssFeed *stream = feed_parent->addStream(feed_url);
RssFeedPtr stream = feed_parent->addStream(this, feed_url);
const QString alias = aliases.at(i);
if(!alias.isEmpty()) {
stream->rename(alias);
@ -103,7 +101,7 @@ void RssManager::forwardFeedIconChanged(const QString &url, const QString &icon_ @@ -103,7 +101,7 @@ void RssManager::forwardFeedIconChanged(const QString &url, const QString &icon_
emit feedIconChanged(url, icon_path);
}
void RssManager::moveFile(IRssFile* file, RssFolder* dest_folder) {
void RssManager::moveFile(const RssFilePtr& file, const RssFolderPtr& dest_folder) {
RssFolder* src_folder = file->parent();
if(dest_folder != src_folder) {
// Remove reference in old folder
@ -118,8 +116,8 @@ void RssManager::moveFile(IRssFile* file, RssFolder* dest_folder) { @@ -118,8 +116,8 @@ void RssManager::moveFile(IRssFile* file, RssFolder* dest_folder) {
void RssManager::saveStreamList() const {
QStringList streamsUrl;
QStringList aliases;
const QList<RssFeed*> streams = getAllFeeds();
foreach(const RssFeed *stream, streams) {
QList<RssFeedPtr> streams = getAllFeeds();
foreach(const RssFeedPtr& stream, streams) {
QString stream_path = stream->pathHierarchy().join("\\");
if(stream_path.isNull()) {
stream_path = "";
@ -138,21 +136,6 @@ static bool laterItemDate(const RssArticlePtr& a, const RssArticlePtr& b) @@ -138,21 +136,6 @@ static bool laterItemDate(const RssArticlePtr& a, const RssArticlePtr& b)
return (a->date() > b->date());
}
void RssManager::sortNewsList(QList<RssArticlePtr>& news_list) {
void RssManager::sortNewsList(RssArticleList& news_list) {
qSort(news_list.begin(), news_list.end(), laterItemDate);
}
RssManager * RssManager::instance()
{
if(!m_instance)
m_instance = new RssManager;
return m_instance;
}
void RssManager::drop()
{
if(m_instance) {
delete m_instance;
m_instance = 0;
}
}

17
src/rss/rssmanager.h

@ -32,31 +32,32 @@ @@ -32,31 +32,32 @@
#define RSSMANAGER_H
#include <QTimer>
#include <QSharedPointer>
#include "rssfolder.h"
class DownloadThread;
class RssManager;
typedef QSharedPointer<RssManager> RssManagerPtr;
class RssManager: public RssFolder {
Q_OBJECT
private:
explicit RssManager();
static RssManager* m_instance;
public:
static RssManager* instance();
static void drop();
RssManager();
virtual ~RssManager();
inline DownloadThread* rssDownloader() const { return m_rssDownloader; }
static void insertSortElem(QList<RssArticlePtr> &list, const RssArticlePtr &item);
static void sortNewsList(QList<RssArticlePtr>& news_list);
static void insertSortElem(RssArticleList &list, const RssArticlePtr &item);
static void sortNewsList(RssArticleList& news_list);
public slots:
void loadStreamList();
void saveStreamList() const;
void forwardFeedInfosChanged(const QString &url, const QString &aliasOrUrl, uint nbUnread);
void forwardFeedIconChanged(const QString &url, const QString &icon_path);
void moveFile(IRssFile* file, RssFolder* dest_folder);
void moveFile(const RssFilePtr& file, const RssFolderPtr& dest_folder);
void updateRefreshInterval(uint val);
signals:

Loading…
Cancel
Save