From 00b4ad6ec808341703a9714ec29222406a7c0bb5 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 20 Feb 2012 19:49:35 +0200 Subject: [PATCH] RSS: Remove last singleton --- src/rss/automatedrssdownloader.cpp | 2 +- src/rss/rssdownloadrulelist.cpp | 20 ++------------------ src/rss/rssdownloadrulelist.h | 7 +------ src/rss/rssfeed.cpp | 3 ++- src/rss/rssmanager.cpp | 17 ++++++++++++----- src/rss/rssmanager.h | 6 ++++-- 6 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/rss/automatedrssdownloader.cpp b/src/rss/automatedrssdownloader.cpp index c052ca4d5..a7bfaefd0 100644 --- a/src/rss/automatedrssdownloader.cpp +++ b/src/rss/automatedrssdownloader.cpp @@ -67,7 +67,7 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer& m Q_ASSERT(ok); ok = connect(ui->listRules, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRulesListMenu(const QPoint&))); Q_ASSERT(ok); - m_ruleList = RssDownloadRuleList::instance(); + m_ruleList = manager.toStrongRef()->downloadRules(); initLabelCombobox(); loadFeedList(); loadSettings(); diff --git a/src/rss/rssdownloadrulelist.cpp b/src/rss/rssdownloadrulelist.cpp index a92181413..4b0c24d5e 100644 --- a/src/rss/rssdownloadrulelist.cpp +++ b/src/rss/rssdownloadrulelist.cpp @@ -36,25 +36,9 @@ #include "rsssettings.h" #include "qinisettings.h" -RssDownloadRuleList* RssDownloadRuleList::m_instance = 0; - -RssDownloadRuleList::RssDownloadRuleList(){ - loadRulesFromStorage(); -} - -RssDownloadRuleList* RssDownloadRuleList::instance() +RssDownloadRuleList::RssDownloadRuleList() { - if (!m_instance) - m_instance = new RssDownloadRuleList; - return m_instance; -} - -void RssDownloadRuleList::drop() -{ - if (m_instance) { - delete m_instance; - m_instance = 0; - } + loadRulesFromStorage(); } RssDownloadRulePtr RssDownloadRuleList::findMatchingRule(const QString &feed_url, const QString &article_title) const diff --git a/src/rss/rssdownloadrulelist.h b/src/rss/rssdownloadrulelist.h index eea3e9af6..21df2b6e8 100644 --- a/src/rss/rssdownloadrulelist.h +++ b/src/rss/rssdownloadrulelist.h @@ -42,13 +42,8 @@ class RssDownloadRuleList { Q_DISABLE_COPY(RssDownloadRuleList) -private: - explicit RssDownloadRuleList(); - static RssDownloadRuleList* m_instance; - public: - static RssDownloadRuleList* instance(); - static void drop(); + RssDownloadRuleList(); RssDownloadRulePtr findMatchingRule(const QString &feed_url, const QString &article_title) const; // Operators void saveRule(const RssDownloadRulePtr &rule); diff --git a/src/rss/rssfeed.cpp b/src/rss/rssfeed.cpp index f492e47c2..0fa5e4e95 100644 --- a/src/rss/rssfeed.cpp +++ b/src/rss/rssfeed.cpp @@ -293,6 +293,7 @@ bool RssFeed::parseRSS(QIODevice* device) { void RssFeed::downloadMatchingArticleTorrents() { Q_ASSERT(RssSettings().isRssDownloadingEnabled()); + RssDownloadRuleList *download_rules = m_manager->downloadRules(); for (RssArticleHash::ConstIterator it = m_articles.begin(); it != m_articles.end(); it++) { RssArticlePtr item = it.value(); if (item->isRead()) continue; @@ -302,7 +303,7 @@ void RssFeed::downloadMatchingArticleTorrents() { else torrent_url = item->link(); // Check if the item should be automatically downloaded - RssDownloadRulePtr matching_rule = RssDownloadRuleList::instance()->findMatchingRule(m_url, item->title()); + RssDownloadRulePtr matching_rule = download_rules->findMatchingRule(m_url, item->title()); if (matching_rule) { // Item was downloaded, consider it as Read item->markAsRead(); diff --git a/src/rss/rssmanager.cpp b/src/rss/rssmanager.cpp index b78c64ebb..0816f8220 100644 --- a/src/rss/rssmanager.cpp +++ b/src/rss/rssmanager.cpp @@ -37,17 +37,18 @@ #include "rssdownloadrulelist.h" #include "downloadthread.h" -RssManager::RssManager(): m_rssDownloader(new DownloadThread(this)) { +RssManager::RssManager(): + m_rssDownloader(new DownloadThread(this)), m_downloadRules(new RssDownloadRuleList) +{ connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); m_refreshInterval = RssSettings().getRSSRefreshInterval(); m_refreshTimer.start(m_refreshInterval*60000); } RssManager::~RssManager(){ - qDebug("Deleting RSSManager"); - m_refreshTimer.stop(); + qDebug("Deleting RSSManager..."); delete m_rssDownloader; - RssDownloadRuleList::drop(); + delete m_downloadRules; saveItemsToDisk(); saveStreamList(); qDebug("RSSManager deleted"); @@ -117,7 +118,7 @@ void RssManager::moveFile(const RssFilePtr& file, const RssFolderPtr& dest_folde void RssManager::saveStreamList() const { QStringList streamsUrl; QStringList aliases; - QList streams = getAllFeeds(); + RssFeedList streams = getAllFeeds(); foreach (const RssFeedPtr& stream, streams) { QString stream_path = stream->pathHierarchy().join("\\"); if (stream_path.isNull()) { @@ -140,3 +141,9 @@ static bool laterItemDate(const RssArticlePtr& a, const RssArticlePtr& b) void RssManager::sortNewsList(RssArticleList& news_list) { qSort(news_list.begin(), news_list.end(), laterItemDate); } + +RssDownloadRuleList *RssManager::downloadRules() const +{ + Q_ASSERT(m_downloadRules); + return m_downloadRules; +} diff --git a/src/rss/rssmanager.h b/src/rss/rssmanager.h index d39ef107f..c296dd7ab 100644 --- a/src/rss/rssmanager.h +++ b/src/rss/rssmanager.h @@ -37,6 +37,7 @@ #include "rssfolder.h" class DownloadThread; +class RssDownloadRuleList; class RssManager; typedef QSharedPointer RssManagerPtr; @@ -49,9 +50,10 @@ public: virtual ~RssManager(); inline DownloadThread* rssDownloader() const { return m_rssDownloader; } - static void insertSortElem(RssArticleList &list, const RssArticlePtr &item); static void sortNewsList(RssArticleList& news_list); + RssDownloadRuleList* downloadRules() const; + public slots: void loadStreamList(); void saveStreamList() const; @@ -68,7 +70,7 @@ private: QTimer m_refreshTimer; uint m_refreshInterval; DownloadThread *m_rssDownloader; - + RssDownloadRuleList *m_downloadRules; }; #endif // RSSMANAGER_H