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; } }
bool UBImportDocument::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) { QFileInfo fi(pFile); UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true); QString path = UBFileSystemUtils::createTempDir(); QString documentRootFolder = expandFileToDir(pFile, path); UBPersistenceManager::persistenceManager()->addDirectoryContentToDocument(documentRootFolder, pDocument); UBFileSystemUtils::deleteDir(path); UBApplication::showMessage(tr("Import successful.")); return true; }
bool UBImportCFF::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) { 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 unzip it is probably just xml file contentFile = pFile.fileName(); else //get path to content xml (according to iwbcff specification) contentFile = documentRootFolder.append("/content.xml"); if(!contentFile.length()){ UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName())); return false; } else{ //TODO convert expanded CFF file content to the destination document //create destination document proxy //fill metadata and save UBDocumentProxy* destDocument = new UBDocumentProxy(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath()); QDir dir; dir.mkdir(destDocument->persistencePath()); //try to import cff to document if (UBCFFSubsetAdaptor::ConvertCFFFileToUbz(contentFile, destDocument)) { UBPersistenceManager::persistenceManager()->addDirectoryContentToDocument(destDocument->persistencePath(), pDocument); UBFileSystemUtils::deleteDir(destDocument->persistencePath()); delete destDocument; UBApplication::showMessage(tr("Import successful.")); return true; } else { UBFileSystemUtils::deleteDir(destDocument->persistencePath()); delete destDocument; UBApplication::showMessage(tr("Import failed.")); return false; } } }
UBDocumentProxy* UBImportDocument::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 QString path = UBSettings::userDocumentDirectory(); QString documentRootFolder = expandFileToDir(pFile, path); if(!documentRootFolder.length()){ UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName())); return 0; } else{ UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup); UBApplication::showMessage(tr("Import successful.")); return newDocument; } }