1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-02-04 19:04:30 +00:00

RSS: Remove last singleton

This commit is contained in:
Christophe Dumez 2012-02-20 19:49:35 +02:00
parent a8a7b61ea9
commit 00b4ad6ec8
6 changed files with 22 additions and 33 deletions

View File

@ -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();

View File

@ -36,27 +36,11 @@
#include "rsssettings.h"
#include "qinisettings.h"
RssDownloadRuleList* RssDownloadRuleList::m_instance = 0;
RssDownloadRuleList::RssDownloadRuleList(){
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;
m_instance = 0;
}
}
RssDownloadRulePtr RssDownloadRuleList::findMatchingRule(const QString &feed_url, const QString &article_title) const
{
Q_ASSERT(RssSettings().isRssDownloadingEnabled());

View File

@ -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);

View File

@ -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();

View File

@ -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<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)
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;
}

View File

@ -37,6 +37,7 @@
#include "rssfolder.h"
class DownloadThread;
class RssDownloadRuleList;
class RssManager;
typedef QSharedPointer<RssManager> 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