UBDocumentProxy* UBImportCFF::importFile(const QFile& pFile, const QString& pGroup) { Q_UNUSED(pGroup); // group is defined in the imported file QFileInfo fi(pFile); UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true); // first unzip the file to the correct place //TODO create temporary path for iwb file content QString path = QDir::tempPath(); QString documentRootFolder = expandFileToDir(pFile, path); QString contentFile; if (documentRootFolder.isEmpty()) //if file has failed to umzip it is probably just xml file contentFile = pFile.fileName(); else //get path to content xml contentFile = QString("%1/content.xml").arg(documentRootFolder); if(!contentFile.length()){ UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName())); return 0; } else{ //create destination document proxy //fill metadata and save UBDocumentProxy* destDocument = new UBDocumentProxy(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath()); QDir dir; dir.mkdir(destDocument->persistencePath()); if (pGroup.length() > 0) destDocument->setMetaData(UBSettings::documentGroupName, pGroup); if (fi.baseName() > 0) destDocument->setMetaData(UBSettings::documentName, fi.baseName()); destDocument->setMetaData(UBSettings::documentVersion, UBSettings::currentFileVersion); destDocument->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); UBDocumentProxy* newDocument = NULL; //try to import cff to document if (UBCFFSubsetAdaptor::ConvertCFFFileToUbz(contentFile, destDocument)) { newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(destDocument->persistencePath()); UBApplication::showMessage(tr("Import successful.")); } else { UBFileSystemUtils::deleteDir(destDocument->persistencePath()); UBApplication::showMessage(tr("Import failed.")); } delete destDocument; if (documentRootFolder.length() != 0) UBFileSystemUtils::deleteDir(documentRootFolder); return newDocument; } }
void UBExportDocumentSetAdaptor::persist(UBDocumentProxy* pDocumentProxy) { QModelIndex treeViewParentIndex; UBPersistenceManager *persistenceManager = UBPersistenceManager::persistenceManager(); UBDocumentTreeModel *treeModel = persistenceManager->mDocumentTreeStructureModel; QString filename; if (pDocumentProxy) { treeViewParentIndex = treeModel->indexForProxy(pDocumentProxy); if (!treeViewParentIndex.isValid()) { qDebug() << "failed to export"; UBApplication::showMessage(tr("Failed to export...")); return; } filename = askForFileName(pDocumentProxy, tr("Export as UBX File")); } else { treeViewParentIndex = UBApplication::documentController->firstSelectedTreeIndex(); if (!treeViewParentIndex.isValid()) { qDebug() << "failed to export"; UBApplication::showMessage(tr("Failed to export...")); return; } UBDocumentTreeNode* node = treeModel->nodeFromIndex(treeViewParentIndex); UBDocumentProxy proxy; proxy.setMetaData(UBSettings::documentName,node->displayName()); filename = askForFileName(&proxy, tr("Export as UBX File")); } if (filename.length() > 0) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); if (mIsVerbose) UBApplication::showMessage(tr("Exporting document...")); if (persistData(treeViewParentIndex, filename)) { if (mIsVerbose) { UBApplication::showMessage(tr("Export successful.")); } } else { if (mIsVerbose) { UBApplication::showMessage(tr("Export failed.")); } } QApplication::restoreOverrideCursor(); } }