Browse Source

RSS optimization

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
954e010493
  1. 42
      src/rss/rss_imp.cpp
  2. 26
      src/rss/rssarticle.cpp
  3. 7
      src/rss/rssarticle.h
  4. 6
      src/rss/rssdownloadrule.cpp
  5. 74
      src/rss/rssfeed.cpp
  6. 48
      src/rss/rssfeed.h
  7. 5
      src/rss/rssfile.h
  8. 16
      src/rss/rssfolder.cpp
  9. 4
      src/rss/rssfolder.h
  10. 10
      src/rss/rssmanager.cpp
  11. 4
      src/rss/rssmanager.h

42
src/rss/rss_imp.cpp

@ -99,7 +99,7 @@ void RSSImp::displayItemsListMenu(const QPoint&){
foreach(QTreeWidgetItem *item, selectedItems) { foreach(QTreeWidgetItem *item, selectedItems) {
qDebug("text(3) URL: %s", qPrintable(item->text(NEWS_URL_COL))); qDebug("text(3) URL: %s", qPrintable(item->text(NEWS_URL_COL)));
qDebug("text(2) TITLE: %s", qPrintable(item->text(NEWS_TITLE_COL))); qDebug("text(2) TITLE: %s", qPrintable(item->text(NEWS_TITLE_COL)));
if(listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID))->hasAttachment()) { if(listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID)).hasAttachment()) {
has_attachment = true; has_attachment = true;
break; break;
} }
@ -308,11 +308,11 @@ void RSSImp::on_updateAllButton_clicked() {
void RSSImp::downloadTorrent() { void RSSImp::downloadTorrent() {
QList<QTreeWidgetItem *> selected_items = listNews->selectedItems(); QList<QTreeWidgetItem *> selected_items = listNews->selectedItems();
foreach(const QTreeWidgetItem* item, selected_items) { foreach(const QTreeWidgetItem* item, selected_items) {
RssArticle* article = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID)); const RssArticle article = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID));
if(article->hasAttachment()) { if(article.hasAttachment()) {
QBtSession::instance()->downloadFromUrl(article->torrentUrl()); QBtSession::instance()->downloadFromUrl(article.torrentUrl());
} else { } else {
QBtSession::instance()->downloadFromUrl(article->link()); QBtSession::instance()->downloadFromUrl(article.link());
} }
} }
} }
@ -321,8 +321,8 @@ void RSSImp::downloadTorrent() {
void RSSImp::openNewsUrl() { void RSSImp::openNewsUrl() {
QList<QTreeWidgetItem *> selected_items = listNews->selectedItems(); QList<QTreeWidgetItem *> selected_items = listNews->selectedItems();
foreach(const QTreeWidgetItem* item, selected_items) { foreach(const QTreeWidgetItem* item, selected_items) {
RssArticle* news = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID)); const RssArticle news = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL))->getItem(item->text(NEWS_ID));
QString link = news->link(); const QString link = news.link();
if(!link.isEmpty()) if(!link.isEmpty())
QDesktopServices::openUrl(QUrl(link)); QDesktopServices::openUrl(QUrl(link));
} }
@ -442,7 +442,7 @@ void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
if(!rss_item) return; if(!rss_item) return;
qDebug("Getting the list of news"); qDebug("Getting the list of news");
QList<RssArticle*> news; QList<RssArticle> news;
if(rss_item == rssmanager) if(rss_item == rssmanager)
news = RssManager::sortNewsList(rss_item->getUnreadNewsList()); news = RssManager::sortNewsList(rss_item->getUnreadNewsList());
else if(rss_item) else if(rss_item)
@ -452,12 +452,12 @@ void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
previous_news = 0; previous_news = 0;
listNews->clear(); listNews->clear();
qDebug("Got the list of news"); qDebug("Got the list of news");
foreach(RssArticle* article, news){ foreach(const RssArticle &article, news){
QTreeWidgetItem* it = new QTreeWidgetItem(listNews); QTreeWidgetItem* it = new QTreeWidgetItem(listNews);
it->setText(NEWS_TITLE_COL, article->title()); it->setText(NEWS_TITLE_COL, article.title());
it->setText(NEWS_URL_COL, article->parent()->getUrl()); it->setText(NEWS_URL_COL, article.parent()->getUrl());
it->setText(NEWS_ID, article->guid()); it->setText(NEWS_ID, article.guid());
if(article->isRead()){ if(article.isRead()){
it->setData(NEWS_TITLE_COL, Qt::ForegroundRole, QVariant(QColor("grey"))); it->setData(NEWS_TITLE_COL, Qt::ForegroundRole, QVariant(QColor("grey")));
it->setData(NEWS_ICON, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png"))); it->setData(NEWS_ICON, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
}else{ }else{
@ -489,20 +489,20 @@ void RSSImp::refreshTextBrowser() {
previous_news = item; previous_news = item;
} }
RssFeed *stream = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL)); RssFeed *stream = listStreams->getRSSItemFromUrl(item->text(NEWS_URL_COL));
RssArticle* article = stream->getItem(item->text(NEWS_ID)); RssArticle article = stream->getItem(item->text(NEWS_ID));
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->title() + "</div>"; html += "<div style='background-color: #678db2; font-weight: bold; color: #fff;'>"+article.title() + "</div>";
if(article->date().isValid()) { if(article.date().isValid()) {
html += "<div style='background-color: #efefef;'><b>"+tr("Date: ")+"</b>"+article->date().toLocalTime().toString(Qt::SystemLocaleLongDate)+"</div>"; html += "<div style='background-color: #efefef;'><b>"+tr("Date: ")+"</b>"+article.date().toLocalTime().toString(Qt::SystemLocaleLongDate)+"</div>";
} }
if(!article->author().isEmpty()) { if(!article.author().isEmpty()) {
html += "<div style='background-color: #efefef;'><b>"+tr("Author: ")+"</b>"+article->author()+"</div>"; html += "<div style='background-color: #efefef;'><b>"+tr("Author: ")+"</b>"+article.author()+"</div>";
} }
html += "</div>"; html += "</div>";
html += "<divstyle='margin-left: 5px; margin-right: 5px;'>"+article->description()+"</div>"; html += "<divstyle='margin-left: 5px; margin-right: 5px;'>"+article.description()+"</div>";
textBrowser->setHtml(html); textBrowser->setHtml(html);
article->markAsRead(); article.markAsRead();
item->setData(NEWS_TITLE_COL, Qt::ForegroundRole, QVariant(QColor("grey"))); item->setData(NEWS_TITLE_COL, Qt::ForegroundRole, QVariant(QColor("grey")));
item->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png"))); item->setData(0, Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
// Decrement feed nb unread news // Decrement feed nb unread news

26
src/rss/rssarticle.cpp

@ -251,19 +251,19 @@ QVariantHash RssArticle::toHash() const {
return item; return item;
} }
RssArticle* hashToRssArticle(RssFeed* parent, const QVariantHash &h) { RssArticle hashToRssArticle(RssFeed* parent, const QVariantHash &h) {
const QString guid = h.value("id").toString(); const QString guid = h.value("id").toString();
if(guid.isEmpty()) return 0; if(guid.isEmpty()) return RssArticle();
RssArticle *art = new RssArticle(parent, guid); RssArticle art(parent, guid);
art->m_title = h.value("title", "").toString(); art.m_title = h.value("title", "").toString();
art->m_torrentUrl = h.value("torrent_url", "").toString(); art.m_torrentUrl = h.value("torrent_url", "").toString();
art->m_link = h.value("news_link", "").toString(); art.m_link = h.value("news_link", "").toString();
art->m_description = h.value("description").toString(); art.m_description = h.value("description").toString();
art->m_date = h.value("date").toDateTime(); art.m_date = h.value("date").toDateTime();
art->m_author = h.value("author").toString(); art.m_author = h.value("author").toString();
art->m_read = h.value("read").toBool(); art.m_read = h.value("read").toBool();
Q_ASSERT(art->isValid()); Q_ASSERT(art.isValid());
return art; return art;
} }
@ -288,8 +288,8 @@ QString RssArticle::link() const {
} }
QString RssArticle::description() const{ QString RssArticle::description() const{
if(m_description.isEmpty()) if(m_description.isNull())
return tr("No description available"); return "";
return m_description; return m_description;
} }

