- Started to implement drag n drop in feed list but it is still very buggy

This commit is contained in:
Christophe Dumez 2009-08-23 08:10:56 +00:00
parent b9f1586068
commit 2fa43dd973
7 changed files with 141 additions and 71 deletions

View file

@ -158,7 +158,9 @@ downloadThread::~downloadThread(){
abort = true;
condition.wakeOne();
mutex.unlock();
qDebug("downloadThread deleting subthreads...");
qDeleteAll(subThreads);
qDebug("downloadThread deleted subthreads");
wait();
}
@ -174,25 +176,31 @@ void downloadThread::downloadUrl(QString url){
void downloadThread::run(){
forever{
if(abort)
if(abort) {
qDebug("DownloadThread aborting...");
return;
}
mutex.lock();
if(!urls_queue.empty() && subThreads.size() < MAX_THREADS){
QString url = urls_queue.dequeue();
mutex.unlock();
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...");
condition.wait(&mutex);
qDebug("DownloadThread woke up");
mutex.unlock();
}
}
}
void downloadThread::propagateDownloadedFile(subDownloadThread* st, QString url, QString path){
qDebug("Downloading %s was successful", url.toLocal8Bit().data());
mutex.lock();
int index = subThreads.indexOf(st);
Q_ASSERT(index != -1);
@ -208,6 +216,7 @@ void downloadThread::propagateDownloadedFile(subDownloadThread* st, QString url,
}
void downloadThread::propagateDownloadFailure(subDownloadThread* st, QString url, QString reason){
qDebug("Downloading %s failed", url.toLocal8Bit().data());
mutex.lock();
int index = subThreads.indexOf(st);
Q_ASSERT(index != -1);

71
src/feedList.h Normal file
View file

@ -0,0 +1,71 @@
#ifndef FEEDLIST_H
#define FEEDLIST_H
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QDropEvent>
#include <QDragMoveEvent>
#include <QStringList>
#include "rss.h"
class FeedList : public QTreeWidget {
private:
RssManager *rssmanager;
public:
FeedList(QWidget *parent, RssManager *rssmanager): QTreeWidget(parent), rssmanager(rssmanager) {
setContextMenuPolicy(Qt::CustomContextMenu);
setDragDropMode(QAbstractItemView::InternalMove);
setSelectionMode(QAbstractItemView::ExtendedSelection);
setColumnCount(3);
QTreeWidgetItem *___qtreewidgetitem = headerItem();
___qtreewidgetitem->setText(2, QApplication::translate("RSS", "type", 0, QApplication::UnicodeUTF8));
___qtreewidgetitem->setText(1, QApplication::translate("RSS", "url", 0, QApplication::UnicodeUTF8));
___qtreewidgetitem->setText(0, QApplication::translate("RSS", "RSS feeds", 0, QApplication::UnicodeUTF8));
// Hide second column (url) and third column (type)
hideColumn(1);
hideColumn(2);
}
QStringList getItemPath(QTreeWidgetItem *item) const {
QStringList path;
if(item) {
if(item->parent()) {
path = getItemPath(item->parent());
}
path << item->text(1);
}
return path;
}
protected:
void dragMoveEvent(QDragMoveEvent * event) {
QTreeWidgetItem *item = itemAt(event->pos());
if(item && rssmanager->getFile(getItemPath(item))->getType() != RssFile::FOLDER)
event->ignore();
else {
QAbstractItemView::dragMoveEvent(event);
}
}
void dropEvent(QDropEvent *event) {
qDebug("dropEvent");
QTreeWidgetItem *dest_item = itemAt(event->pos());
QStringList dest_folder_path = getItemPath(dest_item);
QList<QTreeWidgetItem *> src_items = selectedItems();
foreach(QTreeWidgetItem *src_item, src_items) {
QStringList src_path = getItemPath(src_item);
QStringList dest_path = dest_folder_path;
dest_path << src_item->text(1);
qDebug("Moving file %s to %s", src_path.join("\\").toLocal8Bit().data(), dest_path.join("\\").toLocal8Bit().data());
rssmanager->moveFile(src_path, dest_path);
}
QAbstractItemView::dropEvent (event);
if(dest_item)
dest_item->setExpanded(true);
}
};
#endif // FEEDLIST_H

View file

@ -40,9 +40,11 @@ RssFolder::RssFolder(RssFolder *parent, RssManager *rssmanager, bittorrent *BTSe
}
RssFolder::~RssFolder() {
qDebug("Deleting downloader thread");
qDebug("Deleting a RSS folder, removing elements");
qDeleteAll(this->values());
qDebug("Deleting downloader thread");
delete downloader;
qDebug("Downloader thread removed");
}
unsigned int RssFolder::getNbUnRead() const {
@ -165,6 +167,7 @@ void RssFolder::refresh(QStringList full_path) {
}
RssFile* RssFolder::getFile(QStringList full_path) const {
if(full_path.isEmpty()) return rssmanager;
QString name = full_path.last();
if(full_path.size() == 1) {
Q_ASSERT(this->contains(name));
@ -363,8 +366,22 @@ void RssManager::moveFile(QStringList old_path, QStringList new_path) {
RssFolder* src_folder = item->getParent();
QString new_name = new_path.takeLast();
RssFolder* dest_folder = (RssFolder*)getFile(new_path);
dest_folder->addFile(item);
src_folder->removeFileRef(item);
if(dest_folder != src_folder) {
dest_folder->addFile(item);
src_folder->removeFileRef(item);
} else {
qDebug("Nothing to move, same destination folder");
}
// Need to rename?
QString current_name;
if(item->getType() == RssFile::FOLDER)
current_name = item->getName();
else
current_name = ((RssStream*)item)->getUrl();
if(current_name != new_name) {
qDebug("Renaming file from %s to %s...", current_name.toLocal8Bit().data(), new_name.toLocal8Bit().data());
dest_folder->rename(item->getPath(), new_name);
}
}
void RssManager::saveStreamList(){
@ -373,7 +390,9 @@ void RssManager::saveStreamList(){
QStringList aliases;
QList<RssStream*> streams = getAllFeeds();
foreach(RssStream *stream, streams) {
streamsUrl << stream->getPath().join("\\");
QString stream_path = stream->getPath().join("\\");
qDebug("Saving stream path: %s", stream_path.toLocal8Bit().data());
streamsUrl << stream_path;
aliases << stream->getName();
}
QSettings settings("qBittorrent", "qBittorrent");
@ -401,6 +420,7 @@ RssStream::RssStream(RssFolder* parent, RssManager *rssmanager, bittorrent *BTSe
}
RssStream::~RssStream(){
qDebug("Deleting a RSS stream: %s", getName().toLocal8Bit().data());
if(refreshed) {
QSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QVariantList old_items;
@ -412,7 +432,9 @@ RssStream::~RssStream(){
all_old_items[url] = old_items;
qBTRSS.setValue("old_items", all_old_items);
}
qDebug("Removing all item from feed");
removeAllItems();
qDebug("All items were removed");
if(QFile::exists(filePath))
QFile::remove(filePath);
if(QFile::exists(iconPath) && !iconPath.startsWith(":/"))
@ -469,14 +491,14 @@ void RssStream::rename(QStringList, QString new_name){
// Return the alias if the stream has one, the url if it has no alias
QString RssStream::getName() const{
if(!alias.isEmpty()) {
qDebug("getName() returned alias: %s", (const char*)alias.toLocal8Bit());
//qDebug("getName() returned alias: %s", (const char*)alias.toLocal8Bit());
return alias;
}
if(!title.isEmpty()) {
qDebug("getName() returned title: %s", (const char*)title.toLocal8Bit());
//qDebug("getName() returned title: %s", (const char*)title.toLocal8Bit());
return title;
}
qDebug("getName() returned url: %s", (const char*)url.toLocal8Bit());
//qDebug("getName() returned url: %s", (const char*)url.toLocal8Bit());
return url;
}

View file

@ -10,6 +10,9 @@
<height>447</height>
</rect>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="windowTitle">
<string>Search</string>
</property>
@ -93,32 +96,6 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QTreeWidget" name="listStreams">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="columnCount">
<number>3</number>
</property>
<column>
<property name="text">
<string>RSS feeds</string>
</property>
</column>
<column>
<property name="text">
<string>url</string>
</property>
</column>
<column>
<property name="text">
<string>type</string>
</property>
</column>
</widget>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
@ -274,13 +251,6 @@ p, li { white-space: pre-wrap; }
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKit/QWebView</header>
</customwidget>
</customwidgets>
<resources>
<include location="icons.qrc"/>
</resources>

View file

@ -35,9 +35,11 @@
#include <QMessageBox>
#include <QString>
#include <QClipboard>
#include <QDragMoveEvent>
#include "rss_imp.h"
#include "FeedDownloader.h"
#include "feedList.h"
#include "bittorrent.h"
// display a right-click menu
@ -54,7 +56,7 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){
myRSSListMenu.addSeparator();
if(selectedItems.size() == 1) {
myRSSListMenu.addAction(actionRename);
RssFile *rss_item = rssmanager->getFile(getItemPath(selectedItems.first()));
RssFile *rss_item = rssmanager->getFile(listStreams->getItemPath(selectedItems.first()));
if(rss_item->getType() == RssFile::FOLDER)
myRSSListMenu.addAction(actionNew_folder);
}
@ -85,19 +87,8 @@ void RSSImp::displayItemsListMenu(const QPoint&){
myItemListMenu.exec(QCursor::pos());
}
QStringList RSSImp::getItemPath(QTreeWidgetItem *item) const {
QStringList path;
if(item) {
if(item->parent()) {
path = getItemPath(item->parent());
}
path << item->text(1);
}
return path;
}
QStringList RSSImp::getCurrentFeedPath() const {
return getItemPath(listStreams->currentItem());
return listStreams->getItemPath(listStreams->currentItem());
}
RssFile::FileType RSSImp::getItemType(QTreeWidgetItem *item) const {
@ -111,7 +102,7 @@ void RSSImp::askNewFolder() {
QTreeWidgetItem *parent_item = 0;
if(listStreams->selectedItems().size() > 0) {
parent_item = listStreams->selectedItems().at(0);
foreach(QString name, getItemPath(parent_item)) {
foreach(QString name, listStreams->getItemPath(parent_item)) {
dest_path << name;
}
}
@ -130,7 +121,8 @@ void RSSImp::askNewFolder() {
folder_item->setData(2,Qt::DisplayRole, QVariant((int)RssFile::FOLDER));
folder_item->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/oxygen/folder.png")));
// Expand parent folder to display new folder
parent_item->setExpanded(true);
if(parent_item)
parent_item->setExpanded(true);
rssmanager->saveStreamList();
}
}
@ -140,9 +132,9 @@ void RSSImp::on_newFeedButton_clicked() {
QStringList dest_path;
QTreeWidgetItem *current_item = listStreams->currentItem();
if(getItemType(current_item) != RssFile::FOLDER)
dest_path = getItemPath(current_item->parent());
dest_path = listStreams->getItemPath(current_item->parent());
else
dest_path = getItemPath(current_item);
dest_path = listStreams->getItemPath(current_item);
bool ok;
QString clip_txt = qApp->clipboard()->text();
QString default_url = "http://";
@ -189,7 +181,7 @@ void RSSImp::deleteSelectedItems() {
textBrowser->clear();
listNews->clear();
}
rssmanager->removeFile(getItemPath(item));
rssmanager->removeFile(listStreams->getItemPath(item));
delete item;
}
rssmanager->saveStreamList();
@ -229,9 +221,9 @@ void RSSImp::renameFiles() {
Q_ASSERT(selectedItems.size() == 1);
QTreeWidgetItem *item = selectedItems.at(0);
bool ok;
QString newName = QInputDialog::getText(this, tr("Please choose a new name for this RSS feed"), tr("New feed name:"), QLineEdit::Normal, rssmanager->getFile(getItemPath(item))->getName(), &ok);
QString newName = QInputDialog::getText(this, tr("Please choose a new name for this RSS feed"), tr("New feed name:"), QLineEdit::Normal, rssmanager->getFile(listStreams->getItemPath(item))->getName(), &ok);
if(ok) {
rssmanager->rename(getItemPath(item), newName);
rssmanager->rename(listStreams->getItemPath(item), newName);
item->setText(0, newName);
item->setText(1, newName);
}
@ -242,7 +234,7 @@ void RSSImp::refreshSelectedStreams() {
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
QTreeWidgetItem* item;
foreach(item, selectedItems){
rssmanager->refresh(getItemPath(item));
rssmanager->refresh(listStreams->getItemPath(item));
if(getItemType(item) == RssFile::STREAM)
item->setData(0,Qt::DecorationRole, QVariant(QIcon(":/Icons/loading.png")));
}
@ -260,7 +252,7 @@ void RSSImp::copySelectedFeedsURL() {
void RSSImp::showFeedDownloader() {
QTreeWidgetItem* item = listStreams->selectedItems()[0];
RssFile* rss_item = rssmanager->getFile(getItemPath(item));
RssFile* rss_item = rssmanager->getFile(listStreams->getItemPath(item));
if(rss_item->getType() == RssFile::STREAM)
new FeedDownloaderDlg(this, item->text(1), rss_item->getName(), BTSession);
}
@ -269,7 +261,7 @@ void RSSImp::on_markReadButton_clicked() {
QList<QTreeWidgetItem*> selectedItems = listStreams->selectedItems();
QTreeWidgetItem* item;
foreach(item, selectedItems){
RssFile *rss_item = rssmanager->getFile(getItemPath(item));
RssFile *rss_item = rssmanager->getFile(listStreams->getItemPath(item));
rss_item->markAllAsRead();
item->setData(0, Qt::DisplayRole, rss_item->getName()+ QString::fromUtf8(" (0)"));
}
@ -407,7 +399,7 @@ QString RSSImp::getCurrentFeedUrl() const {
void RSSImp::updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnread){
QTreeWidgetItem *item = getTreeItemFromUrl(url);
RssStream *stream = (RssStream*)rssmanager->getFile(getItemPath(item));
RssStream *stream = (RssStream*)rssmanager->getFile(listStreams->getItemPath(item));
item->setText(0, aliasOrUrl + QString::fromUtf8(" (") + QString::number(nbUnread, 10)+ QString(")"));
item->setData(0,Qt::DecorationRole, QVariant(QIcon(stream->getIconPath())));
// If the feed is selected, update the displayed news
@ -419,11 +411,11 @@ void RSSImp::updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnr
RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){
setupUi(this);
// Hide second column (url) and third column (type)
listStreams->hideColumn(1);
listStreams->hideColumn(2);
rssmanager = new RssManager(BTSession);
listStreams = new FeedList(splitter_h, rssmanager);
splitter_h->insertWidget(0, listStreams);
fillFeedsList();
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)));
@ -458,6 +450,7 @@ RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){
// Bind saveSliders slots
connect(splitter_v, SIGNAL(splitterMoved(int, int)), this, SLOT(saveSlidersPosition()));
connect(splitter_h, SIGNAL(splitterMoved(int, int)), this, SLOT(saveSlidersPosition()));
qDebug("RSSImp constructed");
}
@ -470,6 +463,7 @@ void RSSImp::selectFirstFeed(){
RSSImp::~RSSImp(){
qDebug("Deleting RSSImp...");
delete listStreams;
delete rssmanager;
qDebug("RSSImp deleted");
}

View file

@ -36,6 +36,8 @@
#include "rss.h"
class bittorrent;
class FeedList;
class QTreeWidgetItem;
class RSSImp : public QWidget, public Ui::RSS{
Q_OBJECT
@ -43,6 +45,7 @@ class RSSImp : public QWidget, public Ui::RSS{
private:
RssManager *rssmanager;
bittorrent *BTSession;
FeedList *listStreams;
public slots:
void deleteSelectedItems();
@ -76,9 +79,9 @@ public:
QTreeWidgetItem* getTreeItemFromUrl(QString url) const;
QString getCurrentFeedUrl() const;
QTreeWidgetItem* getItemFromPath(QStringList path) const;
QStringList getItemPath(QTreeWidgetItem *item) const;
QStringList getCurrentFeedPath() const;
RssFile::FileType getItemType(QTreeWidgetItem *item) const;
};
#endif

View file

@ -184,7 +184,8 @@ HEADERS += GUI.h \
ico.h \
stacktrace.h \
torrentPersistentData.h \
FeedDownloader.h
FeedDownloader.h \
feedList.h
FORMS += MainWindow.ui \
options.ui \
about.ui \