work on rss, right-click menu, refresh functions, and anticrash methods

This commit is contained in:
Arnaud Demaiziere 2007-04-05 18:30:20 +00:00
parent d3eda2e8be
commit 1ae635a8b5
4 changed files with 69 additions and 33 deletions

View file

@ -151,7 +151,7 @@ class downloadThread : public QThread {
++retries;
SleeperThread::msleep(1000);
}
}while(to_many_users && retries < 10);
}while(to_many_users && retries < 10 && response!=0);
// Cleanup
curl_easy_cleanup(curl);
// Close tmp file

View file

@ -19,9 +19,9 @@
* Contact : chris@qbittorrent.org, arnaud@qbittorrent.org
*/
#define STREAM_MAX_ITEM 15
// TODO : not used yet
#define GLOBAL_MAX_ITEM 150
#define STREAM_MAX_ITEM 20
#ifndef RSS_H
#define RSS_H
@ -191,6 +191,7 @@ class RssStream : public QObject{
return this->alias;
}
//prefer the RssManager::setAlias, do not save the changed ones
void setAlias(const QString& _alias){
this->alias = _alias;
}
@ -319,7 +320,6 @@ class RssManager{
private :
QList<RssStream*> streamList;
QList<RssStream*> ignoredStreamList;
QStringList streamListUrl;
QStringList streamListAlias;
@ -333,9 +333,6 @@ class RssManager{
for(unsigned short i=0; i<streamList.size(); i++){
delete getStream(i);
}
for(unsigned short i=0; i<ignoredStreamList.size(); i++){
delete getIgnored(i);
}
}
// load the list of the rss stream
@ -395,12 +392,6 @@ class RssManager{
void removeStream(RssStream* stream){
short index = hasStream(stream);
if(index>=0){
for(unsigned short i=0; i<ignoredStreamList.size(); i++){
if(getIgnored(i)->getUrl()==stream->getUrl()){
delete ignoredStreamList.at(i);
this->ignoredStreamList.removeAt(i);
}
}
for(unsigned short i=0; i<streamList.size(); i++){
if(getStream(i)->getUrl()==stream->getUrl()){
delete streamList.at(i);
@ -414,37 +405,38 @@ class RssManager{
// remove all the streams in the manager
void removeAll(){
QList<RssStream*> newIgnoredList, newStreamList;
QList<RssStream*> newStreamList;
QStringList newUrlList, newAliasList;
for(unsigned short i=0; i<streamList.size(); i++){
delete getStream(i);
}
for(unsigned short i=0; i<ignoredStreamList.size(); i++){
delete getIgnored(i);
}
this->streamList = newStreamList;
this->ignoredStreamList = newIgnoredList;
this->streamListUrl = newUrlList;
this->streamListAlias = newAliasList;
}
// reload all the xml files from the web
void refreshAll(){
QList<RssStream*> newIgnoredList, newStreamList;
QList<RssStream*> newStreamList;
for(unsigned short i=0; i<streamList.size(); i++){
delete getStream(i);
}
for(unsigned short i=0; i<ignoredStreamList.size(); i++){
delete getIgnored(i);
}
this->streamList = newStreamList;
this->ignoredStreamList = newIgnoredList;
for(unsigned short i=0; i<streamListUrl.size(); i++){
RssStream *stream = new RssStream(this->streamListUrl.at(i));
stream->setAlias(this->streamListAlias.at(i));
this->streamList.append(stream);
}
}
void refresh(int index) {
if(index>=0 && index<getNbStream()) {
delete getStream(index);
RssStream *stream = new RssStream(this->streamListUrl.at(index));
stream->setAlias(this->streamListAlias.at(index));
this->streamList.replace(index, stream);
}
}
// return the position index of a stream, if the manager owns it
short hasStream(RssStream* stream) const{
@ -460,23 +452,23 @@ class RssManager{
return streamList.at(index);
}
RssStream* getIgnored(const int& index) const{
return ignoredStreamList.at(index);
}
void displayManager(){
for(unsigned short i=0; i<streamList.size(); i++){
getStream(i)->displayStream();
}
qDebug("#### rss ignored streams ####");
for(unsigned short i=0; i<ignoredStreamList.size(); i++){
qDebug(" _ (ignored) "+getIgnored(i)->getTitle().toUtf8()+" - "+getIgnored(i)->getUrl().toUtf8()+" // "+getIgnored(i)->getAlias().toUtf8());
}
}
int getNbStream() {
return streamList.size();
}
//set an alias to an stream and save it for later
void setAlias(int index, QString newAlias) {
if(newAlias.length()>=2 && !streamListAlias.contains(newAlias, Qt::CaseInsensitive)) {
getStream(index)->setAlias(newAlias);
streamListAlias.replace(index, newAlias);
}
}
};

View file

@ -49,7 +49,11 @@
</widget>
</item>
<item>
<widget class="QListWidget" name="listStreams" />
<widget class="QListWidget" name="listStreams" >
<property name="contextMenuPolicy" >
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
@ -171,7 +175,7 @@
<widget class="QListWidget" name="listNews" >
<property name="minimumSize" >
<size>
<width>600</width>
<width>520</width>
<height>0</height>
</size>
</property>
@ -195,6 +199,31 @@
</layout>
</item>
</layout>
<action name="actionDelete" >
<property name="text" >
<string>Delete</string>
</property>
</action>
<action name="actionRename" >
<property name="text" >
<string>Rename</string>
</property>
</action>
<action name="actionRefresh" >
<property name="text" >
<string>Refresh</string>
</property>
</action>
<action name="actionCreate" >
<property name="text" >
<string>Create</string>
</property>
</action>
<action name="actionRefreshAll" >
<property name="text" >
<string>RefreshAll</string>
</property>
</action>
</widget>
<resources/>
<connections/>

View file

@ -21,8 +21,14 @@
#ifndef __RSS_IMP_H__
#define __RSS_IMP_H__
// avoid crash if too many refresh
#define REFRESH_FREQ_MAX 5000
#include <QTimer>
#include <QTime>
#include "ui_rss.h"
#include "rss.h"
#include "GUI.h"
class RSSImp : public QWidget, public Ui::RSS{
Q_OBJECT
@ -32,6 +38,8 @@ class RSSImp : public QWidget, public Ui::RSS{
void refreshStreamList();
void refreshNewsList();
void refreshTextBrowser();
QTimer* timer;
QTime lastRefresh;
protected slots:
void on_addStream_button_clicked();
@ -40,6 +48,13 @@ class RSSImp : public QWidget, public Ui::RSS{
void on_listStreams_clicked();
void on_listNews_clicked();
void on_listNews_doubleClicked();
void displayFinishedListMenu(const QPoint&);
void deleteStream();
void renameStream();
void refreshStream();
void createStream();
void refreshAllStream();
void updateStreamNbNews();
public:
RSSImp();