mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 15:27:54 +00:00
RSS code clean up
This commit is contained in:
parent
42d7e20c1d
commit
462c821df9
@ -122,7 +122,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QTreeWidget" name="listNews">
|
<widget class="QListWidget" name="listArticles">
|
||||||
<property name="contextMenuPolicy">
|
<property name="contextMenuPolicy">
|
||||||
<enum>Qt::CustomContextMenu</enum>
|
<enum>Qt::CustomContextMenu</enum>
|
||||||
</property>
|
</property>
|
||||||
@ -132,39 +132,6 @@ p, li { white-space: pre-wrap; }
|
|||||||
<property name="selectionBehavior">
|
<property name="selectionBehavior">
|
||||||
<enum>QAbstractItemView::SelectItems</enum>
|
<enum>QAbstractItemView::SelectItems</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="rootIsDecorated">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="itemsExpandable">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="allColumnsShowFocus">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="expandsOnDoubleClick">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<attribute name="headerVisible">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="headerStretchLastSection">
|
|
||||||
<bool>true</bool>
|
|
||||||
</attribute>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">Bullet</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Article title</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Feed URL</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QTextBrowser" name="textBrowser"/>
|
<widget class="QTextBrowser" name="textBrowser"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -51,7 +51,15 @@
|
|||||||
#include "automatedrssdownloader.h"
|
#include "automatedrssdownloader.h"
|
||||||
#include "iconprovider.h"
|
#include "iconprovider.h"
|
||||||
|
|
||||||
enum NewsCols { NEWS_ICON, NEWS_TITLE_COL, NEWS_URL_COL, NEWS_ID };
|
namespace Article {
|
||||||
|
enum ArticleRoles {
|
||||||
|
TitleRole = Qt::DisplayRole,
|
||||||
|
IconRole = Qt::DecorationRole,
|
||||||
|
ColorRole = Qt::ForegroundRole,
|
||||||
|
IdRole = Qt::UserRole + 1,
|
||||||
|
FeedUrlRole = Qt::UserRole + 2
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// display a right-click menu
|
// display a right-click menu
|
||||||
void RSSImp::displayRSSListMenu(const QPoint& pos){
|
void RSSImp::displayRSSListMenu(const QPoint& pos){
|
||||||
@ -93,13 +101,14 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){
|
|||||||
|
|
||||||
void RSSImp::displayItemsListMenu(const QPoint&){
|
void RSSImp::displayItemsListMenu(const QPoint&){
|
||||||
QMenu myItemListMenu(this);
|
QMenu myItemListMenu(this);
|
||||||
QList<QTreeWidgetItem*> selectedItems = listNews->selectedItems();
|
QList<QListWidgetItem*> selectedItems = listArticles->selectedItems();
|
||||||
if(selectedItems.size() > 0) {
|
if(selectedItems.size() > 0) {
|
||||||
bool has_attachment = false;
|
bool has_attachment = false;
|
||||||
foreach(QTreeWidgetItem *item, selectedItems) {
|
foreach(const QListWidgetItem *item, selectedItems) {
|
||||||
qDebug("text(3) URL: %s", qPrintable(item->text(NEWS_URL_COL)));
|
qDebug("text(3) URL: %s", qPrintable(item->data(Article::FeedUrlRole).toString()));
|
||||||
qDebug("text(2) TITLE: %s", qPrintable(item->text(NEWS_TITLE_COL)));
|
qDebug("text(2) TITLE: %s", qPrintable(item->data(Article::TitleRole).toString()));
|
||||||
if(listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID)).hasAttachment()) {
|
if(listStreams->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
|
||||||
|
->getItem(item->data(Article::IdRole).toString()).hasAttachment()) {
|
||||||
has_attachment = true;
|
has_attachment = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -236,8 +245,8 @@ void RSSImp::deleteSelectedItems() {
|
|||||||
foreach(QTreeWidgetItem *item, selectedItems){
|
foreach(QTreeWidgetItem *item, selectedItems){
|
||||||
if(listStreams->currentFeed() == item){
|
if(listStreams->currentFeed() == item){
|
||||||
textBrowser->clear();
|
textBrowser->clear();
|
||||||
previous_news = 0;
|
m_currentArticle = 0;
|
||||||
listNews->clear();
|
listArticles->clear();
|
||||||
}
|
}
|
||||||
RssFile *rss_item = listStreams->getRSSItem(item);
|
RssFile *rss_item = listStreams->getRSSItem(item);
|
||||||
// Notify TreeWidget
|
// Notify TreeWidget
|
||||||
@ -306,9 +315,10 @@ void RSSImp::on_updateAllButton_clicked() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RSSImp::downloadTorrent() {
|
void RSSImp::downloadTorrent() {
|
||||||
QList<QTreeWidgetItem *> selected_items = listNews->selectedItems();
|
QList<QListWidgetItem *> selected_items = listArticles->selectedItems();
|
||||||
foreach(const QTreeWidgetItem* item, selected_items) {
|
foreach(const QListWidgetItem* item, selected_items) {
|
||||||
const RssArticle article = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID));
|
const RssArticle article = listStreams->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
|
||||||
|
->getItem(item->data(Article::IdRole).toString());
|
||||||
if(article.hasAttachment()) {
|
if(article.hasAttachment()) {
|
||||||
QBtSession::instance()->downloadFromUrl(article.torrentUrl());
|
QBtSession::instance()->downloadFromUrl(article.torrentUrl());
|
||||||
} else {
|
} else {
|
||||||
@ -319,9 +329,10 @@ void RSSImp::downloadTorrent() {
|
|||||||
|
|
||||||
// open the url of the news in a browser
|
// open the url of the news in a browser
|
||||||
void RSSImp::openNewsUrl() {
|
void RSSImp::openNewsUrl() {
|
||||||
QList<QTreeWidgetItem *> selected_items = listNews->selectedItems();
|
QList<QListWidgetItem *> selected_items = listArticles->selectedItems();
|
||||||
foreach(const QTreeWidgetItem* item, selected_items) {
|
foreach(const QListWidgetItem* item, selected_items) {
|
||||||
const RssArticle news = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID));
|
const RssArticle news = listStreams->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
|
||||||
|
->getItem(item->data(Article::IdRole).toString());
|
||||||
const QString link = news.link();
|
const QString link = news.link();
|
||||||
if(!link.isEmpty())
|
if(!link.isEmpty())
|
||||||
QDesktopServices::openUrl(QUrl(link));
|
QDesktopServices::openUrl(QUrl(link));
|
||||||
@ -434,7 +445,7 @@ void RSSImp::fillFeedsList(QTreeWidgetItem *parent, RssFolder *rss_parent) {
|
|||||||
// fills the newsList
|
// fills the newsList
|
||||||
void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
|
void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
|
||||||
if(!item) {
|
if(!item) {
|
||||||
listNews->clear();
|
listArticles->clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,20 +460,20 @@ void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
|
|||||||
news = RssManager::sortNewsList(rss_item->articleList());
|
news = RssManager::sortNewsList(rss_item->articleList());
|
||||||
// Clear the list first
|
// Clear the list first
|
||||||
textBrowser->clear();
|
textBrowser->clear();
|
||||||
previous_news = 0;
|
m_currentArticle = 0;
|
||||||
listNews->clear();
|
listArticles->clear();
|
||||||
qDebug("Got the list of news");
|
qDebug("Got the list of news");
|
||||||
foreach(const RssArticle &article, news){
|
foreach(const RssArticle &article, news){
|
||||||
QTreeWidgetItem* it = new QTreeWidgetItem(listNews);
|
QListWidgetItem* it = new QListWidgetItem(listArticles);
|
||||||
it->setText(NEWS_TITLE_COL, article.title());
|
it->setData(Article::TitleRole, article.title());
|
||||||
it->setText(NEWS_URL_COL, article.parent()->url());
|
it->setData(Article::FeedUrlRole, article.parent()->url());
|
||||||
it->setText(NEWS_ID, article.guid());
|
it->setData(Article::IdRole, article.guid());
|
||||||
if(article.isRead()){
|
if(article.isRead()){
|
||||||
it->setData(NEWS_TITLE_COL, Qt::ForegroundRole, QVariant(QColor("grey")));
|
it->setData(Article::ColorRole, QVariant(QColor("grey")));
|
||||||
it->setData(NEWS_ICON, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
|
it->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere.png")));
|
||||||
}else{
|
}else{
|
||||||
it->setData(NEWS_TITLE_COL, Qt::ForegroundRole, QVariant(QColor("blue")));
|
it->setData(Article::ColorRole, QVariant(QColor("blue")));
|
||||||
it->setData(NEWS_ICON, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere2.png")));
|
it->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere2.png")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug("Added all news to the GUI");
|
qDebug("Added all news to the GUI");
|
||||||
@ -471,25 +482,25 @@ void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
|
|||||||
|
|
||||||
// display a news
|
// display a news
|
||||||
void RSSImp::refreshTextBrowser() {
|
void RSSImp::refreshTextBrowser() {
|
||||||
QList<QTreeWidgetItem*> selection = listNews->selectedItems();
|
QList<QListWidgetItem*> selection = listArticles->selectedItems();
|
||||||
if(selection.empty()) return;
|
if(selection.empty()) return;
|
||||||
Q_ASSERT(selection.size() == 1);
|
Q_ASSERT(selection.size() == 1);
|
||||||
QTreeWidgetItem *item = selection.first();
|
QListWidgetItem *item = selection.first();
|
||||||
Q_ASSERT(item);
|
Q_ASSERT(item);
|
||||||
if(item == previous_news) return;
|
if(item == m_currentArticle) return;
|
||||||
// Stop displaying previous news if necessary
|
// Stop displaying previous news if necessary
|
||||||
if(listStreams->currentFeed() == listStreams->getUnreadItem()) {
|
if(listStreams->currentFeed() == listStreams->getUnreadItem()) {
|
||||||
if(previous_news) {
|
if(m_currentArticle) {
|
||||||
disconnect(listNews, SIGNAL(itemSelectionChanged()), this, SLOT(refreshTextBrowser()));
|
disconnect(listArticles, SIGNAL(itemSelectionChanged()), this, SLOT(refreshTextBrowser()));
|
||||||
listNews->removeItemWidget(previous_news, 0);
|
listArticles->removeItemWidget(m_currentArticle);
|
||||||
Q_ASSERT(previous_news);
|
Q_ASSERT(m_currentArticle);
|
||||||
delete previous_news;
|
delete m_currentArticle;
|
||||||
connect(listNews, SIGNAL(itemSelectionChanged()), this, SLOT(refreshTextBrowser()));
|
connect(listArticles, SIGNAL(itemSelectionChanged()), this, SLOT(refreshTextBrowser()));
|
||||||
}
|
}
|
||||||
previous_news = item;
|
m_currentArticle = item;
|
||||||
}
|
}
|
||||||
RssFeed *stream = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL));
|
RssFeed *stream = listStreams->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString());
|
||||||
RssArticle article = stream->getItem(item->text(NEWS_ID));
|
RssArticle article = stream->getItem(item->data(Article::IdRole).toString());
|
||||||
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.title() + "</div>";
|
html += "<div style='background-color: #678db2; font-weight: bold; color: #fff;'>"+article.title() + "</div>";
|
||||||
@ -503,11 +514,11 @@ void RSSImp::refreshTextBrowser() {
|
|||||||
html += "<divstyle='margin-left: 5px; margin-right: 5px;'>"+article.description()+"</div>";
|
html += "<divstyle='margin-left: 5px; margin-right: 5px;'>"+article.description()+"</div>";
|
||||||
textBrowser->setHtml(html);
|
textBrowser->setHtml(html);
|
||||||
article.markAsRead();
|
article.markAsRead();
|
||||||
item->setData(NEWS_TITLE_COL, Qt::ForegroundRole, QVariant(QColor("grey")));
|
item->setData(Article::ColorRole, QVariant(QColor("grey")));
|
||||||
item->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
|
item->setData(Article::IconRole, 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(NEWS_URL_COL)));
|
updateItemInfos(listStreams->getTreeItemFromUrl(item->data(Article::FeedUrlRole).toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSImp::saveSlidersPosition() {
|
void RSSImp::saveSlidersPosition() {
|
||||||
@ -605,10 +616,8 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) {
|
|||||||
|
|
||||||
listStreams = new FeedListWidget(splitter_h, rssmanager);
|
listStreams = new FeedListWidget(splitter_h, rssmanager);
|
||||||
splitter_h->insertWidget(0, listStreams);
|
splitter_h->insertWidget(0, listStreams);
|
||||||
listNews->hideColumn(NEWS_URL_COL);
|
listArticles->setSelectionBehavior(QAbstractItemView::SelectItems);
|
||||||
listNews->setColumnWidth(0, 16);
|
listArticles->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
listNews->setSelectionBehavior(QAbstractItemView::SelectItems);
|
|
||||||
listNews->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
||||||
|
|
||||||
rssmanager->loadStreamList();
|
rssmanager->loadStreamList();
|
||||||
fillFeedsList();
|
fillFeedsList();
|
||||||
@ -619,7 +628,7 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) {
|
|||||||
connect(rssmanager, SIGNAL(feedIconChanged(QString, QString)), this, SLOT(updateFeedIcon(QString, QString)));
|
connect(rssmanager, SIGNAL(feedIconChanged(QString, QString)), this, SLOT(updateFeedIcon(QString, QString)));
|
||||||
|
|
||||||
connect(listStreams, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRSSListMenu(const QPoint&)));
|
connect(listStreams, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRSSListMenu(const QPoint&)));
|
||||||
connect(listNews, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayItemsListMenu(const QPoint&)));
|
connect(listArticles, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayItemsListMenu(const QPoint&)));
|
||||||
|
|
||||||
// Feeds list actions
|
// Feeds list actions
|
||||||
connect(actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelectedItems()));
|
connect(actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelectedItems()));
|
||||||
@ -638,8 +647,8 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) {
|
|||||||
connect(listStreams, SIGNAL(foldersAltered(QList<QTreeWidgetItem*>)), this, SLOT(updateItemsInfos(QList<QTreeWidgetItem*>)));
|
connect(listStreams, SIGNAL(foldersAltered(QList<QTreeWidgetItem*>)), this, SLOT(updateItemsInfos(QList<QTreeWidgetItem*>)));
|
||||||
connect(listStreams, SIGNAL(overwriteAttempt(QString)), this, SLOT(displayOverwriteError(QString)));
|
connect(listStreams, SIGNAL(overwriteAttempt(QString)), this, SLOT(displayOverwriteError(QString)));
|
||||||
|
|
||||||
connect(listNews, SIGNAL(itemSelectionChanged()), this, SLOT(refreshTextBrowser()));
|
connect(listArticles, SIGNAL(itemSelectionChanged()), this, SLOT(refreshTextBrowser()));
|
||||||
connect(listNews, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(downloadTorrent()));
|
connect(listArticles, SIGNAL(itemDoubleClicked(QListWidgetItem *, int)), this, SLOT(downloadTorrent()));
|
||||||
|
|
||||||
// Refresh all feeds
|
// Refresh all feeds
|
||||||
rssmanager->refresh();
|
rssmanager->refresh();
|
||||||
|
@ -85,7 +85,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
RssManager *rssmanager;
|
RssManager *rssmanager;
|
||||||
FeedListWidget *listStreams;
|
FeedListWidget *listStreams;
|
||||||
QTreeWidgetItem* previous_news;
|
QListWidgetItem* m_currentArticle;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user