Merge pull request #203 from vedgy/fix-library-crash-at-exit-after-deletion

Library: don't crash at exit after a folder or a comic is deleted
This commit is contained in:
Luis Ángel San Martín 2021-06-19 18:13:51 +02:00 committed by GitHub
commit 85677afc7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,6 +94,20 @@
#include <shellapi.h>
#endif
namespace {
template<class Remover>
void moveAndConnectRemoverToThread(Remover *remover, QThread *thread)
{
Q_ASSERT(remover);
Q_ASSERT(thread);
remover->moveToThread(thread);
QObject::connect(thread, &QThread::started, remover, &Remover::process);
QObject::connect(remover, &Remover::finished, remover, &QObject::deleteLater);
QObject::connect(remover, &Remover::finished, thread, &QThread::quit);
QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater);
}
}
using namespace YACReader;
LibraryWindow::LibraryWindow()
@ -1576,22 +1590,14 @@ void LibraryWindow::deleteSelectedFolder()
paths << folderPath;
auto remover = new FoldersRemover(indexList, paths);
const auto thread = new QThread(this);
moveAndConnectRemoverToThread(remover, thread);
QThread *thread = NULL;
thread = new QThread(this);
remover->moveToThread(thread);
connect(thread, SIGNAL(started()), remover, SLOT(process()));
connect(remover, SIGNAL(remove(QModelIndex)), foldersModel, SLOT(deleteFolder(QModelIndex)));
connect(remover, SIGNAL(removeError()), this, SLOT(errorDeletingFolder()));
connect(remover, SIGNAL(finished()), navigationController, SLOT(reselectCurrentFolder()));
connect(remover, SIGNAL(finished()), remover, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
if (thread != NULL)
thread->start();
thread->start();
}
}
}
@ -2562,28 +2568,20 @@ void LibraryWindow::deleteComicsFromDisk()
}
auto remover = new ComicsRemover(indexList, paths, comics.at(0).parentId);
QThread *thread = NULL;
thread = new QThread(this);
remover->moveToThread(thread);
const auto thread = new QThread(this);
moveAndConnectRemoverToThread(remover, thread);
comicsModel->startTransaction();
connect(thread, SIGNAL(started()), remover, SLOT(process()));
connect(remover, SIGNAL(remove(int)), comicsModel, SLOT(remove(int)));
connect(remover, SIGNAL(removeError()), this, SLOT(setRemoveError()));
connect(remover, SIGNAL(finished()), comicsModel, SLOT(finishTransaction()));
connect(remover, SIGNAL(finished()), comicsModel, SLOT(finishTransaction()));
connect(remover, SIGNAL(removedItemsFromFolder(qulonglong)), foldersModel, SLOT(updateFolderChildrenInfo(qulonglong)));
connect(remover, SIGNAL(finished()), this, SLOT(checkEmptyFolder()));
connect(remover, SIGNAL(finished()), this, SLOT(checkRemoveError()));
connect(remover, SIGNAL(finished()), remover, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
if (thread != NULL)
thread->start();
thread->start();
}
}