2010-10-16 17:39:03 +00:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
|
|
|
* Copyright (C) 2010 Christophe Dumez, Arnaud Demaiziere
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*
|
|
|
|
* Contact: chris@qbittorrent.org, arnaud@qbittorrent.org
|
|
|
|
*/
|
|
|
|
|
2011-01-29 11:57:52 +00:00
|
|
|
#include <QDebug>
|
2010-10-16 17:39:03 +00:00
|
|
|
#include "rssmanager.h"
|
2010-10-31 12:35:07 +00:00
|
|
|
#include "rsssettings.h"
|
2010-10-16 17:39:03 +00:00
|
|
|
#include "qbtsession.h"
|
|
|
|
#include "rssfeed.h"
|
|
|
|
#include "rssarticle.h"
|
2010-11-13 10:49:22 +00:00
|
|
|
#include "rssdownloadrulelist.h"
|
2011-01-27 17:18:56 +00:00
|
|
|
#include "downloadthread.h"
|
2010-10-16 17:39:03 +00:00
|
|
|
|
2010-11-13 19:36:46 +00:00
|
|
|
RssManager* RssManager::m_instance = 0;
|
|
|
|
|
2012-02-19 15:42:51 +02:00
|
|
|
RssManager::RssManager(): m_rssDownloader(new DownloadThread(this)) {
|
2011-01-27 19:28:05 +00:00
|
|
|
connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
|
|
|
|
m_refreshInterval = RssSettings().getRSSRefreshInterval();
|
|
|
|
m_refreshTimer.start(m_refreshInterval*60000);
|
2010-10-16 17:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RssManager::~RssManager(){
|
|
|
|
qDebug("Deleting RSSManager");
|
2011-09-26 20:09:24 +03:00
|
|
|
m_refreshTimer.stop();
|
2011-01-27 17:18:56 +00:00
|
|
|
delete m_rssDownloader;
|
2010-11-13 10:49:22 +00:00
|
|
|
RssDownloadRuleList::drop();
|
2010-10-16 17:39:03 +00:00
|
|
|
saveStreamList();
|
|
|
|
qDebug("RSSManager deleted");
|
|
|
|
}
|
|
|
|
|
2011-01-27 19:28:05 +00:00
|
|
|
void RssManager::updateRefreshInterval(uint val){
|
|
|
|
if(m_refreshInterval != val) {
|
|
|
|
m_refreshInterval = val;
|
|
|
|
m_refreshTimer.start(m_refreshInterval*60000);
|
|
|
|
qDebug("New RSS refresh interval is now every %dmin", m_refreshInterval);
|
2010-10-16 17:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-13 10:49:22 +00:00
|
|
|
void RssManager::loadStreamList() {
|
2010-11-17 20:21:03 +00:00
|
|
|
RssSettings settings;
|
|
|
|
const QStringList streamsUrl = settings.getRssFeedsUrls();
|
|
|
|
const QStringList aliases = settings.getRssFeedsAliases();
|
2010-10-16 17:39:03 +00:00
|
|
|
if(streamsUrl.size() != aliases.size()){
|
|
|
|
std::cerr << "Corrupted Rss list, not loading it\n";
|
|
|
|
return;
|
|
|
|
}
|
2011-01-27 17:18:56 +00:00
|
|
|
uint i = 0;
|
|
|
|
qDebug() << Q_FUNC_INFO << streamsUrl;
|
2010-10-16 17:39:03 +00:00
|
|
|
foreach(QString s, streamsUrl){
|
2011-01-27 17:18:56 +00:00
|
|
|
QStringList path = s.split("\\", QString::SkipEmptyParts);
|
2010-10-16 17:39:03 +00:00
|
|
|
if(path.empty()) continue;
|
2011-01-27 17:18:56 +00:00
|
|
|
const QString feed_url = path.takeLast();
|
|
|
|
qDebug() << "Feed URL:" << feed_url;
|
2010-10-16 17:39:03 +00:00
|
|
|
// Create feed path (if it does not exists)
|
|
|
|
RssFolder * feed_parent = this;
|
2011-01-27 17:18:56 +00:00
|
|
|
foreach(const QString &folder_name, path) {
|
|
|
|
qDebug() << "Adding parent folder:" << folder_name;
|
2010-10-16 17:39:03 +00:00
|
|
|
feed_parent = feed_parent->addFolder(folder_name);
|
|
|
|
}
|
|
|
|
// Create feed
|
2011-01-27 17:18:56 +00:00
|
|
|
qDebug() << "Adding feed to parent folder";
|
2010-10-16 17:39:03 +00:00
|
|
|
RssFeed *stream = feed_parent->addStream(feed_url);
|
2011-01-27 17:18:56 +00:00
|
|
|
const QString alias = aliases.at(i);
|
2010-10-16 17:39:03 +00:00
|
|
|
if(!alias.isEmpty()) {
|
2011-01-27 18:03:28 +00:00
|
|
|
stream->rename(alias);
|
2010-10-16 17:39:03 +00:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
qDebug("NB RSS streams loaded: %d", streamsUrl.size());
|
|
|
|
}
|
|
|
|
|
2011-01-27 19:28:05 +00:00
|
|
|
void RssManager::forwardFeedInfosChanged(const QString &url, const QString &display_name, uint nbUnread) {
|
|
|
|
emit feedInfosChanged(url, display_name, nbUnread);
|
2010-10-16 17:39:03 +00:00
|
|
|
}
|
|
|
|
|
2011-01-27 19:28:05 +00:00
|
|
|
void RssManager::forwardFeedIconChanged(const QString &url, const QString &icon_path) {
|
2010-10-16 17:39:03 +00:00
|
|
|
emit feedIconChanged(url, icon_path);
|
|
|
|
}
|
|
|
|
|
2011-01-29 13:44:56 +00:00
|
|
|
void RssManager::moveFile(IRssFile* file, RssFolder* dest_folder) {
|
2011-01-27 17:18:56 +00:00
|
|
|
RssFolder* src_folder = file->parent();
|
2010-10-16 17:39:03 +00:00
|
|
|
if(dest_folder != src_folder) {
|
|
|
|
// Remove reference in old folder
|
2011-01-27 18:03:28 +00:00
|
|
|
src_folder->takeChild(file->id());
|
|
|
|
// add to new Folder
|
|
|
|
dest_folder->addFile(file);
|
2010-10-16 17:39:03 +00:00
|
|
|
} else {
|
|
|
|
qDebug("Nothing to move, same destination folder");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-27 19:28:05 +00:00
|
|
|
void RssManager::saveStreamList() const {
|
2010-10-16 17:39:03 +00:00
|
|
|
QStringList streamsUrl;
|
|
|
|
QStringList aliases;
|
|
|
|
const QList<RssFeed*> streams = getAllFeeds();
|
|
|
|
foreach(const RssFeed *stream, streams) {
|
2011-01-27 17:18:56 +00:00
|
|
|
QString stream_path = stream->pathHierarchy().join("\\");
|
2010-10-16 17:39:03 +00:00
|
|
|
if(stream_path.isNull()) {
|
|
|
|
stream_path = "";
|
|
|
|
}
|
|
|
|
qDebug("Saving stream path: %s", qPrintable(stream_path));
|
|
|
|
streamsUrl << stream_path;
|
2011-01-27 17:18:56 +00:00
|
|
|
aliases << stream->displayName();
|
2010-10-16 17:39:03 +00:00
|
|
|
}
|
2010-11-17 20:21:03 +00:00
|
|
|
RssSettings settings;
|
|
|
|
settings.setRssFeedsUrls(streamsUrl);
|
|
|
|
settings.setRssFeedsAliases(aliases);
|
2010-10-16 17:39:03 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 15:18:59 +02:00
|
|
|
static bool laterItemDate(const RssArticle& a, const RssArticle& b)
|
2012-02-19 15:13:39 +02:00
|
|
|
{
|
2012-02-19 15:18:59 +02:00
|
|
|
return (a.date() > b.date());
|
2010-10-16 17:39:03 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 15:13:39 +02:00
|
|
|
void RssManager::sortNewsList(QList<RssArticle>& news_list) {
|
2012-02-19 15:18:59 +02:00
|
|
|
qSort(news_list.begin(), news_list.end(), laterItemDate);
|
2010-10-16 17:39:03 +00:00
|
|
|
}
|
2010-11-13 19:36:46 +00:00
|
|
|
|
|
|
|
RssManager * RssManager::instance()
|
|
|
|
{
|
|
|
|
if(!m_instance)
|
|
|
|
m_instance = new RssManager;
|
|
|
|
return m_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RssManager::drop()
|
|
|
|
{
|
2010-11-13 20:14:59 +00:00
|
|
|
if(m_instance) {
|
2010-11-13 19:36:46 +00:00
|
|
|
delete m_instance;
|
2010-11-13 20:14:59 +00:00
|
|
|
m_instance = 0;
|
|
|
|
}
|
2010-11-13 19:36:46 +00:00
|
|
|
}
|