mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-14 08:48:17 +00:00
RSS optimizations
This commit is contained in:
parent
f0f7924325
commit
3bc75bb068
@ -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;
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
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() {}
|
||||
|
||||
|
@ -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),
|
||||
|
@ -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) {
|
||||
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() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
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;
|
||||
|
@ -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()
|
||||
|
@ -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…
Reference in New Issue
Block a user