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 @@ -67,7 +67,7 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<RssManager>& 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();

20
src/rss/rssdownloadrulelist.cpp

@ -36,25 +36,9 @@ @@ -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

7
src/rss/rssdownloadrulelist.h

@ -42,13 +42,8 @@ class RssDownloadRuleList @@ -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);

3
src/rss/rssfeed.cpp

@ -293,6 +293,7 @@ bool RssFeed::parseRSS(QIODevice* device) { @@ -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() { @@ -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();

17
src/rss/rssmanager.cpp

@ -37,17 +37,18 @@ @@ -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 @@ -117,7 +118,7 @@ void RssManager::moveFile(const RssFilePtr& file, const RssFolderPtr& dest_folde
void RssManager::saveStreamList() const {
QStringList streamsUrl;
QStringList aliases;
QList<RssFeedPtr> 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) @@ -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;
}

6
src/rss/rssmanager.h

@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
#include "rssfolder.h"
class DownloadThread;
class RssDownloadRuleList;
class RssManager;
typedef QSharedPointer<RssManager> RssManagerPtr;
@ -49,9 +50,10 @@ public: @@ -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: @@ -68,7 +70,7 @@ private:
QTimer m_refreshTimer;
uint m_refreshInterval;
DownloadThread *m_rssDownloader;
RssDownloadRuleList *m_downloadRules;
};
#endif // RSSMANAGER_H

Loading…
Cancel
Save