| 449 | } |
| 450 | |
| 451 | void LibraryCreator::update(QDir dirS) |
| 452 | { |
| 453 | if (stopRunning) { |
| 454 | return; |
| 455 | } |
| 456 | |
| 457 | auto _database = QSqlDatabase::database(_databaseConnection); |
| 458 | // QLOG_TRACE() << "Updating" << dirS.absolutePath(); |
| 459 | // QLOG_TRACE() << "Getting info from dir" << dirS.absolutePath(); |
| 460 | dirS.setNameFilters(_nameFilter); |
| 461 | dirS.setFilter(QDir::AllDirs | QDir::NoDotAndDotDot); |
| 462 | dirS.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); |
| 463 | QFileInfoList listSFolders = dirS.entryInfoList(); |
| 464 | dirS.setFilter(QDir::Files | QDir::NoDotAndDotDot); |
| 465 | dirS.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); |
| 466 | QFileInfoList listSFiles = dirS.entryInfoList(); |
| 467 | |
| 468 | std::sort(listSFolders.begin(), listSFolders.end(), naturalSortLessThanCIFileInfo); |
| 469 | std::sort(listSFiles.begin(), listSFiles.end(), naturalSortLessThanCIFileInfo); |
| 470 | |
| 471 | QFileInfoList listS; |
| 472 | listS.append(listSFolders); |
| 473 | listS.append(listSFiles); |
| 474 | // QLOG_DEBUG() << "---------------------------------------------------------"; |
| 475 | // for (const QFileInfo &info : listS) |
| 476 | // QLOG_DEBUG() << info.fileName(); |
| 477 | |
| 478 | // QLOG_TRACE() << "END Getting info from dir" << dirS.absolutePath(); |
| 479 | |
| 480 | // QLOG_TRACE() << "Getting info from DB" << dirS.absolutePath(); |
| 481 | QList<LibraryItem *> folders = DBHelper::getFoldersFromParent(_currentPathFolders.last().id, _database); |
| 482 | QList<LibraryItem *> comics = DBHelper::getComicsFromParent(_currentPathFolders.last().id, _database); |
| 483 | // QLOG_TRACE() << "END Getting info from DB" << dirS.absolutePath(); |
| 484 | |
| 485 | QList<LibraryItem *> listD; |
| 486 | std::sort(folders.begin(), folders.end(), naturalSortLessThanCILibraryItem); |
| 487 | std::sort(comics.begin(), comics.end(), naturalSortLessThanCILibraryItem); |
| 488 | listD.append(folders); |
| 489 | listD.append(comics); |
| 490 | // QLOG_DEBUG() << "---------------------------------------------------------"; |
| 491 | // for (auto *info : listD) |
| 492 | // QLOG_DEBUG() << info->name; |
| 493 | // QLOG_DEBUG() << "---------------------------------------------------------"; |
| 494 | int lenghtS = listS.size(); |
| 495 | int lenghtD = listD.size(); |
| 496 | // QLOG_DEBUG() << "S len" << lenghtS << "D len" << lenghtD; |
| 497 | // QLOG_DEBUG() << "---------------------------------------------------------"; |
| 498 | |
| 499 | bool updated; |
| 500 | int i, j; |
| 501 | for (i = 0, j = 0; (i < lenghtS) || (j < lenghtD);) { |
| 502 | if (stopRunning) { |
| 503 | qDeleteAll(listD); |
| 504 | return; |
| 505 | } |
| 506 | updated = false; |
| 507 | if (i >= lenghtS) // finished source files/dirs |
| 508 | { |