7
src/rss/rssarticle.h

@ -38,12 +38,11 @@
class RssFeed; class RssFeed;
// Item of a rss stream, single information // Item of a rss stream, single information
class RssArticle: public QObject { class RssArticle {
Q_OBJECT
public: public:
RssArticle(RssFeed* parent, QXmlStreamReader& xml); RssArticle(RssFeed* parent, QXmlStreamReader& xml);
RssArticle(RssFeed* parent, const QString &guid); RssArticle(RssFeed* parent = 0, const QString &guid = QString());
~RssArticle(); ~RssArticle();
// Accessors // Accessors
bool isValid() const; bool isValid() const;
@ -61,7 +60,7 @@ public:
void markAsRead(); void markAsRead();
// Serialization // Serialization
QVariantHash toHash() const; QVariantHash toHash() const;
friend RssArticle* hashToRssArticle(RssFeed* parent, const QVariantHash &hash); friend RssArticle hashToRssArticle(RssFeed* parent, const QVariantHash &hash);
protected: protected:
QDateTime parseDate(const QString &string); QDateTime parseDate(const QString &string);

6
src/rss/rssdownloadrule.cpp

@ -129,9 +129,9 @@ void RssDownloadRule::setSavePath(const QString &save_path)
QStringList RssDownloadRule::findMatchingArticles(const RssFeed *feed) const QStringList RssDownloadRule::findMatchingArticles(const RssFeed *feed) const
{ {
QStringList ret; QStringList ret;
foreach(const RssArticle *art, feed->values()) { foreach(const RssArticle &art, feed->values()) {
if(matches(art->title())) if(matches(art.title()))
ret << art->title(); ret << art.title();
} }
return ret; return ret;
} }

74
src/rss/rssfeed.cpp

@ -46,9 +46,9 @@ RssFeed::RssFeed(RssFolder* parent, QString _url): parent(parent), alias(""), ic
qDebug("Loading %d old items for feed %s", old_items.size(), getName().toLocal8Bit().data()); qDebug("Loading %d old items for feed %s", old_items.size(), getName().toLocal8Bit().data());
foreach(const QVariant &var_it, old_items) { foreach(const QVariant &var_it, old_items) {
QHash<QString, QVariant> item = var_it.toHash(); QHash<QString, QVariant> item = var_it.toHash();
RssArticle *rss_item = hashToRssArticle(this, item); const RssArticle rss_item = hashToRssArticle(this, item);
if(rss_item) { if(rss_item.isValid()) {
insert(rss_item->guid(), rss_item); insert(rss_item.guid(), rss_item);
} }
} }
} }
@ -58,16 +58,14 @@ RssFeed::~RssFeed(){
if(refreshed) { if(refreshed) {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QVariantList old_items; QVariantList old_items;
foreach(RssArticle *item, this->values()) { foreach(const RssArticle &item, this->values()) {
old_items << item->toHash(); old_items << item.toHash();
} }
qDebug("Saving %d old items for feed %s", old_items.size(), getName().toLocal8Bit().data()); qDebug("Saving %d old items for feed %s", old_items.size(), getName().toLocal8Bit().data());
QHash<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash();
all_old_items[url] = old_items; all_old_items[url] = old_items;
qBTRSS.setValue("old_items", all_old_items); qBTRSS.setValue("old_items", all_old_items);
} }
qDebug("Removing all item from feed");
removeAllItems();
qDebug("All items were removed"); qDebug("All items were removed");
if(QFile::exists(filePath)) if(QFile::exists(filePath))
misc::safeRemove(filePath); misc::safeRemove(filePath);
@ -83,12 +81,6 @@ void RssFeed::refresh() {
parent->refreshStream(url); parent->refreshStream(url);
} }
// delete all the items saved
void RssFeed::removeAllItems() {
qDeleteAll(this->values());
this->clear();
}
void RssFeed::removeAllSettings() { void RssFeed::removeAllSettings() {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QHash<QString, QVariant> feeds_w_downloader = qBTRSS.value("downloader_on", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> feeds_w_downloader = qBTRSS.value("downloader_on", QHash<QString, QVariant>()).toHash();
@ -172,8 +164,8 @@ void RssFeed::setIconPath(QString path) {
iconPath = path; iconPath = path;
} }
RssArticle* RssFeed::getItem(QString id) const{ RssArticle& RssFeed::getItem(QString id) {
return this->value(id); return (*this)[id];
} }
unsigned int RssFeed::getNbNews() const{ unsigned int RssFeed::getNbNews() const{
@ -181,29 +173,30 @@ unsigned int RssFeed::getNbNews() const{
} }
void RssFeed::markAllAsRead() { void RssFeed::markAllAsRead() {
foreach(RssArticle *item, this->values()){ QHash<QString, RssArticle>::iterator it;
item->markAsRead(); for(it = this->begin(); it != this->end(); it++) {
it.value().markAsRead();
} }
RssManager::instance()->forwardFeedInfosChanged(url, getName(), 0); RssManager::instance()->forwardFeedInfosChanged(url, getName(), 0);
} }
unsigned int RssFeed::getNbUnRead() const{ unsigned int RssFeed::getNbUnRead() const{
unsigned int nbUnread=0; unsigned int nbUnread=0;
foreach(RssArticle *item, this->values()) { foreach(const RssArticle &item, this->values()) {
if(!item->isRead()) if(!item.isRead())
++nbUnread; ++nbUnread;
} }
return nbUnread; return nbUnread;
} }
QList<RssArticle*> RssFeed::getNewsList() const{ QList<RssArticle> RssFeed::getNewsList() const{
return this->values(); return this->values();
} }
QList<RssArticle*> RssFeed::getUnreadNewsList() const { QList<RssArticle> RssFeed::getUnreadNewsList() const {
QList<RssArticle*> unread_news; QList<RssArticle> unread_news;
foreach(RssArticle *item, this->values()) { foreach(const RssArticle &item, this->values()) {
if(!item->isRead()) if(!item.isRead())
unread_news << item; unread_news << item;
} }
return unread_news; return unread_news;
@ -272,11 +265,9 @@ short RssFeed::readDoc(QIODevice* device) {
image = xml.attributes().value("url").toString(); image = xml.attributes().value("url").toString();
} }
else if(xml.name() == "item") { else if(xml.name() == "item") {
RssArticle * item = new RssArticle(this, xml); RssArticle item(this, xml);
if(item->isValid() && !itemAlreadyExists(item->guid())) { if(item.isValid() && !itemAlreadyExists(item.guid())) {
this->insert(item->guid(), item); this->insert(item.guid(), item);
} else {
delete item;
} }
} }
} }
@ -289,21 +280,23 @@ short RssFeed::readDoc(QIODevice* device) {
// RSS Feed Downloader // RSS Feed Downloader
if(RssSettings().isRssDownloadingEnabled()) { if(RssSettings().isRssDownloadingEnabled()) {
foreach(RssArticle* item, values()) { QHash<QString, RssArticle>::iterator it;
if(item->isRead()) continue; for(it = this->begin(); it != this->end(); it++) {
RssArticle &item = it.value();
if(item.isRead()) continue;
QString torrent_url; QString torrent_url;
if(item->hasAttachment()) if(item.hasAttachment())
torrent_url = item->torrentUrl(); torrent_url = item.torrentUrl();
else else
torrent_url = item->link(); torrent_url = item.link();
// Check if the item should be automatically downloaded // Check if the item should be automatically downloaded
const RssDownloadRule matching_rule = RssDownloadRuleList::instance()->findMatchingRule(url, item->title()); const RssDownloadRule matching_rule = RssDownloadRuleList::instance()->findMatchingRule(url, item.title());
if(matching_rule.isValid()) { if(matching_rule.isValid()) {
// Download the torrent // Download the torrent
QBtSession::instance()->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(item->title()).arg(getName())); QBtSession::instance()->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(item.title()).arg(getName()));
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule.savePath(), matching_rule.label()); QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule.savePath(), matching_rule.label());
// Item was downloaded, consider it as Read // Item was downloaded, consider it as Read
item->markAsRead(); item.markAsRead();
} }
} }
} }
@ -314,11 +307,10 @@ void RssFeed::resizeList() {
const unsigned int max_articles = RssSettings().getRSSMaxArticlesPerFeed(); const unsigned int max_articles = RssSettings().getRSSMaxArticlesPerFeed();
const unsigned int nb_articles = this->size(); const unsigned int nb_articles = this->size();
if(nb_articles > max_articles) { if(nb_articles > max_articles) {
QList<RssArticle*> listItem = RssManager::sortNewsList(this->values()); const QList<RssArticle> listItem = RssManager::sortNewsList(this->values());
const int excess = nb_articles - max_articles; const int excess = nb_articles - max_articles;
for(int i=0; i<excess; ++i){ for(uint i=nb_articles-excess; i<nb_articles; ++i){
RssArticle *lastItem = listItem.takeLast(); this->remove(listItem.at(i).guid());
delete this->take(lastItem->guid());
} }
} }
} }

