Added state to the tracked monitored files

Semantically, nothing changes at this point but the possibility for
an enhancement is now open.
This commit is contained in:
Veloman Yunkan 2024-08-25 17:31:15 +04:00 committed by Kelson
parent 076c19b645
commit bc05c75448
2 changed files with 20 additions and 4 deletions

View File

@ -865,9 +865,14 @@ void ContentManager::setMonitoredDirectories(QStringSet dirList)
m_watcher.removePath(path); m_watcher.removePath(path);
} }
m_knownZimsInDir.clear(); m_knownZimsInDir.clear();
MonitoredZimFileInfo libraryZimFileInfo;
libraryZimFileInfo.status = MonitoredZimFileInfo::ADDED_TO_THE_LIBRARY;
for (auto dir : dirList) { for (auto dir : dirList) {
if (dir != "") { if (dir != "") {
m_knownZimsInDir[dir] = mp_library->getLibraryZimsFromDir(dir); auto& zimsInDir = m_knownZimsInDir[dir];
for ( const auto& fname : mp_library->getLibraryZimsFromDir(dir) ) {
zimsInDir.insert(fname, libraryZimFileInfo);
}
m_watcher.addPath(dir); m_watcher.addPath(dir);
asyncUpdateLibraryFromDir(dir); asyncUpdateLibraryFromDir(dir);
} }
@ -919,6 +924,7 @@ namespace
// indexed by MonitoredZimFileInfo::ZimFileStatus enum // indexed by MonitoredZimFileInfo::ZimFileStatus enum
const char* monitoredDirZimFileHandlingMsgs[] = { const char* monitoredDirZimFileHandlingMsgs[] = {
"",
"it is being downloaded by us, ignoring...", "it is being downloaded by us, ignoring...",
"the file was added to the library", "the file was added to the library",
"the file could not be added to the library" "the file could not be added to the library"
@ -944,7 +950,7 @@ int ContentManager::handleZimFileInMonitoredDir(QString dir, QString fileName)
if ( mp_library->isBeingDownloadedByUs(bookPath) ) { if ( mp_library->isBeingDownloadedByUs(bookPath) ) {
return MonitoredZimFileInfo::BEING_DOWNLOADED_BY_US; return MonitoredZimFileInfo::BEING_DOWNLOADED_BY_US;
} else if ( manager.addBookFromPath(bookPath.toStdString()) ) { } else if ( manager.addBookFromPath(bookPath.toStdString()) ) {
m_knownZimsInDir[dir].insert(fileName); m_knownZimsInDir[dir].insert(fileName, MonitoredZimFileInfo());
return MonitoredZimFileInfo::ADDED_TO_THE_LIBRARY; return MonitoredZimFileInfo::ADDED_TO_THE_LIBRARY;
} else { } else {
return MonitoredZimFileInfo::COULD_NOT_BE_ADDED_TO_THE_LIBRARY; return MonitoredZimFileInfo::COULD_NOT_BE_ADDED_TO_THE_LIBRARY;
@ -953,7 +959,13 @@ int ContentManager::handleZimFileInMonitoredDir(QString dir, QString fileName)
ContentManager::QStringSet ContentManager::getLibraryZims(QString dirPath) const ContentManager::QStringSet ContentManager::getLibraryZims(QString dirPath) const
{ {
return m_knownZimsInDir[dirPath]; QStringSet zimFileNames;
const auto& zimsInDir = m_knownZimsInDir[dirPath];
for ( auto it = zimsInDir.begin(); it != zimsInDir.end(); ++it ) {
if ( it.value().status == MonitoredZimFileInfo::ADDED_TO_THE_LIBRARY )
zimFileNames.insert(it.key());
}
return zimFileNames;
} }
void ContentManager::updateLibraryFromDir(QString dirPath) void ContentManager::updateLibraryFromDir(QString dirPath)

View File

@ -122,8 +122,12 @@ private: // types
// the attempt to add the file to the library failed // the attempt to add the file to the library failed
COULD_NOT_BE_ADDED_TO_THE_LIBRARY COULD_NOT_BE_ADDED_TO_THE_LIBRARY
}; };
ZimFileStatus status = ADDED_TO_THE_LIBRARY;
}; };
typedef QMap<QString, MonitoredZimFileInfo> ZimFileName2InfoMap;
private: // functions private: // functions
QStringList getBookIds(); QStringList getBookIds();
// reallyEraseBook() doesn't ask for confirmation (unlike eraseBook()) // reallyEraseBook() doesn't ask for confirmation (unlike eraseBook())
@ -171,7 +175,7 @@ private: // data
QFileSystemWatcher m_watcher; QFileSystemWatcher m_watcher;
QMutex m_updateFromDirMutex; QMutex m_updateFromDirMutex;
QMap<QString, QStringSet> m_knownZimsInDir; QMap<QString, ZimFileName2InfoMap> m_knownZimsInDir;
}; };
#endif // CONTENTMANAGER_H #endif // CONTENTMANAGER_H