diff --git a/src/rss.cpp b/src/rss.cpp index c5fdab245..cac932f77 100644 --- a/src/rss.cpp +++ b/src/rss.cpp @@ -392,7 +392,7 @@ RssStream::RssStream(RssFolder* parent, RssManager *rssmanager, Bittorrent *BTSe QHash item = var_it.toHash(); RssItem *rss_item = RssItem::fromHash(this, item); if(rss_item->isValid()) { - (*this)[rss_item->getTitle()] = rss_item; + (*this)[rss_item->getId()] = rss_item; } else { delete rss_item; } @@ -518,8 +518,8 @@ void RssStream::setIconPath(QString path) { iconPath = path; } -RssItem* RssStream::getItem(QString name) const{ - return this->value(name); +RssItem* RssStream::getItem(QString id) const{ + return this->value(id); } unsigned int RssStream::getNbNews() const{ @@ -619,8 +619,8 @@ short RssStream::readDoc(QIODevice* device) { } else if(xml.name() == "item") { RssItem * item = new RssItem(this, xml); - if(item->isValid() && !itemAlreadyExists(item->getTitle())) { - this->insert(item->getTitle(), item); + if(item->isValid() && !itemAlreadyExists(item->getId())) { + this->insert(item->getId(), item); } else { delete item; } @@ -673,7 +673,7 @@ void RssStream::resizeList() { int excess = nb_articles - max_articles; for(int i=0; itake(lastItem->getTitle()); + delete this->take(lastItem->getId()); } } } diff --git a/src/rss.h b/src/rss.h index 5c0d58730..f8be682c0 100644 --- a/src/rss.h +++ b/src/rss.h @@ -122,6 +122,7 @@ class RssItem: public QObject { Q_OBJECT private: RssStream* parent; + QString id; QString title; QString torrent_url; QString news_link; @@ -281,10 +282,6 @@ public: if(xml.isStartElement()) { if(xml.name() == "title") { title = xml.readElementText(); - if(title.isEmpty()) { - is_valid = false; - return; - } } else if(xml.name() == "enclosure") { if(xml.attributes().value("type") == "application/x-bittorrent") { @@ -293,6 +290,8 @@ public: } else if(xml.name() == "link") { news_link = xml.readElementText(); + if(id.isEmpty()) + id = news_link; } else if(xml.name() == "description") { description = xml.readElementText(); @@ -303,15 +302,20 @@ public: else if(xml.name() == "author") { author = xml.readElementText(); } + else if(xml.name() == "guid") { + id = xml.readElementText(); + } } } - if(!title.isEmpty()) + if(!id.isEmpty()) is_valid = true; } - RssItem(RssStream* parent, 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){ - if(!title.isEmpty()) { + RssItem(RssStream* parent, QString _id, QString _title, QString _torrent_url, QString _news_link, QString _description, QDateTime _date, QString _author, bool _read): + parent(parent), id(_id), title(_title), torrent_url(_torrent_url), news_link(_news_link), description(_description), date(_date), author(_author), read(_read){ + if(id.isEmpty()) + id = news_link; + if(!id.isEmpty()) { is_valid = true; } else { std::cerr << "ERROR: an invalid RSS item was saved" << std::endl; @@ -326,9 +330,12 @@ public: return !torrent_url.isEmpty(); } + QString getId() const { return id; } + QHash toHash() const { QHash item; item["title"] = title; + item["id"] = id; item["torrent_url"] = torrent_url; item["news_link"] = news_link; item["description"] = description; @@ -339,7 +346,7 @@ public: } static RssItem* fromHash(RssStream* parent, QHash 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()); } diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp index 31ad25027..815befa2e 100644 --- a/src/rss_imp.cpp +++ b/src/rss_imp.cpp @@ -42,8 +42,7 @@ #include "feedList.h" #include "bittorrent.h" -#define NEWS_TITLE_COL 1 -#define NEWS_URL_COL 2 +enum NewsCols { NEWS_ICON, NEWS_TITLE_COL, NEWS_URL_COL, NEWS_ID }; // display a right-click menu void RSSImp::displayRSSListMenu(const QPoint& pos){ @@ -92,7 +91,7 @@ void RSSImp::displayItemsListMenu(const QPoint&){ foreach(QTreeWidgetItem *item, selectedItems) { qDebug("text(3) URL: %s", qPrintable(item->text(NEWS_URL_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; break; } @@ -287,7 +286,7 @@ void RSSImp::on_updateAllButton_clicked() { void RSSImp::downloadTorrent() { QList selected_items = listNews->selectedItems(); 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()) { BTSession->downloadFromUrl(article->getTorrentUrl()); } else { @@ -300,7 +299,7 @@ void RSSImp::downloadTorrent() { void RSSImp::openNewsUrl() { QList selected_items = listNews->selectedItems(); 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(); if(!link.isEmpty()) QDesktopServices::openUrl(QUrl(link)); @@ -444,12 +443,13 @@ void RSSImp::refreshNewsList(QTreeWidgetItem* item) { QTreeWidgetItem* it = new QTreeWidgetItem(listNews); it->setText(NEWS_TITLE_COL, article->getTitle()); it->setText(NEWS_URL_COL, article->getParent()->getUrl()); + it->setText(NEWS_ID, article->getId()); if(article->isRead()){ 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{ 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"); @@ -471,7 +471,7 @@ void RSSImp::refreshTextBrowser() { previous_news = item; } 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; html += "
"; html += "
"+article->getTitle() + "
";