Browse Source

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

adaptive-webui-19844
Arnaud Demaiziere 18 years ago
parent
commit
1ae635a8b5
  1. 2
      src/downloadThread.h
  2. 52
      src/rss.h
  3. 33
      src/rss.ui
  4. 15
      src/rss_imp.h

2
src/downloadThread.h

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

52
src/rss.h

@ -19,9 +19,9 @@
* Contact : chris@qbittorrent.org, arnaud@qbittorrent.org * Contact : chris@qbittorrent.org, arnaud@qbittorrent.org
*/ */
#define STREAM_MAX_ITEM 15
// TODO : not used yet
#define GLOBAL_MAX_ITEM 150 #define GLOBAL_MAX_ITEM 150
#define STREAM_MAX_ITEM 20
#ifndef RSS_H #ifndef RSS_H
#define RSS_H #define RSS_H
@ -191,6 +191,7 @@ class RssStream : public QObject{
return this->alias; return this->alias;
} }
//prefer the RssManager::setAlias, do not save the changed ones
void setAlias(const QString& _alias){ void setAlias(const QString& _alias){
this->alias = _alias; this->alias = _alias;
} }
@ -319,7 +320,6 @@ class RssManager{
private : private :
QList<RssStream*> streamList; QList<RssStream*> streamList;
QList<RssStream*> ignoredStreamList;
QStringList streamListUrl; QStringList streamListUrl;
QStringList streamListAlias; QStringList streamListAlias;
@ -333,9 +333,6 @@ class RssManager{
for(unsigned short i=0; i<streamList.size(); i++){ for(unsigned short i=0; i<streamList.size(); i++){
delete getStream(i); delete getStream(i);
} }
for(unsigned short i=0; i<ignoredStreamList.size(); i++){
delete getIgnored(i);
}
} }
// load the list of the rss stream // load the list of the rss stream
@ -395,12 +392,6 @@ class RssManager{
void removeStream(RssStream* stream){ void removeStream(RssStream* stream){
short index = hasStream(stream); short index = hasStream(stream);
if(index>=0){ 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++){ for(unsigned short i=0; i<streamList.size(); i++){
if(getStream(i)->getUrl()==stream->getUrl()){ if(getStream(i)->getUrl()==stream->getUrl()){
delete streamList.at(i); delete streamList.at(i);
@ -414,31 +405,23 @@ class RssManager{
// remove all the streams in the manager // remove all the streams in the manager
void removeAll(){ void removeAll(){
QList<RssStream*> newIgnoredList, newStreamList; QList<RssStream*> newStreamList;
QStringList newUrlList, newAliasList; QStringList newUrlList, newAliasList;
for(unsigned short i=0; i<streamList.size(); i++){ for(unsigned short i=0; i<streamList.size(); i++){
delete getStream(i); delete getStream(i);
} }
for(unsigned short i=0; i<ignoredStreamList.size(); i++){
delete getIgnored(i);
}
this->streamList = newStreamList; this->streamList = newStreamList;
this->ignoredStreamList = newIgnoredList;
this->streamListUrl = newUrlList; this->streamListUrl = newUrlList;
this->streamListAlias = newAliasList; this->streamListAlias = newAliasList;
} }
// reload all the xml files from the web // reload all the xml files from the web
void refreshAll(){ void refreshAll(){
QList<RssStream*> newIgnoredList, newStreamList; QList<RssStream*> newStreamList;
for(unsigned short i=0; i<streamList.size(); i++){ for(unsigned short i=0; i<streamList.size(); i++){
delete getStream(i); delete getStream(i);
} }
for(unsigned short i=0; i<ignoredStreamList.size(); i++){
delete getIgnored(i);
}
this->streamList = newStreamList; this->streamList = newStreamList;
this->ignoredStreamList = newIgnoredList;
for(unsigned short i=0; i<streamListUrl.size(); i++){ for(unsigned short i=0; i<streamListUrl.size(); i++){
RssStream *stream = new RssStream(this->streamListUrl.at(i)); RssStream *stream = new RssStream(this->streamListUrl.at(i));
stream->setAlias(this->streamListAlias.at(i)); stream->setAlias(this->streamListAlias.at(i));
@ -446,6 +429,15 @@ class RssManager{
} }
} }
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 // return the position index of a stream, if the manager owns it
short hasStream(RssStream* stream) const{ short hasStream(RssStream* stream) const{
QString url = stream->getUrl(); QString url = stream->getUrl();
@ -460,24 +452,24 @@ class RssManager{
return streamList.at(index); return streamList.at(index);
} }
RssStream* getIgnored(const int& index) const{
return ignoredStreamList.at(index);
}
void displayManager(){ void displayManager(){
for(unsigned short i=0; i<streamList.size(); i++){ for(unsigned short i=0; i<streamList.size(); i++){
getStream(i)->displayStream(); 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() { int getNbStream() {
return streamList.size(); 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);
}
}
}; };
#endif #endif

33
src/rss.ui

@ -49,7 +49,11 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QListWidget" name="listStreams" /> <widget class="QListWidget" name="listStreams" >
<property name="contextMenuPolicy" >
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
@ -171,7 +175,7 @@
<widget class="QListWidget" name="listNews" > <widget class="QListWidget" name="listNews" >
<property name="minimumSize" > <property name="minimumSize" >
<size> <size>
<width>600</width> <width>520</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
@ -195,6 +199,31 @@
</layout> </layout>
</item> </item>
</layout> </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> </widget>
<resources/> <resources/>
<connections/> <connections/>

15
src/rss_imp.h

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

Loading…
Cancel
Save