mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-14 16:57:55 +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");
|
qDebug("Getting the list of news");
|
||||||
QList<RssArticle> news;
|
QList<RssArticle> news;
|
||||||
if(rss_item == m_rssManager)
|
if(rss_item == m_rssManager)
|
||||||
news = RssManager::sortNewsList(rss_item->unreadArticleList());
|
news = rss_item->unreadArticleList();
|
||||||
else if(rss_item)
|
else if(rss_item)
|
||||||
news = RssManager::sortNewsList(rss_item->articleList());
|
news = rss_item->articleList();
|
||||||
|
// Sort
|
||||||
|
RssManager::sortNewsList(news);
|
||||||
// Clear the list first
|
// Clear the list first
|
||||||
textBrowser->clear();
|
textBrowser->clear();
|
||||||
m_currentArticle = 0;
|
m_currentArticle = 0;
|
||||||
|
@ -191,10 +191,9 @@ QDateTime RssArticle::parseDate(const QString &string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// public constructor
|
// 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()) {
|
while(!xml.atEnd()) {
|
||||||
xml.readNext();
|
xml.readNext();
|
||||||
|
|
||||||
@ -231,11 +230,8 @@ RssArticle::RssArticle(RssFeed* parent, QXmlStreamReader& xml)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RssArticle::RssArticle(RssFeed* parent, const QString &guid) {
|
RssArticle::RssArticle(RssFeed* parent, const QString &guid):
|
||||||
d = new RssArticleData;
|
d(new RssArticleData(parent, guid)) {}
|
||||||
d->parent = parent;
|
|
||||||
d->guid = guid;
|
|
||||||
}
|
|
||||||
|
|
||||||
RssArticle::~RssArticle() {}
|
RssArticle::~RssArticle() {}
|
||||||
|
|
||||||
|
@ -39,7 +39,8 @@ class RssFeed;
|
|||||||
|
|
||||||
class RssArticleData: public QSharedData {
|
class RssArticleData: public QSharedData {
|
||||||
public:
|
public:
|
||||||
RssArticleData(): QSharedData(), read(false) {}
|
RssArticleData(RssFeed* _parent, const QString& _guid = QString()):
|
||||||
|
parent(_parent), guid(_guid), read(false) {}
|
||||||
~RssArticleData() {}
|
~RssArticleData() {}
|
||||||
RssArticleData(const RssArticleData& other):
|
RssArticleData(const RssArticleData& other):
|
||||||
QSharedData(other), parent(other.parent),
|
QSharedData(other), parent(other.parent),
|
||||||
|
@ -123,8 +123,8 @@ void RssFeed::removeAllSettings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RssFeed::itemAlreadyExists(const QString &hash) const {
|
bool RssFeed::itemAlreadyExists(const QString &guid) const {
|
||||||
return m_articles.contains(hash);
|
return m_articles.contains(guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RssFeed::setLoading(bool val) {
|
void RssFeed::setLoading(bool val) {
|
||||||
@ -177,8 +177,8 @@ void RssFeed::setIconPath(const QString &path) {
|
|||||||
m_icon = path;
|
m_icon = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
RssArticle& RssFeed::getItem(const QString &id) {
|
RssArticle& RssFeed::getItem(const QString &guid) {
|
||||||
return m_articles[id];
|
return m_articles[guid];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint RssFeed::count() const{
|
uint RssFeed::count() const{
|
||||||
@ -323,10 +323,11 @@ void RssFeed::resizeList() {
|
|||||||
const uint max_articles = RssSettings().getRSSMaxArticlesPerFeed();
|
const uint max_articles = RssSettings().getRSSMaxArticlesPerFeed();
|
||||||
const uint nb_articles = m_articles.size();
|
const uint nb_articles = m_articles.size();
|
||||||
if(nb_articles > max_articles) {
|
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;
|
const int excess = nb_articles - max_articles;
|
||||||
for(uint i=nb_articles-excess; i<nb_articles; ++i){
|
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:
|
public:
|
||||||
RssFeed(RssFolder* m_parent, const QString &url);
|
RssFeed(RssFolder* m_parent, const QString &url);
|
||||||
~RssFeed();
|
virtual ~RssFeed();
|
||||||
inline RssFolder* parent() const { return m_parent; }
|
inline RssFolder* parent() const { return m_parent; }
|
||||||
void setParent(RssFolder* parent) { m_parent = parent; }
|
void setParent(RssFolder* parent) { m_parent = parent; }
|
||||||
FileType type() const;
|
FileType type() const;
|
||||||
void refresh();
|
void refresh();
|
||||||
QString id() const { return m_url; }
|
QString id() const { return m_url; }
|
||||||
void removeAllSettings();
|
void removeAllSettings();
|
||||||
bool itemAlreadyExists(const QString &hash) const;
|
bool itemAlreadyExists(const QString &guid) const;
|
||||||
void setLoading(bool val);
|
void setLoading(bool val);
|
||||||
bool isLoading() const;
|
bool isLoading() const;
|
||||||
QString title() const;
|
QString title() const;
|
||||||
@ -59,7 +59,7 @@ public:
|
|||||||
QString icon() const;
|
QString icon() const;
|
||||||
bool hasCustomIcon() const;
|
bool hasCustomIcon() const;
|
||||||
void setIconPath(const QString &pathHierarchy);
|
void setIconPath(const QString &pathHierarchy);
|
||||||
RssArticle& getItem(const QString &name);
|
RssArticle& getItem(const QString &guid);
|
||||||
uint count() const;
|
uint count() const;
|
||||||
void markAsRead();
|
void markAsRead();
|
||||||
uint unreadCount() const;
|
uint unreadCount() const;
|
||||||
|
@ -134,20 +134,13 @@ void RssManager::saveStreamList() const {
|
|||||||
settings.setRssFeedsAliases(aliases);
|
settings.setRssFeedsAliases(aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RssManager::insertSortElem(QList<RssArticle> &list, const RssArticle &item) {
|
static bool earlierItemDate(const RssArticle& a, const RssArticle& b)
|
||||||
int i = 0;
|
{
|
||||||
while(i < list.size() && item.date() < list.at(i).date()) {
|
return (a.date() < b.date());
|
||||||
++i;
|
|
||||||
}
|
|
||||||
list.insert(i, item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<RssArticle> RssManager::sortNewsList(const QList<RssArticle>& news_list) {
|
void RssManager::sortNewsList(QList<RssArticle>& news_list) {
|
||||||
QList<RssArticle> new_list;
|
qSort(news_list.begin(), news_list.end(), earlierItemDate);
|
||||||
foreach(const RssArticle &item, news_list) {
|
|
||||||
insertSortElem(new_list, item);
|
|
||||||
}
|
|
||||||
return new_list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RssManager * RssManager::instance()
|
RssManager * RssManager::instance()
|
||||||
|
@ -46,10 +46,10 @@ private:
|
|||||||
public:
|
public:
|
||||||
static RssManager* instance();
|
static RssManager* instance();
|
||||||
static void drop();
|
static void drop();
|
||||||
~RssManager();
|
virtual ~RssManager();
|
||||||
inline DownloadThread* rssDownloader() const { return m_rssDownloader; }
|
inline DownloadThread* rssDownloader() const { return m_rssDownloader; }
|
||||||
static void insertSortElem(QList<RssArticle> &list, const RssArticle &item);
|
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:
|
public slots:
|
||||||
void loadStreamList();
|
void loadStreamList();
|
||||||
|
Loading…
Reference in New Issue
Block a user