ContentManager::handleZimFileInMonitoredDir()

Indentation is intentionally not fixed (to keep the diff minimal).
This commit is contained in:
Veloman Yunkan 2024-07-31 17:47:18 +04:00 committed by Kelson
parent 26b4430199
commit 2df3e2db0b
2 changed files with 12 additions and 4 deletions

View File

@ -905,10 +905,18 @@ void ContentManager::handleDisappearedZimFiles(const QString& dirPath, const QSt
size_t ContentManager::handleNewZimFiles(const QString& dirPath, const QStringSet& fileNames)
{
size_t countOfSuccessfullyAddedZims = 0;
for (const auto& file : fileNames) {
const bool addedToLib = handleZimFileInMonitoredDir(dirPath, file);
countOfSuccessfullyAddedZims += addedToLib;
}
return countOfSuccessfullyAddedZims;
}
int ContentManager::handleZimFileInMonitoredDir(QString dirPath, QString file)
{
const auto kiwixLib = mp_library->getKiwixLibrary();
kiwix::Manager manager(kiwixLib);
auto& zimsInDir = m_knownZimsInDir[dirPath];
for (const auto& file : fileNames) {
const auto bookPath = QDir::toNativeSeparators(dirPath + "/" + file);
DBGOUT("directory monitoring: file appeared: " << bookPath);
if ( mp_library->isBeingDownloadedByUs(bookPath) ) {
@ -916,12 +924,11 @@ size_t ContentManager::handleNewZimFiles(const QString& dirPath, const QStringSe
} else if ( manager.addBookFromPath(bookPath.toStdString()) ) {
DBGOUT(" and was added to the library");
zimsInDir.insert(file);
++countOfSuccessfullyAddedZims;
return 1;
} else {
DBGOUT(" but could not be added to the library");
}
}
return countOfSuccessfullyAddedZims;
return 0;
}
void ContentManager::updateLibraryFromDir(QString dirPath)

View File

@ -120,6 +120,7 @@ private: // functions
void updateLibraryFromDir(QString dir);
void handleDisappearedZimFiles(const QString& dirPath, const QStringSet& fileNames);
size_t handleNewZimFiles(const QString& dirPath, const QStringSet& fileNames);
int handleZimFileInMonitoredDir(QString dirPath, QString fileName);
bool handleDisappearedBook(QString bookId);
// Get the book with the specified id from