1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-02-03 10:25:02 +00:00

- Slightly improved RSS feeds loading: Saved news can be displayed before the Feed is effectively updated

This commit is contained in:
Christophe Dumez 2009-08-21 14:48:33 +00:00
parent 955d8069e2
commit 2cbbd6ef50
3 changed files with 20 additions and 18 deletions

View File

@ -367,9 +367,11 @@ public slots :
void processDownloadedFile(QString file_path) { void processDownloadedFile(QString file_path) {
filePath = file_path; filePath = file_path;
downloadFailure = false; downloadFailure = false;
lastRefresh.start();
if(openRss() >= 0) { if(openRss() >= 0) {
lastRefresh.start();
refreshed = true; refreshed = true;
} else {
qDebug("OpenRss: Feed update Failed");
} }
} }
@ -381,6 +383,16 @@ void setDownloadFailed(){
public: public:
RssStream(bittorrent *BTSession, QString _url): BTSession(BTSession), url(_url), alias(""), iconPath(":/Icons/rss16.png"), refreshed(false), downloadFailure(false), currently_loading(false) { RssStream(bittorrent *BTSession, QString _url): BTSession(BTSession), url(_url), alias(""), iconPath(":/Icons/rss16.png"), refreshed(false), downloadFailure(false), currently_loading(false) {
qDebug("RSSStream constructed"); qDebug("RSSStream constructed");
QSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QHash<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash();
QVariantList old_items = all_old_items.value(url, QVariantList()).toList();
qDebug("Loading %d old items for feed %s", old_items.size(), getAliasOrUrl().toLocal8Bit().data());
foreach(const QVariant &var_it, old_items) {
QHash<QString, QVariant> item = var_it.toHash();
RssItem *rss_item = RssItem::fromHash(item);
if(rss_item->isValid())
listItem << rss_item;
}
} }
~RssStream(){ ~RssStream(){
@ -537,18 +549,6 @@ QString getIconUrl() {
private: private:
// read and create items from a rss document // read and create items from a rss document
short readDoc(const QDomDocument& doc) { short readDoc(const QDomDocument& doc) {
if(!refreshed) {
QSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QHash<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash();
QVariantList old_items = all_old_items.value(url, QVariantList()).toList();
qDebug("Loading %d old items for feed %s", old_items.size(), getAliasOrUrl().toLocal8Bit().data());
foreach(const QVariant &var_it, old_items) {
QHash<QString, QVariant> item = var_it.toHash();
RssItem *rss_item = RssItem::fromHash(item);
if(rss_item->isValid())
listItem << rss_item;
}
}
// is it a rss file ? // is it a rss file ?
QDomElement root = doc.documentElement(); QDomElement root = doc.documentElement();
if(root.tagName() == QString::fromUtf8("html")){ if(root.tagName() == QString::fromUtf8("html")){
@ -890,6 +890,7 @@ void refreshAll(){
} }
void refresh(QString url) { void refresh(QString url) {
qDebug("Refreshing feed: %s", url.toLocal8Bit().data());
Q_ASSERT(streams.contains(url)); Q_ASSERT(streams.contains(url));
RssStream *stream = streams[url]; RssStream *stream = streams[url];
if(stream->isLoading()) return; if(stream->isLoading()) return;

View File

@ -188,7 +188,7 @@ void RSSImp::on_actionMark_all_as_read_triggered() {
item->setData(0, Qt::DisplayRole, feed->getAliasOrUrl()+ QString::fromUtf8(" (0)")); item->setData(0, Qt::DisplayRole, feed->getAliasOrUrl()+ QString::fromUtf8(" (0)"));
} }
if(selectedItems.size()) if(selectedItems.size())
refreshNewsList(selectedItems.last(), 0); refreshNewsList(selectedItems.last());
} }
//right-click somewhere, refresh all the streams //right-click somewhere, refresh all the streams
@ -257,7 +257,8 @@ void RSSImp::updateLastRefreshedTimeForStreams() {
} }
// fills the newsList // fills the newsList
void RSSImp::refreshNewsList(QTreeWidgetItem* item, int) { void RSSImp::refreshNewsList(QTreeWidgetItem* item) {
if(!item) return;
selectedFeedUrl = item->text(1); selectedFeedUrl = item->text(1);
RssStream *stream = rssmanager->getFeed(selectedFeedUrl); RssStream *stream = rssmanager->getFeed(selectedFeedUrl);
qDebug("Getting the list of news"); qDebug("Getting the list of news");
@ -352,7 +353,7 @@ void RSSImp::updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnr
item->setToolTip(0, QString::fromUtf8("<b>")+tr("Description:")+QString::fromUtf8("</b> ")+stream->getDescription()+QString::fromUtf8("<br/><b>")+tr("url:")+QString::fromUtf8("</b> ")+stream->getUrl()+QString::fromUtf8("<br/><b>")+tr("Last refresh:")+QString::fromUtf8("</b> ")+stream->getLastRefreshElapsedString()); item->setToolTip(0, QString::fromUtf8("<b>")+tr("Description:")+QString::fromUtf8("</b> ")+stream->getDescription()+QString::fromUtf8("<br/><b>")+tr("url:")+QString::fromUtf8("</b> ")+stream->getUrl()+QString::fromUtf8("<br/><b>")+tr("Last refresh:")+QString::fromUtf8("</b> ")+stream->getLastRefreshElapsedString());
// If the feed is selected, update the displayed news // If the feed is selected, update the displayed news
if(selectedFeedUrl == url){ if(selectedFeedUrl == url){
refreshNewsList(getTreeItemFromUrl(url), 0); refreshNewsList(item);
} }
} }
@ -392,7 +393,7 @@ RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){
connect(actionOpen_news_URL, SIGNAL(triggered()), this, SLOT(openNewsUrl())); connect(actionOpen_news_URL, SIGNAL(triggered()), this, SLOT(openNewsUrl()));
connect(actionDownload_torrent, SIGNAL(triggered()), this, SLOT(downloadTorrent())); connect(actionDownload_torrent, SIGNAL(triggered()), this, SLOT(downloadTorrent()));
connect(listStreams, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(refreshNewsList(QTreeWidgetItem*,int))); connect(listStreams, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(refreshNewsList(QTreeWidgetItem*)));
connect(listNews, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(refreshTextBrowser(QListWidgetItem *))); connect(listNews, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(refreshTextBrowser(QListWidgetItem *)));
connect(listNews, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(downloadTorrent())); connect(listNews, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(downloadTorrent()));
refreshTimeTimer = new QTimer(this); refreshTimeTimer = new QTimer(this);

View File

@ -60,7 +60,7 @@ class RSSImp : public QWidget, public Ui::RSS{
void copySelectedFeedsURL(); void copySelectedFeedsURL();
void createStream(); void createStream();
void refreshAllStreams(); void refreshAllStreams();
void refreshNewsList(QTreeWidgetItem* item, int); void refreshNewsList(QTreeWidgetItem* item);
void refreshTextBrowser(QListWidgetItem *); void refreshTextBrowser(QListWidgetItem *);
void updateLastRefreshedTimeForStreams(); void updateLastRefreshedTimeForStreams();
void updateFeedIcon(QString url, QString icon_path); void updateFeedIcon(QString url, QString icon_path);