mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -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()
|
void LibraryCreator::run()
|
||||||
{
|
{
|
||||||
stopRunning = false;
|
stopRunning = false;
|
||||||
|
canceled = false;
|
||||||
#if !defined use_unarr && !defined use_libarchive
|
#if !defined use_unarr && !defined use_libarchive
|
||||||
// check for 7z lib
|
// check for 7z lib
|
||||||
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
|
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
|
||||||
@ -187,13 +188,15 @@ void LibraryCreator::run()
|
|||||||
update(QDir(_source));
|
update(QDir(_source));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partialUpdate) {
|
if (!canceled) {
|
||||||
auto folder = DBHelper::updateChildrenInfo(folderDestinationModelIndex.data(FolderModel::IdRole).toULongLong(), _database);
|
if (partialUpdate) {
|
||||||
DBHelper::propagateFolderUpdatesToParent(folder, _database);
|
auto folder = DBHelper::updateChildrenInfo(folderDestinationModelIndex.data(FolderModel::IdRole).toULongLong(), _database);
|
||||||
} else
|
DBHelper::propagateFolderUpdatesToParent(folder, _database);
|
||||||
DBHelper::updateChildrenInfo(_database);
|
} else
|
||||||
|
DBHelper::updateChildrenInfo(_database);
|
||||||
|
|
||||||
_database.commit();
|
_database.commit();
|
||||||
|
}
|
||||||
_database.close();
|
_database.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +227,13 @@ void LibraryCreator::stop()
|
|||||||
stopRunning = true;
|
stopRunning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LibraryCreator::cancel()
|
||||||
|
{
|
||||||
|
QSqlDatabase::database(_databaseConnection).rollback();
|
||||||
|
canceled = true;
|
||||||
|
stopRunning = true;
|
||||||
|
}
|
||||||
|
|
||||||
// retorna el id del ultimo de los folders
|
// retorna el id del ultimo de los folders
|
||||||
qulonglong LibraryCreator::insertFolders()
|
qulonglong LibraryCreator::insertFolders()
|
||||||
{
|
{
|
||||||
@ -291,7 +301,7 @@ QString pseudoHash(const QFileInfo &fileInfo)
|
|||||||
QCryptographicHash crypto(QCryptographicHash::Sha1);
|
QCryptographicHash crypto(QCryptographicHash::Sha1);
|
||||||
QFile file(fileInfo.absoluteFilePath());
|
QFile file(fileInfo.absoluteFilePath());
|
||||||
file.open(QFile::ReadOnly);
|
file.open(QFile::ReadOnly);
|
||||||
crypto.addData(file.read(524288));
|
crypto.addData(file.read(52428));
|
||||||
file.close();
|
file.close();
|
||||||
// hash Sha1 del primer 0.5MB + filesize
|
// hash Sha1 del primer 0.5MB + filesize
|
||||||
return QString(crypto.result().toHex().constData()) + QString::number(fileInfo.size());
|
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)
|
void LibraryCreator::update(QDir dirS)
|
||||||
{
|
{
|
||||||
|
if (stopRunning) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto _database = QSqlDatabase::database(_databaseConnection);
|
auto _database = QSqlDatabase::database(_databaseConnection);
|
||||||
// QLOG_TRACE() << "Updating" << dirS.absolutePath();
|
// QLOG_TRACE() << "Updating" << dirS.absolutePath();
|
||||||
// QLOG_TRACE() << "Getting info from dir" << dirS.absolutePath();
|
// QLOG_TRACE() << "Getting info from dir" << dirS.absolutePath();
|
||||||
|
@ -26,7 +26,8 @@ public:
|
|||||||
void createLibrary(const QString &source, const QString &target);
|
void createLibrary(const QString &source, const QString &target);
|
||||||
void updateLibrary(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 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:
|
private:
|
||||||
void processLibrary(const QString &source, const QString &target);
|
void processLibrary(const QString &source, const QString &target);
|
||||||
@ -51,6 +52,7 @@ private:
|
|||||||
// qulonglong insertFolder(qulonglong parentId,const Folder & folder);
|
// qulonglong insertFolder(qulonglong parentId,const Folder & folder);
|
||||||
// qulonglong insertComic(const Comic & comic);
|
// qulonglong insertComic(const Comic & comic);
|
||||||
bool stopRunning;
|
bool stopRunning;
|
||||||
|
bool canceled;
|
||||||
// LibraryCreator está en modo creación si creation == true;
|
// LibraryCreator está en modo creación si creation == true;
|
||||||
bool creation;
|
bool creation;
|
||||||
bool partialUpdate;
|
bool partialUpdate;
|
||||||
|
Loading…
Reference in New Issue
Block a user