Make possible to cancel updates/creations

This commit is contained in:
Luis Ángel San Martín 2023-08-20 12:36:40 +02:00
parent a6caf98af9
commit 45043cf36e
2 changed files with 24 additions and 8 deletions

View File

@ -110,6 +110,7 @@ void LibraryCreator::processLibrary(const QString &source, const QString &target
void LibraryCreator::run()
{
stopRunning = false;
canceled = false;
#if !defined use_unarr && !defined use_libarchive
// check for 7z lib
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
@ -187,6 +188,7 @@ void LibraryCreator::run()
update(QDir(_source));
}
if (!canceled) {
if (partialUpdate) {
auto folder = DBHelper::updateChildrenInfo(folderDestinationModelIndex.data(FolderModel::IdRole).toULongLong(), _database);
DBHelper::propagateFolderUpdatesToParent(folder, _database);
@ -194,6 +196,7 @@ void LibraryCreator::run()
DBHelper::updateChildrenInfo(_database);
_database.commit();
}
_database.close();
}
@ -224,6 +227,13 @@ void LibraryCreator::stop()
stopRunning = true;
}
void LibraryCreator::cancel()
{
QSqlDatabase::database(_databaseConnection).rollback();
canceled = true;
stopRunning = true;
}
// retorna el id del ultimo de los folders
qulonglong LibraryCreator::insertFolders()
{
@ -291,7 +301,7 @@ QString pseudoHash(const QFileInfo &fileInfo)
QCryptographicHash crypto(QCryptographicHash::Sha1);
QFile file(fileInfo.absoluteFilePath());
file.open(QFile::ReadOnly);
crypto.addData(file.read(524288));
crypto.addData(file.read(52428));
file.close();
// hash Sha1 del primer 0.5MB + filesize
return QString(crypto.result().toHex().constData()) + QString::number(fileInfo.size());
@ -376,6 +386,10 @@ void LibraryCreator::replaceComic(const QString &relativePath, const QFileInfo &
void LibraryCreator::update(QDir dirS)
{
if (stopRunning) {
return;
}
auto _database = QSqlDatabase::database(_databaseConnection);
// QLOG_TRACE() << "Updating" << dirS.absolutePath();
// QLOG_TRACE() << "Getting info from dir" << dirS.absolutePath();

View File

@ -26,7 +26,8 @@ public:
void createLibrary(const QString &source, const QString &target);
void updateLibrary(const QString &source, const QString &target);
void updateFolder(const QString &source, const QString &target, const QString &folder, const QModelIndex &dest);
void stop();
void stop(); // used to stop the process and keep the changes
void cancel(); // cancels this run and changes in the DB are rolled back
private:
void processLibrary(const QString &source, const QString &target);
@ -51,6 +52,7 @@ private:
// qulonglong insertFolder(qulonglong parentId,const Folder & folder);
// qulonglong insertComic(const Comic & comic);
bool stopRunning;
bool canceled;
// LibraryCreator está en modo creación si creation == true;
bool creation;
bool partialUpdate;