Browse Source

RSS: Remove last singleton

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
00b4ad6ec8
  1. 2
      src/rss/automatedrssdownloader.cpp
  2. 20
      src/rss/rssdownloadrulelist.cpp
  3. 7
      src/rss/rssdownloadrulelist.h
  4. 3
      src/rss/rssfeed.cpp
  5. 17
      src/rss/rssmanager.cpp
  6. 6
      src/rss/rssmanager.h

2
src/rss/automatedrssdownloader.cpp

@ -67,7 +67,7 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<RssManager>& m
Q_ASSERT(ok); Q_ASSERT(ok);
ok = connect(ui->listRules, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRulesListMenu(const QPoint&))); ok = connect(ui->listRules, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRulesListMenu(const QPoint&)));
Q_ASSERT(ok); Q_ASSERT(ok);
m_ruleList = RssDownloadRuleList::instance(); m_ruleList = manager.toStrongRef()->downloadRules();
initLabelCombobox(); initLabelCombobox();
loadFeedList(); loadFeedList();
loadSettings(); loadSettings();

20
src/rss/rssdownloadrulelist.cpp

@ -36,25 +36,9 @@
#include "rsssettings.h" #include "rsssettings.h"
#include "qinisettings.h" #include "qinisettings.h"
RssDownloadRuleList* RssDownloadRuleList::m_instance = 0; RssDownloadRuleList::RssDownloadRuleList()
RssDownloadRuleList::RssDownloadRuleList(){
loadRulesFromStorage();
}
RssDownloadRuleList* RssDownloadRuleList::instance()
{ {
if (!m_instance) loadRulesFromStorage();
m_instance = new RssDownloadRuleList;
return m_instance;
}
void RssDownloadRuleList::drop()
{
if (m_instance) {
delete m_instance;
m_instance = 0;
}
} }
RssDownloadRulePtr RssDownloadRuleList::findMatchingRule(const QString &feed_url, const QString &article_title) const RssDownloadRulePtr RssDownloadRuleList::findMatchingRule(const QString &feed_url, const QString &article_title) const

7
src/rss/rssdownloadrulelist.h

@ -42,13 +42,8 @@ class RssDownloadRuleList
{ {
Q_DISABLE_COPY(RssDownloadRuleList) Q_DISABLE_COPY(RssDownloadRuleList)
private:
explicit RssDownloadRuleList();
static RssDownloadRuleList* m_instance;
public: public:
static RssDownloadRuleList* instance(); RssDownloadRuleList();
static void drop();
RssDownloadRulePtr findMatchingRule(const QString &feed_url, const QString &article_title) const; RssDownloadRulePtr findMatchingRule(const QString &feed_url, const QString &article_title) const;
// Operators // Operators
void saveRule(const RssDownloadRulePtr &rule); void saveRule(const RssDownloadRulePtr &rule);

3
src/rss/rssfeed.cpp

@ -293,6 +293,7 @@ bool RssFeed::parseRSS(QIODevice* device) {
void RssFeed::downloadMatchingArticleTorrents() { void RssFeed::downloadMatchingArticleTorrents() {
Q_ASSERT(RssSettings().isRssDownloadingEnabled()); Q_ASSERT(RssSettings().isRssDownloadingEnabled());
RssDownloadRuleList *download_rules = m_manager->downloadRules();
for (RssArticleHash::ConstIterator it = m_articles.begin(); it != m_articles.end(); it++) { for (RssArticleHash::ConstIterator it = m_articles.begin(); it != m_articles.end(); it++) {
RssArticlePtr item = it.value(); RssArticlePtr item = it.value();
if (item->isRead()) continue; if (item->isRead()) continue;
@ -302,7 +303,7 @@ void RssFeed::downloadMatchingArticleTorrents() {
else else
torrent_url = item->link(); torrent_url = item->link();
// Check if the item should be automatically downloaded // 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) { if (matching_rule) {
// Item was downloaded, consider it as Read // Item was downloaded, consider it as Read
item->markAsRead(); item->markAsRead();

17
src/rss/rssmanager.cpp

@ -37,17 +37,18 @@
#include "rssdownloadrulelist.h" #include "rssdownloadrulelist.h"
#include "downloadthread.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())); connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
m_refreshInterval = RssSettings().getRSSRefreshInterval(); m_refreshInterval = RssSettings().getRSSRefreshInterval();
m_refreshTimer.start(m_refreshInterval*60000); m_refreshTimer.start(m_refreshInterval*60000);
} }
RssManager::~RssManager(){ RssManager::~RssManager(){
qDebug("Deleting RSSManager"); qDebug("Deleting RSSManager...");
m_refreshTimer.stop();
delete m_rssDownloader; delete m_rssDownloader;
RssDownloadRuleList::drop(); delete m_downloadRules;
saveItemsToDisk(); saveItemsToDisk();
saveStreamList(); saveStreamList();
qDebug("RSSManager deleted"); qDebug("RSSManager deleted");
@ -117,7 +118,7 @@ void RssManager::moveFile(const RssFilePtr& file, const RssFolderPtr& dest_folde
void RssManager::saveStreamList() const { void RssManager::saveStreamList() const {
QStringList streamsUrl; QStringList streamsUrl;
QStringList aliases; QStringList aliases;
QList<RssFeedPtr> streams = getAllFeeds(); RssFeedList streams = getAllFeeds();
foreach (const RssFeedPtr& stream, streams) { foreach (const RssFeedPtr& stream, streams) {
QString stream_path = stream->pathHierarchy().join("\\"); QString stream_path = stream->pathHierarchy().join("\\");
if (stream_path.isNull()) { if (stream_path.isNull()) {
@ -140,3 +141,9 @@ static bool laterItemDate(const RssArticlePtr& a, const RssArticlePtr& b)
void RssManager::sortNewsList(RssArticleList& news_list) { void RssManager::sortNewsList(RssArticleList& news_list) {
qSort(news_list.begin(), news_list.end(), laterItemDate); qSort(news_list.begin(), news_list.end(), laterItemDate);
} }
RssDownloadRuleList *RssManager::downloadRules() const
{
Q_ASSERT(m_downloadRules);
return m_downloadRules;
}

6
src/rss/rssmanager.h

@ -37,6 +37,7 @@
#include "rssfolder.h" #include "rssfolder.h"
class DownloadThread; class DownloadThread;
class RssDownloadRuleList;
class RssManager; class RssManager;
typedef QSharedPointer<RssManager> RssManagerPtr; typedef QSharedPointer<RssManager> RssManagerPtr;
@ -49,9 +50,10 @@ public:
virtual ~RssManager(); virtual ~RssManager();
inline DownloadThread* rssDownloader() const { return m_rssDownloader; } inline DownloadThread* rssDownloader() const { return m_rssDownloader; }
static void insertSortElem(RssArticleList &list, const RssArticlePtr &item);
static void sortNewsList(RssArticleList& news_list); static void sortNewsList(RssArticleList& news_list);
RssDownloadRuleList* downloadRules() const;
public slots: public slots:
void loadStreamList(); void loadStreamList();
void saveStreamList() const; void saveStreamList() const;
@ -68,7 +70,7 @@ private:
QTimer m_refreshTimer; QTimer m_refreshTimer;
uint m_refreshInterval; uint m_refreshInterval;
DownloadThread *m_rssDownloader; DownloadThread *m_rssDownloader;
RssDownloadRuleList *m_downloadRules;
}; };
#endif // RSSMANAGER_H #endif // RSSMANAGER_H

Loading…
Cancel
Save