Refresh library with monitory directory changes on startup

This refreshes the library on every startup
list of elements already in monitor directory (before changes) are taken by filtering library.xml
This commit is contained in:
Nikhil Tanwar 2022-02-03 16:16:34 +05:30 committed by Emmanuel Engelhart
parent 45a09cfae6
commit e0337d0caf
No known key found for this signature in database
GPG Key ID: 120B30D020B553D3
2 changed files with 18 additions and 0 deletions

View File

@ -101,6 +101,11 @@ void KiwixApp::init()
this->openZimFile(message);
}
});
QString monitorDir = m_settingsManager.getMonitorDir();
if (monitorDir != "") {
m_library.setMonitorDirZims(m_library.getLibraryZimsFromDir(monitorDir));
m_library.asyncLoadMonitorDir(monitorDir);
}
}
KiwixApp::~KiwixApp()

View File

@ -130,6 +130,19 @@ void Library::setMonitorDirZims(QStringList zimList)
m_monitorDirZims = zimList;
}
QStringList Library::getLibraryZimsFromDir(QString dir) const
{
QStringList zimsInDir;
for (auto str : getBookIds()) {
auto filePath = QString::fromStdString(getBookById(str).getPath());
QDir absoluteDir = QFileInfo(filePath).absoluteDir();
if (absoluteDir == dir) {
zimsInDir.push_back(filePath);
}
}
return zimsInDir;
}
void Library::loadMonitorDir(QString monitorDir)
{
QMutex mutex;