Skip to content

Commit

Permalink
fixed a bug where dropping a PDF on Board then deleting one of the ad…
Browse files Browse the repository at this point in the history
…ded pages would end in a crash if document was also active on Document Mode
  • Loading branch information
kaamui committed Oct 17, 2024
1 parent 16c8a17 commit 78ee945
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/board/UBBoardController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,12 +1453,13 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QUrl
qDebug() << "sourceurl : " + sourceUrl.toString();
QString sUrl = sourceUrl.toString();

int result = 0;
int numberOfImportedDocuments = 0;
int currentNumberOfThumbnails = selectedDocument()->pageCount();
if(!sourceUrl.isEmpty() && (sUrl.startsWith("file://") || sUrl.startsWith("/")))
{
QStringList fileNames;
fileNames << sourceUrl.toLocalFile();
result = UBDocumentManager::documentManager()->addFilesToDocument(selectedDocument(), fileNames);
numberOfImportedDocuments = UBDocumentManager::documentManager()->addFilesToDocument(selectedDocument(), fileNames);
}
else if(pData.size()){
QTemporaryFile pdfFile("XXXXXX.pdf");
Expand All @@ -1467,17 +1468,35 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QUrl
pdfFile.write(pData);
QStringList fileNames;
fileNames << pdfFile.fileName();
result = UBDocumentManager::documentManager()->addFilesToDocument(selectedDocument(), fileNames);
numberOfImportedDocuments = UBDocumentManager::documentManager()->addFilesToDocument(selectedDocument(), fileNames);

pdfFile.close();
}
}

if (result)
if (numberOfImportedDocuments > 0)
{

QDateTime now = QDateTime::currentDateTime();
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(now));
updateActionStates();
reloadThumbnails();

int numberOfThumbnailsToAdd = selectedDocument()->pageCount() - currentNumberOfThumbnails;

bool updateDocumentThumbnailsView = UBApplication::documentController->selectedDocument() == selectedDocument();
for (int i = 0; i < numberOfThumbnailsToAdd; i++)
{
emit addThumbnailRequired(selectedDocument(), currentNumberOfThumbnails+i);

if (updateDocumentThumbnailsView)
{
UBApplication::documentController->insertThumbPage(currentNumberOfThumbnails+i);
}
}
if (updateDocumentThumbnailsView)
{
UBApplication::documentController->reloadThumbnails();
}
}
}
else if (UBMimeType::OpenboardTool == itemMimeType)
Expand Down

0 comments on commit 78ee945

Please sign in to comment.