mirror of
https://github.com/YACReader/yacreader
synced 2025-05-27 10:50:27 -04:00
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:
commit
85677afc7b
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user