Browse Source

- RSS code remodeling to improve robustness

adaptive-webui-19844
Christophe Dumez 16 years ago
parent
commit
9ca4e2f1f6
  1. 39
      src/rss_imp.cpp
  2. 2
      src/rss_imp.h

39
src/rss_imp.cpp

@ -118,27 +118,20 @@ void RSSImp::on_newFeedButton_clicked() {
// delete a stream by a button // delete a stream by a button
void RSSImp::deleteSelectedFeeds() { void RSSImp::deleteSelectedFeeds() {
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems(); QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
QTreeWidgetItem *item; if(selectedItems.size() == 0) return;
if(!selectedItems.size()) return; if(!selectedItems.size()) return;
int ret = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to delete this stream from the list?"), int ret = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to delete this stream from the list?"),
tr("&Yes"), tr("&No"), tr("&Yes"), tr("&No"),
QString(), 0, 1); QString(), 0, 1);
if(!ret) { if(!ret) {
QStringList urlsToDelete; foreach(QTreeWidgetItem *item, selectedItems){
foreach(item, selectedItems){ if(listStreams->currentItem() == item){
QString url = item->data(1, Qt::DisplayRole).toString();
urlsToDelete << url;
}
QString url;
foreach(url, urlsToDelete){
if(selectedFeedUrl == url){
textBrowser->clear(); textBrowser->clear();
listNews->clear(); listNews->clear();
} }
rssmanager->removeStream(url); rssmanager->removeStream(item->text(1));
delete getTreeItemFromUrl(url); delete item;
} }
if(urlsToDelete.size())
rssmanager->saveStreamList(); rssmanager->saveStreamList();
} }
} }
@ -155,7 +148,7 @@ void RSSImp::on_updateAllButton_clicked() {
void RSSImp::downloadTorrent() { void RSSImp::downloadTorrent() {
QList<QListWidgetItem *> selected_items = listNews->selectedItems(); QList<QListWidgetItem *> selected_items = listNews->selectedItems();
foreach(const QListWidgetItem* item, selected_items) { foreach(const QListWidgetItem* item, selected_items) {
RssItem* news = rssmanager->getFeed(selectedFeedUrl)->getItem(listNews->row(item)); RssItem* news = rssmanager->getFeed(getCurrentFeedUrl())->getItem(listNews->row(item));
BTSession->downloadFromUrl(news->getTorrentUrl()); BTSession->downloadFromUrl(news->getTorrentUrl());
} }
} }
@ -164,7 +157,7 @@ void RSSImp::downloadTorrent() {
void RSSImp::openNewsUrl() { void RSSImp::openNewsUrl() {
QList<QListWidgetItem *> selected_items = listNews->selectedItems(); QList<QListWidgetItem *> selected_items = listNews->selectedItems();
foreach(const QListWidgetItem* item, selected_items) { foreach(const QListWidgetItem* item, selected_items) {
RssItem* news = rssmanager->getFeed(selectedFeedUrl)->getItem(listNews->row(item)); RssItem* news = rssmanager->getFeed(getCurrentFeedUrl())->getItem(listNews->row(item));
QString link = news->getLink(); QString link = news->getLink();
if(!link.isEmpty()) if(!link.isEmpty())
QDesktopServices::openUrl(QUrl(link)); QDesktopServices::openUrl(QUrl(link));
@ -247,12 +240,10 @@ void RSSImp::updateLastRefreshedTimeForStreams() {
// fills the newsList // fills the newsList
void RSSImp::refreshNewsList(QTreeWidgetItem* item) { void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
if(!item) { if(!item) {
selectedFeedUrl = QString::null;
listNews->clear(); listNews->clear();
return; return;
} }
selectedFeedUrl = item->text(1); RssStream *stream = rssmanager->getFeed(getCurrentFeedUrl());
RssStream *stream = rssmanager->getFeed(selectedFeedUrl);
qDebug("Getting the list of news"); qDebug("Getting the list of news");
QList<RssItem*> news = stream->getNewsList(); QList<RssItem*> news = stream->getNewsList();
// Clear the list first // Clear the list first
@ -277,7 +268,7 @@ void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
// display a news // display a news
void RSSImp::refreshTextBrowser(QListWidgetItem *item) { void RSSImp::refreshTextBrowser(QListWidgetItem *item) {
if(!item) return; if(!item) return;
RssItem* article = rssmanager->getFeed(selectedFeedUrl)->getItem(listNews->row(item)); RssItem* article = rssmanager->getFeed(getCurrentFeedUrl())->getItem(listNews->row(item));
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>";
@ -293,7 +284,7 @@ void RSSImp::refreshTextBrowser(QListWidgetItem *item) {
article->setRead(); article->setRead();
item->setData(Qt::ForegroundRole, QVariant(QColor("grey"))); item->setData(Qt::ForegroundRole, QVariant(QColor("grey")));
item->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png"))); item->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
updateFeedNbNews(selectedFeedUrl); updateFeedNbNews(getCurrentFeedUrl());
} }
void RSSImp::saveSlidersPosition() { void RSSImp::saveSlidersPosition() {
@ -339,6 +330,13 @@ void RSSImp::updateFeedNbNews(QString url){
item->setText(0, stream->getAliasOrUrl() + QString::fromUtf8(" (") + QString::number(stream->getNbUnRead(), 10)+ QString(")")); item->setText(0, stream->getAliasOrUrl() + QString::fromUtf8(" (") + QString::number(stream->getNbUnRead(), 10)+ QString(")"));
} }
QString RSSImp::getCurrentFeedUrl() const {
QTreeWidgetItem *item = listStreams->currentItem();
if(item)
return item->text(1);
return QString::null;
}
void RSSImp::updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnread){ void RSSImp::updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnread){
QTreeWidgetItem *item = getTreeItemFromUrl(url); QTreeWidgetItem *item = getTreeItemFromUrl(url);
RssStream *stream = rssmanager->getFeed(url); RssStream *stream = rssmanager->getFeed(url);
@ -346,14 +344,13 @@ void RSSImp::updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnr
item->setData(0,Qt::DecorationRole, QVariant(QIcon(stream->getIconPath()))); item->setData(0,Qt::DecorationRole, QVariant(QIcon(stream->getIconPath())));
item->setToolTip(0, QString::fromUtf8("<b>")+tr("Description:")+QString::fromUtf8("</b> ")+stream->getDescription()+QString::fromUtf8("<br/><b>")+tr("url:")+QString::fromUtf8("</b> ")+stream->getUrl()+QString::fromUtf8("<br/><b>")+tr("Last refresh:")+QString::fromUtf8("</b> ")+stream->getLastRefreshElapsedString()); item->setToolTip(0, QString::fromUtf8("<b>")+tr("Description:")+QString::fromUtf8("</b> ")+stream->getDescription()+QString::fromUtf8("<br/><b>")+tr("url:")+QString::fromUtf8("</b> ")+stream->getUrl()+QString::fromUtf8("<br/><b>")+tr("Last refresh:")+QString::fromUtf8("</b> ")+stream->getLastRefreshElapsedString());
// If the feed is selected, update the displayed news // If the feed is selected, update the displayed news
if(selectedFeedUrl == url){ if(listStreams->currentItem() == item){
refreshNewsList(item); refreshNewsList(item);
} }
} }
RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){ RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){
setupUi(this); setupUi(this);
selectedFeedUrl = QString::null;
// Hide second column (url) // Hide second column (url)
listStreams->hideColumn(1); listStreams->hideColumn(1);

2
src/rss_imp.h

@ -44,7 +44,6 @@ class RSSImp : public QWidget, public Ui::RSS{
private: private:
RssManager *rssmanager; RssManager *rssmanager;
QTimer *refreshTimeTimer; QTimer *refreshTimeTimer;
QString selectedFeedUrl;
bittorrent *BTSession; bittorrent *BTSession;
public slots: public slots:
@ -77,6 +76,7 @@ public:
RSSImp(bittorrent *BTSession); RSSImp(bittorrent *BTSession);
~RSSImp(); ~RSSImp();
QTreeWidgetItem* getTreeItemFromUrl(QString url) const; QTreeWidgetItem* getTreeItemFromUrl(QString url) const;
QString getCurrentFeedUrl() const;
}; };
#endif #endif

Loading…
Cancel
Save