mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 20:44:15 +00:00
RSS: News title is no longer used as identifier (use guid or url instead)
This commit is contained in:
parent
2f7728f987
commit
54b53f3aba
12
src/rss.cpp
12
src/rss.cpp
@ -392,7 +392,7 @@ RssStream::RssStream(RssFolder* parent, RssManager *rssmanager, Bittorrent *BTSe
|
|||||||
QHash<QString, QVariant> item = var_it.toHash();
|
QHash<QString, QVariant> item = var_it.toHash();
|
||||||
RssItem *rss_item = RssItem::fromHash(this, item);
|
RssItem *rss_item = RssItem::fromHash(this, item);
|
||||||
if(rss_item->isValid()) {
|
if(rss_item->isValid()) {
|
||||||
(*this)[rss_item->getTitle()] = rss_item;
|
(*this)[rss_item->getId()] = rss_item;
|
||||||
} else {
|
} else {
|
||||||
delete rss_item;
|
delete rss_item;
|
||||||
}
|
}
|
||||||
@ -518,8 +518,8 @@ void RssStream::setIconPath(QString path) {
|
|||||||
iconPath = path;
|
iconPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
RssItem* RssStream::getItem(QString name) const{
|
RssItem* RssStream::getItem(QString id) const{
|
||||||
return this->value(name);
|
return this->value(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int RssStream::getNbNews() const{
|
unsigned int RssStream::getNbNews() const{
|
||||||
@ -619,8 +619,8 @@ short RssStream::readDoc(QIODevice* device) {
|
|||||||
}
|
}
|
||||||
else if(xml.name() == "item") {
|
else if(xml.name() == "item") {
|
||||||
RssItem * item = new RssItem(this, xml);
|
RssItem * item = new RssItem(this, xml);
|
||||||
if(item->isValid() && !itemAlreadyExists(item->getTitle())) {
|
if(item->isValid() && !itemAlreadyExists(item->getId())) {
|
||||||
this->insert(item->getTitle(), item);
|
this->insert(item->getId(), item);
|
||||||
} else {
|
} else {
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
@ -673,7 +673,7 @@ void RssStream::resizeList() {
|
|||||||
int excess = nb_articles - max_articles;
|
int excess = nb_articles - max_articles;
|
||||||
for(int i=0; i<excess; ++i){
|
for(int i=0; i<excess; ++i){
|
||||||
RssItem *lastItem = listItem.takeLast();
|
RssItem *lastItem = listItem.takeLast();
|
||||||
delete this->take(lastItem->getTitle());
|
delete this->take(lastItem->getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
src/rss.h
25
src/rss.h
@ -122,6 +122,7 @@ class RssItem: public QObject {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
RssStream* parent;
|
RssStream* parent;
|
||||||
|
QString id;
|
||||||
QString title;
|
QString title;
|
||||||
QString torrent_url;
|
QString torrent_url;
|
||||||
QString news_link;
|
QString news_link;
|
||||||
@ -281,10 +282,6 @@ public:
|
|||||||
if(xml.isStartElement()) {
|
if(xml.isStartElement()) {
|
||||||
if(xml.name() == "title") {
|
if(xml.name() == "title") {
|
||||||
title = xml.readElementText();
|
title = xml.readElementText();
|
||||||
if(title.isEmpty()) {
|
|
||||||
is_valid = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(xml.name() == "enclosure") {
|
else if(xml.name() == "enclosure") {
|
||||||
if(xml.attributes().value("type") == "application/x-bittorrent") {
|
if(xml.attributes().value("type") == "application/x-bittorrent") {
|
||||||
@ -293,6 +290,8 @@ public:
|
|||||||
}
|
}
|
||||||
else if(xml.name() == "link") {
|
else if(xml.name() == "link") {
|
||||||
news_link = xml.readElementText();
|
news_link = xml.readElementText();
|
||||||
|
if(id.isEmpty())
|
||||||
|
id = news_link;
|
||||||
}
|
}
|
||||||
else if(xml.name() == "description") {
|
else if(xml.name() == "description") {
|
||||||
description = xml.readElementText();
|
description = xml.readElementText();
|
||||||
@ -303,15 +302,20 @@ public:
|
|||||||
else if(xml.name() == "author") {
|
else if(xml.name() == "author") {
|
||||||
author = xml.readElementText();
|
author = xml.readElementText();
|
||||||
}
|
}
|
||||||
|
else if(xml.name() == "guid") {
|
||||||
|
id = xml.readElementText();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!title.isEmpty())
|
if(!id.isEmpty())
|
||||||
is_valid = true;
|
is_valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RssItem(RssStream* parent, QString _title, QString _torrent_url, QString _news_link, QString _description, QDateTime _date, QString _author, bool _read):
|
RssItem(RssStream* parent, QString _id, QString _title, QString _torrent_url, QString _news_link, QString _description, QDateTime _date, QString _author, bool _read):
|
||||||
parent(parent), title(_title), torrent_url(_torrent_url), news_link(_news_link), description(_description), date(_date), author(_author), read(_read){
|
parent(parent), id(_id), title(_title), torrent_url(_torrent_url), news_link(_news_link), description(_description), date(_date), author(_author), read(_read){
|
||||||
if(!title.isEmpty()) {
|
if(id.isEmpty())
|
||||||
|
id = news_link;
|
||||||
|
if(!id.isEmpty()) {
|
||||||
is_valid = true;
|
is_valid = true;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "ERROR: an invalid RSS item was saved" << std::endl;
|
std::cerr << "ERROR: an invalid RSS item was saved" << std::endl;
|
||||||
@ -326,9 +330,12 @@ public:
|
|||||||
return !torrent_url.isEmpty();
|
return !torrent_url.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getId() const { return id; }
|
||||||
|
|
||||||
QHash<QString, QVariant> toHash() const {
|
QHash<QString, QVariant> toHash() const {
|
||||||
QHash<QString, QVariant> item;
|
QHash<QString, QVariant> item;
|
||||||
item["title"] = title;
|
item["title"] = title;
|
||||||
|
item["id"] = id;
|
||||||
item["torrent_url"] = torrent_url;
|
item["torrent_url"] = torrent_url;
|
||||||
item["news_link"] = news_link;
|
item["news_link"] = news_link;
|
||||||
item["description"] = description;
|
item["description"] = description;
|
||||||
@ -339,7 +346,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static RssItem* fromHash(RssStream* parent, QHash<QString, QVariant> h) {
|
static RssItem* fromHash(RssStream* parent, QHash<QString, QVariant> h) {
|
||||||
return new RssItem(parent, h["title"].toString(), h["torrent_url"].toString(), h["news_link"].toString(),
|
return new RssItem(parent, h.value("id", "").toString(), h["title"].toString(), h["torrent_url"].toString(), h["news_link"].toString(),
|
||||||
h["description"].toString(), h["date"].toDateTime(), h["author"].toString(), h["read"].toBool());
|
h["description"].toString(), h["date"].toDateTime(), h["author"].toString(), h["read"].toBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +42,7 @@
|
|||||||
#include "feedList.h"
|
#include "feedList.h"
|
||||||
#include "bittorrent.h"
|
#include "bittorrent.h"
|
||||||
|
|
||||||
#define NEWS_TITLE_COL 1
|
enum NewsCols { NEWS_ICON, NEWS_TITLE_COL, NEWS_URL_COL, NEWS_ID };
|
||||||
#define NEWS_URL_COL 2
|
|
||||||
|
|
||||||
// display a right-click menu
|
// display a right-click menu
|
||||||
void RSSImp::displayRSSListMenu(const QPoint& pos){
|
void RSSImp::displayRSSListMenu(const QPoint& pos){
|
||||||
@ -92,7 +91,7 @@ void RSSImp::displayItemsListMenu(const QPoint&){
|
|||||||
foreach(QTreeWidgetItem *item, selectedItems) {
|
foreach(QTreeWidgetItem *item, selectedItems) {
|
||||||
qDebug("text(3) URL: %s", qPrintable(item->text(NEWS_URL_COL)));
|
qDebug("text(3) URL: %s", qPrintable(item->text(NEWS_URL_COL)));
|
||||||
qDebug("text(2) TITLE: %s", qPrintable(item->text(NEWS_TITLE_COL)));
|
qDebug("text(2) TITLE: %s", qPrintable(item->text(NEWS_TITLE_COL)));
|
||||||
if(listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_TITLE_COL))->has_attachment()) {
|
if(listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID))->has_attachment()) {
|
||||||
has_attachment = true;
|
has_attachment = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -287,7 +286,7 @@ void RSSImp::on_updateAllButton_clicked() {
|
|||||||
void RSSImp::downloadTorrent() {
|
void RSSImp::downloadTorrent() {
|
||||||
QList<QTreeWidgetItem *> selected_items = listNews->selectedItems();
|
QList<QTreeWidgetItem *> selected_items = listNews->selectedItems();
|
||||||
foreach(const QTreeWidgetItem* item, selected_items) {
|
foreach(const QTreeWidgetItem* item, selected_items) {
|
||||||
RssItem* article = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_TITLE_COL));
|
RssItem* article = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID));
|
||||||
if(article->has_attachment()) {
|
if(article->has_attachment()) {
|
||||||
BTSession->downloadFromUrl(article->getTorrentUrl());
|
BTSession->downloadFromUrl(article->getTorrentUrl());
|
||||||
} else {
|
} else {
|
||||||
@ -300,7 +299,7 @@ void RSSImp::downloadTorrent() {
|
|||||||
void RSSImp::openNewsUrl() {
|
void RSSImp::openNewsUrl() {
|
||||||
QList<QTreeWidgetItem *> selected_items = listNews->selectedItems();
|
QList<QTreeWidgetItem *> selected_items = listNews->selectedItems();
|
||||||
foreach(const QTreeWidgetItem* item, selected_items) {
|
foreach(const QTreeWidgetItem* item, selected_items) {
|
||||||
RssItem* news = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_TITLE_COL));
|
RssItem* news = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID));
|
||||||
QString link = news->getLink();
|
QString link = news->getLink();
|
||||||
if(!link.isEmpty())
|
if(!link.isEmpty())
|
||||||
QDesktopServices::openUrl(QUrl(link));
|
QDesktopServices::openUrl(QUrl(link));
|
||||||
@ -444,12 +443,13 @@ void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
|
|||||||
QTreeWidgetItem* it = new QTreeWidgetItem(listNews);
|
QTreeWidgetItem* it = new QTreeWidgetItem(listNews);
|
||||||
it->setText(NEWS_TITLE_COL, article->getTitle());
|
it->setText(NEWS_TITLE_COL, article->getTitle());
|
||||||
it->setText(NEWS_URL_COL, article->getParent()->getUrl());
|
it->setText(NEWS_URL_COL, article->getParent()->getUrl());
|
||||||
|
it->setText(NEWS_ID, article->getId());
|
||||||
if(article->isRead()){
|
if(article->isRead()){
|
||||||
it->setData(NEWS_TITLE_COL, Qt::ForegroundRole, QVariant(QColor("grey")));
|
it->setData(NEWS_TITLE_COL, Qt::ForegroundRole, QVariant(QColor("grey")));
|
||||||
it->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
|
it->setData(NEWS_ICON, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
|
||||||
}else{
|
}else{
|
||||||
it->setData(NEWS_TITLE_COL, Qt::ForegroundRole, QVariant(QColor("blue")));
|
it->setData(NEWS_TITLE_COL, Qt::ForegroundRole, QVariant(QColor("blue")));
|
||||||
it->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere2.png")));
|
it->setData(NEWS_ICON, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere2.png")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug("Added all news to the GUI");
|
qDebug("Added all news to the GUI");
|
||||||
@ -471,7 +471,7 @@ void RSSImp::refreshTextBrowser() {
|
|||||||
previous_news = item;
|
previous_news = item;
|
||||||
}
|
}
|
||||||
RssStream *stream = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL));
|
RssStream *stream = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL));
|
||||||
RssItem* article = stream->getItem(item->text(NEWS_TITLE_COL));
|
RssItem* article = stream->getItem(item->text(NEWS_ID));
|
||||||
QString html;
|
QString html;
|
||||||
html += "<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>";
|
html += "<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>";
|
||||||
html += "<div style='background-color: #678db2; font-weight: bold; color: #fff;'>"+article->getTitle() + "</div>";
|
html += "<div style='background-color: #678db2; font-weight: bold; color: #fff;'>"+article->getTitle() + "</div>";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user