mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-16 01:30:09 +00:00
204 lines
5.6 KiB
C++
204 lines
5.6 KiB
C++
/*
|
|
* 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
|
|
*/
|
|
|
|
#include <QDebug>
|
|
|
|
#include "rssfolder.h"
|
|
#include "rssarticle.h"
|
|
#include "qbtsession.h"
|
|
#include "downloadthread.h"
|
|
#include "rssmanager.h"
|
|
#include "rssfeed.h"
|
|
|
|
RssFolder::RssFolder(RssFolder *parent, QString name): m_parent(parent), m_name(name) {
|
|
}
|
|
|
|
RssFolder::~RssFolder() {
|
|
qDebug("Deleting a RSS folder, removing elements");
|
|
qDeleteAll(this->values());
|
|
}
|
|
|
|
unsigned int RssFolder::unreadCount() const {
|
|
unsigned int nb_unread = 0;
|
|
foreach(RssFile *file, this->values()) {
|
|
nb_unread += file->unreadCount();
|
|
}
|
|
return nb_unread;
|
|
}
|
|
|
|
RssFile::FileType RssFolder::type() const {
|
|
return RssFile::FOLDER;
|
|
}
|
|
|
|
void RssFolder::removeFile(QString ID) {
|
|
if(this->contains(ID)) {
|
|
RssFile* child = this->take(ID);
|
|
child->removeAllSettings();
|
|
delete child;
|
|
}
|
|
}
|
|
|
|
RssFolder* RssFolder::addFolder(QString name) {
|
|
RssFolder *subfolder;
|
|
if(!this->contains(name)) {
|
|
subfolder = new RssFolder(this, name);
|
|
(*this)[name] = subfolder;
|
|
} else {
|
|
subfolder = (RssFolder*)this->value(name);
|
|
}
|
|
return subfolder;
|
|
}
|
|
|
|
RssFeed* RssFolder::addStream(QString url) {
|
|
RssFeed* stream = new RssFeed(this, url);
|
|
Q_ASSERT(!this->contains(stream->url()));
|
|
(*this)[stream->url()] = stream;
|
|
stream->refresh();
|
|
return stream;
|
|
}
|
|
|
|
// Refresh All Children
|
|
void RssFolder::refresh() {
|
|
foreach(RssFile *child, this->values()) {
|
|
child->refresh();
|
|
}
|
|
}
|
|
|
|
QList<RssArticle> RssFolder::articleList() const {
|
|
QList<RssArticle> news;
|
|
foreach(const RssFile *child, this->values()) {
|
|
news << child->articleList();
|
|
}
|
|
return news;
|
|
}
|
|
|
|
QList<RssArticle> RssFolder::unreadArticleList() const {
|
|
QList<RssArticle> unread_news;
|
|
foreach(const RssFile *child, this->values()) {
|
|
unread_news << child->unreadArticleList();
|
|
}
|
|
return unread_news;
|
|
}
|
|
|
|
QList<RssFile*> RssFolder::getContent() const {
|
|
return this->values();
|
|
}
|
|
|
|
unsigned int RssFolder::getNbFeeds() const {
|
|
unsigned int nbFeeds = 0;
|
|
foreach(RssFile* item, this->values()) {
|
|
if(item->type() == RssFile::FOLDER)
|
|
nbFeeds += ((RssFolder*)item)->getNbFeeds();
|
|
else
|
|
nbFeeds += 1;
|
|
}
|
|
return nbFeeds;
|
|
}
|
|
|
|
QString RssFolder::displayName() const {
|
|
return m_name;
|
|
}
|
|
|
|
void RssFolder::setAlias(const QString &new_name) {
|
|
Q_ASSERT(!m_parent->contains(new_name));
|
|
if(!m_parent->contains(new_name)) {
|
|
// Update parent
|
|
(*m_parent)[new_name] = m_parent->take(m_name);
|
|
// Actually rename
|
|
m_name = new_name;
|
|
}
|
|
}
|
|
|
|
void RssFolder::markAsRead() {
|
|
foreach(RssFile *item, this->values()) {
|
|
item->markAsRead();
|
|
}
|
|
}
|
|
|
|
QList<RssFeed*> RssFolder::getAllFeeds() const {
|
|
QList<RssFeed*> streams;
|
|
foreach(RssFile *item, this->values()) {
|
|
if(item->type() == RssFile::FEED) {
|
|
streams << static_cast<RssFeed*>(item);
|
|
} else {
|
|
streams << static_cast<RssFolder*>(item)->getAllFeeds();
|
|
}
|
|
}
|
|
return streams;
|
|
}
|
|
|
|
QHash<QString, RssFeed*> RssFolder::getAllFeedsAsHash() const {
|
|
QHash<QString, RssFeed*> ret;
|
|
foreach(RssFile *item, this->values()) {
|
|
if(item->type() == RssFile::FEED) {
|
|
RssFeed* feed = dynamic_cast<RssFeed*>(item);
|
|
Q_ASSERT(feed);
|
|
qDebug() << Q_FUNC_INFO << feed->url();
|
|
ret[feed->url()] = feed;
|
|
} else {
|
|
ret.unite(static_cast<RssFolder*>(item)->getAllFeedsAsHash());
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void RssFolder::addFile(RssFile * item) {
|
|
if(item->type() == RssFile::FEED) {
|
|
Q_ASSERT(!this->contains(((RssFeed*)item)->url()));
|
|
(*this)[((RssFeed*)item)->url()] = item;
|
|
qDebug("Added feed %s to folder ./%s", ((RssFeed*)item)->url().toLocal8Bit().data(), m_name.toLocal8Bit().data());
|
|
} else {
|
|
Q_ASSERT(!this->contains(((RssFolder*)item)->displayName()));
|
|
(*this)[((RssFolder*)item)->displayName()] = item;
|
|
qDebug("Added folder %s to folder ./%s", ((RssFolder*)item)->displayName().toLocal8Bit().data(), m_name.toLocal8Bit().data());
|
|
}
|
|
// Update parent
|
|
item->setParent(this);
|
|
}
|
|
|
|
void RssFolder::removeAllItems() {
|
|
qDeleteAll(values());
|
|
clear();
|
|
}
|
|
|
|
void RssFolder::removeAllSettings() {
|
|
foreach(RssFile* child, values()) {
|
|
child->removeAllSettings();
|
|
}
|
|
}
|
|
|
|
QString RssFolder::id() const {
|
|
return m_name;
|
|
}
|
|
|
|
bool RssFolder::hasChild(QString ID) {
|
|
return this->contains(ID);
|
|
}
|