From e126de8ff5a7289ce6aa4065c553e101a944645c Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 23 Aug 2009 13:05:47 +0000 Subject: [PATCH] - Always keep number of unread news per folders up to date - RefreshAllFeeds() only sets loading.png icon for feeds (and not folders) --- src/feedList.h | 4 ++++ src/rss.cpp | 7 +++++-- src/rss_imp.cpp | 24 +++++++++++++++--------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/feedList.h b/src/feedList.h index 725b4a83f..a7a9b9a32 100644 --- a/src/feedList.h +++ b/src/feedList.h @@ -46,6 +46,10 @@ public: return feeds_items.contains(QUrl(url).toString()); } + QList getAllFeedItems() { + return feeds_items.values(); + } + RssFile* getRSSItem(QTreeWidgetItem *item) { return mapping[item]; } diff --git a/src/rss.cpp b/src/rss.cpp index 214d98a53..8a8238567 100644 --- a/src/rss.cpp +++ b/src/rss.cpp @@ -49,8 +49,11 @@ RssFolder::~RssFolder() { } unsigned int RssFolder::getNbUnRead() const { - // FIXME - return 0; + unsigned int nb_unread = 0; + foreach(RssFile *file, this->values()) { + nb_unread += file->getNbUnRead(); + } + return nb_unread; } RssFile::FileType RssFolder::getType() const { diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp index c4f3a3b03..6221b2dce 100644 --- a/src/rss_imp.cpp +++ b/src/rss_imp.cpp @@ -202,9 +202,9 @@ void RSSImp::deleteSelectedItems() { // refresh all streams by a button void RSSImp::on_updateAllButton_clicked() { - unsigned int nbFeeds = listStreams->topLevelItemCount(); - for(unsigned int i=0; itopLevelItem(i)->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png"))); + foreach(QTreeWidgetItem *item, listStreams->getAllFeedItems()) { + item->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png"))); + } rssmanager->refreshAll(); } @@ -236,12 +236,12 @@ void RSSImp::renameFiles() { bool ok; QString newName; do { - newName = QInputDialog::getText(this, tr("Please choose a new name for this RSS feed"), tr("New feed name:"), QLineEdit::Normal, listStreams->getRSSItem(item)->getName(), &ok); - // Check if name is already taken - if(ok && rss_item->getParent()->contains(newName)) { - QMessageBox::warning(0, tr("Name already in use"), tr("This name is already used by another item, please choose another one.")); - ok = false; - } + newName = QInputDialog::getText(this, tr("Please choose a new name for this RSS feed"), tr("New feed name:"), QLineEdit::Normal, listStreams->getRSSItem(item)->getName(), &ok); + // Check if name is already taken + if(ok && rss_item->getParent()->contains(newName)) { + QMessageBox::warning(0, tr("Name already in use"), tr("This name is already used by another item, please choose another one.")); + ok = false; + } }while(!ok); if(ok) { // Rename item @@ -405,6 +405,9 @@ void RSSImp::updateItemsInfos(QList items) { void RSSImp::updateItemInfos(QTreeWidgetItem *item) { RssFile *rss_item = listStreams->getRSSItem(item); item->setText(0, rss_item->getName() + QString::fromUtf8(" (") + QString::number(rss_item->getNbUnRead(), 10)+ QString(")")); + // If item has a parent, update it too + if(item->parent()) + updateItemInfos(item->parent()); } void RSSImp::updateFeedIcon(QString url, QString icon_path){ @@ -422,6 +425,9 @@ void RSSImp::updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnr RssStream *stream = (RssStream*)listStreams->getRSSItem(item); item->setText(0, aliasOrUrl + QString::fromUtf8(" (") + QString::number(nbUnread, 10)+ QString(")")); item->setData(0,Qt::DecorationRole, QVariant(QIcon(stream->getIconPath()))); + // Update parent + if(item->parent()) + updateItemInfos(item->parent()); // If the feed is selected, update the displayed news if(listStreams->currentItem() == item){ refreshNewsList(item);