| 647 | } |
| 648 | |
| 649 | std::shared_ptr<UBDocumentProxy> UBPersistenceManager::createDocumentFromDir(const QString& pDocumentDirectory |
| 650 | , const QString& pGroupName |
| 651 | , const QString& pName |
| 652 | , bool withEmptyPage |
| 653 | , bool addTitlePage |
| 654 | , bool promptDialogIfExists) |
| 655 | { |
| 656 | checkIfDocumentRepositoryExists(); |
| 657 | |
| 658 | std::shared_ptr<UBDocumentProxy> doc = std::make_shared<UBDocumentProxy>(pDocumentDirectory); // deleted in UBPersistenceManager::destructor |
| 659 | |
| 660 | QMap<QString, QVariant> metadatas = UBMetadataDcSubsetAdaptor::load(pDocumentDirectory); |
| 661 | |
| 662 | if(withEmptyPage) |
| 663 | { |
| 664 | createDocumentSceneAt(doc, 0); |
| 665 | } |
| 666 | |
| 667 | if(addTitlePage) |
| 668 | { |
| 669 | persistDocumentScene(doc, mSceneCache.createScene(doc, 0, false), 0); |
| 670 | } |
| 671 | |
| 672 | foreach(QString key, metadatas.keys()) |
| 673 | { |
| 674 | doc->setMetaData(key, metadatas.value(key)); |
| 675 | } |
| 676 | |
| 677 | if (pGroupName.length() > 0) |
| 678 | { |
| 679 | doc->setMetaData(UBSettings::documentGroupName, pGroupName); |
| 680 | } |
| 681 | |
| 682 | if (pName.length() > 0) |
| 683 | { |
| 684 | doc->setMetaData(UBSettings::documentName, pName); |
| 685 | } |
| 686 | |
| 687 | doc->setUuid(QUuid::createUuid()); |
| 688 | doc->setPageCount(sceneCount(doc)); |
| 689 | |
| 690 | for(int i = 0; i < doc->pageCount(); i++) |
| 691 | { |
| 692 | UBSvgSubsetAdaptor::setSceneUuid(doc, i, QUuid::createUuid()); |
| 693 | } |
| 694 | |
| 695 | //work around the |
| 696 | bool addDoc = false; |
| 697 | if (!promptDialogIfExists) { |
| 698 | addDoc = true; |
| 699 | mDocumentTreeStructureModel->addDocument(doc); |
| 700 | } else if (processInteractiveReplacementDialog(doc) == QDialog::Accepted) { |
| 701 | addDoc = true; |
| 702 | } |
| 703 | if (addDoc) { |
| 704 | persistDocumentMetadata(doc); |
| 705 | emit documentCreated(doc); |
| 706 | } else { |
no test coverage detected