diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index da1c5db..31bd3d0 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -864,6 +864,21 @@ void ContentManager::asyncUpdateLibraryFromDir(QString dir) }); } +void ContentManager::handleDisappearedZimFiles(const QStringSet& zimPaths) +{ + const auto kiwixLib = mp_library->getKiwixLibrary(); + for (auto bookPath : zimPaths) { + try { + DBGOUT("directory monitoring: file disappeared: " << bookPath); + const auto book = kiwixLib->getBookByPath(bookPath.toStdString()); + handleDisappearedZimFile(QString::fromStdString(book.getId())); + } catch (const std::exception& err) { + DBGOUT("directory monitoring: " + "error while dropping the disappeared book: " << err.what()); + } + } +} + void ContentManager::updateLibraryFromDir(QString monitorDir) { typedef Library::QStringSet QStringSet; @@ -880,25 +895,17 @@ void ContentManager::updateLibraryFromDir(QString monitorDir) const auto kiwixLib = mp_library->getKiwixLibrary(); kiwix::Manager manager(kiwixLib); bool needsRefresh = !removedZims.empty(); - for (auto bookPath : removedZims) { - try { - DBGOUT("ContentManager::updateLibraryFromDir(): " - << "file disappeared: " << bookPath); - const auto book = kiwixLib->getBookByPath(bookPath.toStdString()); - handleDisappearedZimFile(QString::fromStdString(book.getId())); - } catch (...) {} - } + handleDisappearedZimFiles(removedZims); for (auto bookPath : addedZims) { if ( mp_library->isBeingDownloadedByUs(bookPath) ) { - DBGOUT("ContentManager::updateLibraryFromDir(): " << bookPath + DBGOUT("directory monitoring: " << bookPath << " ignored since it is being downloaded by us."); } else { - DBGOUT("ContentManager::updateLibraryFromDir(): " - << "file appeared: " << bookPath); + DBGOUT("directory monitoring: file appeared: " << bookPath); const bool added = manager.addBookFromPath(bookPath.toStdString()); - DBGOUT(" " + DBGOUT(" " << (added ? "and was added" : "but could not be added") - << " to the library"); + << "to the library"); needsRefresh |= added; } } diff --git a/src/contentmanager.h b/src/contentmanager.h index e92a158..b25a266 100644 --- a/src/contentmanager.h +++ b/src/contentmanager.h @@ -19,6 +19,7 @@ public: // types typedef QList> FilterList; typedef ContentManagerModel::BookInfo BookInfo; typedef ContentManagerModel::BookInfoList BookInfoList; + typedef Library::QStringSet QStringSet; enum class BookState { @@ -69,7 +70,7 @@ public: // functions QStringList getCategories() const { return m_categories; } LanguageList getLanguages() const { return m_languages; } - void setMonitorDirZims(QString monitorDir, Library::QStringSet zimList); + void setMonitorDirZims(QString monitorDir, QStringSet zimList); void asyncUpdateLibraryFromDir(QString dir); signals: @@ -117,6 +118,7 @@ private: // functions void setCategories(); void setLanguages(); void updateLibraryFromDir(QString dir); + void handleDisappearedZimFiles(const QStringSet& zimPaths); void handleDisappearedZimFile(QString bookId); // Get the book with the specified id from @@ -148,7 +150,7 @@ private: // data QMutex remoteLibraryLocker; QMutex m_updateFromDirMutex; - QMap m_knownZimsInDir; + QMap m_knownZimsInDir; }; #endif // CONTENTMANAGER_H