mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 01:33:07 -07:00
- Mostly rewritten RSS part
* Fixed a lot of bugs * Improved CPU & memory usage * Improved usability Please report any bug you may experience.
This commit is contained in:
parent
2589d4e682
commit
dcb6642394
5 changed files with 404 additions and 379 deletions
3
TODO
3
TODO
|
@ -47,7 +47,8 @@
|
||||||
- make use of finishedChecking alert if hydri implements it
|
- make use of finishedChecking alert if hydri implements it
|
||||||
- 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
|
||||||
- use abort() for session deletion?
|
- add delete hotkey for rss feeds
|
||||||
|
- Test rss now that it has been rewritten
|
||||||
- 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)
|
||||||
|
|
395
src/rss.h
395
src/rss.h
|
@ -29,11 +29,6 @@
|
||||||
// avoid crash if too many refresh
|
// avoid crash if too many refresh
|
||||||
#define REFRESH_FREQ_MAX 5000
|
#define REFRESH_FREQ_MAX 5000
|
||||||
|
|
||||||
// type of refresh
|
|
||||||
#define ICON 0
|
|
||||||
#define NEWS 1
|
|
||||||
#define LATENCY 2
|
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
@ -42,6 +37,7 @@
|
||||||
#include <QDomDocument>
|
#include <QDomDocument>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "downloadThread.h"
|
#include "downloadThread.h"
|
||||||
|
@ -129,18 +125,15 @@ class RssStream : public QObject{
|
||||||
QString filePath;
|
QString filePath;
|
||||||
QString iconPath;
|
QString iconPath;
|
||||||
QList<RssItem*> listItem;
|
QList<RssItem*> listItem;
|
||||||
downloadThread* downloaderRss;
|
|
||||||
downloadThread* downloaderIcon;
|
|
||||||
QTime lastRefresh;
|
QTime lastRefresh;
|
||||||
bool read;
|
bool read;
|
||||||
bool downloadFailure;
|
bool downloadFailure;
|
||||||
|
bool refreshed;
|
||||||
signals:
|
bool currently_loading;
|
||||||
void refreshFinished(QString msg, const unsigned short& type);
|
|
||||||
|
|
||||||
public slots :
|
public slots :
|
||||||
// read and store the downloaded rss' informations
|
// read and store the downloaded rss' informations
|
||||||
void processDownloadedFile(QString, QString file_path) {
|
void processDownloadedFile(QString file_path) {
|
||||||
// delete the former file
|
// delete the former file
|
||||||
if(QFile::exists(filePath)) {
|
if(QFile::exists(filePath)) {
|
||||||
QFile::remove(filePath);
|
QFile::remove(filePath);
|
||||||
|
@ -148,38 +141,30 @@ class RssStream : public QObject{
|
||||||
filePath = file_path;
|
filePath = file_path;
|
||||||
downloadFailure = false;
|
downloadFailure = false;
|
||||||
openRss();
|
openRss();
|
||||||
emit refreshFinished(url, NEWS);
|
lastRefresh.start();
|
||||||
|
refreshed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// display the icon in the rss window
|
void setDownloadFailed(){
|
||||||
void displayIcon(QString, QString file_path) {
|
// Change the stream icon to a red cross
|
||||||
iconPath = file_path;
|
downloadFailure = true;
|
||||||
openIcon();
|
lastRefresh.start();
|
||||||
emit refreshFinished(url, ICON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RssStream(QString _url) {
|
RssStream(QString _url) {
|
||||||
url = _url;
|
url = _url;
|
||||||
alias = url;
|
alias = "";
|
||||||
read = true;
|
refreshed = false;
|
||||||
downloadFailure = false;
|
downloadFailure = false;
|
||||||
downloaderRss = new downloadThread(this);
|
currently_loading = false;
|
||||||
downloaderIcon = new downloadThread(this);
|
|
||||||
connect(downloaderRss, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString)));
|
|
||||||
connect(downloaderRss, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
|
|
||||||
downloaderRss->downloadUrl(url);
|
|
||||||
// XXX: remove it when gif can be displayed
|
// XXX: remove it when gif can be displayed
|
||||||
iconPath = ":/Icons/rss.png";
|
iconPath = ":/Icons/rss.png";
|
||||||
getIcon();
|
|
||||||
lastRefresh.start();
|
|
||||||
qDebug("RSSStream constructed");
|
qDebug("RSSStream constructed");
|
||||||
}
|
}
|
||||||
|
|
||||||
~RssStream(){
|
~RssStream(){
|
||||||
removeAllItem();
|
removeAllItems();
|
||||||
delete downloaderRss;
|
|
||||||
delete downloaderIcon;
|
|
||||||
if(QFile::exists(filePath))
|
if(QFile::exists(filePath))
|
||||||
QFile::remove(filePath);
|
QFile::remove(filePath);
|
||||||
if(QFile::exists(iconPath) && !iconPath.startsWith(":/"))
|
if(QFile::exists(iconPath) && !iconPath.startsWith(":/"))
|
||||||
|
@ -187,16 +172,19 @@ class RssStream : public QObject{
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete all the items saved
|
// delete all the items saved
|
||||||
void removeAllItem() {
|
void removeAllItems() {
|
||||||
unsigned int listSize = listItem.size();
|
unsigned int listSize = listItem.size();
|
||||||
for(unsigned int i=0; i<listSize; ++i){
|
for(unsigned int i=0; i<listSize; ++i){
|
||||||
delete getItem(i);
|
delete listItem.at(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh() {
|
void setLoading(bool val) {
|
||||||
downloaderRss->downloadUrl(url);
|
currently_loading = val;
|
||||||
lastRefresh.start();
|
}
|
||||||
|
|
||||||
|
bool isLoading() {
|
||||||
|
return currently_loading;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getTitle() const{
|
QString getTitle() const{
|
||||||
|
@ -207,11 +195,20 @@ class RssStream : public QObject{
|
||||||
return alias;
|
return alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
//prefer the RssManager::setAlias, do not save the changed ones
|
// Prefer the RssManager::setAlias to save the changed ones
|
||||||
void setAlias(QString _alias){
|
void setAlias(QString _alias){
|
||||||
alias = _alias;
|
alias = _alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the alias if the stream has one, the url if it has no alias
|
||||||
|
QString getAliasOrUrl() const{
|
||||||
|
if(!alias.isEmpty())
|
||||||
|
return alias;
|
||||||
|
if(!title.isEmpty())
|
||||||
|
return title;
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
QString getLink() const{
|
QString getLink() const{
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
@ -233,31 +230,44 @@ class RssStream : public QObject{
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getIconPath() const{
|
QString getIconPath() const{
|
||||||
|
if(downloadFailure)
|
||||||
|
return ":/Icons/unavailable.png";
|
||||||
return iconPath;
|
return iconPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasCustomIcon() const{
|
||||||
|
return !iconPath.startsWith(":/");
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIconPath(QString path) {
|
||||||
|
iconPath = path;
|
||||||
|
}
|
||||||
|
|
||||||
RssItem* getItem(unsigned int index) const{
|
RssItem* getItem(unsigned int index) const{
|
||||||
return listItem.at(index);
|
return listItem.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short getListSize() const{
|
unsigned int getNbNews() const{
|
||||||
return listItem.size();
|
return listItem.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short getNbNonRead() const{
|
unsigned int getNbUnRead() const{
|
||||||
int i=0, nbnonread=0;
|
unsigned int nbUnread=0;
|
||||||
for(i=0; i<listItem.size(); ++i) {
|
RssItem *item;
|
||||||
if(!listItem.at(i)->isRead())
|
foreach(item, listItem){
|
||||||
nbnonread++;
|
if(!item->isRead())
|
||||||
|
++nbUnread;
|
||||||
}
|
}
|
||||||
return nbnonread;
|
return nbUnread;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<RssItem*> getListItem() const{
|
QList<RssItem*> getNewsList() const{
|
||||||
return listItem;
|
return listItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getLastRefreshElapsedString() const{
|
QString getLastRefreshElapsedString() const{
|
||||||
|
if(!refreshed)
|
||||||
|
return tr("Never");
|
||||||
return tr("%1 ago", "10min ago").arg(misc::userFriendlyDuration((long)(lastRefresh.elapsed()/1000.)).replace("<", "<"));
|
return tr("%1 ago", "10min ago").arg(misc::userFriendlyDuration((long)(lastRefresh.elapsed()/1000.)).replace("<", "<"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,24 +275,10 @@ class RssStream : public QObject{
|
||||||
return lastRefresh.elapsed();
|
return lastRefresh.elapsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getLastRefresh() const{
|
|
||||||
return QString::number(lastRefresh.hour())+"h"+QString::number(lastRefresh.minute())+"m";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isRead() const {
|
|
||||||
return read;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRead() {
|
|
||||||
read = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// download the icon from the adress
|
// download the icon from the adress
|
||||||
void getIcon() {
|
QString getIconUrl() {
|
||||||
QUrl siteUrl(url);
|
QUrl siteUrl(url);
|
||||||
QString iconUrl = "http://"+siteUrl.host()+"/favicon.ico";
|
return QString("http://"+siteUrl.host()+"/favicon.ico");
|
||||||
connect(downloaderIcon, SIGNAL(downloadFinished(QString, QString)), this, SLOT(displayIcon(QString, QString)));
|
|
||||||
downloaderIcon->downloadUrl(iconUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -300,7 +296,7 @@ class RssStream : public QObject{
|
||||||
}
|
}
|
||||||
QDomNode rss = root.firstChild();
|
QDomNode rss = root.firstChild();
|
||||||
QDomElement channel = root.firstChild().toElement();
|
QDomElement channel = root.firstChild().toElement();
|
||||||
unsigned short listsize = getListSize();
|
unsigned short listsize = getNbNews();
|
||||||
for(unsigned short i=0; i<listsize; ++i) {
|
for(unsigned short i=0; i<listsize; ++i) {
|
||||||
listItem.removeLast();
|
listItem.removeLast();
|
||||||
}
|
}
|
||||||
|
@ -322,13 +318,12 @@ class RssStream : public QObject{
|
||||||
else if (property.tagName() == "image")
|
else if (property.tagName() == "image")
|
||||||
image = property.text();
|
image = property.text();
|
||||||
else if(property.tagName() == "item") {
|
else if(property.tagName() == "item") {
|
||||||
if(getListSize() < STREAM_MAX_ITEM) {
|
if(getNbNews() < STREAM_MAX_ITEM) {
|
||||||
listItem.append(new RssItem(property));
|
listItem.append(new RssItem(property));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
property = property.nextSibling().toElement();
|
property = property.nextSibling().toElement();
|
||||||
}
|
}
|
||||||
read = false;
|
|
||||||
}
|
}
|
||||||
channel = channel.nextSibling().toElement();
|
channel = channel.nextSibling().toElement();
|
||||||
}
|
}
|
||||||
|
@ -339,7 +334,7 @@ class RssStream : public QObject{
|
||||||
void resizeList() {
|
void resizeList() {
|
||||||
unsigned short lastindex = 0;
|
unsigned short lastindex = 0;
|
||||||
QString firstTitle = getItem(0)->getTitle();
|
QString firstTitle = getItem(0)->getTitle();
|
||||||
unsigned short listsize = getListSize();
|
unsigned short listsize = getNbNews();
|
||||||
for(unsigned short i=0; i<listsize; ++i) {
|
for(unsigned short i=0; i<listsize; ++i) {
|
||||||
if(getItem(i)->getTitle() == firstTitle)
|
if(getItem(i)->getTitle() == firstTitle)
|
||||||
lastindex = i;
|
lastindex = i;
|
||||||
|
@ -347,7 +342,7 @@ class RssStream : public QObject{
|
||||||
for(unsigned short i=0; i<lastindex; ++i) {
|
for(unsigned short i=0; i<lastindex; ++i) {
|
||||||
listItem.removeFirst();
|
listItem.removeFirst();
|
||||||
}
|
}
|
||||||
while(getListSize()>STREAM_MAX_ITEM) {
|
while(getNbNews()>STREAM_MAX_ITEM) {
|
||||||
listItem.removeAt(STREAM_MAX_ITEM);
|
listItem.removeAt(STREAM_MAX_ITEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,31 +375,6 @@ class RssStream : public QObject{
|
||||||
}
|
}
|
||||||
return return_lecture;
|
return return_lecture;
|
||||||
}
|
}
|
||||||
|
|
||||||
void openIcon() {
|
|
||||||
QImage fileIcon(iconPath,0);
|
|
||||||
if(!fileIcon.load(iconPath, 0)) {
|
|
||||||
qDebug("error: icon open failed, no file or empty file at "+iconPath.toUtf8());
|
|
||||||
if(QFile::exists(iconPath)) {
|
|
||||||
QFile::remove(iconPath);
|
|
||||||
if(downloadFailure){
|
|
||||||
iconPath = ":/Icons/unavailable.png";
|
|
||||||
qDebug("Could not open favicon nor rss stream, setting icon to unavailable (%s)",(const char*)getAlias().toUtf8());
|
|
||||||
} else {
|
|
||||||
iconPath = ":/Icons/rss.png";
|
|
||||||
qDebug("Could not open favicon, setting default icon (%s)",(const char*)getAlias().toUtf8());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
void handleDownloadFailure(QString, QString){
|
|
||||||
// Change the stream icon to a red cross
|
|
||||||
iconPath = ":/Icons/unavailable.png";
|
|
||||||
downloadFailure = true;
|
|
||||||
emit refreshFinished(url, ICON);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// global class, manage the whole rss stream
|
// global class, manage the whole rss stream
|
||||||
|
@ -412,162 +382,225 @@ class RssManager : public QObject{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private :
|
private :
|
||||||
QList<RssStream*> streamList;
|
QHash<QString, RssStream*> streams;
|
||||||
QStringList streamListUrl;
|
downloadThread *downloader;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void streamNeedRefresh(const unsigned short&, const unsigned short&);
|
void feedInfosChanged(QString url, QString aliasOrUrl, unsigned int nbUnread);
|
||||||
|
void feedIconChanged(QString url, QString icon_path);
|
||||||
|
|
||||||
public slots :
|
public slots :
|
||||||
void streamNeedRefresh(QString _url, const unsigned short& type) {
|
|
||||||
emit(streamNeedRefresh(hasStream(_url), type));
|
void processFinishedDownload(QString url, QString path) {
|
||||||
|
if(url.endsWith("favicon.ico")){
|
||||||
|
// Icon downloaded
|
||||||
|
QImage fileIcon;
|
||||||
|
if(fileIcon.load(path)) {
|
||||||
|
QList<RssStream*> res = findFeedsWithIcon(url);
|
||||||
|
RssStream* stream;
|
||||||
|
foreach(stream, res){
|
||||||
|
stream->setIconPath(path);
|
||||||
|
if(!stream->isLoading())
|
||||||
|
emit feedIconChanged(stream->getUrl(), stream->getIconPath());
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
qDebug("Unsupported icon format at %s", (const char*)url.toUtf8());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RssStream *stream = streams.value(url, 0);
|
||||||
|
if(!stream){
|
||||||
|
qDebug("This rss stream was deleted in the meantime, nothing to update");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
stream->processDownloadedFile(path);
|
||||||
|
stream->setLoading(false);
|
||||||
|
// If the feed has no alias, then we use the title as Alias
|
||||||
|
// this is more user friendly
|
||||||
|
if(stream->getAlias().isEmpty()){
|
||||||
|
if(!stream->getTitle().isEmpty())
|
||||||
|
stream->setAlias(stream->getTitle());
|
||||||
|
}
|
||||||
|
emit feedInfosChanged(url, stream->getAliasOrUrl(), stream->getNbUnRead());
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleDownloadFailure(QString url, QString reason) {
|
||||||
|
if(url.endsWith("favicon.ico")){
|
||||||
|
// Icon download failure
|
||||||
|
qDebug("Could not download icon at %s, reason: %s", (const char*)url.toUtf8(), (const char*)reason.toUtf8());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RssStream *stream = streams.value(url, 0);
|
||||||
|
if(!stream){
|
||||||
|
qDebug("This rss stream was deleted in the meantime, nothing to update");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
stream->setLoading(false);
|
||||||
|
qDebug("Could not download Rss at %s, reason: %s", (const char*)url.toUtf8(), (const char*)reason.toUtf8());
|
||||||
|
stream->setDownloadFailed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public :
|
public :
|
||||||
RssManager(){
|
RssManager(){
|
||||||
|
downloader = new downloadThread(this);
|
||||||
|
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processFinishedDownload(QString, QString)));
|
||||||
|
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
|
||||||
loadStreamList();
|
loadStreamList();
|
||||||
}
|
}
|
||||||
|
|
||||||
~RssManager(){
|
~RssManager(){
|
||||||
saveStreamList();
|
RssStream *stream;
|
||||||
unsigned int streamListSize = streamList.size();
|
foreach(stream, streams){
|
||||||
for(unsigned int i=0; i<streamListSize; ++i){
|
delete stream;
|
||||||
delete getStream(i);
|
|
||||||
}
|
}
|
||||||
|
delete downloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the list of the rss stream
|
// load the list of the rss stream
|
||||||
void loadStreamList(){
|
void loadStreamList(){
|
||||||
QSettings settings("qBittorrent", "qBittorrent");
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
settings.beginGroup("Rss");
|
QStringList streamsUrl = settings.value("Rss/streamList").toStringList();
|
||||||
streamListUrl = settings.value("streamList").toStringList();
|
QStringList aliases = settings.value("Rss/streamAlias").toStringList();
|
||||||
QStringList streamListAlias = settings.value("streamAlias").toStringList();
|
if(streamsUrl.size() != aliases.size()){
|
||||||
//check that both list have same size
|
std::cerr << "Corrupted Rss list, not loading it\n";
|
||||||
while(streamListUrl.size()>streamListAlias.size())
|
return;
|
||||||
streamListUrl.removeLast();
|
|
||||||
while(streamListAlias.size()>streamListUrl.size())
|
|
||||||
streamListAlias.removeLast();
|
|
||||||
qDebug("NB RSS streams loaded: %d", streamListUrl.size());
|
|
||||||
settings.endGroup();
|
|
||||||
unsigned int streamListUrlSize = streamListUrl.size();
|
|
||||||
for(unsigned int i=0; i<streamListUrlSize; ++i){
|
|
||||||
RssStream *stream = new RssStream(streamListUrl.at(i));
|
|
||||||
stream->setAlias(streamListAlias.at(i));
|
|
||||||
streamList.append(stream);
|
|
||||||
connect(stream, SIGNAL(refreshFinished(QString, const unsigned short&)), this, SLOT(streamNeedRefresh(QString, const unsigned short&)));
|
|
||||||
}
|
}
|
||||||
qDebug("Streams loaded");
|
QString url;
|
||||||
|
unsigned int i = 0;
|
||||||
|
foreach(url, streamsUrl){
|
||||||
|
RssStream *stream = new RssStream(url);
|
||||||
|
QString alias = aliases.at(i);
|
||||||
|
if(!alias.isEmpty()) {
|
||||||
|
stream->setAlias(alias);
|
||||||
|
}
|
||||||
|
streams[url] = stream;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
qDebug("NB RSS streams loaded: %d", streamsUrl.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the list of the rss stream for the next session
|
// save the list of the rss stream for the next session
|
||||||
void saveStreamList(){
|
void saveStreamList(){
|
||||||
streamListUrl.clear();
|
QList<QPair<QString, QString> > streamsList;
|
||||||
QStringList streamListAlias;
|
QStringList streamsUrl;
|
||||||
unsigned int nbStreams = getNbStreams();
|
QStringList aliases;
|
||||||
for(unsigned int i=0; i<nbStreams; ++i) {
|
RssStream *stream;
|
||||||
streamListUrl.append(getStream(i)->getUrl());
|
foreach(stream, streams){
|
||||||
streamListAlias.append(getStream(i)->getAlias());
|
streamsUrl << stream->getUrl();
|
||||||
|
aliases << stream->getAlias();
|
||||||
}
|
}
|
||||||
QSettings settings("qBittorrent", "qBittorrent");
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
settings.beginGroup("Rss");
|
settings.beginGroup("Rss");
|
||||||
settings.setValue("streamList", streamListUrl);
|
settings.setValue("streamList", streamsUrl);
|
||||||
settings.setValue("streamAlias", streamListAlias);
|
settings.setValue("streamAlias", aliases);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a stream to the manager
|
// add a stream to the manager
|
||||||
void addStream(RssStream* stream){
|
void addStream(RssStream* stream){
|
||||||
if(hasStream(stream) < 0){
|
QString url = stream->getUrl();
|
||||||
streamList.append(stream);
|
if(streams.contains(url)){
|
||||||
streamListUrl.append(stream->getUrl());
|
|
||||||
connect(stream, SIGNAL(refreshFinished(QString, const unsigned short&)), this, SLOT(streamNeedRefresh(QString, const unsigned short&)));
|
|
||||||
}else{
|
|
||||||
qDebug("Not adding the Rss stream because it is already in the list");
|
qDebug("Not adding the Rss stream because it is already in the list");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
streams[url] = stream;
|
||||||
|
emit feedIconChanged(url, stream->getIconPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a stream to the manager
|
// add a stream to the manager
|
||||||
void addStream(QString url){
|
RssStream* addStream(QString url){
|
||||||
if(hasStream(url) < 0) {
|
if(streams.contains(url)){
|
||||||
RssStream* stream = new RssStream(url);
|
|
||||||
streamList.append(stream);
|
|
||||||
streamListUrl.append(url);
|
|
||||||
connect(stream, SIGNAL(refreshFinished(QString, const unsigned short&)), this, SLOT(streamNeedRefresh(QString, const unsigned short&)));
|
|
||||||
}else {
|
|
||||||
qDebug("Not adding the Rss stream because it is already in the list");
|
qDebug("Not adding the Rss stream because it is already in the list");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
RssStream* stream = new RssStream(url);
|
||||||
|
streams[url] = stream;
|
||||||
|
refresh(url);
|
||||||
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove a stream from the manager
|
// remove a stream from the manager
|
||||||
void removeStream(RssStream* stream){
|
void removeStream(RssStream* stream){
|
||||||
short index = hasStream(stream);
|
QString url = stream->getUrl();
|
||||||
if(index != -1){
|
Q_ASSERT(streams.contains(url));
|
||||||
delete streamList.takeAt(index);
|
delete streams.take(url);
|
||||||
streamListUrl.removeAt(index);
|
}
|
||||||
|
|
||||||
|
QList<RssStream*> findFeedsWithIcon(QString icon_url){
|
||||||
|
QList<RssStream*> res;
|
||||||
|
RssStream* stream;
|
||||||
|
foreach(stream, streams){
|
||||||
|
if(stream->getIconUrl() == icon_url)
|
||||||
|
res << stream;
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeStream(QString url){
|
||||||
|
Q_ASSERT(streams.contains(url));
|
||||||
|
delete streams.take(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all the streams in the manager
|
// remove all the streams in the manager
|
||||||
void removeAll(){
|
void removeAll(){
|
||||||
QList<RssStream*> newStreamList;
|
RssStream *stream;
|
||||||
QStringList newUrlList;
|
foreach(stream, streams){
|
||||||
unsigned int streamListSize = streamList.size();
|
delete stream;
|
||||||
for(unsigned int i=0; i<streamListSize; ++i){
|
|
||||||
delete getStream(i);
|
|
||||||
}
|
}
|
||||||
streamList = newStreamList;
|
streams.clear();
|
||||||
streamListUrl = newUrlList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reload all the xml files from the web
|
// reload all the xml files from the web
|
||||||
void refreshAll(){
|
void refreshAll(){
|
||||||
unsigned int streamListUrlSize = streamListUrl.size();
|
qDebug("Refreshing all rss feeds");
|
||||||
for(unsigned int i=0; i<streamListUrlSize; ++i){
|
RssStream *stream;
|
||||||
getStream(i)->refresh();
|
foreach(stream, streams){
|
||||||
connect(getStream(i), SIGNAL(refreshFinished(QString, const unsigned short&)), this, SLOT(streamNeedRefresh(QString, const unsigned short&)));
|
QString url = stream->getUrl();
|
||||||
|
if(stream->isLoading()) return;
|
||||||
|
qDebug("Refreshing feed: %s...", (const char*)url.toUtf8());
|
||||||
|
stream->setLoading(true);
|
||||||
|
downloader->downloadUrl(url);
|
||||||
|
if(!stream->hasCustomIcon()){
|
||||||
|
downloader->downloadUrl(stream->getIconUrl());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh(unsigned int index) {
|
void refresh(QString url) {
|
||||||
if(index<getNbStreams()) {
|
Q_ASSERT(streams.contains(url));
|
||||||
if(getStream(index)->getLastRefreshElapsed()>REFRESH_FREQ_MAX) {
|
RssStream *stream = streams[url];
|
||||||
getStream(index)->refresh();
|
if(stream->isLoading()) return;
|
||||||
connect(getStream(index), SIGNAL(refreshFinished(QString, const unsigned short&)), this, SLOT(streamNeedRefresh(QString, const unsigned short&)));
|
stream->setLoading(true);
|
||||||
}
|
downloader->downloadUrl(url);
|
||||||
|
if(!stream->hasCustomIcon()){
|
||||||
|
downloader->downloadUrl(stream->getIconUrl());
|
||||||
|
}else{
|
||||||
|
qDebug("No need to download this feed's icon, it was already downloaded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the position index of a stream, if the manager owns it
|
// XXX: Used?
|
||||||
short hasStream(RssStream* stream) const{
|
unsigned int getNbFeeds() {
|
||||||
return hasStream(stream->getUrl());
|
return streams.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
short hasStream(QString url) const{
|
RssStream* getFeed(QString url){
|
||||||
return streamListUrl.indexOf(url);
|
Q_ASSERT(streams.contains(url));
|
||||||
|
return streams[url];
|
||||||
}
|
}
|
||||||
|
|
||||||
RssStream* getStream(const unsigned short& index) const{
|
// Set an alias for a stream and save it for later
|
||||||
return streamList.at(index);
|
void setAlias(QString url, QString newAlias) {
|
||||||
|
Q_ASSERT(!newAlias.isEmpty());
|
||||||
|
RssStream * stream = streams.value(url, 0);
|
||||||
|
Q_ASSERT(stream != 0);
|
||||||
|
stream->setAlias(newAlias);
|
||||||
|
emit feedInfosChanged(url, stream->getAliasOrUrl(), stream->getNbUnRead());
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int getNbStreams() {
|
// Return all the rss feeds we have
|
||||||
return streamList.size();
|
QList<RssStream*> getRssFeeds() const {
|
||||||
}
|
return streams.values();
|
||||||
|
|
||||||
//set an alias to an stream and save it for later
|
|
||||||
void setAlias(unsigned short index, QString newAlias) {
|
|
||||||
if(newAlias.length()>=2 && !getListAlias().contains(newAlias, Qt::CaseInsensitive)) {
|
|
||||||
getStream(index)->setAlias(newAlias);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList getListAlias() {
|
|
||||||
QStringList listAlias;
|
|
||||||
unsigned int nbStreams = getNbStreams();
|
|
||||||
for(unsigned short i=0; i<nbStreams; ++i) {
|
|
||||||
listAlias.append(getStream(i)->getAlias());
|
|
||||||
}
|
|
||||||
return listAlias;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
<enum>Qt::CustomContextMenu</enum>
|
<enum>Qt::CustomContextMenu</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="columnCount" >
|
<property name="columnCount" >
|
||||||
<number>1</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<column>
|
<column>
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
|
|
356
src/rss_imp.cpp
356
src/rss_imp.cpp
|
@ -31,12 +31,13 @@
|
||||||
|
|
||||||
// display a right-click menu
|
// display a right-click menu
|
||||||
void RSSImp::displayRSSListMenu(const QPoint& pos){
|
void RSSImp::displayRSSListMenu(const QPoint& pos){
|
||||||
moveCurrentItem();
|
|
||||||
QMenu myFinishedListMenu(this);
|
QMenu myFinishedListMenu(this);
|
||||||
QTreeWidgetItem* item = listStreams->itemAt(pos);
|
QTreeWidgetItem* item = listStreams->itemAt(pos);
|
||||||
if(item!=NULL) {
|
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
|
||||||
|
if(item != 0) {
|
||||||
myFinishedListMenu.addAction(actionDelete);
|
myFinishedListMenu.addAction(actionDelete);
|
||||||
myFinishedListMenu.addAction(actionRename);
|
if(selectedItems.size() == 1)
|
||||||
|
myFinishedListMenu.addAction(actionRename);
|
||||||
myFinishedListMenu.addAction(actionRefresh);
|
myFinishedListMenu.addAction(actionRefresh);
|
||||||
}else{
|
}else{
|
||||||
myFinishedListMenu.addAction(actionCreate);
|
myFinishedListMenu.addAction(actionCreate);
|
||||||
|
@ -52,19 +53,29 @@
|
||||||
|
|
||||||
// delete a stream by a button
|
// delete a stream by a button
|
||||||
void RSSImp::on_delStream_button_clicked() {
|
void RSSImp::on_delStream_button_clicked() {
|
||||||
if(getNumStreamSelected()<0 || rssmanager->getNbStreams()==0) {
|
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
|
||||||
qDebug("no stream selected");
|
QTreeWidgetItem *item;
|
||||||
return;
|
if(!selectedItems.size()) return;
|
||||||
}else {
|
int ret = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to delete this stream from the list?"),
|
||||||
int ok = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to delete this stream from the list?"),
|
tr("&Yes"), tr("&No"),
|
||||||
tr("&Yes"), tr("&No"),
|
QString(), 0, 1);
|
||||||
QString(), 0, 1);
|
if(!ret) {
|
||||||
if(ok==0) {
|
QStringList urlsToDelete;
|
||||||
textBrowser->clear();
|
foreach(item, selectedItems){
|
||||||
listNews->clear();
|
QString url = item->data(1, Qt::DisplayRole).toString();
|
||||||
rssmanager->removeStream(rssmanager->getStream(getNumStreamSelected()));
|
urlsToDelete << url;
|
||||||
refreshStreamList();
|
}
|
||||||
}
|
QString url;
|
||||||
|
foreach(url, urlsToDelete){
|
||||||
|
if(selectedFeedUrl == url){
|
||||||
|
textBrowser->clear();
|
||||||
|
listNews->clear();
|
||||||
|
}
|
||||||
|
rssmanager->removeStream(url);
|
||||||
|
delete getTreeItemFromUrl(url);
|
||||||
|
}
|
||||||
|
if(urlsToDelete.size())
|
||||||
|
rssmanager->saveStreamList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,205 +84,167 @@
|
||||||
refreshAllStreams();
|
refreshAllStreams();
|
||||||
}
|
}
|
||||||
|
|
||||||
// display the news of a stream when click on it
|
|
||||||
void RSSImp::on_listStreams_clicked() {
|
|
||||||
if(rssmanager->getNbStreams()>0) {
|
|
||||||
moveCurrentItem();
|
|
||||||
rssmanager->getStream(getNumStreamSelected())->setRead();
|
|
||||||
// update the color of the stream, is it old ?
|
|
||||||
updateStreamName(getNumStreamSelected(), LATENCY);
|
|
||||||
refreshNewsList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// display the content of a new when clicked on it
|
|
||||||
void RSSImp::on_listNews_clicked() {
|
|
||||||
listNews->item(listNews->currentRow())->setData(Qt::ForegroundRole, QVariant(QColor("grey")));
|
|
||||||
listNews->item(listNews->currentRow())->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
|
|
||||||
refreshTextBrowser();
|
|
||||||
}
|
|
||||||
|
|
||||||
// open the url of the news in a browser
|
// open the url of the news in a browser
|
||||||
void RSSImp::on_listNews_doubleClicked() {
|
void RSSImp::openInBrowser(QListWidgetItem *item) {
|
||||||
if(getNumStreamSelected()>=0 && listNews->currentRow()>=0 && rssmanager->getStream(getNumStreamSelected())->getListSize()>0) {
|
RssItem* news = rssmanager->getFeed(selectedFeedUrl)->getItem(listNews->row(item));
|
||||||
RssItem* currentItem = rssmanager->getStream(getNumStreamSelected())->getItem(listNews->currentRow());
|
QString link = news->getLink();
|
||||||
if(currentItem->getLink()!=NULL && currentItem->getLink().length()>5)
|
if(!link.isEmpty())
|
||||||
QDesktopServices::openUrl(QUrl(currentItem->getLink()));
|
QDesktopServices::openUrl(QUrl(link));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// move the current selection if it is not a toplevelitem (id : stream)
|
//right-click on stream : give him an alias
|
||||||
void RSSImp::moveCurrentItem() {
|
|
||||||
if(getNumStreamSelected()<0) {
|
|
||||||
int index = listStreams->indexOfTopLevelItem(listStreams->currentItem()->parent());
|
|
||||||
if(index>=0)
|
|
||||||
listStreams->setCurrentItem(listStreams->topLevelItem(index));
|
|
||||||
else
|
|
||||||
listStreams->setCurrentItem(listStreams->topLevelItem(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//right-clik on stream : delete it
|
|
||||||
void RSSImp::deleteStream() {
|
|
||||||
if(rssmanager->getNbStreams()==0) {
|
|
||||||
qDebug("no stream selected");
|
|
||||||
return;
|
|
||||||
}else {
|
|
||||||
int ok = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to delete this stream from the list ?"), tr("&Yes"), tr("&No"), QString(), 0, 1);
|
|
||||||
if(ok==0) {
|
|
||||||
moveCurrentItem();
|
|
||||||
textBrowser->clear();
|
|
||||||
listNews->clear();
|
|
||||||
rssmanager->removeStream(rssmanager->getStream(getNumStreamSelected()));
|
|
||||||
refreshStreamList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//right-clik on stream : give him an alias
|
|
||||||
void RSSImp::renameStream() {
|
void RSSImp::renameStream() {
|
||||||
if(rssmanager->getNbStreams()==0) {
|
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
|
||||||
qDebug("no stream selected");
|
Q_ASSERT(selectedItems.size() == 1);
|
||||||
return;
|
QTreeWidgetItem *item = selectedItems.at(0);
|
||||||
}else {
|
QString url = item->data(1, Qt::DisplayRole).toString();
|
||||||
moveCurrentItem();
|
bool ok;
|
||||||
bool ok;
|
QString newAlias = QInputDialog::getText(this, tr("Please choose a new name for this stream"), tr("New stream name:"), QLineEdit::Normal, rssmanager->getFeed(url)->getAlias(), &ok);
|
||||||
short index = getNumStreamSelected();
|
if(ok) {
|
||||||
QString newAlias = QInputDialog::getText(this, tr("Please choose a new name for this stream"), tr("New stream name:"), QLineEdit::Normal, rssmanager->getStream(index)->getAlias(), &ok);
|
rssmanager->setAlias(url, newAlias);
|
||||||
if(ok) {
|
|
||||||
rssmanager->setAlias(index, newAlias);
|
|
||||||
updateStreamName(index, NEWS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//right-clik on stream : refresh it
|
//right-click on stream : refresh it
|
||||||
void RSSImp::refreshStream() {
|
void RSSImp::refreshSelectedStreams() {
|
||||||
if(rssmanager->getNbStreams()>0) {
|
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
|
||||||
moveCurrentItem();
|
QTreeWidgetItem* item;
|
||||||
short index = getNumStreamSelected();
|
foreach(item, selectedItems){
|
||||||
textBrowser->clear();
|
QString url = item->text(1);
|
||||||
listNews->clear();
|
textBrowser->clear();
|
||||||
listStreams->topLevelItem(index)->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
|
listNews->clear();
|
||||||
rssmanager->refresh(index);
|
rssmanager->refresh(url);
|
||||||
|
item->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
|
||||||
}
|
}
|
||||||
updateLastRefreshedTimeForStreams();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//right-click somewhere, refresh all the streams
|
//right-click somewhere, refresh all the streams
|
||||||
void RSSImp::refreshAllStreams() {
|
void RSSImp::refreshAllStreams() {
|
||||||
textBrowser->clear();
|
textBrowser->clear();
|
||||||
listNews->clear();
|
listNews->clear();
|
||||||
unsigned short nbstream = rssmanager->getNbStreams();
|
unsigned int nbFeeds = listStreams->topLevelItemCount();
|
||||||
for(unsigned short i=0; i<nbstream; ++i)
|
for(unsigned int i=0; i<nbFeeds; ++i)
|
||||||
listStreams->topLevelItem(i)->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
|
listStreams->topLevelItem(i)->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
|
||||||
rssmanager->refreshAll();
|
rssmanager->refreshAll();
|
||||||
updateLastRefreshedTimeForStreams();
|
updateLastRefreshedTimeForStreams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RSSImp::fillFeedsList() {
|
||||||
|
QList<RssStream*> feeds = rssmanager->getRssFeeds();
|
||||||
|
RssStream* stream;
|
||||||
|
foreach(stream, feeds){
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem(listStreams);
|
||||||
|
item->setData(0, Qt::DisplayRole, stream->getAliasOrUrl()+ QString(" (0)"));
|
||||||
|
item->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
|
||||||
|
item->setData(1, Qt::DisplayRole, stream->getUrl());
|
||||||
|
item->setToolTip(0, QString("<b>")+tr("Description:")+QString("</b> ")+stream->getDescription()+QString("<br/><b>")+tr("url:")+QString("</b> ")+stream->getUrl()+QString("<br/><b>")+tr("Last refresh:")+QString("</b> ")+stream->getLastRefreshElapsedString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//right-click, register a new stream
|
//right-click, register a new stream
|
||||||
void RSSImp::createStream() {
|
void RSSImp::createStream() {
|
||||||
bool ok;
|
bool ok;
|
||||||
QString newUrl = QInputDialog::getText(this, tr("Please type a rss stream url"), tr("Stream URL:"), QLineEdit::Normal, "http://", &ok);
|
QString newUrl = QInputDialog::getText(this, tr("Please type a rss stream url"), tr("Stream URL:"), QLineEdit::Normal, "http://", &ok);
|
||||||
if(ok) {
|
if(ok) {
|
||||||
newUrl = newUrl.trimmed();
|
newUrl = newUrl.trimmed();
|
||||||
if(!newUrl.isEmpty() && newUrl != "http://"){
|
if(!newUrl.isEmpty()){
|
||||||
rssmanager->addStream(newUrl);
|
RssStream *stream = rssmanager->addStream(newUrl);
|
||||||
refreshStreamList();
|
if(stream == 0){
|
||||||
|
// Already existing
|
||||||
|
QMessageBox::warning(this, tr("qBittorrent"),
|
||||||
|
tr("This rss feed is already in the list."),
|
||||||
|
QMessageBox::Ok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem(listStreams);
|
||||||
|
item->setText(0, stream->getAliasOrUrl() + QString(" (0)"));
|
||||||
|
item->setText(1, stream->getUrl());
|
||||||
|
item->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
|
||||||
|
item->setToolTip(0, QString("<b>")+tr("Description:")+QString("</b> ")+stream->getDescription()+QString("<br/><b>")+tr("url:")+QString("</b> ")+stream->getUrl()+QString("<br/><b>")+tr("Last refresh:")+QString("</b> ")+stream->getLastRefreshElapsedString());
|
||||||
|
if(listStreams->topLevelItemCount() == 1)
|
||||||
|
selectFirstFeed();
|
||||||
|
rssmanager->refresh(newUrl);
|
||||||
|
rssmanager->saveStreamList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fills the streamList
|
void RSSImp::updateLastRefreshedTimeForStreams() {
|
||||||
void RSSImp::refreshStreamList() {
|
qDebug("Refreshing last refresh time in rss list");
|
||||||
qDebug("Refreshing stream list");
|
unsigned int nbFeeds = listStreams->topLevelItemCount();
|
||||||
unsigned short nbstream = rssmanager->getNbStreams();
|
for(unsigned int i=0; i<nbFeeds; ++i){
|
||||||
listStreams->clear();
|
QTreeWidgetItem* item = listStreams->topLevelItem(i);
|
||||||
QList<QTreeWidgetItem *> streams;
|
RssStream* stream = rssmanager->getFeed(item->data(1, Qt::DisplayRole).toString());
|
||||||
for(unsigned short i=0; i<nbstream; ++i) {
|
item->setToolTip(0, QString("<b>")+tr("Description:")+QString("</b> ")+stream->getDescription()+QString("<br/><b>")+tr("url:")+QString("</b> ")+stream->getUrl()+QString("<br/><b>")+tr("Last refresh:")+QString("</b> ")+stream->getLastRefreshElapsedString());
|
||||||
QTreeWidgetItem* stream = new QTreeWidgetItem(listStreams);
|
|
||||||
updateStreamName(i, NEWS);
|
|
||||||
stream->setToolTip(0, QString("<b>")+tr("Description:")+QString("</b> ")+rssmanager->getStream(i)->getDescription()+QString("<br/><b>")+tr("url:")+QString("</b> ")+rssmanager->getStream(i)->getUrl()+QString("<br/><b>")+tr("Last refresh:")+QString("</b> ")+rssmanager->getStream(i)->getLastRefreshElapsedString());
|
|
||||||
}
|
}
|
||||||
qDebug("Stream list refreshed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fills the newsList
|
// fills the newsList
|
||||||
void RSSImp::refreshNewsList() {
|
void RSSImp::refreshNewsList(QTreeWidgetItem* item, int) {
|
||||||
if(rssmanager->getNbStreams()>0) {
|
selectedFeedUrl = item->text(1);
|
||||||
RssStream* currentstream = rssmanager->getStream(getNumStreamSelected());
|
RssStream *stream = rssmanager->getFeed(selectedFeedUrl);
|
||||||
listNews->clear();
|
listNews->clear();
|
||||||
unsigned short currentStreamSize = currentstream->getListSize();
|
qDebug("Getting the list of news");
|
||||||
for(unsigned short i=0; i<currentStreamSize; ++i) {
|
QList<RssItem*> news = stream->getNewsList();
|
||||||
new QListWidgetItem(currentstream->getItem(i)->getTitle(), listNews);
|
qDebug("Got the list of news");
|
||||||
if(currentstream->getItem(i)->isRead()){
|
RssItem* article;
|
||||||
listNews->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("grey")));
|
foreach(article, news){
|
||||||
listNews->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
|
QListWidgetItem* it = new QListWidgetItem(article->getTitle(), listNews);
|
||||||
} else {
|
if(article->isRead()){
|
||||||
listNews->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere2.png")));
|
it->setData(Qt::ForegroundRole, QVariant(QColor("grey")));
|
||||||
listNews->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("blue")));
|
it->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
|
||||||
}
|
}else{
|
||||||
if(i%2==0)
|
it->setData(Qt::ForegroundRole, QVariant(QColor("blue")));
|
||||||
listNews->item(i)->setData(Qt::BackgroundRole, QVariant(QColor(0, 255, 255, 20)));
|
it->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere2.png")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
qDebug("Added all news to the GUI");
|
||||||
|
selectFirstNews();
|
||||||
|
qDebug("First news selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
// display a news
|
// display a news
|
||||||
void RSSImp::refreshTextBrowser() {
|
void RSSImp::refreshTextBrowser(QListWidgetItem *item) {
|
||||||
if(getNumStreamSelected()>=0 && listNews->currentRow()>=0) {
|
RssItem* article = rssmanager->getFeed(selectedFeedUrl)->getItem(listNews->row(item));
|
||||||
RssItem* currentitem = rssmanager->getStream(getNumStreamSelected())->getItem(listNews->currentRow());
|
textBrowser->setHtml(article->getTitle()+":<br/>"+article->getDescription());
|
||||||
textBrowser->setHtml(currentitem->getTitle()+" : \n"+currentitem->getDescription());
|
article->setRead();
|
||||||
currentitem->setRead();
|
item->setData(Qt::ForegroundRole, QVariant(QColor("grey")));
|
||||||
}
|
item->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
|
||||||
|
updateFeedNbNews(selectedFeedUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSImp::updateLastRefreshedTimeForStreams() {
|
QTreeWidgetItem* RSSImp::getTreeItemFromUrl(QString url) const{
|
||||||
unsigned int nbStreams = rssmanager->getNbStreams();
|
unsigned int nbItems = listStreams->topLevelItemCount();
|
||||||
for(unsigned int i=0; i<nbStreams; ++i){
|
for(unsigned int i = 0; i<nbItems; ++i){
|
||||||
listStreams->topLevelItem(i)->setToolTip(0, QString("<b>")+tr("Description:")+QString("</b> ")+rssmanager->getStream(i)->getDescription()+QString("<br/><b>")+tr("url:")+QString("</b> ")+rssmanager->getStream(i)->getUrl()+QString("<br/><b>")+tr("Last refresh:")+QString("</b> ")+rssmanager->getStream(i)->getLastRefreshElapsedString());
|
QTreeWidgetItem* item = listStreams->topLevelItem(i);
|
||||||
|
if(item->text(1) == url)
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
qDebug("Cannot find url %s in feeds list", (const char*)url.toUtf8());
|
||||||
|
Q_ASSERT(false); // Should never go through here
|
||||||
|
return (QTreeWidgetItem*)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// show the number of news for a stream, his status and an icon
|
void RSSImp::updateFeedIcon(QString url, QString icon_path){
|
||||||
void RSSImp::updateStreamName(const unsigned short& i, const unsigned short& type) {
|
QTreeWidgetItem *item = getTreeItemFromUrl(url);
|
||||||
// icon has just been download
|
item->setData(0,Qt::DecorationRole, QVariant(QIcon(icon_path)));
|
||||||
if(type == ICON) {
|
}
|
||||||
listStreams->topLevelItem(i)->setData(0,Qt::DecorationRole, QVariant(QIcon(rssmanager->getStream(i)->getIconPath())));
|
|
||||||
}
|
|
||||||
// on click, show the age of the stream
|
|
||||||
if(type == LATENCY) {
|
|
||||||
unsigned short nbitem = rssmanager->getStream(i)->getNbNonRead();
|
|
||||||
listStreams->topLevelItem(i)->setText(0,rssmanager->getStream(i)->getAlias().toUtf8()+" ("+QString::number(nbitem,10).toUtf8()+")");
|
|
||||||
if(nbitem==0)
|
|
||||||
listStreams->topLevelItem(i)->setData(0,Qt::ForegroundRole, QVariant(QColor("red")));
|
|
||||||
else if(rssmanager->getStream(i)->getLastRefreshElapsed()>REFRESH_MAX_LATENCY)
|
|
||||||
listStreams->topLevelItem(i)->setData(0,Qt::ForegroundRole, QVariant(QColor("orange")));
|
|
||||||
else
|
|
||||||
listStreams->topLevelItem(i)->setData(0,Qt::ForegroundRole, QVariant(QColor("green")));
|
|
||||||
listStreams->topLevelItem(getNumStreamSelected())->setData(0,Qt::BackgroundRole, QVariant(QColor("white")));
|
|
||||||
}
|
|
||||||
// when news are refreshed, update all informations
|
|
||||||
if(type == NEWS) {
|
|
||||||
unsigned short nbitem = rssmanager->getStream(i)->getListSize();
|
|
||||||
listStreams->topLevelItem(i)->setText(0,rssmanager->getStream(i)->getAlias().toUtf8()+" ("+QString::number(nbitem,10).toUtf8()+")");
|
|
||||||
if(nbitem==0)
|
|
||||||
listStreams->topLevelItem(i)->setData(0,Qt::ForegroundRole, QVariant(QColor("red")));
|
|
||||||
else if(rssmanager->getStream(i)->getLastRefreshElapsed()>REFRESH_MAX_LATENCY)
|
|
||||||
listStreams->topLevelItem(i)->setData(0,Qt::ForegroundRole, QVariant(QColor("orange")));
|
|
||||||
else
|
|
||||||
listStreams->topLevelItem(i)->setData(0,Qt::ForegroundRole, QVariant(QColor("green")));
|
|
||||||
|
|
||||||
if(!rssmanager->getStream(i)->isRead())
|
void RSSImp::updateFeedNbNews(QString url){
|
||||||
listStreams->topLevelItem(i)->setData(0,Qt::BackgroundRole, QVariant(QColor(0, 255, 0, 20)));
|
QTreeWidgetItem *item = getTreeItemFromUrl(url);
|
||||||
if(getNumStreamSelected()==i) {
|
RssStream *stream = rssmanager->getFeed(url);
|
||||||
listNews->clear();
|
item->setText(0, stream->getAliasOrUrl() + QString(" (") + QString::number(stream->getNbUnRead(), 10)+ String(")"));
|
||||||
refreshNewsList();
|
}
|
||||||
}
|
|
||||||
listStreams->topLevelItem(i)->setData(0,Qt::DecorationRole, QVariant(QIcon(rssmanager->getStream(i)->getIconPath())));
|
void RSSImp::updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnread){
|
||||||
// update description and display last refresh
|
QTreeWidgetItem *item = getTreeItemFromUrl(url);
|
||||||
listStreams->topLevelItem(i)->setToolTip(0, QString("<b>")+tr("Description:")+QString("</b> ")+rssmanager->getStream(i)->getDescription()+QString("<br/><b>")+tr("url:")+QString("</b> ")+rssmanager->getStream(i)->getUrl()+QString("<br/><b>")+tr("Last refresh:")+QString("</b> ")+rssmanager->getStream(i)->getLastRefreshElapsedString());
|
RssStream *stream = rssmanager->getFeed(url);
|
||||||
|
item->setText(0, aliasOrUrl + QString(" (") + QString::number(nbUnread, 10)+ String(")"));
|
||||||
|
item->setData(0,Qt::DecorationRole, QVariant(QIcon(stream->getIconPath())));
|
||||||
|
item->setToolTip(0, QString("<b>")+tr("Description:")+QString("</b> ")+stream->getDescription()+QString("<br/><b>")+tr("url:")+QString("</b> ")+stream->getUrl()+QString("<br/><b>")+tr("Last refresh:")+QString("</b> ")+stream->getLastRefreshElapsedString());
|
||||||
|
// If the feed is selected, update the displayed news
|
||||||
|
if(selectedFeedUrl == url){
|
||||||
|
refreshNewsList(getTreeItemFromUrl(url), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,29 +261,50 @@
|
||||||
actionCreate->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png")));
|
actionCreate->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png")));
|
||||||
actionRefreshAll->setIcon(QIcon(QString::fromUtf8(":/Icons/refresh.png")));
|
actionRefreshAll->setIcon(QIcon(QString::fromUtf8(":/Icons/refresh.png")));
|
||||||
|
|
||||||
|
// Hide second column (url)
|
||||||
|
listStreams->hideColumn(1);
|
||||||
|
|
||||||
rssmanager = new RssManager();
|
rssmanager = new RssManager();
|
||||||
connect(rssmanager, SIGNAL(streamNeedRefresh(const unsigned short&, const unsigned short&)), this, SLOT(updateStreamName(const unsigned short&, const unsigned short&)));
|
fillFeedsList();
|
||||||
|
connect(rssmanager, SIGNAL(feedInfosChanged(QString, QString, unsigned int)), this, SLOT(updateFeedInfos(QString, QString, unsigned int)));
|
||||||
|
connect(rssmanager, SIGNAL(feedIconChanged(QString, QString)), this, SLOT(updateFeedIcon(QString, QString)));
|
||||||
|
|
||||||
connect(listStreams, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRSSListMenu(const QPoint&)));
|
connect(listStreams, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRSSListMenu(const QPoint&)));
|
||||||
connect(actionDelete, SIGNAL(triggered()), this, SLOT(deleteStream()));
|
connect(actionDelete, SIGNAL(triggered()), this, SLOT(on_delStream_button_clicked()));
|
||||||
connect(actionRename, SIGNAL(triggered()), this, SLOT(renameStream()));
|
connect(actionRename, SIGNAL(triggered()), this, SLOT(renameStream()));
|
||||||
connect(actionRefresh, SIGNAL(triggered()), this, SLOT(refreshStream()));
|
connect(actionRefresh, SIGNAL(triggered()), this, SLOT(refreshSelectedStreams()));
|
||||||
connect(actionCreate, SIGNAL(triggered()), this, SLOT(createStream()));
|
connect(actionCreate, SIGNAL(triggered()), this, SLOT(createStream()));
|
||||||
connect(actionRefreshAll, SIGNAL(triggered()), this, SLOT(refreshAllStreams()));
|
connect(actionRefreshAll, SIGNAL(triggered()), this, SLOT(refreshAllStreams()));
|
||||||
|
connect(listStreams, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(refreshNewsList(QTreeWidgetItem*,int)));
|
||||||
|
connect(listNews, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(refreshTextBrowser(QListWidgetItem *)));
|
||||||
|
connect(listNews, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(openInBrowser(QListWidgetItem *)));
|
||||||
refreshTimeTimer = new QTimer(this);
|
refreshTimeTimer = new QTimer(this);
|
||||||
connect(refreshTimeTimer, SIGNAL(timeout()), this, SLOT(updateLastRefreshedTimeForStreams()));
|
connect(refreshTimeTimer, SIGNAL(timeout()), this, SLOT(updateLastRefreshedTimeForStreams()));
|
||||||
refreshTimeTimer->start(60000); // 1min
|
refreshTimeTimer->start(60000); // 1min
|
||||||
refreshStreamList();
|
// Select first news of first feed
|
||||||
refreshTextBrowser();
|
selectFirstFeed();
|
||||||
|
// Refresh all feeds
|
||||||
|
rssmanager->refreshAll();
|
||||||
qDebug("RSSImp constructed");
|
qDebug("RSSImp constructed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RSSImp::selectFirstFeed(){
|
||||||
|
if(listStreams->topLevelItemCount()){
|
||||||
|
QTreeWidgetItem *first = listStreams->topLevelItem(0);
|
||||||
|
listStreams->setCurrentItem(first);
|
||||||
|
selectedFeedUrl = first->text(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RSSImp::selectFirstNews(){
|
||||||
|
if(listNews->count()){
|
||||||
|
listNews->setCurrentRow(0);
|
||||||
|
refreshTextBrowser(listNews->currentItem());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RSSImp::~RSSImp(){
|
RSSImp::~RSSImp(){
|
||||||
delete refreshTimeTimer;
|
delete refreshTimeTimer;
|
||||||
delete rssmanager;
|
delete rssmanager;
|
||||||
}
|
}
|
||||||
|
|
||||||
short RSSImp::getNumStreamSelected(){
|
|
||||||
return listStreams->indexOfTopLevelItem(listStreams->currentItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,6 @@
|
||||||
|
|
||||||
#include "ui_rss.h"
|
#include "ui_rss.h"
|
||||||
|
|
||||||
#define DESCRIPTION_CHILD 0
|
|
||||||
#define URL_CHILD 1
|
|
||||||
#define TIME_CHILD 2
|
|
||||||
|
|
||||||
class QTimer;
|
class QTimer;
|
||||||
class RssManager;
|
class RssManager;
|
||||||
|
|
||||||
|
@ -38,31 +34,32 @@ class RSSImp : public QWidget, public Ui::RSS{
|
||||||
private:
|
private:
|
||||||
RssManager *rssmanager;
|
RssManager *rssmanager;
|
||||||
QTimer *refreshTimeTimer;
|
QTimer *refreshTimeTimer;
|
||||||
|
QString selectedFeedUrl;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void on_addStream_button_clicked();
|
void on_addStream_button_clicked();
|
||||||
void on_delStream_button_clicked();
|
void on_delStream_button_clicked();
|
||||||
void on_refreshAll_button_clicked();
|
void on_refreshAll_button_clicked();
|
||||||
void on_listStreams_clicked();
|
|
||||||
void on_listNews_clicked();
|
|
||||||
void on_listNews_doubleClicked();
|
|
||||||
void displayRSSListMenu(const QPoint&);
|
void displayRSSListMenu(const QPoint&);
|
||||||
void moveCurrentItem();
|
|
||||||
void deleteStream();
|
|
||||||
void renameStream();
|
void renameStream();
|
||||||
void refreshStream();
|
void refreshSelectedStreams();
|
||||||
void createStream();
|
void createStream();
|
||||||
void updateStreamName(const unsigned short&, const unsigned short&);
|
|
||||||
void refreshAllStreams();
|
void refreshAllStreams();
|
||||||
void refreshStreamList();
|
void refreshNewsList(QTreeWidgetItem* item, int);
|
||||||
void refreshNewsList();
|
void refreshTextBrowser(QListWidgetItem *);
|
||||||
void refreshTextBrowser();
|
|
||||||
short getNumStreamSelected();
|
|
||||||
void updateLastRefreshedTimeForStreams();
|
void updateLastRefreshedTimeForStreams();
|
||||||
|
void updateFeedIcon(QString url, QString icon_path);
|
||||||
|
void updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnread);
|
||||||
|
void openInBrowser(QListWidgetItem *);
|
||||||
|
void fillFeedsList();
|
||||||
|
void selectFirstFeed();
|
||||||
|
void selectFirstNews();
|
||||||
|
void updateFeedNbNews(QString url);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RSSImp();
|
RSSImp();
|
||||||
~RSSImp();
|
~RSSImp();
|
||||||
|
QTreeWidgetItem* getTreeItemFromUrl(QString url) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue