| 168 | } |
| 169 | |
| 170 | std::shared_ptr<UBDocumentProxy> UBDocumentManager::importFile(const QFile& pFile, const QString& pGroup) |
| 171 | { |
| 172 | QFileInfo fileInfo(pFile); |
| 173 | |
| 174 | foreach (UBImportAdaptor *adaptor, mImportAdaptors) |
| 175 | { |
| 176 | if (adaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1) |
| 177 | { |
| 178 | std::shared_ptr<UBDocumentProxy> document; |
| 179 | UBApplication::setDisabled(true); |
| 180 | |
| 181 | if (adaptor->isDocumentBased()) |
| 182 | { |
| 183 | UBDocumentBasedImportAdaptor* importAdaptor = (UBDocumentBasedImportAdaptor*)adaptor; |
| 184 | |
| 185 | document = importAdaptor->importFile(pFile, pGroup); |
| 186 | |
| 187 | } |
| 188 | else |
| 189 | { |
| 190 | UBPageBasedImportAdaptor* importAdaptor = (UBPageBasedImportAdaptor*)adaptor; |
| 191 | |
| 192 | // Document import procedure..... |
| 193 | QString documentName = QFileInfo(pFile.fileName()).completeBaseName(); |
| 194 | document = UBPersistenceManager::persistenceManager()->createDocument(pGroup |
| 195 | ,documentName |
| 196 | , false // Issue 1630 - CFA - 201410503 - suppression de la page vide ajoutee à l'import des pdfs |
| 197 | , QString() |
| 198 | , 0 |
| 199 | , true); |
| 200 | |
| 201 | if (document) |
| 202 | { |
| 203 | auto doc = UBDocument::getDocument(document); |
| 204 | QUuid uuid = QUuid::createUuid(); |
| 205 | QString filepath = pFile.fileName(); |
| 206 | if (importAdaptor->folderToCopy() != "") |
| 207 | { |
| 208 | bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(document, pFile.fileName(), importAdaptor->folderToCopy() , uuid, filepath); |
| 209 | if (!b) |
| 210 | { |
| 211 | UBApplication::setDisabled(false); |
| 212 | return NULL; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | QList<UBGraphicsItem*> pages = importAdaptor->import(uuid, filepath); |
| 217 | int pageIndex = 0; |
| 218 | |
| 219 | UBApplication::showMessage(tr("Creating %1 pages. Please wait...").arg(pages.size()), true); |
| 220 | foreach(UBGraphicsItem* page, pages) |
| 221 | { |
| 222 | #ifdef Q_WS_MACX |
| 223 | //Workaround for issue 912 |
| 224 | QApplication::processEvents(); |
| 225 | #endif |
| 226 | std::shared_ptr<UBGraphicsScene> scene = doc->createPage(pageIndex); |
| 227 | importAdaptor->placeImportedItemToScene(scene, page); |
no outgoing calls
no test coverage detected