Browse Source

RSS code clean up

adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
0efcdbaf52
  1. 66
      src/rss/rss_imp.cpp
  2. 5
      src/rss/rss_imp.h

66
src/rss/rss_imp.cpp

@ -447,7 +447,7 @@ void RSSImp::on_markReadButton_clicked() {
updateItemInfos(item); updateItemInfos(item);
} }
if (selectedItems.size()) if (selectedItems.size())
refreshArticleList(m_feedList->currentItem()); populateArticleList(m_feedList->currentItem());
} }
void RSSImp::fillFeedsList(QTreeWidgetItem *parent, const RssFolderPtr& rss_parent) { void RSSImp::fillFeedsList(QTreeWidgetItem *parent, const RssFolderPtr& rss_parent) {
@ -477,42 +477,55 @@ void RSSImp::fillFeedsList(QTreeWidgetItem *parent, const RssFolderPtr& rss_pare
} }
} }
QListWidgetItem* RSSImp::createArticleListItem(const RssArticlePtr& article)
{
Q_ASSERT(article);
QListWidgetItem* item = new QListWidgetItem;
item->setData(Article::TitleRole, article->title());
item->setData(Article::FeedUrlRole, article->parent()->url());
item->setData(Article::IdRole, article->guid());
if (article->isRead()) {
item->setData(Article::ColorRole, QVariant(QColor("grey")));
item->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere.png")));
} else {
item->setData(Article::ColorRole, QVariant(QColor("blue")));
item->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere2.png")));
}
return item;
}
// fills the newsList // fills the newsList
void RSSImp::refreshArticleList(QTreeWidgetItem* item) { void RSSImp::populateArticleList(QTreeWidgetItem* item)
{
if (!item) { if (!item) {
listArticles->clear(); listArticles->clear();
return; return;
} }
RssFilePtr rss_item = m_feedList->getRSSItem(item); RssFilePtr rss_item = m_feedList->getRSSItem(item);
if (!rss_item) return; if (!rss_item)
return;
qDebug("Getting the list of news");
RssArticleList news;
if (rss_item == m_rssManager)
news = rss_item->unreadArticleListByDateDesc();
else if (rss_item)
news = rss_item->articleListByDateDesc();
// Clear the list first // Clear the list first
textBrowser->clear(); textBrowser->clear();
m_currentArticle = 0; m_currentArticle = 0;
listArticles->clear(); listArticles->clear();
qDebug("Getting the list of news");
RssArticleList articles;
if (rss_item == m_rssManager)
articles = rss_item->unreadArticleListByDateDesc();
else
articles = rss_item->articleListByDateDesc();
qDebug("Got the list of news"); qDebug("Got the list of news");
foreach (const RssArticlePtr &article, news) { foreach (const RssArticlePtr& article, articles) {
QListWidgetItem* it = new QListWidgetItem(listArticles); QListWidgetItem* articleItem = createArticleListItem(article);
it->setData(Article::TitleRole, article->title()); listArticles->addItem(articleItem);
it->setData(Article::FeedUrlRole, article->parent()->url());
it->setData(Article::IdRole, article->guid());
if (article->isRead()) {
it->setData(Article::ColorRole, QVariant(QColor("grey")));
it->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere.png")));
}else{
it->setData(Article::ColorRole, QVariant(QColor("blue")));
it->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere2.png")));
}
} }
qDebug("Added all news to the GUI"); qDebug("Added all news to the GUI");
qDebug("First news selected");
} }
// display a news // display a news
@ -624,11 +637,11 @@ void RSSImp::onFeedContentChanged(const QString& url)
QTreeWidgetItem *item = m_feedList->getTreeItemFromUrl(url); QTreeWidgetItem *item = m_feedList->getTreeItemFromUrl(url);
// If the feed is selected, update the displayed news // If the feed is selected, update the displayed news
if (m_feedList->currentItem() == item ) { if (m_feedList->currentItem() == item ) {
refreshArticleList(item); populateArticleList(item);
} else { } else {
// Update unread items // Update unread items
if (m_feedList->currentItem() == m_feedList->stickyUnreadItem()) { if (m_feedList->currentItem() == m_feedList->stickyUnreadItem()) {
refreshArticleList(m_feedList->stickyUnreadItem()); populateArticleList(m_feedList->stickyUnreadItem());
} }
} }
} }
@ -664,7 +677,7 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent), m_rssManager(new RssManager)
m_rssManager->loadStreamList(); m_rssManager->loadStreamList();
fillFeedsList(); fillFeedsList();
refreshArticleList(m_feedList->currentItem()); populateArticleList(m_feedList->currentItem());
loadFoldersOpenState(); loadFoldersOpenState();
connect(m_rssManager.data(), SIGNAL(feedInfosChanged(QString, QString, unsigned int)), SLOT(updateFeedInfos(QString, QString, unsigned int))); connect(m_rssManager.data(), SIGNAL(feedInfosChanged(QString, QString, unsigned int)), SLOT(updateFeedInfos(QString, QString, unsigned int)));
@ -687,7 +700,7 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent), m_rssManager(new RssManager)
connect(actionOpen_news_URL, SIGNAL(triggered()), this, SLOT(openNewsUrl())); connect(actionOpen_news_URL, SIGNAL(triggered()), this, SLOT(openNewsUrl()));
connect(actionDownload_torrent, SIGNAL(triggered()), this, SLOT(downloadTorrent())); connect(actionDownload_torrent, SIGNAL(triggered()), this, SLOT(downloadTorrent()));
connect(m_feedList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(refreshArticleList(QTreeWidgetItem*))); connect(m_feedList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(populateArticleList(QTreeWidgetItem*)));
connect(m_feedList, SIGNAL(foldersAltered(QList<QTreeWidgetItem*>)), this, SLOT(updateItemsInfos(QList<QTreeWidgetItem*>))); connect(m_feedList, SIGNAL(foldersAltered(QList<QTreeWidgetItem*>)), this, SLOT(updateItemsInfos(QList<QTreeWidgetItem*>)));
connect(m_feedList, SIGNAL(overwriteAttempt(QString)), this, SLOT(displayOverwriteError(QString))); connect(m_feedList, SIGNAL(overwriteAttempt(QString)), this, SLOT(displayOverwriteError(QString)));
@ -712,7 +725,6 @@ RSSImp::~RSSImp() {
qDebug("RSSImp deleted"); qDebug("RSSImp deleted");
} }
void RSSImp::on_settingsButton_clicked() { void RSSImp::on_settingsButton_clicked() {
RssSettingsDlg dlg(this); RssSettingsDlg dlg(this);
if (dlg.exec()) if (dlg.exec())

5
src/rss/rss_imp.h

@ -64,7 +64,7 @@ private slots:
void renameFiles(); void renameFiles();
void refreshSelectedItems(); void refreshSelectedItems();
void copySelectedFeedsURL(); void copySelectedFeedsURL();
void refreshArticleList(QTreeWidgetItem* item); void populateArticleList(QTreeWidgetItem* item);
void refreshTextBrowser(); void refreshTextBrowser();
void updateFeedIcon(const QString &url, const QString &icon_path); void updateFeedIcon(const QString &url, const QString &icon_path);
void updateFeedInfos(const QString &url, const QString &display_name, uint nbUnread); void updateFeedInfos(const QString &url, const QString &display_name, uint nbUnread);
@ -84,6 +84,9 @@ private slots:
void on_settingsButton_clicked(); void on_settingsButton_clicked();
void on_rssDownloaderBtn_clicked(); void on_rssDownloaderBtn_clicked();
private:
static QListWidgetItem* createArticleListItem(const RssArticlePtr& article);
private: private:
RssManagerPtr m_rssManager; RssManagerPtr m_rssManager;
FeedListWidget *m_feedList; FeedListWidget *m_feedList;

Loading…
Cancel
Save