1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-25 14:04:23 +00:00

rss : from qlistwidget to qtreewidget

This commit is contained in:
Arnaud Demaiziere 2007-04-15 19:06:19 +00:00
parent 9a4466e74f
commit 2c6b66a834
3 changed files with 67 additions and 55 deletions

View File

@ -36,23 +36,18 @@
<number>6</number> <number>6</number>
</property> </property>
<item> <item>
<widget class="QLabel" name="lbl_streams" > <widget class="QTreeWidget" name="listStreams" >
<property name="font" >
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text" >
<string>RSS streams:</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listStreams" >
<property name="contextMenuPolicy" > <property name="contextMenuPolicy" >
<enum>Qt::CustomContextMenu</enum> <enum>Qt::CustomContextMenu</enum>
</property> </property>
<property name="columnCount" >
<number>1</number>
</property>
<column>
<property name="text" >
<string>RSS streams :</string>
</property>
</column>
</widget> </widget>
</item> </item>
<item> <item>

View File

@ -27,8 +27,9 @@
// 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);
QListWidgetItem* item = listStreams->itemAt(pos); QTreeWidgetItem* item = listStreams->itemAt(pos);
if(item!=NULL) { if(item!=NULL) {
myFinishedListMenu.addAction(actionDelete); myFinishedListMenu.addAction(actionDelete);
myFinishedListMenu.addAction(actionRename); myFinishedListMenu.addAction(actionRename);
@ -47,13 +48,13 @@
// 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(listStreams->currentRow()<0 || rssmanager.getNbStream()==0) { if(getNumStreamSelected()<0 || rssmanager.getNbStream()==0) {
qDebug("no stream selected"); qDebug("no stream selected");
return; return;
}else { }else {
textBrowser->clear(); textBrowser->clear();
listNews->clear(); listNews->clear();
rssmanager.removeStream(rssmanager.getStream(listStreams->currentRow())); rssmanager.removeStream(rssmanager.getStream(getNumStreamSelected()));
refreshStreamList(); refreshStreamList();
} }
} }
@ -65,11 +66,13 @@
// 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() {
rssmanager.getStream(listStreams->currentRow())->setRead(); if(rssmanager.getNbStream()>0) {
listStreams->item(listStreams->currentRow())->setData(Qt::BackgroundRole, QVariant(QColor("white"))); moveCurrentItem();
// update the color of the stream, is it old ? rssmanager.getStream(getNumStreamSelected())->setRead();
updateStreamName(listStreams->currentRow(), LATENCY); // update the color of the stream, is it old ?
refreshNewsList(); updateStreamName(getNumStreamSelected(), LATENCY);
refreshNewsList();
}
} }
// display the content of a new when clicked on it // display the content of a new when clicked on it
@ -80,22 +83,34 @@
// 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::on_listNews_doubleClicked() {
if(listStreams->currentRow()>=0 && listNews->currentRow()>=0 && rssmanager.getStream(listStreams->currentRow())->getListSize()>0) { if(getNumStreamSelected()>=0 && listNews->currentRow()>=0 && rssmanager.getStream(getNumStreamSelected())->getListSize()>0) {
RssItem* currentItem = rssmanager.getStream(listStreams->currentRow())->getItem(listNews->currentRow()); RssItem* currentItem = rssmanager.getStream(getNumStreamSelected())->getItem(listNews->currentRow());
if(currentItem->getLink()!=NULL && currentItem->getLink().length()>5) if(currentItem->getLink()!=NULL && currentItem->getLink().length()>5)
QDesktopServices::openUrl(QUrl(currentItem->getLink())); QDesktopServices::openUrl(QUrl(currentItem->getLink()));
} }
} }
// move the current selection if it is not a toplevelitem (id : stream)
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 //right-clik on stream : delete it
void RSSImp::deleteStream() { void RSSImp::deleteStream() {
if(rssmanager.getNbStream()==0) { if(rssmanager.getNbStream()==0) {
qDebug("no stream selected"); qDebug("no stream selected");
return; return;
}else { }else {
moveCurrentItem();
textBrowser->clear(); textBrowser->clear();
listNews->clear(); listNews->clear();
rssmanager.removeStream(rssmanager.getStream(listStreams->currentRow())); rssmanager.removeStream(rssmanager.getStream(getNumStreamSelected()));
refreshStreamList(); refreshStreamList();
} }
} }
@ -106,8 +121,9 @@
qDebug("no stream selected"); qDebug("no stream selected");
return; return;
}else { }else {
moveCurrentItem();
bool ok; bool ok;
short index = listStreams->currentRow(); 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) { if(ok) {
rssmanager.setAlias(index, newAlias); rssmanager.setAlias(index, newAlias);
@ -119,11 +135,12 @@
//right-clik on stream : refresh it //right-clik on stream : refresh it
void RSSImp::refreshStream() { void RSSImp::refreshStream() {
short index = listStreams->currentRow();
if(rssmanager.getNbStream()>0) { if(rssmanager.getNbStream()>0) {
moveCurrentItem();
short index = getNumStreamSelected();
textBrowser->clear(); textBrowser->clear();
listNews->clear(); listNews->clear();
listStreams->item(index)->setData(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);
} }
} }
@ -134,7 +151,7 @@
listNews->clear(); listNews->clear();
unsigned short nbstream = rssmanager.getNbStream(); unsigned short nbstream = rssmanager.getNbStream();
for(unsigned short i=0; i<nbstream; i++) for(unsigned short i=0; i<nbstream; i++)
listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png"))); listStreams->topLevelItem(i)->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
rssmanager.refreshAll(); rssmanager.refreshAll();
} }
@ -153,24 +170,21 @@
// fills the streamList // fills the streamList
void RSSImp::refreshStreamList() { void RSSImp::refreshStreamList() {
//short currentStream = listStreams->currentRow();
unsigned short nbstream = rssmanager.getNbStream(); unsigned short nbstream = rssmanager.getNbStream();
listStreams->clear(); listStreams->clear();
QList<QTreeWidgetItem *> streams;
for(unsigned short i=0; i<nbstream; i++) { for(unsigned short i=0; i<nbstream; i++) {
new QListWidgetItem(rssmanager.getStream(i)->getAlias()+" ("+QString::number(rssmanager.getStream(i)->getListSize(),10).toUtf8()+")", listStreams); QTreeWidgetItem* stream = new QTreeWidgetItem(listStreams);
QTreeWidgetItem* description = new QTreeWidgetItem(stream);
description->setText(0, tr("no description avalaible"));
updateStreamName(i, NEWS); updateStreamName(i, NEWS);
} }
/*if(currentStream>=0 && currentStream<nbstream) {
listStreams->setCurrentRow(currentStream);
listNews->clear();
refreshNewsList();
}*/
} }
// fills the newsList // fills the newsList
void RSSImp::refreshNewsList() { void RSSImp::refreshNewsList() {
if(rssmanager.getNbStream()>0) { if(rssmanager.getNbStream()>0) {
RssStream* currentstream = rssmanager.getStream(listStreams->currentRow()); RssStream* currentstream = rssmanager.getStream(getNumStreamSelected());
listNews->clear(); listNews->clear();
unsigned short currentStreamSize = currentstream->getListSize(); unsigned short currentStreamSize = currentstream->getListSize();
for(unsigned short i=0; i<currentStreamSize; ++i) { for(unsigned short i=0; i<currentStreamSize; ++i) {
@ -185,8 +199,8 @@
// display a news // display a news
void RSSImp::refreshTextBrowser() { void RSSImp::refreshTextBrowser() {
if(listStreams->currentRow()>=0 && listNews->currentRow()>=0) { if(getNumStreamSelected()>=0 && listNews->currentRow()>=0) {
RssItem* currentitem = rssmanager.getStream(listStreams->currentRow())->getItem(listNews->currentRow()); RssItem* currentitem = rssmanager.getStream(getNumStreamSelected())->getItem(listNews->currentRow());
textBrowser->setHtml(currentitem->getTitle()+" : \n"+currentitem->getDescription()); textBrowser->setHtml(currentitem->getTitle()+" : \n"+currentitem->getDescription());
currentitem->setRead(); currentitem->setRead();
} }
@ -196,39 +210,39 @@
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
if(type == ICON) { if(type == ICON) {
//qDebug("###################"+rssmanager.getStream(i)->getIconPath().toUtf8()); listStreams->topLevelItem(i)->setData(0,Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath())));
listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath())));
} }
// on click, show the age of the stream // on click, show the age of the stream
if(type == LATENCY) { if(type == LATENCY) {
unsigned short nbitem = rssmanager.getStream(i)->getListSize(); unsigned short nbitem = rssmanager.getStream(i)->getListSize();
listStreams->item(i)->setText(rssmanager.getStream(i)->getAlias().toUtf8()+" ("+QString::number(nbitem,10).toUtf8()+")"); listStreams->topLevelItem(i)->setText(0,rssmanager.getStream(i)->getAlias().toUtf8()+" ("+QString::number(nbitem,10).toUtf8()+")");
if(nbitem==0) if(nbitem==0)
listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("red"))); 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->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("orange"))); listStreams->topLevelItem(i)->setData(0,Qt::ForegroundRole, QVariant(QColor("orange")));
else else
listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("green"))); 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 // when news are refreshed, update all informations
if(type == NEWS) { if(type == NEWS) {
//qDebug("###################"+rssmanager.getStream(i)->getIconPath().toUtf8());
unsigned short nbitem = rssmanager.getStream(i)->getListSize(); unsigned short nbitem = rssmanager.getStream(i)->getListSize();
listStreams->item(i)->setText(rssmanager.getStream(i)->getAlias().toUtf8()+" ("+QString::number(nbitem,10).toUtf8()+")"); listStreams->topLevelItem(i)->setText(0,rssmanager.getStream(i)->getAlias().toUtf8()+" ("+QString::number(nbitem,10).toUtf8()+")");
if(nbitem==0) if(nbitem==0)
listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("red"))); 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->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("orange"))); listStreams->topLevelItem(i)->setData(0,Qt::ForegroundRole, QVariant(QColor("orange")));
else else
listStreams->item(i)->setData(Qt::ForegroundRole, QVariant(QColor("green"))); listStreams->topLevelItem(i)->setData(0,Qt::ForegroundRole, QVariant(QColor("green")));
if(!rssmanager.getStream(i)->isRead()) if(!rssmanager.getStream(i)->isRead())
listStreams->item(i)->setData(Qt::BackgroundRole, QVariant(QColor(0, 255, 0, 20))); listStreams->topLevelItem(i)->setData(0,Qt::BackgroundRole, QVariant(QColor(0, 255, 0, 20)));
if(listStreams->currentRow()==i) { if(getNumStreamSelected()==i) {
listNews->clear(); listNews->clear();
refreshNewsList(); refreshNewsList();
} }
listStreams->item(i)->setData(Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath()))); listStreams->topLevelItem(i)->setData(0,Qt::DecorationRole, QVariant(QIcon(rssmanager.getStream(i)->getIconPath())));
listStreams->topLevelItem(i)->child(0)->setText(0, rssmanager.getStream(i)->getDescription());
} }
} }
@ -251,5 +265,7 @@
RSSImp::~RSSImp(){ RSSImp::~RSSImp(){
} }
short RSSImp::getNumStreamSelected(){
return listStreams->indexOfTopLevelItem(listStreams->currentItem());
}

View File

@ -42,16 +42,17 @@ class RSSImp : public QWidget, public Ui::RSS{
void on_listNews_clicked(); void on_listNews_clicked();
void on_listNews_doubleClicked(); void on_listNews_doubleClicked();
void displayRSSListMenu(const QPoint&); void displayRSSListMenu(const QPoint&);
void moveCurrentItem();
void deleteStream(); void deleteStream();
void renameStream(); void renameStream();
void refreshStream(); void refreshStream();
void createStream(); void createStream();
void updateStreamName(const unsigned short&, const unsigned short&); void updateStreamName(const unsigned short&, const unsigned short&);
//void updateAllStreamsName();
void refreshAllStreams(); void refreshAllStreams();
void refreshStreamList(); void refreshStreamList();
void refreshNewsList(); void refreshNewsList();
void refreshTextBrowser(); void refreshTextBrowser();
short getNumStreamSelected();
public: public:
RSSImp(); RSSImp();