Browse Source

- rss feeds are now updated automatically every 10 minutes

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
db9bc24b5f
  1. 1
      TODO
  2. 39
      src/rss.h
  3. 1
      src/rss_imp.cpp

1
TODO

@ -48,7 +48,6 @@
- Clean up delayed progress column sorting code - Clean up delayed progress column sorting code
- Clean up pause after checking code - Clean up pause after checking code
- Test rss now that it has been rewritten - Test rss now that it has been rewritten
- Refresh rss feeds periodically
- Wait for some bug fixes in libtorrent : - Wait for some bug fixes in libtorrent :
- upload/download limit per torrent (Ticket #83) - upload/download limit per torrent (Ticket #83)
- double free or corruption on exit (Ticket #84) - double free or corruption on exit (Ticket #84)

39
src/rss.h

@ -23,20 +23,19 @@
#define RSS_H #define RSS_H
// MAX ITEM A STREAM // MAX ITEM A STREAM
#define STREAM_MAX_ITEM 18 #define STREAM_MAX_ITEM 50
// FIXME: not used yet // 10min
#define GLOBAL_MAX_ITEM 150 #define STREAM_REFRESH_INTERVAL 600000
// avoid crash if too many refresh
#define REFRESH_FREQ_MAX 5000
#include <QFile> #include <QFile>
#include <QImage>
#include <QList> #include <QList>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QSettings> #include <QSettings>
#include <QDomDocument> #include <QDomDocument>
#include <QTime> #include <QTime>
#include <QUrl> #include <QUrl>
#include <QTimer>
#include <QImage>
#include <QHash> #include <QHash>
#include "misc.h" #include "misc.h"
@ -134,7 +133,7 @@ class RssStream : public QObject{
public slots : public slots :
// read and store the downloaded rss' informations // read and store the downloaded rss' informations
void processDownloadedFile(QString file_path) { void processDownloadedFile(QString file_path) {
// delete the former file // delete the old file
if(QFile::exists(filePath)) { if(QFile::exists(filePath)) {
QFile::remove(filePath); QFile::remove(filePath);
} }
@ -146,7 +145,6 @@ class RssStream : public QObject{
} }
void setDownloadFailed(){ void setDownloadFailed(){
// Change the stream icon to a red cross
downloadFailure = true; downloadFailure = true;
lastRefresh.start(); lastRefresh.start();
} }
@ -158,7 +156,6 @@ class RssStream : public QObject{
refreshed = false; refreshed = false;
downloadFailure = false; downloadFailure = false;
currently_loading = false; currently_loading = false;
// XXX: remove it when gif can be displayed
iconPath = ":/Icons/rss.png"; iconPath = ":/Icons/rss.png";
qDebug("RSSStream constructed"); qDebug("RSSStream constructed");
} }
@ -195,7 +192,6 @@ class RssStream : public QObject{
return alias; return alias;
} }
// Prefer the RssManager::setAlias to save the changed ones
void setAlias(QString _alias){ void setAlias(QString _alias){
alias = _alias; alias = _alias;
} }
@ -272,6 +268,8 @@ class RssStream : public QObject{
} }
unsigned int getLastRefreshElapsed() const{ unsigned int getLastRefreshElapsed() const{
if(!refreshed)
return STREAM_REFRESH_INTERVAL+1;
return lastRefresh.elapsed(); return lastRefresh.elapsed();
} }
@ -302,7 +300,7 @@ class RssStream : public QObject{
} }
while(!channel.isNull()) { while(!channel.isNull()) {
// we are reading the rss'main info // we are reading the rss'main info
if (channel.tagName() == "channel") { if (channel.tagName() == "channel") {
QDomElement property = channel.firstChild().toElement(); QDomElement property = channel.firstChild().toElement();
while(!property.isNull()) { while(!property.isNull()) {
@ -384,6 +382,7 @@ class RssManager : public QObject{
private : private :
QHash<QString, RssStream*> streams; QHash<QString, RssStream*> streams;
downloadThread *downloader; downloadThread *downloader;
QTimer newsRefresher;
signals: signals:
void feedInfosChanged(QString url, QString aliasOrUrl, unsigned int nbUnread); void feedInfosChanged(QString url, QString aliasOrUrl, unsigned int nbUnread);
@ -441,12 +440,30 @@ class RssManager : public QObject{
emit feedInfosChanged(url, stream->getAliasOrUrl(), stream->getNbUnRead()); emit feedInfosChanged(url, stream->getAliasOrUrl(), stream->getNbUnRead());
} }
void refreshOldFeeds(){
qDebug("Refreshing old rss feeds");
RssStream *stream;
foreach(stream, streams){
QString url = stream->getUrl();
if(stream->isLoading()) return;
if(stream->getLastRefreshElapsed() < STREAM_REFRESH_INTERVAL) return;
qDebug("Refreshing feed: %s...", (const char*)url.toUtf8());
stream->setLoading(true);
downloader->downloadUrl(url);
if(!stream->hasCustomIcon()){
downloader->downloadUrl(stream->getIconUrl());
}
}
}
public : public :
RssManager(){ RssManager(){
downloader = new downloadThread(this); downloader = new downloadThread(this);
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processFinishedDownload(QString, QString))); connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processFinishedDownload(QString, QString)));
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
loadStreamList(); loadStreamList();
connect(&newsRefresher, SIGNAL(timeout()), this, SLOT(refreshOldFeeds()));
newsRefresher.start(60000);
} }
~RssManager(){ ~RssManager(){

1
src/rss_imp.cpp

@ -170,7 +170,6 @@
} }
void RSSImp::updateLastRefreshedTimeForStreams() { void RSSImp::updateLastRefreshedTimeForStreams() {
qDebug("Refreshing last refresh time in rss list");
unsigned int nbFeeds = listStreams->topLevelItemCount(); unsigned int nbFeeds = listStreams->topLevelItemCount();
for(unsigned int i=0; i<nbFeeds; ++i){ for(unsigned int i=0; i<nbFeeds; ++i){
QTreeWidgetItem* item = listStreams->topLevelItem(i); QTreeWidgetItem* item = listStreams->topLevelItem(i);

Loading…
Cancel
Save