Browse Source

- Remembering open state of RSS folders on startup

adaptive-webui-19844
Christophe Dumez 16 years ago
parent
commit
fd81567ecd
  1. 10
      src/downloadThread.cpp
  2. 37
      src/feedList.h
  3. 48
      src/rss_imp.cpp
  4. 2
      src/rss_imp.h

10
src/downloadThread.cpp

@ -158,9 +158,9 @@ downloadThread::~downloadThread(){ @@ -158,9 +158,9 @@ downloadThread::~downloadThread(){
abort = true;
condition.wakeOne();
mutex.unlock();
qDebug("downloadThread deleting subthreads...");
//qDebug("downloadThread deleting subthreads...");
qDeleteAll(subThreads);
qDebug("downloadThread deleted subthreads");
//qDebug("downloadThread deleted subthreads");
wait();
}
@ -184,16 +184,16 @@ void downloadThread::run(){ @@ -184,16 +184,16 @@ void downloadThread::run(){
if(!urls_queue.empty() && subThreads.size() < MAX_THREADS){
QString url = urls_queue.dequeue();
mutex.unlock();
qDebug("DownloadThread downloading %s...", url.toLocal8Bit().data());
//qDebug("DownloadThread downloading %s...", url.toLocal8Bit().data());
subDownloadThread *st = new subDownloadThread(0, url);
subThreads << st;
connect(st, SIGNAL(downloadFinishedST(subDownloadThread*, QString, QString)), this, SLOT(propagateDownloadedFile(subDownloadThread*, QString, QString)));
connect(st, SIGNAL(downloadFailureST(subDownloadThread*, QString, QString)), this, SLOT(propagateDownloadFailure(subDownloadThread*, QString, QString)));
st->start();
}else{
qDebug("DownloadThread sleeping...");
//qDebug("DownloadThread sleeping...");
condition.wait(&mutex);
qDebug("DownloadThread woke up");
//qDebug("DownloadThread woke up");
mutex.unlock();
}
}

37
src/feedList.h

@ -53,11 +53,46 @@ public: @@ -53,11 +53,46 @@ public:
return feeds_items.values();
}
QStringList getItemPath(QTreeWidgetItem* item) {
QStringList path;
if(item) {
if(item->parent())
path.append(getItemPath(item->parent()));
path.append(getRSSItem(item)->getID());
}
return path;
}
QList<QTreeWidgetItem*> getAllOpenFolders(QTreeWidgetItem *parent=0) {
QList<QTreeWidgetItem*> open_folders;
int nbChildren;
if(parent)
nbChildren = parent->childCount();
else
nbChildren = topLevelItemCount();
for(int i=0; i<nbChildren; ++i) {
QTreeWidgetItem *item;
if(parent)
item = parent->child(i);
else
item = topLevelItem(i);
if(getItemType(item) == RssFile::FOLDER && item->isExpanded()) {
QList<QTreeWidgetItem*> open_subfolders = getAllOpenFolders(item);
if(!open_subfolders.empty()) {
open_folders.append(open_subfolders);
} else {
open_folders << item;
}
}
}
return open_folders;
}
QList<QTreeWidgetItem*> getAllFeedItems(QTreeWidgetItem* folder) {
QList<QTreeWidgetItem*> feeds;
int nbChildren = folder->childCount();
for(int i=0; i<nbChildren; ++i) {
QTreeWidgetItem *item = folder->child(i);
QTreeWidgetItem *item = folder->child(i);
if(getItemType(item) == RssFile::STREAM) {
feeds << item;
} else {

48
src/rss_imp.cpp

@ -198,6 +198,52 @@ void RSSImp::deleteSelectedItems() { @@ -198,6 +198,52 @@ void RSSImp::deleteSelectedItems() {
}
}
void RSSImp::loadFoldersOpenState() {
QSettings settings("qBittorrent", "qBittorrent");
settings.beginGroup("Rss");
QVariantList open_folders = settings.value("open_folders", QVariantList()).toList();
settings.endGroup();
foreach(QVariant var_path, open_folders) {
QStringList path = var_path.toString().split("\\");
QTreeWidgetItem *parent = 0;
foreach(QString name, path) {
QList<QTreeWidgetItem*> children;
int nbChildren = 0;
if(parent)
nbChildren = parent->childCount();
else
nbChildren = listStreams->topLevelItemCount();
for(int i=0; i<nbChildren; ++i) {
QTreeWidgetItem* child;
if(parent)
child = parent->child(i);
else
child = listStreams->topLevelItem(i);
if(listStreams->getRSSItem(child)->getID() == name) {
parent = child;
parent->setExpanded(true);
qDebug("expanding folder %s", name.toLocal8Bit().data());
break;
}
}
}
}
}
void RSSImp::saveFoldersOpenState() {
QVariantList open_folders;
QList<QTreeWidgetItem*> items = listStreams->getAllOpenFolders();
foreach(QTreeWidgetItem* item, items) {
QString path = listStreams->getItemPath(item).join("\\");
qDebug("saving open folder: %s", path.toLocal8Bit().data());
open_folders << path;
}
QSettings settings("qBittorrent", "qBittorrent");
settings.beginGroup("Rss");
settings.setValue("open_folders", open_folders);
settings.endGroup();
}
// refresh all streams by a button
void RSSImp::on_updateAllButton_clicked() {
foreach(QTreeWidgetItem *item, listStreams->getAllFeedItems()) {
@ -443,6 +489,7 @@ RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){ @@ -443,6 +489,7 @@ RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){
splitter_h->insertWidget(0, listStreams);
fillFeedsList();
loadFoldersOpenState();
connect(rssmanager, SIGNAL(feedInfosChanged(QString, QString, unsigned int)), this, SLOT(updateFeedInfos(QString, QString, unsigned int)));
connect(rssmanager, SIGNAL(feedIconChanged(QString, QString)), this, SLOT(updateFeedIcon(QString, QString)));
@ -482,6 +529,7 @@ RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){ @@ -482,6 +529,7 @@ RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){
RSSImp::~RSSImp(){
qDebug("Deleting RSSImp...");
saveFoldersOpenState();
delete listStreams;
delete rssmanager;
qDebug("RSSImp deleted");

2
src/rss_imp.h

@ -72,6 +72,8 @@ protected slots: @@ -72,6 +72,8 @@ protected slots:
void restoreSlidersPosition();
void showFeedDownloader();
void askNewFolder();
void saveFoldersOpenState();
void loadFoldersOpenState();
public:
RSSImp(bittorrent *BTSession);

Loading…
Cancel
Save