Browse Source

- 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)
adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
6f89b1f131
  1. BIN
      src/Icons/oxygen/application-x-kgetlist.png
  2. 1
      src/icons.qrc
  3. 9
      src/rss.cpp
  4. 15
      src/rss.h
  5. 28
      src/rss.ui
  6. 44
      src/rss_imp.cpp

BIN
src/Icons/oxygen/application-x-kgetlist.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 659 B

1
src/icons.qrc

@ -101,6 +101,7 @@
<file>Icons/oxygen/connection.png</file> <file>Icons/oxygen/connection.png</file>
<file>Icons/oxygen/bug.png</file> <file>Icons/oxygen/bug.png</file>
<file>Icons/oxygen/list-add.png</file> <file>Icons/oxygen/list-add.png</file>
<file>Icons/oxygen/application-x-kgetlist.png</file>
<file>Icons/oxygen/folder.png</file> <file>Icons/oxygen/folder.png</file>
<file>Icons/oxygen/edit-cut.png</file> <file>Icons/oxygen/edit-cut.png</file>
<file>Icons/oxygen/unsubscribe.png</file> <file>Icons/oxygen/unsubscribe.png</file>

9
src/rss.cpp

@ -362,6 +362,7 @@ void RssManager::saveStreamList(){
/** RssStream **/ /** 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) { 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"); qDebug("RSSStream constructed");
QSettings qBTRSS("qBittorrent", "qBittorrent-rss"); QSettings qBTRSS("qBittorrent", "qBittorrent-rss");
url = QUrl(_url).toString(); url = QUrl(_url).toString();
@ -371,8 +372,11 @@ RssStream::RssStream(RssFolder* parent, RssManager *rssmanager, bittorrent *BTSe
foreach(const QVariant &var_it, old_items) { foreach(const QVariant &var_it, old_items) {
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->getTitle()] = rss_item;
if(rss_item->has_attachment())
has_attachments = true;
}
} }
} }
@ -559,6 +563,8 @@ short RssStream::readDoc(const QDomDocument& doc) {
RssItem * item = new RssItem(this, property); RssItem * item = new RssItem(this, property);
if(item->isValid() && !itemAlreadyExists(item->getTitle())) { if(item->isValid() && !itemAlreadyExists(item->getTitle())) {
(*this)[item->getTitle()] = item; (*this)[item->getTitle()] = item;
if(item->has_attachment()) {
has_attachments = true;
// Check if the item should be automatically downloaded // Check if the item should be automatically downloaded
FeedFilter * matching_filter = FeedFilters::getFeedFilters(url).matches(item->getTitle()); FeedFilter * matching_filter = FeedFilters::getFeedFilters(url).matches(item->getTitle());
if(matching_filter != 0) { if(matching_filter != 0) {
@ -579,6 +585,7 @@ short RssStream::readDoc(const QDomDocument& doc) {
// Clean up // Clean up
delete matching_filter; delete matching_filter;
} }
}
} else { } else {
delete item; delete item;
} }

15
src/rss.h

@ -268,18 +268,10 @@ public:
is_valid = false; is_valid = false;
return; return;
} }
if(!torrent_url.isEmpty())
is_valid = true;
} }
else if (property.tagName() == "enclosure") { else if (property.tagName() == "enclosure") {
if(property.attribute("type", "") == "application/x-bittorrent") { if(property.attribute("type", "") == "application/x-bittorrent") {
torrent_url = property.attribute("url", QString::null); 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") else if (property.tagName() == "link")
@ -292,6 +284,7 @@ public:
author = property.text(); author = property.text();
property = property.nextSibling().toElement(); 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): 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(){ ~RssItem(){
} }
bool has_attachment() const {
return !torrent_url.isEmpty();
}
QHash<QString, QVariant> toHash() const { QHash<QString, QVariant> toHash() const {
QHash<QString, QVariant> item; QHash<QString, QVariant> item;
item["title"] = title; item["title"] = title;
@ -388,6 +385,7 @@ private:
bool refreshed; bool refreshed;
bool downloadFailure; bool downloadFailure;
bool currently_loading; bool currently_loading;
bool has_attachments;
public slots: public slots:
void processDownloadedFile(QString file_path); void processDownloadedFile(QString file_path);
@ -423,6 +421,7 @@ public:
QList<RssItem*> getNewsList() const; QList<RssItem*> getNewsList() const;
QList<RssItem*> getUnreadNewsList() const; QList<RssItem*> getUnreadNewsList() const;
QString getIconUrl(); QString getIconUrl();
bool hasAttachments() const { return has_attachments; }
private: private:
short readDoc(const QDomDocument& doc); short readDoc(const QDomDocument& doc);

28
src/rss.ui

@ -127,15 +127,37 @@ p, li { white-space: pre-wrap; }
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum> <enum>QAbstractItemView::ExtendedSelection</enum>
</property> </property>
<attribute name="headerVisible"> <property name="rootIsDecorated">
<bool>false</bool> <bool>false</bool>
</attribute> </property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<attribute name="headerVisible"> <attribute name="headerVisible">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<attribute name="headerStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="headerStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>Bullet</string>
</property>
</column>
<column>
<property name="text">
<string>Attachment</string>
</property>
</column>
<column> <column>
<property name="text"> <property name="text">
<string>1</string> <string>Article title</string>
</property> </property>
</column> </column>
<column> <column>

44
src/rss_imp.cpp

@ -68,10 +68,12 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){
myRSSListMenu.addSeparator(); myRSSListMenu.addSeparator();
myRSSListMenu.addAction(actionCopy_feed_URL); myRSSListMenu.addAction(actionCopy_feed_URL);
if(selectedItems.size() == 1) { if(selectedItems.size() == 1) {
if(((RssStream*)listStreams->getRSSItem(selectedItems.first()))->hasAttachments()) {
myRSSListMenu.addSeparator(); myRSSListMenu.addSeparator();
myRSSListMenu.addAction(actionRSS_feed_downloader); myRSSListMenu.addAction(actionRSS_feed_downloader);
} }
} }
}
}else{ }else{
myRSSListMenu.addAction(actionNew_subscription); myRSSListMenu.addAction(actionNew_subscription);
myRSSListMenu.addAction(actionNew_folder); myRSSListMenu.addAction(actionNew_folder);
@ -85,6 +87,14 @@ void RSSImp::displayItemsListMenu(const QPoint&){
QMenu myItemListMenu(this); QMenu myItemListMenu(this);
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems(); QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
if(selectedItems.size() > 0) { if(selectedItems.size() > 0) {
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(actionDownload_torrent);
myItemListMenu.addAction(actionOpen_news_URL); myItemListMenu.addAction(actionOpen_news_URL);
} }
@ -272,8 +282,14 @@ 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* news = listStreams->getRSSItemFromUrl(item->text(1))->getItem(item->text(0)); RssItem* article = listStreams->getRSSItemFromUrl(item->text(3))->getItem(item->text(2));
BTSession->downloadFromUrl(news->getTorrentUrl()); 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() { 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(1))->getItem(item->text(0)); RssItem* news = listStreams->getRSSItemFromUrl(item->text(3))->getItem(item->text(2));
QString link = news->getLink(); QString link = news->getLink();
if(!link.isEmpty()) if(!link.isEmpty())
QDesktopServices::openUrl(QUrl(link)); QDesktopServices::openUrl(QUrl(link));
@ -418,13 +434,15 @@ void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
qDebug("Got the list of news"); qDebug("Got the list of news");
foreach(RssItem* article, news){ foreach(RssItem* article, news){
QTreeWidgetItem* it = new QTreeWidgetItem(listNews); QTreeWidgetItem* it = new QTreeWidgetItem(listNews);
it->setText(0, article->getTitle()); it->setText(2, article->getTitle());
it->setText(1, article->getParent()->getUrl()); 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()){ 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"))); it->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
}else{ }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"))); it->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere2.png")));
} }
} }
@ -443,8 +461,8 @@ void RSSImp::refreshTextBrowser(QTreeWidgetItem *item) {
} }
previous_news = item; previous_news = item;
} }
RssStream *stream = listStreams->getRSSItemFromUrl(item->text(1)); RssStream *stream = listStreams->getRSSItemFromUrl(item->text(3));
RssItem* article = stream->getItem(item->text(0)); RssItem* article = stream->getItem(item->text(2));
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>";
@ -458,11 +476,11 @@ void RSSImp::refreshTextBrowser(QTreeWidgetItem *item) {
html += "<divstyle='margin-left: 5px; margin-right: 5px;'>"+article->getDescription()+"</div>"; html += "<divstyle='margin-left: 5px; margin-right: 5px;'>"+article->getDescription()+"</div>";
textBrowser->setHtml(html); textBrowser->setHtml(html);
article->setRead(); 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"))); item->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
// Decrement feed nb unread news // Decrement feed nb unread news
updateItemInfos(listStreams->getUnreadItem()); updateItemInfos(listStreams->getUnreadItem());
updateItemInfos(listStreams->getTreeItemFromUrl(item->text(1))); updateItemInfos(listStreams->getTreeItemFromUrl(item->text(3)));
} }
void RSSImp::saveSlidersPosition() { void RSSImp::saveSlidersPosition() {
@ -538,7 +556,9 @@ RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){
listStreams = new FeedList(splitter_h, rssmanager); listStreams = new FeedList(splitter_h, rssmanager);
splitter_h->insertWidget(0, listStreams); splitter_h->insertWidget(0, listStreams);
listNews->hideColumn(1); listNews->hideColumn(3);
listNews->setColumnWidth(0, 16);
listNews->setColumnWidth(1, 20);
fillFeedsList(); fillFeedsList();
refreshNewsList(listStreams->currentItem()); refreshNewsList(listStreams->currentItem());

Loading…
Cancel
Save