QHash< QString, QString > ImportOEBPS::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, &ImportOEBPS::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; }
// Loads the referenced files into the main folder of the book; // as the files get a new name, the references are updated QHash<QString, QString> ImportHTML::LoadFolderStructure(const QString & source) { QStringList mediapaths = XhtmlDoc::GetPathsToMediaFiles(source); QStringList stylepaths = XhtmlDoc::GetPathsToStyleFiles(source); QFutureSynchronizer<QHash<QString, QString>> sync; sync.addFuture(QtConcurrent::run(this, &ImportHTML::LoadMediaFiles, mediapaths)); sync.addFuture(QtConcurrent::run(this, &ImportHTML::LoadStyleFiles, stylepaths)); sync.waitForFinished(); QList<QFuture<QHash<QString, QString>>> futures = sync.futures(); int num_futures = futures.count(); QHash<QString, QString> updates; for (int i = 0; i < num_futures; ++i) { updates.unite(futures.at(i).result()); } return updates; }