Browse Source

- Improved rss includes a little and fix a memory leak I just introduced

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
042323a1a8
  1. 74
      src/rss_imp.cpp
  2. 4
      src/rss_imp.h

74
src/rss_imp.cpp

@ -20,6 +20,8 @@ @@ -20,6 +20,8 @@
*/
#include "rss_imp.h"
#include "rss.h"
#include <QDesktopServices>
#include <QInputDialog>
#include <QMenu>
@ -50,7 +52,7 @@ @@ -50,7 +52,7 @@
// delete a stream by a button
void RSSImp::on_delStream_button_clicked() {
if(getNumStreamSelected()<0 || rssmanager.getNbStreams()==0) {
if(getNumStreamSelected()<0 || rssmanager->getNbStreams()==0) {
qDebug("no stream selected");
return;
}else {
@ -60,7 +62,7 @@ @@ -60,7 +62,7 @@
if(ok==0) {
textBrowser->clear();
listNews->clear();
rssmanager.removeStream(rssmanager.getStream(getNumStreamSelected()));
rssmanager->removeStream(rssmanager->getStream(getNumStreamSelected()));
refreshStreamList();
}
}
@ -73,9 +75,9 @@ @@ -73,9 +75,9 @@
// display the news of a stream when click on it
void RSSImp::on_listStreams_clicked() {
if(rssmanager.getNbStreams()>0) {
if(rssmanager->getNbStreams()>0) {
moveCurrentItem();
rssmanager.getStream(getNumStreamSelected())->setRead();
rssmanager->getStream(getNumStreamSelected())->setRead();
// update the color of the stream, is it old ?
updateStreamName(getNumStreamSelected(), LATENCY);
refreshNewsList();
@ -91,8 +93,8 @@ @@ -91,8 +93,8 @@
// open the url of the news in a browser
void RSSImp::on_listNews_doubleClicked() {
if(getNumStreamSelected()>=0 && listNews->currentRow()>=0 && rssmanager.getStream(getNumStreamSelected())->getListSize()>0) {
RssItem* currentItem = rssmanager.getStream(getNumStreamSelected())->getItem(listNews->currentRow());
if(getNumStreamSelected()>=0 && listNews->currentRow()>=0 && rssmanager->getStream(getNumStreamSelected())->getListSize()>0) {
RssItem* currentItem = rssmanager->getStream(getNumStreamSelected())->getItem(listNews->currentRow());
if(currentItem->getLink()!=NULL && currentItem->getLink().length()>5)
QDesktopServices::openUrl(QUrl(currentItem->getLink()));
}
@ -111,7 +113,7 @@ @@ -111,7 +113,7 @@
//right-clik on stream : delete it
void RSSImp::deleteStream() {
if(rssmanager.getNbStreams()==0) {
if(rssmanager->getNbStreams()==0) {
qDebug("no stream selected");
return;
}else {
@ -120,7 +122,7 @@ @@ -120,7 +122,7 @@
moveCurrentItem();
textBrowser->clear();
listNews->clear();
rssmanager.removeStream(rssmanager.getStream(getNumStreamSelected()));
rssmanager->removeStream(rssmanager->getStream(getNumStreamSelected()));
refreshStreamList();
}
}
@ -128,16 +130,16 @@ @@ -128,16 +130,16 @@
//right-clik on stream : give him an alias
void RSSImp::renameStream() {
if(rssmanager.getNbStreams()==0) {
if(rssmanager->getNbStreams()==0) {
qDebug("no stream selected");
return;
}else {
moveCurrentItem();
bool ok;
short index = getNumStreamSelected();
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);
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);
if(ok) {
rssmanager.setAlias(index, newAlias);
rssmanager->setAlias(index, newAlias);
updateStreamName(index, NEWS);
}
}
@ -146,13 +148,13 @@ @@ -146,13 +148,13 @@
//right-clik on stream : refresh it
void RSSImp::refreshStream() {
if(rssmanager.getNbStreams()>0) {
if(rssmanager->getNbStreams()>0) {
moveCurrentItem();
short index = getNumStreamSelected();
textBrowser->clear();
listNews->clear();
listStreams->topLevelItem(index)->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
rssmanager.refresh(index);
rssmanager->refresh(index);
}
updateLastRefreshedTimeForStreams();
}
@ -161,10 +163,10 @@ @@ -161,10 +163,10 @@
void RSSImp::refreshAllStreams() {
textBrowser->clear();
listNews->clear();
unsigned short nbstream = rssmanager.getNbStreams();
unsigned short nbstream = rssmanager->getNbStreams();
for(unsigned short i=0; i<nbstream; ++i)
listStreams->topLevelItem(i)->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
rssmanager.refreshAll();
rssmanager->refreshAll();
updateLastRefreshedTimeForStreams();
}
@ -175,7 +177,7 @@ @@ -175,7 +177,7 @@
if(ok) {
newUrl = newUrl.trimmed();
if(!newUrl.isEmpty() && newUrl != "http://"){
rssmanager.addStream(newUrl);
rssmanager->addStream(newUrl);
refreshStreamList();
}
}
@ -184,21 +186,21 @@ @@ -184,21 +186,21 @@
// fills the streamList
void RSSImp::refreshStreamList() {
qDebug("Refreshing stream list");
unsigned short nbstream = rssmanager.getNbStreams();
unsigned short nbstream = rssmanager->getNbStreams();
listStreams->clear();
QList<QTreeWidgetItem *> streams;
for(unsigned short i=0; i<nbstream; ++i) {
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());
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
void RSSImp::refreshNewsList() {
if(rssmanager.getNbStreams()>0) {
RssStream* currentstream = rssmanager.getStream(getNumStreamSelected());
if(rssmanager->getNbStreams()>0) {
RssStream* currentstream = rssmanager->getStream(getNumStreamSelected());
listNews->clear();
unsigned short currentStreamSize = currentstream->getListSize();
for(unsigned short i=0; i<currentStreamSize; ++i) {
@ -219,16 +221,16 @@ @@ -219,16 +221,16 @@
// display a news
void RSSImp::refreshTextBrowser() {
if(getNumStreamSelected()>=0 && listNews->currentRow()>=0) {
RssItem* currentitem = rssmanager.getStream(getNumStreamSelected())->getItem(listNews->currentRow());
RssItem* currentitem = rssmanager->getStream(getNumStreamSelected())->getItem(listNews->currentRow());
textBrowser->setHtml(currentitem->getTitle()+" : \n"+currentitem->getDescription());
currentitem->setRead();
}
}
void RSSImp::updateLastRefreshedTimeForStreams() {
unsigned int nbStreams = rssmanager.getNbStreams();
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());
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());
}
}
@ -236,15 +238,15 @@ @@ -236,15 +238,15 @@
void RSSImp::updateStreamName(const unsigned short& i, const unsigned short& type) {
// icon has just been download
if(type == ICON) {
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())));
}
// 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()+")");
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)
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")));
@ -252,24 +254,24 @@ @@ -252,24 +254,24 @@
}
// 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()+")");
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)
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())
if(!rssmanager->getStream(i)->isRead())
listStreams->topLevelItem(i)->setData(0,Qt::BackgroundRole, QVariant(QColor(0, 255, 0, 20)));
if(getNumStreamSelected()==i) {
listNews->clear();
refreshNewsList();
}
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
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)->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());
}
}
@ -286,13 +288,15 @@ @@ -286,13 +288,15 @@
actionCreate->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png")));
actionRefreshAll->setIcon(QIcon(QString::fromUtf8(":/Icons/refresh.png")));
rssmanager = new RssManager();
connect(rssmanager, SIGNAL(streamNeedRefresh(const unsigned short&, const unsigned short&)), this, SLOT(updateStreamName(const unsigned short&, const unsigned short&)));
connect(listStreams, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRSSListMenu(const QPoint&)));
connect(actionDelete, SIGNAL(triggered()), this, SLOT(deleteStream()));
connect(actionRename, SIGNAL(triggered()), this, SLOT(renameStream()));
connect(actionRefresh, SIGNAL(triggered()), this, SLOT(refreshStream()));
connect(actionCreate, SIGNAL(triggered()), this, SLOT(createStream()));
connect(actionRefreshAll, SIGNAL(triggered()), this, SLOT(refreshAllStreams()));
connect(&rssmanager, SIGNAL(streamNeedRefresh(const unsigned short&, const unsigned short&)), this, SLOT(updateStreamName(const unsigned short&, const unsigned short&)));
refreshTimeTimer = new QTimer(this);
connect(refreshTimeTimer, SIGNAL(timeout()), this, SLOT(updateLastRefreshedTimeForStreams()));
refreshTimeTimer->start(60000); // 1min
@ -302,6 +306,8 @@ @@ -302,6 +306,8 @@
}
RSSImp::~RSSImp(){
delete refreshTimeTimer;
delete rssmanager;
}
short RSSImp::getNumStreamSelected(){

4
src/rss_imp.h

@ -24,19 +24,19 @@ @@ -24,19 +24,19 @@
#define REFRESH_MAX_LATENCY 600000
#include "ui_rss.h"
#include "rss.h"
#define DESCRIPTION_CHILD 0
#define URL_CHILD 1
#define TIME_CHILD 2
class QTimer;
class RssManager;
class RSSImp : public QWidget, public Ui::RSS{
Q_OBJECT
private:
RssManager rssmanager;
RssManager *rssmanager;
QTimer *refreshTimeTimer;
protected slots:

Loading…
Cancel
Save