QMap< QString, QString > m_Files;
QMap< QString, QString > m_FileMimetypes;
QHash<QString, QString> ImportEPUB::LoadFolderStructure()
{
QList<QString> keys = m_Files.keys();
int num_files = keys.count();
QFutureSynchronizer<tuple<QString, QString> > sync;
for (int i = 0; i < num_files; ++i) {
QString id = keys.at(i);
sync.addFuture(QtConcurrent::run(
this,
&ImportEPUB::LoadOneFile,
m_Files.value(id),
m_FileMimetypes.value(id)));
}
sync.waitForFinished();
QList<QFuture<tuple<QString, QString> > > futures = sync.futures();
int num_futures = futures.count();
QHash<QString, QString> updates;
for (int i = 0; i < num_futures; ++i) {
tuple< QString, QString > result = futures.at(i).result();
updates[result.get<0>()] = result.get< 1 >();
}
updates.remove(UPDATE_ERROR_STRING);
return updates;
}
tuple<QString, QString> ImportEPUB::LoadOneFile(const QString &path, const QString &mimetype)
{
QString fullfilepath = QFileInfo(m_OPFFilePath).absolutePath() + "/" + path;
try {
Resource &resource = m_Book->GetFolderKeeper().AddContentFileToFolder(fullfilepath, false, mimetype);
QString newpath = "../" + resource.GetRelativePathToOEBPS();
return make_tuple(fullfilepath, newpath);
} catch (FileDoesNotExist &) {
qDebug() << "FNDE: " << path;
return make_tuple(UPDATE_ERROR_STRING, UPDATE_ERROR_STRING);
}
}