| 245 | |
| 246 | |
| 247 | int UBDocumentManager::addFilesToDocument(std::shared_ptr<UBDocumentProxy> document, QStringList fileNames) |
| 248 | { |
| 249 | int nImportedDocuments = 0; |
| 250 | auto doc = UBDocument::getDocument(document); |
| 251 | const auto currentNumberOfPages = document->pageCount(); |
| 252 | |
| 253 | foreach(const QString& fileName, fileNames) |
| 254 | { |
| 255 | UBApplication::showMessage(tr("Importing file %1").arg(fileName)); |
| 256 | |
| 257 | QFile file(fileName); |
| 258 | QFileInfo fileInfo(file); |
| 259 | |
| 260 | UBApplication::setDisabled(true); |
| 261 | |
| 262 | foreach (UBImportAdaptor *adaptor, mImportAdaptors) |
| 263 | { |
| 264 | if (adaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1) |
| 265 | { |
| 266 | if (adaptor->isDocumentBased()) |
| 267 | { |
| 268 | //issue 1629 - NNE - 20131212 : Resolve a segfault, but for .ubx, actually |
| 269 | //the file will be not imported... |
| 270 | UBDocumentBasedImportAdaptor* importAdaptor = dynamic_cast<UBDocumentBasedImportAdaptor*>(adaptor); |
| 271 | |
| 272 | if (importAdaptor && importAdaptor->addFileToDocument(document, file)) |
| 273 | { |
| 274 | nImportedDocuments++; |
| 275 | break; |
| 276 | } |
| 277 | } |
| 278 | else |
| 279 | { |
| 280 | UBPageBasedImportAdaptor* importAdaptor = (UBPageBasedImportAdaptor*)adaptor; |
| 281 | |
| 282 | QUuid uuid = QUuid::createUuid(); |
| 283 | QString filepath = file.fileName(); |
| 284 | if (importAdaptor->folderToCopy() != "") |
| 285 | { |
| 286 | bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(document, file.fileName(), importAdaptor->folderToCopy() , uuid, filepath); |
| 287 | if (!b) |
| 288 | { |
| 289 | continue; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | QList<UBGraphicsItem*> pages = importAdaptor->import(uuid, filepath); |
| 294 | int nPage = 0; |
| 295 | foreach(UBGraphicsItem* page, pages) |
| 296 | { |
| 297 | UBApplication::showMessage(tr("Inserting page %1 of %2").arg(++nPage).arg(pages.size()), true); |
| 298 | int pageIndex = document->pageCount(); |
| 299 | std::shared_ptr<UBGraphicsScene> scene = doc->createPage(pageIndex); |
| 300 | importAdaptor->placeImportedItemToScene(scene, page); |
| 301 | doc->persistPage(scene, pageIndex); |
| 302 | } |
| 303 | |
| 304 | UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document); |
no test coverage detected