Browse Source

Rss code clean up

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
87174ef3a4
  1. 91
      src/rss/feedlistwidget.cpp
  2. 36
      src/rss/feedlistwidget.h
  3. 1
      src/rss/rss.pri
  4. 196
      src/rss/rss_imp.cpp
  5. 22
      src/rss/rss_imp.h
  6. 4
      src/rss/rssfeed.cpp
  7. 2
      src/rss/rssfeed.h
  8. 40
      src/rss/rssfile.cpp
  9. 18
      src/rss/rssfile.h
  10. 40
      src/rss/rssfolder.cpp
  11. 10
      src/rss/rssfolder.h
  12. 2
      src/rss/rssmanager.cpp
  13. 2
      src/rss/rssmanager.h
  14. 1
      src/rss/rsssettings.h

91
src/rss/feedlistwidget.cpp

@ -33,54 +33,53 @@ @@ -33,54 +33,53 @@
#include "rssfeed.h"
#include "iconprovider.h"
FeedListWidget::FeedListWidget(QWidget *parent, RssManager *rssmanager): QTreeWidget(parent), rssmanager(rssmanager) {
FeedListWidget::FeedListWidget(QWidget *parent, RssManager *rssmanager): QTreeWidget(parent), m_rssManager(rssmanager) {
setContextMenuPolicy(Qt::CustomContextMenu);
setDragDropMode(QAbstractItemView::InternalMove);
setSelectionMode(QAbstractItemView::ExtendedSelection);
setColumnCount(1);
headerItem()->setText(0, tr("RSS feeds"));
unread_item = new QTreeWidgetItem(this);
unread_item->setText(0, tr("Unread") + QString::fromUtf8(" (") + QString::number(rssmanager->unreadCount(), 10)+ QString(")"));
unread_item->setData(0,Qt::DecorationRole, IconProvider::instance()->getIcon("mail-folder-inbox"));
itemAdded(unread_item, rssmanager);
connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(updateCurrentFeed(QTreeWidgetItem*)));
setCurrentItem(unread_item);
m_unreadStickyItem = new QTreeWidgetItem(this);
m_unreadStickyItem->setText(0, tr("Unread") + QString::fromUtf8(" (") + QString::number(rssmanager->unreadCount(), 10)+ QString(")"));
m_unreadStickyItem->setData(0,Qt::DecorationRole, IconProvider::instance()->getIcon("mail-folder-inbox"));
itemAdded(m_unreadStickyItem, rssmanager);
connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), SLOT(updateCurrentFeed(QTreeWidgetItem*)));
setCurrentItem(m_unreadStickyItem);
}
FeedListWidget::~FeedListWidget() {
disconnect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(updateCurrentFeed(QTreeWidgetItem*)));
delete unread_item;
delete m_unreadStickyItem;
}
void FeedListWidget::itemAdded(QTreeWidgetItem *item, RssFile* file) {
mapping[item] = file;
if(file->type() == RssFile::FEED) {
feeds_items[file->id()] = item;
void FeedListWidget::itemAdded(QTreeWidgetItem *item, IRssFile* file) {
m_rssMapping[item] = file;
if(file->type() == IRssFile::FEED) {
m_feedsItems[file->id()] = item;
}
}
void FeedListWidget::itemAboutToBeRemoved(QTreeWidgetItem *item) {
RssFile* file = mapping.take(item);
if(file->type() == RssFile::FEED) {
feeds_items.remove(file->id());
IRssFile* file = m_rssMapping.take(item);
if(file->type() == IRssFile::FEED) {
m_feedsItems.remove(file->id());
} else {
QList<RssFeed*> feeds = ((RssFolder*)file)->getAllFeeds();
foreach(RssFeed* feed, feeds) {
feeds_items.remove(feed->id());
m_feedsItems.remove(feed->id());
}
}
}
bool FeedListWidget::hasFeed(QString url) const {
return feeds_items.contains(QUrl(url).toString());
bool FeedListWidget::hasFeed(const QString &url) const {
return m_feedsItems.contains(QUrl(url).toString());
}
QList<QTreeWidgetItem*> FeedListWidget::getAllFeedItems() const {
return feeds_items.values();
return m_feedsItems.values();
}
QTreeWidgetItem* FeedListWidget::getUnreadItem() const {
return unread_item;
QTreeWidgetItem* FeedListWidget::stickyUnreadItem() const {
return m_unreadStickyItem;
}
QStringList FeedListWidget::getItemPath(QTreeWidgetItem* item) const {
@ -106,7 +105,7 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllOpenFolders(QTreeWidgetItem *paren @@ -106,7 +105,7 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllOpenFolders(QTreeWidgetItem *paren
item = parent->child(i);
else
item = topLevelItem(i);
if(getItemType(item) == RssFile::FOLDER && item->isExpanded()) {
if(getItemType(item) == IRssFile::FOLDER && item->isExpanded()) {
QList<QTreeWidgetItem*> open_subfolders = getAllOpenFolders(item);
if(!open_subfolders.empty()) {
open_folders << open_subfolders;
@ -120,10 +119,10 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllOpenFolders(QTreeWidgetItem *paren @@ -120,10 +119,10 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllOpenFolders(QTreeWidgetItem *paren
QList<QTreeWidgetItem*> FeedListWidget::getAllFeedItems(QTreeWidgetItem* folder) {
QList<QTreeWidgetItem*> feeds;
int nbChildren = folder->childCount();
const int nbChildren = folder->childCount();
for(int i=0; i<nbChildren; ++i) {
QTreeWidgetItem *item = folder->child(i);
if(getItemType(item) == RssFile::FEED) {
if(getItemType(item) == IRssFile::FEED) {
feeds << item;
} else {
feeds << getAllFeedItems(item);
@ -132,50 +131,50 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllFeedItems(QTreeWidgetItem* folder) @@ -132,50 +131,50 @@ QList<QTreeWidgetItem*> FeedListWidget::getAllFeedItems(QTreeWidgetItem* folder)
return feeds;
}
RssFile* FeedListWidget::getRSSItem(QTreeWidgetItem *item) const {
return mapping.value(item, 0);
IRssFile* FeedListWidget::getRSSItem(QTreeWidgetItem *item) const {
return m_rssMapping.value(item, 0);
}
RssFile::FileType FeedListWidget::getItemType(QTreeWidgetItem *item) const {
return mapping.value(item)->type();
IRssFile::FileType FeedListWidget::getItemType(QTreeWidgetItem *item) const {
return m_rssMapping.value(item)->type();
}
QString FeedListWidget::getItemID(QTreeWidgetItem *item) const {
return mapping.value(item)->id();
return m_rssMapping.value(item)->id();
}
QTreeWidgetItem* FeedListWidget::getTreeItemFromUrl(QString url) const{
return feeds_items.value(url, 0);
QTreeWidgetItem* FeedListWidget::getTreeItemFromUrl(const QString &url) const{
return m_feedsItems.value(url, 0);
}
RssFeed* FeedListWidget::getRSSItemFromUrl(QString url) const {
return (RssFeed*)getRSSItem(getTreeItemFromUrl(url));
RssFeed* FeedListWidget::getRSSItemFromUrl(const QString &url) const {
return dynamic_cast<RssFeed*>(getRSSItem(getTreeItemFromUrl(url)));
}
QTreeWidgetItem* FeedListWidget::currentItem() const {
return current_feed;
return m_currentFeed;
}
QTreeWidgetItem* FeedListWidget::currentFeed() const {
return current_feed;
return m_currentFeed;
}
void FeedListWidget::updateCurrentFeed(QTreeWidgetItem* new_item) {
if(!new_item) return;
if(!mapping.contains(new_item)) return;
if((getItemType(new_item) == RssFile::FEED) || new_item == unread_item)
current_feed = new_item;
if(!m_rssMapping.contains(new_item)) return;
if((getItemType(new_item) == IRssFile::FEED) || new_item == m_unreadStickyItem)
m_currentFeed = new_item;
}
void FeedListWidget::dragMoveEvent(QDragMoveEvent * event) {
QTreeWidgetItem *item = itemAt(event->pos());
if(item == unread_item) {
if(item == m_unreadStickyItem) {
event->ignore();
} else {
if(item && getItemType(item) != RssFile::FOLDER)
if(item && getItemType(item) != IRssFile::FOLDER)
event->ignore();
else {
if(selectedItems().contains(unread_item)) {
if(selectedItems().contains(m_unreadStickyItem)) {
event->ignore();
} else {
QTreeWidget::dragMoveEvent(event);
@ -193,12 +192,12 @@ void FeedListWidget::dropEvent(QDropEvent *event) { @@ -193,12 +192,12 @@ void FeedListWidget::dropEvent(QDropEvent *event) {
dest_folder = (RssFolder*)getRSSItem(dest_folder_item);
folders_altered << dest_folder_item;
} else {
dest_folder = rssmanager;
dest_folder = m_rssManager;
}
QList<QTreeWidgetItem *> src_items = selectedItems();
// Check if there is not going to overwrite another file
foreach(QTreeWidgetItem *src_item, src_items) {
RssFile *file = getRSSItem(src_item);
IRssFile *file = getRSSItem(src_item);
if(dest_folder->hasChild(file->id())) {
emit overwriteAttempt(file->id());
return;
@ -210,8 +209,8 @@ void FeedListWidget::dropEvent(QDropEvent *event) { @@ -210,8 +209,8 @@ void FeedListWidget::dropEvent(QDropEvent *event) {
if(parent_folder && !folders_altered.contains(parent_folder))
folders_altered << parent_folder;
// Actually move the file
RssFile *file = getRSSItem(src_item);
rssmanager->moveFile(file, dest_folder);
IRssFile *file = getRSSItem(src_item);
m_rssManager->moveFile(file, dest_folder);
}
QTreeWidget::dropEvent(event);
if(dest_folder_item)

36
src/rss/feedlistwidget.h

@ -48,30 +48,32 @@ class FeedListWidget: public QTreeWidget { @@ -48,30 +48,32 @@ class FeedListWidget: public QTreeWidget {
Q_OBJECT
public:
FeedListWidget(QWidget *parent, RssManager *rssmanager);
FeedListWidget(QWidget *parent, RssManager *m_rssManager);
~FeedListWidget();
void itemAdded(QTreeWidgetItem *item, RssFile* file);
void itemAboutToBeRemoved(QTreeWidgetItem *item);
bool hasFeed(QString url) const;
bool hasFeed(const QString &url) const;
QList<QTreeWidgetItem*> getAllFeedItems() const;
QTreeWidgetItem* getUnreadItem() const;
QTreeWidgetItem* stickyUnreadItem() const;
QStringList getItemPath(QTreeWidgetItem* item) const;
QList<QTreeWidgetItem*> getAllOpenFolders(QTreeWidgetItem *parent=0) const;
QList<QTreeWidgetItem*> getAllFeedItems(QTreeWidgetItem* folder);
RssFile* getRSSItem(QTreeWidgetItem *item) const;
RssFile::FileType getItemType(QTreeWidgetItem *item) const;
IRssFile* getRSSItem(QTreeWidgetItem *item) const;
IRssFile::FileType getItemType(QTreeWidgetItem *item) const;
QString getItemID(QTreeWidgetItem *item) const;
QTreeWidgetItem* getTreeItemFromUrl(QString url) const;
RssFeed* getRSSItemFromUrl(QString url) const;
QTreeWidgetItem* getTreeItemFromUrl(const QString &url) const;
RssFeed* getRSSItemFromUrl(const QString &url) const;
QTreeWidgetItem* currentItem() const;
QTreeWidgetItem* currentFeed() const;
public slots:
void itemAdded(QTreeWidgetItem *item, IRssFile* file);
void itemAboutToBeRemoved(QTreeWidgetItem *item);
signals:
void foldersAltered(QList<QTreeWidgetItem*> folders);
void overwriteAttempt(QString filename);
void foldersAltered(const QList<QTreeWidgetItem*> &folders);
void overwriteAttempt(const QString &filename);
protected slots:
private slots:
void updateCurrentFeed(QTreeWidgetItem* new_item);
protected:
@ -79,11 +81,11 @@ protected: @@ -79,11 +81,11 @@ protected:
void dropEvent(QDropEvent *event);
private:
RssManager *rssmanager;
QHash<QTreeWidgetItem*, RssFile*> mapping;
QHash<QString, QTreeWidgetItem*> feeds_items;
QTreeWidgetItem* current_feed;
QTreeWidgetItem *unread_item;
RssManager *m_rssManager;
QHash<QTreeWidgetItem*, IRssFile*> m_rssMapping;
QHash<QString, QTreeWidgetItem*> m_feedsItems;
QTreeWidgetItem* m_currentFeed;
QTreeWidgetItem *m_unreadStickyItem;
};
#endif // FEEDLIST_H

1
src/rss/rss.pri

@ -25,6 +25,7 @@ SOURCES += $$PWD/rss_imp.cpp \ @@ -25,6 +25,7 @@ SOURCES += $$PWD/rss_imp.cpp \
$$PWD/rssdownloadrule.cpp \
$$PWD/rssdownloadrulelist.cpp \
$$PWD/cookiesdlg.cpp \
rss/rssfile.cpp
FORMS += $$PWD/rss.ui \
$$PWD/rsssettingsdlg.ui \

196
src/rss/rss_imp.cpp

@ -63,22 +63,22 @@ enum ArticleRoles { @@ -63,22 +63,22 @@ enum ArticleRoles {
// display a right-click menu
void RSSImp::displayRSSListMenu(const QPoint& pos){
if(!listStreams->indexAt(pos).isValid()) {
if(!m_feedList->indexAt(pos).isValid()) {
// No item under the mouse, clear selection
listStreams->clearSelection();
m_feedList->clearSelection();
}
QMenu myRSSListMenu(this);
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
if(selectedItems.size() > 0) {
myRSSListMenu.addAction(actionUpdate);
myRSSListMenu.addAction(actionMark_items_read);
myRSSListMenu.addSeparator();
if(selectedItems.size() == 1) {
if(listStreams->getRSSItem(selectedItems.first()) != rssmanager) {
if(m_feedList->getRSSItem(selectedItems.first()) != m_rssManager) {
myRSSListMenu.addAction(actionRename);
myRSSListMenu.addAction(actionDelete);
myRSSListMenu.addSeparator();
if(listStreams->getItemType(selectedItems.first()) == RssFile::FOLDER) {
if(m_feedList->getItemType(selectedItems.first()) == IRssFile::FOLDER) {
myRSSListMenu.addAction(actionNew_folder);
} else {
myRSSListMenu.addAction(actionManage_cookies);
@ -86,7 +86,7 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){ @@ -86,7 +86,7 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){
}
}
myRSSListMenu.addAction(actionNew_subscription);
if(listStreams->getItemType(selectedItems.first()) == RssFile::FEED) {
if(m_feedList->getItemType(selectedItems.first()) == IRssFile::FEED) {
myRSSListMenu.addSeparator();
myRSSListMenu.addAction(actionCopy_feed_URL);
}
@ -107,7 +107,7 @@ void RSSImp::displayItemsListMenu(const QPoint&){ @@ -107,7 +107,7 @@ void RSSImp::displayItemsListMenu(const QPoint&){
foreach(const QListWidgetItem *item, selectedItems) {
qDebug("text(3) URL: %s", qPrintable(item->data(Article::FeedUrlRole).toString()));
qDebug("text(2) TITLE: %s", qPrintable(item->data(Article::TitleRole).toString()));
if(listStreams->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
if(m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
->getItem(item->data(Article::IdRole).toString()).hasAttachment()) {
has_attachment = true;
break;
@ -121,9 +121,9 @@ void RSSImp::displayItemsListMenu(const QPoint&){ @@ -121,9 +121,9 @@ void RSSImp::displayItemsListMenu(const QPoint&){
}
void RSSImp::on_actionManage_cookies_triggered() {
Q_ASSERT(!listStreams->selectedItems().empty());
Q_ASSERT(!m_feedList->selectedItems().empty());
// Get feed hostname
QString feed_url = listStreams->getItemID(listStreams->selectedItems().first());
QString feed_url = m_feedList->getItemID(m_feedList->selectedItems().first());
QString feed_hostname = QUrl::fromEncoded(feed_url.toLocal8Bit()).host();
qDebug("RSS Feed hostname is: %s", qPrintable(feed_hostname));
Q_ASSERT(!feed_hostname.isEmpty());
@ -138,12 +138,12 @@ void RSSImp::on_actionManage_cookies_triggered() { @@ -138,12 +138,12 @@ void RSSImp::on_actionManage_cookies_triggered() {
void RSSImp::askNewFolder() {
QTreeWidgetItem *parent_item = 0;
RssFolder *rss_parent;
if(listStreams->selectedItems().size() > 0) {
parent_item = listStreams->selectedItems().at(0);
rss_parent = (RssFolder*)listStreams->getRSSItem(parent_item);
Q_ASSERT(rss_parent->type() == RssFile::FOLDER);
if(m_feedList->selectedItems().size() > 0) {
parent_item = m_feedList->selectedItems().at(0);
rss_parent = dynamic_cast<RssFolder*>(m_feedList->getRSSItem(parent_item));
Q_ASSERT(rss_parent->type() == IRssFile::FOLDER);
} else {
rss_parent = rssmanager;
rss_parent = m_rssManager;
}
bool ok;
QString new_name = QInputDialog::getText(this, tr("Please choose a folder name"), tr("Folder name:"), QLineEdit::Normal, tr("New folder"), &ok);
@ -153,20 +153,20 @@ void RSSImp::askNewFolder() { @@ -153,20 +153,20 @@ void RSSImp::askNewFolder() {
if(parent_item)
folder_item = new QTreeWidgetItem(parent_item);
else
folder_item = new QTreeWidgetItem(listStreams);
folder_item = new QTreeWidgetItem(m_feedList);
// Notify TreeWidget
listStreams->itemAdded(folder_item, new_folder);
m_feedList->itemAdded(folder_item, new_folder);
// 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
if(parent_item)
parent_item->setExpanded(true);
rssmanager->saveStreamList();
m_rssManager->saveStreamList();
}
}
void RSSImp::displayOverwriteError(QString filename) {
void RSSImp::displayOverwriteError(const QString &filename) {
QMessageBox::warning(this, tr("Overwrite attempt"),
tr("You cannot overwrite %1 item.", "You cannot overwrite myFolder item.").arg(filename),
QMessageBox::Ok);
@ -176,22 +176,22 @@ void RSSImp::displayOverwriteError(QString filename) { @@ -176,22 +176,22 @@ void RSSImp::displayOverwriteError(QString filename) {
void RSSImp::on_newFeedButton_clicked() {
// Determine parent folder for new feed
QTreeWidgetItem *parent_item = 0;
QList<QTreeWidgetItem *> selected_items = listStreams->selectedItems();
QList<QTreeWidgetItem *> selected_items = m_feedList->selectedItems();
if(!selected_items.empty()) {
parent_item = selected_items.first();
// Consider the case where the user clicked on Unread item
if(parent_item == listStreams->getUnreadItem()) {
if(parent_item == m_feedList->stickyUnreadItem()) {
parent_item = 0;
} else {
if(listStreams->getItemType(parent_item) != RssFile::FOLDER)
if(m_feedList->getItemType(parent_item) != IRssFile::FOLDER)
parent_item = parent_item->parent();
}
}
RssFolder *rss_parent;
if(parent_item) {
rss_parent = (RssFolder*)listStreams->getRSSItem(parent_item);
rss_parent = (RssFolder*)m_feedList->getRSSItem(parent_item);
} else {
rss_parent = rssmanager;
rss_parent = m_rssManager;
}
// Ask for feed URL
bool ok;
@ -204,7 +204,7 @@ void RSSImp::on_newFeedButton_clicked() { @@ -204,7 +204,7 @@ void RSSImp::on_newFeedButton_clicked() {
if(ok) {
newUrl = newUrl.trimmed();
if(!newUrl.isEmpty()){
if(listStreams->hasFeed(newUrl)) {
if(m_feedList->hasFeed(newUrl)) {
QMessageBox::warning(this, tr("qBittorrent"),
tr("This rss feed is already in the list."),
QMessageBox::Ok);
@ -216,21 +216,21 @@ void RSSImp::on_newFeedButton_clicked() { @@ -216,21 +216,21 @@ void RSSImp::on_newFeedButton_clicked() {
if(parent_item)
item = new QTreeWidgetItem(parent_item);
else
item = new QTreeWidgetItem(listStreams);
item = new QTreeWidgetItem(m_feedList);
// Notify TreeWidget
listStreams->itemAdded(item, stream);
m_feedList->itemAdded(item, stream);
// Set text
item->setText(0, stream->displayName() + QString::fromUtf8(" (0)"));
item->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
stream->refresh();
rssmanager->saveStreamList();
m_rssManager->saveStreamList();
}
}
}
// delete a stream by a button
void RSSImp::deleteSelectedItems() {
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
if(selectedItems.size() == 0) return;
int ret;
if(selectedItems.size() > 1)
@ -243,21 +243,21 @@ void RSSImp::deleteSelectedItems() { @@ -243,21 +243,21 @@ void RSSImp::deleteSelectedItems() {
QString(), 0, 1);
if(!ret) {
foreach(QTreeWidgetItem *item, selectedItems){
if(listStreams->currentFeed() == item){
if(m_feedList->currentFeed() == item){
textBrowser->clear();
m_currentArticle = 0;
listArticles->clear();
}
RssFile *rss_item = listStreams->getRSSItem(item);
IRssFile *rss_item = m_feedList->getRSSItem(item);
// Notify TreeWidget
listStreams->itemAboutToBeRemoved(item);
m_feedList->itemAboutToBeRemoved(item);
// Actually delete the item
rss_item->parent()->removeChild(rss_item->id());
delete item;
}
rssmanager->saveStreamList();
m_rssManager->saveStreamList();
// Update Unread items
updateItemInfos(listStreams->getUnreadItem());
updateItemInfos(m_feedList->stickyUnreadItem());
}
}
@ -274,14 +274,14 @@ void RSSImp::loadFoldersOpenState() { @@ -274,14 +274,14 @@ void RSSImp::loadFoldersOpenState() {
if(parent)
nbChildren = parent->childCount();
else
nbChildren = listStreams->topLevelItemCount();
nbChildren = m_feedList->topLevelItemCount();
for(int i=0; i<nbChildren; ++i) {
QTreeWidgetItem* child;
if(parent)
child = parent->child(i);
else
child = listStreams->topLevelItem(i);
if(listStreams->getRSSItem(child)->id() == name) {
child = m_feedList->topLevelItem(i);
if(m_feedList->getRSSItem(child)->id() == name) {
parent = child;
parent->setExpanded(true);
qDebug("expanding folder %s", qPrintable(name));
@ -294,9 +294,9 @@ void RSSImp::loadFoldersOpenState() { @@ -294,9 +294,9 @@ void RSSImp::loadFoldersOpenState() {
void RSSImp::saveFoldersOpenState() {
QStringList open_folders;
QList<QTreeWidgetItem*> items = listStreams->getAllOpenFolders();
QList<QTreeWidgetItem*> items = m_feedList->getAllOpenFolders();
foreach(QTreeWidgetItem* item, items) {
QString path = listStreams->getItemPath(item).join("\\");
QString path = m_feedList->getItemPath(item).join("\\");
qDebug("saving open folder: %s", qPrintable(path));
open_folders << path;
}
@ -308,16 +308,16 @@ void RSSImp::saveFoldersOpenState() { @@ -308,16 +308,16 @@ void RSSImp::saveFoldersOpenState() {
// refresh all streams by a button
void RSSImp::on_updateAllButton_clicked() {
foreach(QTreeWidgetItem *item, listStreams->getAllFeedItems()) {
foreach(QTreeWidgetItem *item, m_feedList->getAllFeedItems()) {
item->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
}
rssmanager->refresh();
m_rssManager->refresh();
}
void RSSImp::downloadTorrent() {
QList<QListWidgetItem *> selected_items = listArticles->selectedItems();
foreach(const QListWidgetItem* item, selected_items) {
const RssArticle article = listStreams->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
const RssArticle article = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
->getItem(item->data(Article::IdRole).toString());
if(article.hasAttachment()) {
QBtSession::instance()->downloadFromUrl(article.torrentUrl());
@ -331,7 +331,7 @@ void RSSImp::downloadTorrent() { @@ -331,7 +331,7 @@ void RSSImp::downloadTorrent() {
void RSSImp::openNewsUrl() {
QList<QListWidgetItem *> selected_items = listArticles->selectedItems();
foreach(const QListWidgetItem* item, selected_items) {
const RssArticle news = listStreams->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
const RssArticle news = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
->getItem(item->data(Article::IdRole).toString());
const QString link = news.link();
if(!link.isEmpty())
@ -341,14 +341,14 @@ void RSSImp::openNewsUrl() { @@ -341,14 +341,14 @@ void RSSImp::openNewsUrl() {
//right-click on stream : give it an alias
void RSSImp::renameFiles() {
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
Q_ASSERT(selectedItems.size() == 1);
QTreeWidgetItem *item = selectedItems.at(0);
RssFile *rss_item = listStreams->getRSSItem(item);
IRssFile *rss_item = m_feedList->getRSSItem(item);
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)->displayName(), &ok);
newName = QInputDialog::getText(this, tr("Please choose a new name for this RSS feed"), tr("New feed name:"), QLineEdit::Normal, m_feedList->getRSSItem(item)->displayName(), &ok);
// Check if name is already taken
if(ok) {
if(rss_item->parent()->hasChild(newName)) {
@ -367,22 +367,22 @@ void RSSImp::renameFiles() { @@ -367,22 +367,22 @@ void RSSImp::renameFiles() {
//right-click on stream : refresh it
void RSSImp::refreshSelectedItems() {
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
foreach(QTreeWidgetItem* item, selectedItems){
RssFile* file = listStreams->getRSSItem(item);
IRssFile* file = m_feedList->getRSSItem(item);
// Update icons
if(item == listStreams->getUnreadItem()) {
foreach(QTreeWidgetItem *feed, listStreams->getAllFeedItems()) {
if(item == m_feedList->stickyUnreadItem()) {
foreach(QTreeWidgetItem *feed, m_feedList->getAllFeedItems()) {
feed->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
}
file->refresh();
break;
} else {
if(file->type() == RssFile::FEED) {
if(file->type() == IRssFile::FEED) {
item->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
} else {
// Update feeds in the folder
foreach(QTreeWidgetItem *feed, listStreams->getAllFeedItems(item)) {
foreach(QTreeWidgetItem *feed, m_feedList->getAllFeedItems(item)) {
feed->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
}
}
@ -394,45 +394,45 @@ void RSSImp::refreshSelectedItems() { @@ -394,45 +394,45 @@ void RSSImp::refreshSelectedItems() {
void RSSImp::copySelectedFeedsURL() {
QStringList URLs;
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
QTreeWidgetItem* item;
foreach(item, selectedItems){
if(listStreams->getItemType(item) == RssFile::FEED)
URLs << listStreams->getItemID(item);
if(m_feedList->getItemType(item) == IRssFile::FEED)
URLs << m_feedList->getItemID(item);
}
qApp->clipboard()->setText(URLs.join("\n"));
}
void RSSImp::on_markReadButton_clicked() {
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
QTreeWidgetItem* item;
foreach(item, selectedItems){
RssFile *rss_item = listStreams->getRSSItem(item);
IRssFile *rss_item = m_feedList->getRSSItem(item);
rss_item->markAsRead();
updateItemInfos(item);
}
if(selectedItems.size())
refreshNewsList(listStreams->currentItem());
refreshArticleList(m_feedList->currentItem());
}
void RSSImp::fillFeedsList(QTreeWidgetItem *parent, RssFolder *rss_parent) {
QList<RssFile*> children;
QList<IRssFile*> children;
if(parent) {
children = rss_parent->getContent();
} else {
children = rssmanager->getContent();
children = m_rssManager->getContent();
}
foreach(RssFile* rss_child, children){
foreach(IRssFile* rss_child, children){
QTreeWidgetItem* item;
if(!parent)
item = new QTreeWidgetItem(listStreams);
item = new QTreeWidgetItem(m_feedList);
else
item = new QTreeWidgetItem(parent);
item->setData(0, Qt::DisplayRole, QVariant(rss_child->displayName()+ QString::fromUtf8(" (")+QString::number(rss_child->unreadCount(), 10)+QString(")")));
// Notify TreeWidget of item addition
listStreams->itemAdded(item, rss_child);
m_feedList->itemAdded(item, rss_child);
// Set Icon
if(rss_child->type() == RssFile::FEED) {
if(rss_child->type() == IRssFile::FEED) {
item->setData(0,Qt::DecorationRole, QVariant(QIcon(QString::fromUtf8(":/Icons/loading.png"))));
} else {
item->setData(0,Qt::DecorationRole, QVariant(IconProvider::instance()->getIcon("inode-directory")));
@ -443,18 +443,18 @@ void RSSImp::fillFeedsList(QTreeWidgetItem *parent, RssFolder *rss_parent) { @@ -443,18 +443,18 @@ void RSSImp::fillFeedsList(QTreeWidgetItem *parent, RssFolder *rss_parent) {
}
// fills the newsList
void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
void RSSImp::refreshArticleList(QTreeWidgetItem* item) {
if(!item) {
listArticles->clear();
return;
}
RssFile *rss_item = listStreams->getRSSItem(item);
IRssFile *rss_item = m_feedList->getRSSItem(item);
if(!rss_item) return;
qDebug("Getting the list of news");
QList<RssArticle> news;
if(rss_item == rssmanager)
if(rss_item == m_rssManager)
news = RssManager::sortNewsList(rss_item->unreadArticleList());
else if(rss_item)
news = RssManager::sortNewsList(rss_item->articleList());
@ -489,7 +489,7 @@ void RSSImp::refreshTextBrowser() { @@ -489,7 +489,7 @@ void RSSImp::refreshTextBrowser() {
Q_ASSERT(item);
if(item == m_currentArticle) return;
// Stop displaying previous news if necessary
if(listStreams->currentFeed() == listStreams->getUnreadItem()) {
if(m_feedList->currentFeed() == m_feedList->stickyUnreadItem()) {
if(m_currentArticle) {
disconnect(listArticles, SIGNAL(itemSelectionChanged()), this, SLOT(refreshTextBrowser()));
listArticles->removeItemWidget(m_currentArticle);
@ -499,7 +499,7 @@ void RSSImp::refreshTextBrowser() { @@ -499,7 +499,7 @@ void RSSImp::refreshTextBrowser() {
}
m_currentArticle = item;
}
RssFeed *stream = listStreams->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString());
RssFeed *stream = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString());
RssArticle article = stream->getItem(item->data(Article::IdRole).toString());
QString html;
html += "<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>";
@ -517,8 +517,8 @@ void RSSImp::refreshTextBrowser() { @@ -517,8 +517,8 @@ void RSSImp::refreshTextBrowser() {
item->setData(Article::ColorRole, QVariant(QColor("grey")));
item->setData(Article::IconRole, QVariant(QIcon(":/Icons/sphere.png")));
// Decrement feed nb unread news
updateItemInfos(listStreams->getUnreadItem());
updateItemInfos(listStreams->getTreeItemFromUrl(item->data(Article::FeedUrlRole).toString()));
updateItemInfos(m_feedList->stickyUnreadItem());
updateItemInfos(m_feedList->getTreeItemFromUrl(item->data(Article::FeedUrlRole).toString()));
}
void RSSImp::saveSlidersPosition() {
@ -541,16 +541,16 @@ void RSSImp::restoreSlidersPosition() { @@ -541,16 +541,16 @@ void RSSImp::restoreSlidersPosition() {
}
}
void RSSImp::updateItemsInfos(QList<QTreeWidgetItem *> items) {
void RSSImp::updateItemsInfos(const QList<QTreeWidgetItem *> &items) {
foreach(QTreeWidgetItem* item, items) {
updateItemInfos(item);
}
}
void RSSImp::updateItemInfos(QTreeWidgetItem *item) {
RssFile *rss_item = listStreams->getRSSItem(item);
IRssFile *rss_item = m_feedList->getRSSItem(item);
QString name;
if(rss_item == rssmanager)
if(rss_item == m_rssManager)
name = tr("Unread");
else
name = rss_item->displayName();
@ -560,15 +560,15 @@ void RSSImp::updateItemInfos(QTreeWidgetItem *item) { @@ -560,15 +560,15 @@ void RSSImp::updateItemInfos(QTreeWidgetItem *item) {
updateItemInfos(item->parent());
}
void RSSImp::updateFeedIcon(QString url, QString icon_path){
QTreeWidgetItem *item = listStreams->getTreeItemFromUrl(url);
void RSSImp::updateFeedIcon(const QString &url, const QString &icon_path){
QTreeWidgetItem *item = m_feedList->getTreeItemFromUrl(url);
item->setData(0,Qt::DecorationRole, QVariant(QIcon(icon_path)));
}
void RSSImp::updateFeedInfos(QString url, QString display_name, unsigned int nbUnread){
void RSSImp::updateFeedInfos(const QString &url, const QString &display_name, uint nbUnread){
qDebug() << Q_FUNC_INFO << display_name;
QTreeWidgetItem *item = listStreams->getTreeItemFromUrl(url);
RssFeed *stream = (RssFeed*)listStreams->getRSSItem(item);
QTreeWidgetItem *item = m_feedList->getTreeItemFromUrl(url);
RssFeed *stream = (RssFeed*)m_feedList->getRSSItem(item);
item->setText(0, display_name + QString::fromUtf8(" (") + QString::number(nbUnread, 10)+ QString(")"));
if(!stream->isLoading())
item->setData(0,Qt::DecorationRole, QVariant(QIcon(stream->icon())));
@ -576,20 +576,20 @@ void RSSImp::updateFeedInfos(QString url, QString display_name, unsigned int nbU @@ -576,20 +576,20 @@ void RSSImp::updateFeedInfos(QString url, QString display_name, unsigned int nbU
if(item->parent())
updateItemInfos(item->parent());
// Update Unread item
updateItemInfos(listStreams->getUnreadItem());
updateItemInfos(m_feedList->stickyUnreadItem());
// If the feed is selected, update the displayed news
if(listStreams->currentItem() == item ){
refreshNewsList(item);
if(m_feedList->currentItem() == item ){
refreshArticleList(item);
} else {
// Update unread items
if(listStreams->currentItem() == listStreams->getUnreadItem()) {
refreshNewsList(listStreams->getUnreadItem());
if(m_feedList->currentItem() == m_feedList->stickyUnreadItem()) {
refreshArticleList(m_feedList->stickyUnreadItem());
}
}
}
void RSSImp::updateRefreshInterval(unsigned int val) {
rssmanager->updateRefreshInterval(val);
void RSSImp::updateRefreshInterval(uint val) {
m_rssManager->updateRefreshInterval(val);
}
RSSImp::RSSImp(QWidget *parent) : QWidget(parent) {
@ -612,22 +612,22 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) { @@ -612,22 +612,22 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) {
rssDownloaderBtn->setIcon(IconProvider::instance()->getIcon("download"));
settingsButton->setIcon(IconProvider::instance()->getIcon("preferences-system"));
rssmanager = RssManager::instance();
m_rssManager = RssManager::instance();
listStreams = new FeedListWidget(splitter_h, rssmanager);
splitter_h->insertWidget(0, listStreams);
m_feedList = new FeedListWidget(splitter_h, m_rssManager);
splitter_h->insertWidget(0, m_feedList);
listArticles->setSelectionBehavior(QAbstractItemView::SelectItems);
listArticles->setSelectionMode(QAbstractItemView::SingleSelection);
rssmanager->loadStreamList();
m_rssManager->loadStreamList();
fillFeedsList();
refreshNewsList(listStreams->currentItem());
refreshArticleList(m_feedList->currentItem());
loadFoldersOpenState();
connect(rssmanager, SIGNAL(feedInfosChanged(QString, QString, unsigned int)), this, SLOT(updateFeedInfos(QString, QString, unsigned int)));
connect(rssmanager, SIGNAL(feedIconChanged(QString, QString)), this, SLOT(updateFeedIcon(QString, QString)));
connect(m_rssManager, SIGNAL(feedInfosChanged(QString, QString, unsigned int)), this, SLOT(updateFeedInfos(QString, QString, unsigned int)));
connect(m_rssManager, SIGNAL(feedIconChanged(QString, QString)), this, SLOT(updateFeedIcon(QString, QString)));
connect(listStreams, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRSSListMenu(const QPoint&)));
connect(m_feedList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRSSListMenu(const QPoint&)));
connect(listArticles, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayItemsListMenu(const QPoint&)));
// Feeds list actions
@ -643,15 +643,15 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) { @@ -643,15 +643,15 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) {
connect(actionOpen_news_URL, SIGNAL(triggered()), this, SLOT(openNewsUrl()));
connect(actionDownload_torrent, SIGNAL(triggered()), this, SLOT(downloadTorrent()));
connect(listStreams, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(refreshNewsList(QTreeWidgetItem*)));
connect(listStreams, SIGNAL(foldersAltered(QList<QTreeWidgetItem*>)), this, SLOT(updateItemsInfos(QList<QTreeWidgetItem*>)));
connect(listStreams, SIGNAL(overwriteAttempt(QString)), this, SLOT(displayOverwriteError(QString)));
connect(m_feedList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(refreshArticleList(QTreeWidgetItem*)));
connect(m_feedList, SIGNAL(foldersAltered(QList<QTreeWidgetItem*>)), this, SLOT(updateItemsInfos(QList<QTreeWidgetItem*>)));
connect(m_feedList, SIGNAL(overwriteAttempt(QString)), this, SLOT(displayOverwriteError(QString)));
connect(listArticles, SIGNAL(itemSelectionChanged()), this, SLOT(refreshTextBrowser()));
connect(listArticles, SIGNAL(itemDoubleClicked(QListWidgetItem *, int)), this, SLOT(downloadTorrent()));
// Refresh all feeds
rssmanager->refresh();
m_rssManager->refresh();
// Restore sliders position
restoreSlidersPosition();
// Bind saveSliders slots
@ -664,7 +664,7 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) { @@ -664,7 +664,7 @@ RSSImp::RSSImp(QWidget *parent) : QWidget(parent) {
RSSImp::~RSSImp(){
qDebug("Deleting RSSImp...");
saveFoldersOpenState();
delete listStreams;
delete m_feedList;
RssManager::drop();
qDebug("RSSImp deleted");
}

22
src/rss/rss_imp.h

@ -41,7 +41,7 @@ class QTreeWidgetItem; @@ -41,7 +41,7 @@ class QTreeWidgetItem;
class RssFolder;
class RssManager;
class RSSImp : public QWidget, public Ui::RSS{
class RSSImp : public QWidget, public Ui::RSS {
Q_OBJECT
public:
@ -50,9 +50,9 @@ public: @@ -50,9 +50,9 @@ public:
public slots:
void deleteSelectedItems();
void updateRefreshInterval(unsigned int val);
void updateRefreshInterval(uint val);
protected slots:
private slots:
void on_newFeedButton_clicked();
void on_updateAllButton_clicked();
void on_markReadButton_clicked();
@ -61,11 +61,11 @@ protected slots: @@ -61,11 +61,11 @@ protected slots:
void renameFiles();
void refreshSelectedItems();
void copySelectedFeedsURL();
void refreshNewsList(QTreeWidgetItem* item);
void refreshArticleList(QTreeWidgetItem* item);
void refreshTextBrowser();
void updateFeedIcon(QString url, QString icon_path);
void updateFeedInfos(QString url, QString display_name, unsigned int nbUnread);
void updateItemsInfos(QList<QTreeWidgetItem*> items);
void updateFeedIcon(const QString &url, const QString &icon_path);
void updateFeedInfos(const QString &url, const QString &display_name, uint nbUnread);
void updateItemsInfos(const QList<QTreeWidgetItem*> &items);
void updateItemInfos(QTreeWidgetItem *item);
void openNewsUrl();
void downloadTorrent();
@ -75,16 +75,14 @@ protected slots: @@ -75,16 +75,14 @@ protected slots:
void askNewFolder();
void saveFoldersOpenState();
void loadFoldersOpenState();
void displayOverwriteError(QString filename);
void displayOverwriteError(const QString &filename);
void on_actionManage_cookies_triggered();
void on_settingsButton_clicked();
private slots:
void on_rssDownloaderBtn_clicked();
private:
RssManager *rssmanager;
FeedListWidget *listStreams;
RssManager *m_rssManager;
FeedListWidget *m_feedList;
QListWidgetItem* m_currentArticle;
};

4
src/rss/rssfeed.cpp

@ -79,8 +79,8 @@ RssFeed::~RssFeed(){ @@ -79,8 +79,8 @@ RssFeed::~RssFeed(){
misc::safeRemove(m_icon);
}
RssFile::FileType RssFeed::type() const {
return RssFile::FEED;
IRssFile::FileType RssFeed::type() const {
return IRssFile::FEED;
}
void RssFeed::refresh() {

2
src/rss/rssfeed.h

@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
class RssManager;
class RssFeed: public RssFile {
class RssFeed: public QObject, public IRssFile {
Q_OBJECT
public:

40
src/rss/rssfile.cpp

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2010 Christophe Dumez, Arnaud Demaiziere
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact: chris@qbittorrent.org, arnaud@qbittorrent.org
*/
#include "rssfile.h"
#include "rssfolder.h"
QStringList IRssFile::pathHierarchy() const {
QStringList path;
if(parent())
path << parent()->pathHierarchy();
path << id();
return path;
}

18
src/rss/rssfile.h

@ -31,22 +31,20 @@ @@ -31,22 +31,20 @@
#ifndef RSSFILE_H
#define RSSFILE_H
#include <QObject>
#include <QList>
#include <QStringList>
class RssArticle;
class RssFolder;
class RssFile: public QObject {
Q_OBJECT
class IRssFile {
public:
enum FileType {FEED, FOLDER};
RssFile(): QObject() {}
virtual ~RssFile() {}
virtual ~IRssFile() {}
virtual unsigned int unreadCount() const = 0;
virtual uint unreadCount() const = 0;
virtual FileType type() const = 0;
virtual QString displayName() const = 0;
virtual QString id() const = 0;
@ -58,13 +56,7 @@ public: @@ -58,13 +56,7 @@ public:
virtual void removeAllSettings() = 0;
virtual QList<RssArticle> articleList() const = 0;
virtual QList<RssArticle> unreadArticleList() const = 0;
QStringList pathHierarchy() const {
QStringList path;
if(parent())
path << ((RssFile*)parent())->pathHierarchy();
path << id();
return path;
}
QStringList pathHierarchy() const;
};
#endif // RSSFILE_H

40
src/rss/rssfolder.cpp

@ -46,19 +46,19 @@ RssFolder::~RssFolder() { @@ -46,19 +46,19 @@ RssFolder::~RssFolder() {
unsigned int RssFolder::unreadCount() const {
unsigned int nb_unread = 0;
foreach(const RssFile *file, m_children.values()) {
foreach(const IRssFile *file, m_children.values()) {
nb_unread += file->unreadCount();
}
return nb_unread;
}
RssFile::FileType RssFolder::type() const {
return RssFile::FOLDER;
IRssFile::FileType RssFolder::type() const {
return IRssFile::FOLDER;
}
void RssFolder::removeChild(const QString &childId) {
if(m_children.contains(childId)) {
RssFile* child = m_children.take(childId);
IRssFile* child = m_children.take(childId);
child->removeAllSettings();
delete child;
}
@ -85,14 +85,14 @@ RssFeed* RssFolder::addStream(const QString &url) { @@ -85,14 +85,14 @@ RssFeed* RssFolder::addStream(const QString &url) {
// Refresh All Children
void RssFolder::refresh() {
foreach(RssFile *child, m_children.values()) {
foreach(IRssFile *child, m_children.values()) {
child->refresh();
}
}
QList<RssArticle> RssFolder::articleList() const {
QList<RssArticle> news;
foreach(const RssFile *child, m_children.values()) {
foreach(const IRssFile *child, m_children.values()) {
news << child->articleList();
}
return news;
@ -100,20 +100,20 @@ QList<RssArticle> RssFolder::articleList() const { @@ -100,20 +100,20 @@ QList<RssArticle> RssFolder::articleList() const {
QList<RssArticle> RssFolder::unreadArticleList() const {
QList<RssArticle> unread_news;
foreach(const RssFile *child, m_children.values()) {
foreach(const IRssFile *child, m_children.values()) {
unread_news << child->unreadArticleList();
}
return unread_news;
}
QList<RssFile*> RssFolder::getContent() const {
QList<IRssFile*> RssFolder::getContent() const {
return m_children.values();
}
unsigned int RssFolder::getNbFeeds() const {
unsigned int nbFeeds = 0;
foreach(RssFile* item, m_children.values()) {
if(item->type() == RssFile::FOLDER)
foreach(IRssFile* item, m_children.values()) {
if(item->type() == IRssFile::FOLDER)
nbFeeds += ((RssFolder*)item)->getNbFeeds();
else
nbFeeds += 1;
@ -137,15 +137,15 @@ void RssFolder::rename(const QString &new_name) { @@ -137,15 +137,15 @@ void RssFolder::rename(const QString &new_name) {
}
void RssFolder::markAsRead() {
foreach(RssFile *item, m_children.values()) {
foreach(IRssFile *item, m_children.values()) {
item->markAsRead();
}
}
QList<RssFeed*> RssFolder::getAllFeeds() const {
QList<RssFeed*> streams;
foreach(RssFile *item, m_children.values()) {
if(item->type() == RssFile::FEED) {
foreach(IRssFile *item, m_children.values()) {
if(item->type() == IRssFile::FEED) {
streams << static_cast<RssFeed*>(item);
} else {
streams << static_cast<RssFolder*>(item)->getAllFeeds();
@ -156,8 +156,8 @@ QList<RssFeed*> RssFolder::getAllFeeds() const { @@ -156,8 +156,8 @@ QList<RssFeed*> RssFolder::getAllFeeds() const {
QHash<QString, RssFeed*> RssFolder::getAllFeedsAsHash() const {
QHash<QString, RssFeed*> ret;
foreach(RssFile *item, m_children.values()) {
if(item->type() == RssFile::FEED) {
foreach(IRssFile *item, m_children.values()) {
if(item->type() == IRssFile::FEED) {
RssFeed* feed = dynamic_cast<RssFeed*>(item);
Q_ASSERT(feed);
qDebug() << Q_FUNC_INFO << feed->url();
@ -169,8 +169,8 @@ QHash<QString, RssFeed*> RssFolder::getAllFeedsAsHash() const { @@ -169,8 +169,8 @@ QHash<QString, RssFeed*> RssFolder::getAllFeedsAsHash() const {
return ret;
}
void RssFolder::addFile(RssFile * item) {
if(item->type() == RssFile::FEED) {
void RssFolder::addFile(IRssFile * item) {
if(item->type() == IRssFile::FEED) {
RssFeed* feedItem = dynamic_cast<RssFeed*>(item);
Q_ASSERT(!m_children.contains(feedItem->url()));
m_children[feedItem->url()] = item;
@ -191,7 +191,7 @@ void RssFolder::removeAllItems() { @@ -191,7 +191,7 @@ void RssFolder::removeAllItems() {
}
void RssFolder::removeAllSettings() {
foreach(RssFile* child, m_children.values()) {
foreach(IRssFile* child, m_children.values()) {
child->removeAllSettings();
}
}
@ -207,11 +207,11 @@ bool RssFolder::hasChild(const QString &childId) { @@ -207,11 +207,11 @@ bool RssFolder::hasChild(const QString &childId) {
void RssFolder::renameChildFolder(const QString &old_name, const QString &new_name)
{
Q_ASSERT(m_children.contains(old_name));
RssFile *folder = m_children.take(old_name);
IRssFile *folder = m_children.take(old_name);
m_children[new_name] = folder;
}
RssFile * RssFolder::takeChild(const QString &childId)
IRssFile * RssFolder::takeChild(const QString &childId)
{
return m_children.take(childId);
}

10
src/rss/rssfolder.h

@ -38,7 +38,7 @@ @@ -38,7 +38,7 @@
class RssArticle;
class RssFeed;
class RssFolder: public RssFile {
class RssFolder: public QObject, public IRssFile {
Q_OBJECT
public:
@ -51,7 +51,7 @@ public: @@ -51,7 +51,7 @@ public:
RssFeed* addStream(const QString &url);
RssFolder* addFolder(const QString &name);
unsigned int getNbFeeds() const;
QList<RssFile*> getContent() const;
QList<IRssFile*> getContent() const;
QList<RssFeed*> getAllFeeds() const;
QHash<QString, RssFeed*> getAllFeedsAsHash() const;
QString displayName() const;
@ -62,11 +62,11 @@ public: @@ -62,11 +62,11 @@ public:
void removeAllSettings();
void removeAllItems();
void renameChildFolder(const QString &old_name, const QString &new_name);
RssFile *takeChild(const QString &childId);
IRssFile *takeChild(const QString &childId);
public slots:
void refresh();
void addFile(RssFile * item);
void addFile(IRssFile * item);
void removeChild(const QString &childId);
void rename(const QString &new_name);
void markAsRead();
@ -74,7 +74,7 @@ public slots: @@ -74,7 +74,7 @@ public slots:
private:
RssFolder *m_parent;
QString m_name;
QHash<QString, RssFile*> m_children;
QHash<QString, IRssFile*> m_children;
};
#endif // RSSFOLDER_H

2
src/rss/rssmanager.cpp

@ -103,7 +103,7 @@ void RssManager::forwardFeedIconChanged(const QString &url, const QString &icon_ @@ -103,7 +103,7 @@ void RssManager::forwardFeedIconChanged(const QString &url, const QString &icon_
emit feedIconChanged(url, icon_path);
}
void RssManager::moveFile(RssFile* file, RssFolder* dest_folder) {
void RssManager::moveFile(IRssFile* file, RssFolder* dest_folder) {
RssFolder* src_folder = file->parent();
if(dest_folder != src_folder) {
// Remove reference in old folder

2
src/rss/rssmanager.h

@ -56,7 +56,7 @@ public slots: @@ -56,7 +56,7 @@ public slots:
void saveStreamList() const;
void forwardFeedInfosChanged(const QString &url, const QString &aliasOrUrl, uint nbUnread);
void forwardFeedIconChanged(const QString &url, const QString &icon_path);
void moveFile(RssFile* file, RssFolder* dest_folder);
void moveFile(IRssFile* file, RssFolder* dest_folder);
void updateRefreshInterval(uint val);
signals:

1
src/rss/rsssettings.h

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#ifndef RSSSETTINGS_H
#define RSSSETTINGS_H
#include <QStringList>
#include "qinisettings.h"
class RssSettings: public QIniSettings{

Loading…
Cancel
Save