mirror of
https://github.com/YACReader/yacreader
synced 2025-05-27 19:00:29 -04:00
Make possible to cancel updates/creations
This commit is contained in:
parent
a6caf98af9
commit
45043cf36e
@ -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,13 +188,15 @@ void LibraryCreator::run()
|
||||
update(QDir(_source));
|
||||
}
|
||||
|
||||
if (partialUpdate) {
|
||||
auto folder = DBHelper::updateChildrenInfo(folderDestinationModelIndex.data(FolderModel::IdRole).toULongLong(), _database);
|
||||
DBHelper::propagateFolderUpdatesToParent(folder, _database);
|
||||
} else
|
||||
DBHelper::updateChildrenInfo(_database);
|
||||
if (!canceled) {
|
||||
if (partialUpdate) {
|
||||
auto folder = DBHelper::updateChildrenInfo(folderDestinationModelIndex.data(FolderModel::IdRole).toULongLong(), _database);
|
||||
DBHelper::propagateFolderUpdatesToParent(folder, _database);
|
||||
} else
|
||||
DBHelper::updateChildrenInfo(_database);
|
||||
|
||||
_database.commit();
|
||||
_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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user