Browse Source

RSS optimizations

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
3bc75bb068
  1. 6
      src/rss/rss_imp.cpp
  2. 12
      src/rss/rssarticle.cpp
  3. 3
      src/rss/rssarticle_p.h
  4. 13
      src/rss/rssfeed.cpp
  5. 6
      src/rss/rssfeed.h
  6. 17
      src/rss/rssmanager.cpp
  7. 4
      src/rss/rssmanager.h

6
src/rss/rss_imp.cpp

@ -461,9 +461,11 @@ void RSSImp::refreshArticleList(QTreeWidgetItem* item) { @@ -461,9 +461,11 @@ void RSSImp::refreshArticleList(QTreeWidgetItem* item) {
qDebug("Getting the list of news");
QList<RssArticle> news;
if(rss_item == m_rssManager)
news = RssManager::sortNewsList(rss_item->unreadArticleList());
news = rss_item->unreadArticleList();
else if(rss_item)
news = RssManager::sortNewsList(rss_item->articleList());
news = rss_item->articleList();
// Sort
RssManager::sortNewsList(news);
// Clear the list first
textBrowser->clear();
m_currentArticle = 0;

12
src/rss/rssarticle.cpp

@ -191,10 +191,9 @@ QDateTime RssArticle::parseDate(const QString &string) { @@ -191,10 +191,9 @@ QDateTime RssArticle::parseDate(const QString &string) {
}
// public constructor
RssArticle::RssArticle(RssFeed* parent, QXmlStreamReader& xml)
RssArticle::RssArticle(RssFeed* parent, QXmlStreamReader& xml):
d(new RssArticleData(parent))
{
d = new RssArticleData;
d->parent = parent;
while(!xml.atEnd()) {
xml.readNext();
@ -231,11 +230,8 @@ RssArticle::RssArticle(RssFeed* parent, QXmlStreamReader& xml) @@ -231,11 +230,8 @@ RssArticle::RssArticle(RssFeed* parent, QXmlStreamReader& xml)
}
}
RssArticle::RssArticle(RssFeed* parent, const QString &guid) {
d = new RssArticleData;
d->parent = parent;
d->guid = guid;
}
RssArticle::RssArticle(RssFeed* parent, const QString &guid):
d(new RssArticleData(parent, guid)) {}
RssArticle::~RssArticle() {}

3
src/rss/rssarticle_p.h

@ -39,7 +39,8 @@ class RssFeed; @@ -39,7 +39,8 @@ class RssFeed;
class RssArticleData: public QSharedData {
public:
RssArticleData(): QSharedData(), read(false) {}
RssArticleData(RssFeed* _parent, const QString& _guid = QString()):
parent(_parent), guid(_guid), read(false) {}
~RssArticleData() {}
RssArticleData(const RssArticleData& other):
QSharedData(other), parent(other.parent),

13
src/rss/rssfeed.cpp

@ -123,8 +123,8 @@ void RssFeed::removeAllSettings() { @@ -123,8 +123,8 @@ void RssFeed::removeAllSettings() {
}
}
bool RssFeed::itemAlreadyExists(const QString &hash) const {
return m_articles.contains(hash);
bool RssFeed::itemAlreadyExists(const QString &guid) const {
return m_articles.contains(guid);
}
void RssFeed::setLoading(bool val) {
@ -177,8 +177,8 @@ void RssFeed::setIconPath(const QString &path) { @@ -177,8 +177,8 @@ void RssFeed::setIconPath(const QString &path) {
m_icon = path;
}
RssArticle& RssFeed::getItem(const QString &id) {
return m_articles[id];
RssArticle& RssFeed::getItem(const QString &guid) {
return m_articles[guid];
}
uint RssFeed::count() const{
@ -323,10 +323,11 @@ void RssFeed::resizeList() { @@ -323,10 +323,11 @@ void RssFeed::resizeList() {
const uint max_articles = RssSettings().getRSSMaxArticlesPerFeed();
const uint nb_articles = m_articles.size();
if(nb_articles > max_articles) {
const QList<RssArticle> listItem = RssManager::sortNewsList(m_articles.values());
QList<RssArticle> listItems = m_articles.values();
RssManager::sortNewsList(listItems);
const int excess = nb_articles - max_articles;
for(uint i=nb_articles-excess; i<nb_articles; ++i){
m_articles.remove(listItem.at(i).guid());
m_articles.remove(listItems.at(i).guid());
}
}
}

6
src/rss/rssfeed.h

@ -42,14 +42,14 @@ class RssFeed: public QObject, public IRssFile { @@ -42,14 +42,14 @@ class RssFeed: public QObject, public IRssFile {
public:
RssFeed(RssFolder* m_parent, const QString &url);
~RssFeed();
virtual ~RssFeed();
inline RssFolder* parent() const { return m_parent; }
void setParent(RssFolder* parent) { m_parent = parent; }
FileType type() const;
void refresh();
QString id() const { return m_url; }
void removeAllSettings();
bool itemAlreadyExists(const QString &hash) const;
bool itemAlreadyExists(const QString &guid) const;
void setLoading(bool val);
bool isLoading() const;
QString title() const;
@ -59,7 +59,7 @@ public: @@ -59,7 +59,7 @@ public:
QString icon() const;
bool hasCustomIcon() const;
void setIconPath(const QString &pathHierarchy);
RssArticle& getItem(const QString &name);
RssArticle& getItem(const QString &guid);
uint count() const;
void markAsRead();
uint unreadCount() const;

17
src/rss/rssmanager.cpp

@ -134,20 +134,13 @@ void RssManager::saveStreamList() const { @@ -134,20 +134,13 @@ void RssManager::saveStreamList() const {
settings.setRssFeedsAliases(aliases);
}
void RssManager::insertSortElem(QList<RssArticle> &list, const RssArticle &item) {
int i = 0;
while(i < list.size() && item.date() < list.at(i).date()) {
++i;
}
list.insert(i, item);
static bool earlierItemDate(const RssArticle& a, const RssArticle& b)
{
return (a.date() < b.date());
}
QList<RssArticle> RssManager::sortNewsList(const QList<RssArticle>& news_list) {
QList<RssArticle> new_list;
foreach(const RssArticle &item, news_list) {
insertSortElem(new_list, item);
}
return new_list;
void RssManager::sortNewsList(QList<RssArticle>& news_list) {
qSort(news_list.begin(), news_list.end(), earlierItemDate);
}
RssManager * RssManager::instance()

4
src/rss/rssmanager.h

@ -46,10 +46,10 @@ private: @@ -46,10 +46,10 @@ private:
public:
static RssManager* instance();
static void drop();
~RssManager();
virtual ~RssManager();
inline DownloadThread* rssDownloader() const { return m_rssDownloader; }
static void insertSortElem(QList<RssArticle> &list, const RssArticle &item);
static QList<RssArticle> sortNewsList(const QList<RssArticle>& news_list);
static void sortNewsList(QList<RssArticle>& news_list);
public slots:
void loadStreamList();

Loading…
Cancel
Save