MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / addFileToDocument

Method addFileToDocument

src/core/UBPersistenceManager.cpp:1319–1373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1317}
1318
1319bool 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
1375bool UBPersistenceManager::addGraphicsWidgetToDocument(std::shared_ptr<UBDocumentProxy> pDocumentProxy,
1376 QString path,

Callers 2

foreachFunction · 0.45
runMethod · 0.45

Calls 6

existsFunction · 0.85
persistencePathMethod · 0.80
lengthMethod · 0.45
copyMethod · 0.45
closeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected