Browse Source

- Quite a few improvements in rss interface

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
d25776ddda
  1. 1
      TODO
  2. 2
      src/misc.h
  3. 32
      src/rss.h
  4. 52
      src/rss_imp.cpp
  5. 2
      src/rss_imp.h

1
TODO

@ -45,6 +45,7 @@
- Windows port (Chris - Peerkoel) - Windows port (Chris - Peerkoel)
- Translations update - Translations update
- Allow to abort a searchby launching another one - Allow to abort a searchby launching another one
- Move addTorrent to a thread
* beta2 * beta2
- Improve RSS code + cleanup (chris) - Improve RSS code + cleanup (chris)
- Wait for some bug fixes in libtorrent : - Wait for some bug fixes in libtorrent :

2
src/misc.h

@ -193,7 +193,7 @@ class misc : public QObject{
// Take a number of seconds and return an user-friendly // Take a number of seconds and return an user-friendly
// time duration like "1d 2h 10m". // time duration like "1d 2h 10m".
static QString userFriendlyDuration(const long int seconds){ static QString userFriendlyDuration(const long int seconds){
if(seconds <= 0){ if(seconds < 0){
return QString::QString(tr("Unknown")); return QString::QString(tr("Unknown"));
} }
if(seconds < 60){ if(seconds < 60){

32
src/rss.h

@ -51,7 +51,8 @@ class RssStream;
class RssItem; class RssItem;
// Item of a rss stream, single information // Item of a rss stream, single information
class RssItem{ class RssItem : public QObject {
Q_OBJECT
private: private:
QString title; QString title;
@ -63,7 +64,7 @@ class RssItem{
public: public:
// public constructor // public constructor
RssItem(const QDomElement& properties){ RssItem(const QDomElement& properties) {
read = false; read = false;
downloadLink = "none"; downloadLink = "none";
QDomElement property = properties.firstChild().toElement(); QDomElement property = properties.firstChild().toElement();
@ -92,6 +93,8 @@ class RssItem{
} }
QString getDescription() const{ QString getDescription() const{
if(description.isEmpty())
return tr("No description available");
return description; return description;
} }
@ -242,7 +245,7 @@ class RssStream : public QObject{
unsigned short getNbNonRead() const{ unsigned short getNbNonRead() const{
int i=0, nbnonread=0; int i=0, nbnonread=0;
for(i=0; i<listItem.size(); i++) { for(i=0; i<listItem.size(); ++i) {
if(!listItem.at(i)->isRead()) if(!listItem.at(i)->isRead())
nbnonread++; nbnonread++;
} }
@ -253,6 +256,11 @@ class RssStream : public QObject{
return listItem; return listItem;
} }
QString getLastRefreshElapsedString() const{
// TODO: remove this debug before release
return tr("%1 ago", "10min ago").arg(misc::userFriendlyDuration((long)(lastRefresh.elapsed()/1000.)).replace("<", "&lt;"));
}
unsigned int getLastRefreshElapsed() const{ unsigned int getLastRefreshElapsed() const{
return lastRefresh.elapsed(); return lastRefresh.elapsed();
} }
@ -293,7 +301,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 = getListSize();
for(unsigned short i=0; i<listsize; i++) { for(unsigned short i=0; i<listsize; ++i) {
listItem.removeLast(); listItem.removeLast();
} }
@ -332,11 +340,11 @@ class RssStream : public QObject{
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 = getListSize();
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;
} }
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(getListSize()>STREAM_MAX_ITEM) {
@ -451,7 +459,8 @@ class RssManager : public QObject{
void saveStreamList(){ void saveStreamList(){
streamListUrl.clear(); streamListUrl.clear();
QStringList streamListAlias; QStringList streamListAlias;
for(unsigned short i=0; i<getNbStream(); i++) { unsigned int nbStreams = getNbStreams();
for(unsigned int i=0; i<nbStreams; ++i) {
streamListUrl.append(getStream(i)->getUrl()); streamListUrl.append(getStream(i)->getUrl());
streamListAlias.append(getStream(i)->getAlias()); streamListAlias.append(getStream(i)->getAlias());
} }
@ -515,8 +524,8 @@ class RssManager : public QObject{
} }
} }
void refresh(int index) { void refresh(unsigned int index) {
if(index>=0 && index<getNbStream()) { if(index<getNbStreams()) {
if(getStream(index)->getLastRefreshElapsed()>REFRESH_FREQ_MAX) { if(getStream(index)->getLastRefreshElapsed()>REFRESH_FREQ_MAX) {
getStream(index)->refresh(); getStream(index)->refresh();
connect(getStream(index), SIGNAL(refreshFinished(QString, const unsigned short&)), this, SLOT(streamNeedRefresh(QString, const unsigned short&))); connect(getStream(index), SIGNAL(refreshFinished(QString, const unsigned short&)), this, SLOT(streamNeedRefresh(QString, const unsigned short&)));
@ -537,7 +546,7 @@ class RssManager : public QObject{
return streamList.at(index); return streamList.at(index);
} }
unsigned short getNbStream() { unsigned int getNbStreams() {
return streamList.size(); return streamList.size();
} }
@ -550,7 +559,8 @@ class RssManager : public QObject{
QStringList getListAlias() { QStringList getListAlias() {
QStringList listAlias; QStringList listAlias;
for(unsigned short i=0; i<getNbStream(); i++) { unsigned int nbStreams = getNbStreams();
for(unsigned short i=0; i<nbStreams; ++i) {
listAlias.append(getStream(i)->getAlias()); listAlias.append(getStream(i)->getAlias());
} }
return listAlias; return listAlias;

52
src/rss_imp.cpp

@ -24,6 +24,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QMenu> #include <QMenu>
#include <QStandardItemModel> #include <QStandardItemModel>
#include "misc.h"
// display a right-click menu // display a right-click menu
void RSSImp::displayRSSListMenu(const QPoint& pos){ void RSSImp::displayRSSListMenu(const QPoint& pos){
@ -48,7 +49,7 @@
// 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.getNbStream()==0) { if(getNumStreamSelected()<0 || rssmanager.getNbStreams()==0) {
qDebug("no stream selected"); qDebug("no stream selected");
return; return;
}else { }else {
@ -71,7 +72,7 @@
// display the news of a stream when click on it // display the news of a stream when click on it
void RSSImp::on_listStreams_clicked() { void RSSImp::on_listStreams_clicked() {
if(rssmanager.getNbStream()>0) { if(rssmanager.getNbStreams()>0) {
moveCurrentItem(); moveCurrentItem();
rssmanager.getStream(getNumStreamSelected())->setRead(); rssmanager.getStream(getNumStreamSelected())->setRead();
// update the color of the stream, is it old ? // update the color of the stream, is it old ?
@ -109,7 +110,7 @@
//right-clik on stream : delete it //right-clik on stream : delete it
void RSSImp::deleteStream() { void RSSImp::deleteStream() {
if(rssmanager.getNbStream()==0) { if(rssmanager.getNbStreams()==0) {
qDebug("no stream selected"); qDebug("no stream selected");
return; return;
}else { }else {
@ -126,7 +127,7 @@
//right-clik on stream : give him an alias //right-clik on stream : give him an alias
void RSSImp::renameStream() { void RSSImp::renameStream() {
if(rssmanager.getNbStream()==0) { if(rssmanager.getNbStreams()==0) {
qDebug("no stream selected"); qDebug("no stream selected");
return; return;
}else { }else {
@ -144,7 +145,7 @@
//right-clik on stream : refresh it //right-clik on stream : refresh it
void RSSImp::refreshStream() { void RSSImp::refreshStream() {
if(rssmanager.getNbStream()>0) { if(rssmanager.getNbStreams()>0) {
moveCurrentItem(); moveCurrentItem();
short index = getNumStreamSelected(); short index = getNumStreamSelected();
textBrowser->clear(); textBrowser->clear();
@ -152,16 +153,18 @@
listStreams->topLevelItem(index)->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png"))); listStreams->topLevelItem(index)->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
rssmanager.refresh(index); rssmanager.refresh(index);
} }
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.getNbStream(); unsigned short nbstream = rssmanager.getNbStreams();
for(unsigned short i=0; i<nbstream; i++) for(unsigned short i=0; i<nbstream; ++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();
} }
//right-click, register a new stream //right-click, register a new stream
@ -179,30 +182,19 @@
// fills the streamList // fills the streamList
void RSSImp::refreshStreamList() { void RSSImp::refreshStreamList() {
unsigned short nbstream = rssmanager.getNbStream(); unsigned short nbstream = rssmanager.getNbStreams();
listStreams->clear(); listStreams->clear();
QList<QTreeWidgetItem *> streams; QList<QTreeWidgetItem *> streams;
for(unsigned short i=0; i<nbstream; i++) { for(unsigned short i=0; i<nbstream; ++i) {
QTreeWidgetItem* stream = new QTreeWidgetItem(listStreams); QTreeWidgetItem* stream = new QTreeWidgetItem(listStreams);
QTreeWidgetItem* description = new QTreeWidgetItem(stream);
QTreeWidgetItem* url = new QTreeWidgetItem(stream);
QTreeWidgetItem* time = new QTreeWidgetItem(stream);
description->setText(0, tr("no description available"));
url->setText(0, rssmanager.getStream(i)->getUrl());
time->setText(0, tr("no refresh"));
description->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/description.png")));
url->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/url.png")));
time->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/time.png")));
description->setData(0,Qt::ForegroundRole, QVariant(QColor("grey")));
url->setData(0,Qt::ForegroundRole, QVariant(QColor("grey")));
time->setData(0,Qt::ForegroundRole, QVariant(QColor("grey")));
updateStreamName(i, NEWS); 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());
} }
} }
// fills the newsList // fills the newsList
void RSSImp::refreshNewsList() { void RSSImp::refreshNewsList() {
if(rssmanager.getNbStream()>0) { if(rssmanager.getNbStreams()>0) {
RssStream* currentstream = rssmanager.getStream(getNumStreamSelected()); RssStream* currentstream = rssmanager.getStream(getNumStreamSelected());
listNews->clear(); listNews->clear();
unsigned short currentStreamSize = currentstream->getListSize(); unsigned short currentStreamSize = currentstream->getListSize();
@ -211,8 +203,7 @@
if(currentstream->getItem(i)->isRead()){ if(currentstream->getItem(i)->isRead()){
listNews->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("grey"))); listNews->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("grey")));
listNews->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png"))); listNews->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere.png")));
} } else {
else {
listNews->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere2.png"))); listNews->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/sphere2.png")));
listNews->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("blue"))); listNews->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("blue")));
} }
@ -231,6 +222,13 @@
} }
} }
void RSSImp::updateLastRefreshedTimeForStreams() {
unsigned int nbStreams = rssmanager.getNbStreams();
for(unsigned int i=0; i<nbStreams; ++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());
}
}
// show the number of news for a stream, his status and an icon // show the number of news for a stream, his status and an icon
void RSSImp::updateStreamName(const unsigned short& i, const unsigned short& type) { void RSSImp::updateStreamName(const unsigned short& i, const unsigned short& type) {
// icon has just been download // icon has just been download
@ -268,9 +266,7 @@
} }
listStreams->topLevelItem(i)->setData(0,Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath()))); listStreams->topLevelItem(i)->setData(0,Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath())));
// update description and display last refresh // update description and display last refresh
if(rssmanager.getStream(i)->getDescription()!="") 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());
listStreams->topLevelItem(i)->child(DESCRIPTION_CHILD)->setText(0, rssmanager.getStream(i)->getDescription());
listStreams->topLevelItem(i)->child(TIME_CHILD)->setText(0, rssmanager.getStream(i)->getLastRefresh());
} }
} }
@ -293,7 +289,9 @@
connect(actionRefresh, SIGNAL(triggered()), this, SLOT(refreshStream())); connect(actionRefresh, SIGNAL(triggered()), this, SLOT(refreshStream()));
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(&refreshTimeTimer, SIGNAL(timeout()), this, SLOT(updateLastRefreshedTimeForStreams()));
connect(&rssmanager, SIGNAL(streamNeedRefresh(const unsigned short&, const unsigned short&)), this, SLOT(updateStreamName(const unsigned short&, const unsigned short&))); connect(&rssmanager, SIGNAL(streamNeedRefresh(const unsigned short&, const unsigned short&)), this, SLOT(updateStreamName(const unsigned short&, const unsigned short&)));
refreshTimeTimer.start(60000); // 1min
refreshStreamList(); refreshStreamList();
refreshTextBrowser(); refreshTextBrowser();
} }

2
src/rss_imp.h

@ -37,6 +37,7 @@ class RSSImp : public QWidget, public Ui::RSS{
private: private:
RssManager rssmanager; RssManager rssmanager;
QTimer refreshTimeTimer;
protected slots: protected slots:
void on_addStream_button_clicked(); void on_addStream_button_clicked();
@ -57,6 +58,7 @@ class RSSImp : public QWidget, public Ui::RSS{
void refreshNewsList(); void refreshNewsList();
void refreshTextBrowser(); void refreshTextBrowser();
short getNumStreamSelected(); short getNumStreamSelected();
void updateLastRefreshedTimeForStreams();
public: public:
RSSImp(); RSSImp();

Loading…
Cancel
Save