48
src/rss/rssfeed.h

@ -37,28 +37,9 @@
class RssManager; class RssManager;
class RssFeed: public RssFile, public QHash<QString, RssArticle*> { class RssFeed: public RssFile, public QHash<QString, RssArticle> {
Q_OBJECT Q_OBJECT
private:
RssFolder *parent;
QString title;
QString link;
QString description;
QString image;
QString url;
QString alias;
QString filePath;
QString iconPath;
bool read;
bool refreshed;
bool downloadFailure;
bool currently_loading;
public slots:
void processDownloadedFile(QString file_path);
void setDownloadFailed();
public: public:
RssFeed(RssFolder* parent, QString _url); RssFeed(RssFolder* parent, QString _url);
~RssFeed(); ~RssFeed();
@ -67,7 +48,6 @@ public:
FileType getType() const; FileType getType() const;
void refresh(); void refresh();
QString getID() const { return url; } QString getID() const { return url; }
void removeAllItems();
void removeAllSettings(); void removeAllSettings();
bool itemAlreadyExists(QString hash); bool itemAlreadyExists(QString hash);
void setLoading(bool val); void setLoading(bool val);
@ -83,18 +63,38 @@ public:
QString getIconPath() const; QString getIconPath() const;
bool hasCustomIcon() const; bool hasCustomIcon() const;
void setIconPath(QString path); void setIconPath(QString path);
RssArticle* getItem(QString name) const; RssArticle& getItem(QString name);
unsigned int getNbNews() const; unsigned int getNbNews() const;
void markAllAsRead(); void markAllAsRead();
unsigned int getNbUnRead() const; unsigned int getNbUnRead() const;
QList<RssArticle*> getNewsList() const; QList<RssArticle> getNewsList() const;
QList<RssArticle*> getUnreadNewsList() const; QList<RssArticle> getUnreadNewsList() const;
QString getIconUrl(); QString getIconUrl();
public slots:
void processDownloadedFile(QString file_path);
void setDownloadFailed();
private: private:
short readDoc(QIODevice* device); short readDoc(QIODevice* device);
void resizeList(); void resizeList();
short openRss(); short openRss();
private:
RssFolder *parent;
QString title;
QString link;
QString description;
QString image;
QString url;
QString alias;
QString filePath;
QString iconPath;
bool read;
bool refreshed;
bool downloadFailure;
bool currently_loading;
}; };

