| 1317 | } |
| 1318 | |
| 1319 | bool UBPersistenceManager::addFileToDocument(std::shared_ptr<UBDocumentProxy> pDocumentProxy, |
| 1320 | QString path, |
| 1321 | const QString& subdir, |
| 1322 | QUuid objectUuid, |
| 1323 | QString& destinationPath, |
| 1324 | QByteArray* data) |
| 1325 | { |
| 1326 | Q_ASSERT(path.length()); |
| 1327 | QFileInfo fi(path); |
| 1328 | |
| 1329 | if (!pDocumentProxy || objectUuid.isNull()) |
| 1330 | return false; |
| 1331 | if (data == NULL && !fi.exists()) |
| 1332 | return false; |
| 1333 | |
| 1334 | qDebug() << fi.suffix(); |
| 1335 | |
| 1336 | QString fileName = subdir + "/" + objectUuid.toString() + "." + fi.suffix(); |
| 1337 | |
| 1338 | destinationPath = pDocumentProxy->persistencePath() + "/" + fileName; |
| 1339 | |
| 1340 | if (!QFile::exists(destinationPath)) |
| 1341 | { |
| 1342 | QDir dir; |
| 1343 | dir.mkdir(pDocumentProxy->persistencePath() + "/" + subdir); |
| 1344 | if (!QFile::exists(pDocumentProxy->persistencePath() + "/" + subdir)) |
| 1345 | return false; |
| 1346 | |
| 1347 | if (data == NULL) |
| 1348 | { |
| 1349 | QFile source(path); |
| 1350 | return source.copy(destinationPath); |
| 1351 | } |
| 1352 | else |
| 1353 | { |
| 1354 | QFile newFile(destinationPath); |
| 1355 | |
| 1356 | if (newFile.open(QIODevice::WriteOnly)) |
| 1357 | { |
| 1358 | qint64 n = newFile.write(*data); |
| 1359 | newFile.flush(); |
| 1360 | newFile.close(); |
| 1361 | return n == data->size(); |
| 1362 | } |
| 1363 | else |
| 1364 | { |
| 1365 | return false; |
| 1366 | } |
| 1367 | } |
| 1368 | } |
| 1369 | else |
| 1370 | { |
| 1371 | return false; |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | bool UBPersistenceManager::addGraphicsWidgetToDocument(std::shared_ptr<UBDocumentProxy> pDocumentProxy, |
| 1376 | QString path, |