Browse Source

RSS code clean up

adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
fd2ba6f635
  1. 69
      src/rss/rss_imp.cpp
  2. 5
      src/rss/rss_imp.h
  3. 7
      src/rss/rssfeed.cpp
  4. 2
      src/rss/rssfeed.h
  5. 2
      src/rss/rssfile.h
  6. 9
      src/rss/rssfolder.cpp
  7. 1
      src/rss/rssfolder.h

69
src/rss/rss_imp.cpp

@ -150,17 +150,14 @@ void RSSImp::askNewFolder() {
bool ok; bool ok;
QString new_name = QInputDialog::getText(this, tr("Please choose a folder name"), tr("Folder name:"), QLineEdit::Normal, tr("New folder"), &ok); QString new_name = QInputDialog::getText(this, tr("Please choose a folder name"), tr("Folder name:"), QLineEdit::Normal, tr("New folder"), &ok);
if (ok) { if (ok) {
RssFolderPtr new_folder = rss_parent->addFolder(new_name); RssFolderPtr newFolder = rss_parent->addFolder(new_name);
QTreeWidgetItem* folder_item; QTreeWidgetItem* folderItem = createFolderListItem(newFolder);
if (parent_item) if (parent_item)
folder_item = new QTreeWidgetItem(parent_item); parent_item->addChild(folderItem);
else else
folder_item = new QTreeWidgetItem(m_feedList); m_feedList->addTopLevelItem(folderItem);
// Notify TreeWidget // Notify TreeWidget
m_feedList->itemAdded(folder_item, new_folder); m_feedList->itemAdded(folderItem, newFolder);
// Set Text
folder_item->setText(0, new_folder->displayName() + QString::fromUtf8(" (0)"));
folder_item->setData(0,Qt::DecorationRole, QVariant(IconProvider::instance()->getIcon("inode-directory")));
// Expand parent folder to display new folder // Expand parent folder to display new folder
if (parent_item) if (parent_item)
parent_item->setExpanded(true); parent_item->setExpanded(true);
@ -357,8 +354,8 @@ void RSSImp::downloadSelectedTorrents() {
} }
} }
// open the url of the news in a browser // open the url of the selected RSS articles in the Web browser
void RSSImp::openNewsUrl() { void RSSImp::openSelectedArticlesUrls() {
QList<QListWidgetItem *> selected_items = listArticles->selectedItems(); QList<QListWidgetItem *> selected_items = listArticles->selectedItems();
foreach (const QListWidgetItem* item, selected_items) { foreach (const QListWidgetItem* item, selected_items) {
RssArticlePtr news = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString()) RssArticlePtr news = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
@ -370,10 +367,10 @@ void RSSImp::openNewsUrl() {
} }
//right-click on stream : give it an alias //right-click on stream : give it an alias
void RSSImp::renameFiles() { void RSSImp::renameSelectedRssFile() {
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems(); QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
Q_ASSERT(selectedItems.size() == 1); Q_ASSERT(selectedItems.size() == 1);
QTreeWidgetItem *item = selectedItems.at(0); QTreeWidgetItem* item = selectedItems.first();
RssFilePtr rss_item = m_feedList->getRSSItem(item); RssFilePtr rss_item = m_feedList->getRSSItem(item);
bool ok; bool ok;
QString newName; QString newName;
@ -432,16 +429,27 @@ void RSSImp::copySelectedFeedsURL() {
void RSSImp::on_markReadButton_clicked() { void RSSImp::on_markReadButton_clicked() {
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems(); QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
QTreeWidgetItem* item; foreach (QTreeWidgetItem* item, selectedItems) {
foreach (item, selectedItems) {
RssFilePtr rss_item = m_feedList->getRSSItem(item); RssFilePtr rss_item = m_feedList->getRSSItem(item);
Q_ASSERT(rss_item);
rss_item->markAsRead(); rss_item->markAsRead();
updateItemInfos(item); updateItemInfos(item);
} }
if (selectedItems.size()) // Update article list
if (!selectedItems.isEmpty())
populateArticleList(m_feedList->currentItem()); populateArticleList(m_feedList->currentItem());
} }
QTreeWidgetItem* RSSImp::createFolderListItem(const RssFilePtr& rssFile)
{
Q_ASSERT(rssFile);
QTreeWidgetItem* item = new QTreeWidgetItem;
item->setData(0, Qt::DisplayRole, QVariant(rssFile->displayName()+ QString::fromUtf8(" (")+QString::number(rssFile->unreadCount(), 10)+QString(")")));
item->setData(0, Qt::DecorationRole, rssFile->icon());
return item;
}
void RSSImp::fillFeedsList(QTreeWidgetItem* parent, const RssFolderPtr& rss_parent) { void RSSImp::fillFeedsList(QTreeWidgetItem* parent, const RssFolderPtr& rss_parent) {
QList<RssFilePtr> children; QList<RssFilePtr> children;
if (parent) { if (parent) {
@ -449,25 +457,22 @@ void RSSImp::fillFeedsList(QTreeWidgetItem *parent, const RssFolderPtr& rss_pare
} else { } else {
children = m_rssManager->getContent(); children = m_rssManager->getContent();
} }
foreach (const RssFilePtr& rss_child, children) { foreach (const RssFilePtr& rssFile, children) {
QTreeWidgetItem* item; QTreeWidgetItem* item = createFolderListItem(rssFile);
if (!parent) Q_ASSERT(item);
item = new QTreeWidgetItem(m_feedList); if (parent)
parent->addChild(item);
else else
item = new QTreeWidgetItem(parent); m_feedList->addTopLevelItem(item);
item->setData(0, Qt::DisplayRole, QVariant(rss_child->displayName()+ QString::fromUtf8(" (")+QString::number(rss_child->unreadCount(), 10)+QString(")")));
// Notify TreeWidget of item addition // Notify TreeWidget of item addition
m_feedList->itemAdded(item, rss_child); m_feedList->itemAdded(item, rssFile);
// Set Icon
if (qSharedPointerDynamicCast<RssFeed>(rss_child)) { // Recursive call if this is a folder.
item->setData(0,Qt::DecorationRole, QVariant(QIcon(QString::fromUtf8(":/Icons/loading.png")))); if (RssFolderPtr folder = qSharedPointerDynamicCast<RssFolder>(rssFile))
} else if (RssFolderPtr folder = qSharedPointerDynamicCast<RssFolder>(rss_child)) {
item->setData(0,Qt::DecorationRole, QVariant(IconProvider::instance()->getIcon("inode-directory")));
// Recurvive call to load sub folders/files
fillFeedsList(item, folder); fillFeedsList(item, folder);
} }
} }
}
QListWidgetItem* RSSImp::createArticleListItem(const RssArticlePtr& article) QListWidgetItem* RSSImp::createArticleListItem(const RssArticlePtr& article)
{ {
@ -615,7 +620,7 @@ void RSSImp::updateFeedInfos(const QString& url, const QString& display_name, ui
RssFeedPtr stream = qSharedPointerCast<RssFeed>(m_feedList->getRSSItem(item)); RssFeedPtr stream = qSharedPointerCast<RssFeed>(m_feedList->getRSSItem(item));
item->setText(0, display_name + QString::fromUtf8(" (") + QString::number(nbUnread)+ QString(")")); item->setText(0, display_name + QString::fromUtf8(" (") + QString::number(nbUnread)+ QString(")"));
if (!stream->isLoading()) if (!stream->isLoading())
item->setData(0, Qt::DecorationRole, QVariant(QIcon(stream->icon()))); item->setData(0, Qt::DecorationRole, QVariant(stream->icon()));
// Update parent // Update parent
if (item->parent()) if (item->parent())
updateItemInfos(item->parent()); updateItemInfos(item->parent());
@ -681,7 +686,7 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent), m_rssManager(new RssManager)
// Feeds list actions // Feeds list actions
connect(actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelectedItems())); connect(actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelectedItems()));
connect(actionRename, SIGNAL(triggered()), this, SLOT(renameFiles())); connect(actionRename, SIGNAL(triggered()), this, SLOT(renameSelectedRssFile()));
connect(actionUpdate, SIGNAL(triggered()), this, SLOT(refreshSelectedItems())); connect(actionUpdate, SIGNAL(triggered()), this, SLOT(refreshSelectedItems()));
connect(actionNew_folder, SIGNAL(triggered()), this, SLOT(askNewFolder())); connect(actionNew_folder, SIGNAL(triggered()), this, SLOT(askNewFolder()));
connect(actionNew_subscription, SIGNAL(triggered()), this, SLOT(on_newFeedButton_clicked())); connect(actionNew_subscription, SIGNAL(triggered()), this, SLOT(on_newFeedButton_clicked()));
@ -690,7 +695,7 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent), m_rssManager(new RssManager)
connect(actionCopy_feed_URL, SIGNAL(triggered()), this, SLOT(copySelectedFeedsURL())); connect(actionCopy_feed_URL, SIGNAL(triggered()), this, SLOT(copySelectedFeedsURL()));
connect(actionMark_items_read, SIGNAL(triggered()), this, SLOT(on_markReadButton_clicked())); connect(actionMark_items_read, SIGNAL(triggered()), this, SLOT(on_markReadButton_clicked()));
// News list actions // News list actions
connect(actionOpen_news_URL, SIGNAL(triggered()), this, SLOT(openNewsUrl())); connect(actionOpen_news_URL, SIGNAL(triggered()), this, SLOT(openSelectedArticlesUrls()));
connect(actionDownload_torrent, SIGNAL(triggered()), this, SLOT(downloadSelectedTorrents())); connect(actionDownload_torrent, SIGNAL(triggered()), this, SLOT(downloadSelectedTorrents()));
connect(m_feedList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(populateArticleList(QTreeWidgetItem*))); connect(m_feedList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(populateArticleList(QTreeWidgetItem*)));

5
src/rss/rss_imp.h

@ -61,7 +61,7 @@ private slots:
void on_markReadButton_clicked(); void on_markReadButton_clicked();
void displayRSSListMenu(const QPoint&); void displayRSSListMenu(const QPoint&);
void displayItemsListMenu(const QPoint&); void displayItemsListMenu(const QPoint&);
void renameFiles(); void renameSelectedRssFile();
void refreshSelectedItems(); void refreshSelectedItems();
void copySelectedFeedsURL(); void copySelectedFeedsURL();
void populateArticleList(QTreeWidgetItem* item); void populateArticleList(QTreeWidgetItem* item);
@ -71,7 +71,7 @@ private slots:
void onFeedContentChanged(const QString& url); void onFeedContentChanged(const QString& url);
void updateItemsInfos(const QList<QTreeWidgetItem*> &items); void updateItemsInfos(const QList<QTreeWidgetItem*> &items);
void updateItemInfos(QTreeWidgetItem *item); void updateItemInfos(QTreeWidgetItem *item);
void openNewsUrl(); void openSelectedArticlesUrls();
void downloadSelectedTorrents(); void downloadSelectedTorrents();
void fillFeedsList(QTreeWidgetItem *parent=0, const RssFolderPtr& rss_parent = RssFolderPtr()); void fillFeedsList(QTreeWidgetItem *parent=0, const RssFolderPtr& rss_parent = RssFolderPtr());
void saveSlidersPosition(); void saveSlidersPosition();
@ -86,6 +86,7 @@ private slots:
private: private:
static QListWidgetItem* createArticleListItem(const RssArticlePtr& article); static QListWidgetItem* createArticleListItem(const RssArticlePtr& article);
static QTreeWidgetItem* createFolderListItem(const RssFilePtr& rssFile);
private: private:
RssManagerPtr m_rssManager; RssManagerPtr m_rssManager;

7
src/rss/rssfeed.cpp

@ -188,10 +188,11 @@ QString RssFeed::url() const {
return m_url; return m_url;
} }
QString RssFeed::icon() const { QIcon RssFeed::icon() const
{
if (m_inErrorState) if (m_inErrorState)
return ":/Icons/oxygen/unavailable.png"; return QIcon(":/Icons/oxygen/unavailable.png");
return m_icon; return QIcon(m_icon);
} }
bool RssFeed::hasCustomIcon() const { bool RssFeed::hasCustomIcon() const {

2
src/rss/rssfeed.h

@ -65,7 +65,7 @@ public:
virtual void rename(const QString &alias); virtual void rename(const QString &alias);
virtual QString displayName() const; virtual QString displayName() const;
QString url() const; QString url() const;
QString icon() const; virtual QIcon icon() const;
bool hasCustomIcon() const; bool hasCustomIcon() const;
void setIconPath(const QString &pathHierarchy); void setIconPath(const QString &pathHierarchy);
RssArticlePtr getItem(const QString &guid) const; RssArticlePtr getItem(const QString &guid) const;

2
src/rss/rssfile.h

@ -31,6 +31,7 @@
#ifndef RSSFILE_H #ifndef RSSFILE_H
#define RSSFILE_H #define RSSFILE_H
#include <QIcon>
#include <QList> #include <QList>
#include <QStringList> #include <QStringList>
#include <QSharedPointer> #include <QSharedPointer>
@ -54,6 +55,7 @@ public:
virtual uint unreadCount() const = 0; virtual uint unreadCount() const = 0;
virtual QString displayName() const = 0; virtual QString displayName() const = 0;
virtual QString id() const = 0; virtual QString id() const = 0;
virtual QIcon icon() const = 0;
virtual void rename(const QString &new_name) = 0; virtual void rename(const QString &new_name) = 0;
virtual void markAsRead() = 0; virtual void markAsRead() = 0;
virtual RssFolder* parent() const = 0; virtual RssFolder* parent() const = 0;

9
src/rss/rssfolder.cpp

@ -30,6 +30,7 @@
#include <QDebug> #include <QDebug>
#include "iconprovider.h"
#include "rssfolder.h" #include "rssfolder.h"
#include "rssarticle.h" #include "rssarticle.h"
#include "qbtsession.h" #include "qbtsession.h"
@ -225,10 +226,16 @@ void RssFolder::saveItemsToDisk()
} }
} }
QString RssFolder::id() const { QString RssFolder::id() const
{
return m_name; return m_name;
} }
QIcon RssFolder::icon() const
{
return IconProvider::instance()->getIcon("inode-directory");
}
bool RssFolder::hasChild(const QString &childId) { bool RssFolder::hasChild(const QString &childId) {
return m_children.contains(childId); return m_children.contains(childId);
} }

1
src/rss/rssfolder.h

@ -61,6 +61,7 @@ public:
QHash<QString, RssFeedPtr> getAllFeedsAsHash() const; QHash<QString, RssFeedPtr> getAllFeedsAsHash() const;
virtual QString displayName() const; virtual QString displayName() const;
virtual QString id() const; virtual QString id() const;
virtual QIcon icon() const;
bool hasChild(const QString &childId); bool hasChild(const QString &childId);
virtual RssArticleList articleListByDateDesc() const; virtual RssArticleList articleListByDateDesc() const;
virtual RssArticleList unreadArticleListByDateDesc() const; virtual RssArticleList unreadArticleListByDateDesc() const;

Loading…
Cancel
Save