From 6f89b1f131b506d8db994258818b1399c15693bb Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 29 Aug 2009 03:47:14 +0000 Subject: [PATCH] - Be less restrictive about RSS feeds, we now display articles even if they don't have embedded torrents. However, RSS feed downloader is not available for said feeds. - Added an icon to differenciate articles with attachment (torrent) --- src/Icons/oxygen/application-x-kgetlist.png | Bin 0 -> 659 bytes src/icons.qrc | 1 + src/rss.cpp | 45 ++++++++++-------- src/rss.h | 15 +++--- src/rss.ui | 28 +++++++++-- src/rss_imp.cpp | 50 ++++++++++++++------ 6 files changed, 94 insertions(+), 45 deletions(-) create mode 100644 src/Icons/oxygen/application-x-kgetlist.png diff --git a/src/Icons/oxygen/application-x-kgetlist.png b/src/Icons/oxygen/application-x-kgetlist.png new file mode 100644 index 0000000000000000000000000000000000000000..55c04aa98f25a6226cb90aa003e2a6d2a7639f07 GIT binary patch literal 659 zcmV;E0&M+>P)mzf$l^)8)D=V!5j-e8 zt?WTOdGIQD5kc@@*n=Y8J;)yR4=B`wKfsIbVWI4zWrb3tCT?j{o3u@nad;%ruuH)& z4D*tC?=v&W8-<9VD9RZCHT<7;iKwk54>iYewqu5=sw$14Ib)?>#!p(-9RL{sF=3%3 zC|%>PGJp_jwviCy@{8-Jlr5-=fa8wv`QZnsq5vh?lLMq>fd~rwSrp-H)xx!NHRyck z-PbRO0O)Fxgnb^6QrYA;AQctc!Y}_2nyR5vG9mcA5CT|GLFNSmiYJ!fB!FVU;8v8} z!J~jA_&e|r#&Z-R1FruALJ_ddDhB=#dKh5YDjf?*dY@r)=P}B*0eiW?v4TjId2l?QOcKK2IRamvzBv<$TR2RK9@_tzewAaoGX(F&0C zcy;v(Iy)U`l`Zs!19?AA7j2x6H?UT%VKSK<+d}Tv-Me%buRi?*N^d~~tPF49_Juk+ zosP`j?RLKb*aIsqXWjRGVmi%cGYZ3y=JPpizJEf`KR%@(2&mO+(Re(jMx)^XxX32w zC>^GCKM1z@Ph@kz0C=8<(P#wIG~v1~dcB@ouh(yKf?ZIcons/oxygen/connection.png Icons/oxygen/bug.png Icons/oxygen/list-add.png + Icons/oxygen/application-x-kgetlist.png Icons/oxygen/folder.png Icons/oxygen/edit-cut.png Icons/oxygen/unsubscribe.png diff --git a/src/rss.cpp b/src/rss.cpp index c276bd67b..dd86e80ef 100644 --- a/src/rss.cpp +++ b/src/rss.cpp @@ -100,7 +100,7 @@ RssFolder* RssFolder::addFolder(QString name) { RssStream* RssFolder::addStream(QString url) { RssStream* stream = new RssStream(this, rssmanager, BTSession, url); - Q_ASSERT(!this->contains(stream->getUrl())); + Q_ASSERT(!this->contains(stream->getUrl())); (*this)[stream->getUrl()] = stream; refreshStream(stream->getUrl()); return stream; @@ -362,6 +362,7 @@ void RssManager::saveStreamList(){ /** RssStream **/ RssStream::RssStream(RssFolder* parent, RssManager *rssmanager, bittorrent *BTSession, QString _url): parent(parent), rssmanager(rssmanager), BTSession(BTSession), alias(""), iconPath(":/Icons/rss16.png"), refreshed(false), downloadFailure(false), currently_loading(false) { + has_attachments = false; qDebug("RSSStream constructed"); QSettings qBTRSS("qBittorrent", "qBittorrent-rss"); url = QUrl(_url).toString(); @@ -371,8 +372,11 @@ RssStream::RssStream(RssFolder* parent, RssManager *rssmanager, bittorrent *BTSe foreach(const QVariant &var_it, old_items) { QHash item = var_it.toHash(); RssItem *rss_item = RssItem::fromHash(this, item); - if(rss_item->isValid()) + if(rss_item->isValid()) { (*this)[rss_item->getTitle()] = rss_item; + if(rss_item->has_attachment()) + has_attachments = true; + } } } @@ -559,25 +563,28 @@ short RssStream::readDoc(const QDomDocument& doc) { RssItem * item = new RssItem(this, property); if(item->isValid() && !itemAlreadyExists(item->getTitle())) { (*this)[item->getTitle()] = item; - // Check if the item should be automatically downloaded - FeedFilter * matching_filter = FeedFilters::getFeedFilters(url).matches(item->getTitle()); - if(matching_filter != 0) { - // Download the torrent - BTSession->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(item->getTitle()).arg(getName())); - if(matching_filter->isValid()) { - QString save_path = matching_filter->getSavePath(); - if(save_path.isEmpty()) + if(item->has_attachment()) { + has_attachments = true; + // Check if the item should be automatically downloaded + FeedFilter * matching_filter = FeedFilters::getFeedFilters(url).matches(item->getTitle()); + if(matching_filter != 0) { + // Download the torrent + BTSession->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(item->getTitle()).arg(getName())); + if(matching_filter->isValid()) { + QString save_path = matching_filter->getSavePath(); + if(save_path.isEmpty()) + BTSession->downloadUrlAndSkipDialog(item->getTorrentUrl()); + else + BTSession->downloadUrlAndSkipDialog(item->getTorrentUrl(), save_path); + } else { + // All torrents are downloaded from this feed BTSession->downloadUrlAndSkipDialog(item->getTorrentUrl()); - else - BTSession->downloadUrlAndSkipDialog(item->getTorrentUrl(), save_path); - } else { - // All torrents are downloaded from this feed - BTSession->downloadUrlAndSkipDialog(item->getTorrentUrl()); + } + // Item was downloaded, consider it as Read + item->setRead(); + // Clean up + delete matching_filter; } - // Item was downloaded, consider it as Read - item->setRead(); - // Clean up - delete matching_filter; } } else { delete item; diff --git a/src/rss.h b/src/rss.h index 0707a5189..740a58ae4 100644 --- a/src/rss.h +++ b/src/rss.h @@ -268,18 +268,10 @@ public: is_valid = false; return; } - if(!torrent_url.isEmpty()) - is_valid = true; } else if (property.tagName() == "enclosure") { if(property.attribute("type", "") == "application/x-bittorrent") { torrent_url = property.attribute("url", QString::null); - if(torrent_url.isNull()) { - qDebug("Error: Torrent URL is null"); - return; - } - if(!title.isEmpty()) - is_valid = true; } } else if (property.tagName() == "link") @@ -292,6 +284,7 @@ public: author = property.text(); property = property.nextSibling().toElement(); } + is_valid = true; } RssItem(RssStream* parent, QString _title, QString _torrent_url, QString _news_link, QString _description, QDateTime _date, QString _author, bool _read): @@ -307,6 +300,10 @@ public: ~RssItem(){ } + bool has_attachment() const { + return !torrent_url.isEmpty(); + } + QHash toHash() const { QHash item; item["title"] = title; @@ -388,6 +385,7 @@ private: bool refreshed; bool downloadFailure; bool currently_loading; + bool has_attachments; public slots: void processDownloadedFile(QString file_path); @@ -423,6 +421,7 @@ public: QList getNewsList() const; QList getUnreadNewsList() const; QString getIconUrl(); + bool hasAttachments() const { return has_attachments; } private: short readDoc(const QDomDocument& doc); diff --git a/src/rss.ui b/src/rss.ui index 52de05617..637b4bd13 100644 --- a/src/rss.ui +++ b/src/rss.ui @@ -127,15 +127,37 @@ p, li { white-space: pre-wrap; } QAbstractItemView::ExtendedSelection - + false - + + + false + + + true + false + + true + + + true + + + + Bullet + + + + + Attachment + + - 1 + Article title diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp index 29dbe4207..527380014 100644 --- a/src/rss_imp.cpp +++ b/src/rss_imp.cpp @@ -68,8 +68,10 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){ myRSSListMenu.addSeparator(); myRSSListMenu.addAction(actionCopy_feed_URL); if(selectedItems.size() == 1) { - myRSSListMenu.addSeparator(); - myRSSListMenu.addAction(actionRSS_feed_downloader); + if(((RssStream*)listStreams->getRSSItem(selectedItems.first()))->hasAttachments()) { + myRSSListMenu.addSeparator(); + myRSSListMenu.addAction(actionRSS_feed_downloader); + } } } }else{ @@ -85,7 +87,15 @@ void RSSImp::displayItemsListMenu(const QPoint&){ QMenu myItemListMenu(this); QList selectedItems = listStreams->selectedItems(); if(selectedItems.size() > 0) { - myItemListMenu.addAction(actionDownload_torrent); + bool has_attachment = false; + foreach(QTreeWidgetItem *item, selectedItems) { + if(listStreams->getRSSItemFromUrl(item->text(3))->getItem(item->text(2))->has_attachment()) { + has_attachment = true; + break; + } + } + if(has_attachment) + myItemListMenu.addAction(actionDownload_torrent); myItemListMenu.addAction(actionOpen_news_URL); } myItemListMenu.exec(QCursor::pos()); @@ -272,8 +282,14 @@ void RSSImp::on_updateAllButton_clicked() { void RSSImp::downloadTorrent() { QList selected_items = listNews->selectedItems(); foreach(const QTreeWidgetItem* item, selected_items) { - RssItem* news = listStreams->getRSSItemFromUrl(item->text(1))->getItem(item->text(0)); - BTSession->downloadFromUrl(news->getTorrentUrl()); + RssItem* article = listStreams->getRSSItemFromUrl(item->text(3))->getItem(item->text(2)); + if(article->has_attachment()) { + BTSession->downloadFromUrl(article->getTorrentUrl()); + } else { + QString link = article->getLink(); + if(!link.isEmpty()) + QDesktopServices::openUrl(QUrl(link)); + } } } @@ -281,7 +297,7 @@ void RSSImp::downloadTorrent() { void RSSImp::openNewsUrl() { QList selected_items = listNews->selectedItems(); foreach(const QTreeWidgetItem* item, selected_items) { - RssItem* news = listStreams->getRSSItemFromUrl(item->text(1))->getItem(item->text(0)); + RssItem* news = listStreams->getRSSItemFromUrl(item->text(3))->getItem(item->text(2)); QString link = news->getLink(); if(!link.isEmpty()) QDesktopServices::openUrl(QUrl(link)); @@ -418,13 +434,15 @@ void RSSImp::refreshNewsList(QTreeWidgetItem* item) { qDebug("Got the list of news"); foreach(RssItem* article, news){ QTreeWidgetItem* it = new QTreeWidgetItem(listNews); - it->setText(0, article->getTitle()); - it->setText(1, article->getParent()->getUrl()); + it->setText(2, article->getTitle()); + if(article->has_attachment()) + it->setData(1, Qt::DecorationRole, QVariant(QIcon(":/Icons/oxygen/application-x-kgetlist.png"))); + it->setText(3, article->getParent()->getUrl()); if(article->isRead()){ - it->setData(0, Qt::ForegroundRole, QVariant(QColor("grey"))); + it->setData(2, Qt::ForegroundRole, QVariant(QColor("grey"))); it->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png"))); }else{ - it->setData(0, Qt::ForegroundRole, QVariant(QColor("blue"))); + it->setData(2, Qt::ForegroundRole, QVariant(QColor("blue"))); it->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere2.png"))); } } @@ -443,8 +461,8 @@ void RSSImp::refreshTextBrowser(QTreeWidgetItem *item) { } previous_news = item; } - RssStream *stream = listStreams->getRSSItemFromUrl(item->text(1)); - RssItem* article = stream->getItem(item->text(0)); + RssStream *stream = listStreams->getRSSItemFromUrl(item->text(3)); + RssItem* article = stream->getItem(item->text(2)); QString html; html += "
"; html += "
"+article->getTitle() + "
"; @@ -458,11 +476,11 @@ void RSSImp::refreshTextBrowser(QTreeWidgetItem *item) { html += ""+article->getDescription()+"
"; textBrowser->setHtml(html); article->setRead(); - item->setData(0, Qt::ForegroundRole, QVariant(QColor("grey"))); + item->setData(2, Qt::ForegroundRole, QVariant(QColor("grey"))); item->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png"))); // Decrement feed nb unread news updateItemInfos(listStreams->getUnreadItem()); - updateItemInfos(listStreams->getTreeItemFromUrl(item->text(1))); + updateItemInfos(listStreams->getTreeItemFromUrl(item->text(3))); } void RSSImp::saveSlidersPosition() { @@ -538,7 +556,9 @@ RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){ listStreams = new FeedList(splitter_h, rssmanager); splitter_h->insertWidget(0, listStreams); - listNews->hideColumn(1); + listNews->hideColumn(3); + listNews->setColumnWidth(0, 16); + listNews->setColumnWidth(1, 20); fillFeedsList(); refreshNewsList(listStreams->currentItem());