5
src/rss/rssfile.h

@ -50,15 +50,14 @@ public:
virtual FileType getType() const = 0; virtual FileType getType() const = 0;
virtual QString getName() const = 0; virtual QString getName() const = 0;
virtual QString getID() const = 0; virtual QString getID() const = 0;
virtual void removeAllItems() = 0;
virtual void rename(QString new_name) = 0; virtual void rename(QString new_name) = 0;
virtual void markAllAsRead() = 0; virtual void markAllAsRead() = 0;
virtual RssFolder* getParent() const = 0; virtual RssFolder* getParent() const = 0;
virtual void setParent(RssFolder*) = 0; virtual void setParent(RssFolder*) = 0;
virtual void refresh() = 0; virtual void refresh() = 0;
virtual void removeAllSettings() = 0; virtual void removeAllSettings() = 0;
virtual QList<RssArticle*> getNewsList() const = 0; virtual QList<RssArticle> getNewsList() const = 0;
virtual QList<RssArticle*> getUnreadNewsList() const = 0; virtual QList<RssArticle> getUnreadNewsList() const = 0;
QStringList getPath() const { QStringList getPath() const {
QStringList path; QStringList path;
if(getParent()) { if(getParent()) {

16
src/rss/rssfolder.cpp

@ -89,7 +89,6 @@ void RssFolder::removeFile(QString ID) {
if(this->contains(ID)) { if(this->contains(ID)) {
RssFile* child = this->take(ID); RssFile* child = this->take(ID);
child->removeAllSettings(); child->removeAllSettings();
child->removeAllItems();
delete child; delete child;
} }
} }
@ -124,17 +123,17 @@ void RssFolder::refresh() {
} }
} }
QList<RssArticle*> RssFolder::getNewsList() const { QList<RssArticle> RssFolder::getNewsList() const {
QList<RssArticle*> news; QList<RssArticle> news;
foreach(RssFile *child, this->values()) { foreach(const RssFile *child, this->values()) {
news << child->getNewsList(); news << child->getNewsList();
} }
return news; return news;
} }
QList<RssArticle*> RssFolder::getUnreadNewsList() const { QList<RssArticle> RssFolder::getUnreadNewsList() const {
QList<RssArticle*> unread_news; QList<RssArticle> unread_news;
foreach(RssFile *child, this->values()) { foreach(const RssFile *child, this->values()) {
unread_news << child->getUnreadNewsList(); unread_news << child->getUnreadNewsList();
} }
return unread_news; return unread_news;
@ -295,9 +294,6 @@ void RssFolder::addFile(RssFile * item) {
} }
void RssFolder::removeAllItems() { void RssFolder::removeAllItems() {
foreach(RssFile* child, values()) {
child->removeAllItems();
}
qDeleteAll(values()); qDeleteAll(values());
clear(); clear();
} }

4
src/rss/rssfolder.h

@ -59,8 +59,8 @@ public:
QString getName() const; QString getName() const;
QString getID() const; QString getID() const;
bool hasChild(QString ID); bool hasChild(QString ID);
QList<RssArticle*> getNewsList() const; QList<RssArticle> getNewsList() const;
QList<RssArticle*> getUnreadNewsList() const; QList<RssArticle> getUnreadNewsList() const;
void removeAllSettings(); void removeAllSettings();
void removeAllItems(); void removeAllItems();

10
src/rss/rssmanager.cpp

@ -126,17 +126,17 @@ void RssManager::saveStreamList(){
settings.setRssFeedsAliases(aliases); settings.setRssFeedsAliases(aliases);
} }
void RssManager::insertSortElem(QList<RssArticle*> &list, RssArticle *item) { void RssManager::insertSortElem(QList<RssArticle> &list, const RssArticle &item) {
int i = 0; int i = 0;
while(i < list.size() && item->date() < list.at(i)->date()) { while(i < list.size() && item.date() < list.at(i).date()) {
++i; ++i;
} }
list.insert(i, item); list.insert(i, item);
} }
QList<RssArticle*> RssManager::sortNewsList(const QList<RssArticle*>& news_list) { QList<RssArticle> RssManager::sortNewsList(const QList<RssArticle>& news_list) {
QList<RssArticle*> new_list; QList<RssArticle> new_list;
foreach(RssArticle *item, news_list) { foreach(const RssArticle &item, news_list) {
insertSortElem(new_list, item); insertSortElem(new_list, item);
} }
return new_list; return new_list;

4
src/rss/rssmanager.h

@ -45,8 +45,8 @@ public:
static RssManager* instance(); static RssManager* instance();
static void drop(); static void drop();
~RssManager(); ~RssManager();
static void insertSortElem(QList<RssArticle*> &list, RssArticle *item); static void insertSortElem(QList<RssArticle> &list, const RssArticle &item);
static QList<RssArticle*> sortNewsList(const QList<RssArticle*>& news_list); static QList<RssArticle> sortNewsList(const QList<RssArticle>& news_list);
public slots: public slots:
void loadStreamList(); void loadStreamList();

Loading…
Cancel
Save