Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 302c3867 authored by Albert Astals Cid's avatar Albert Astals Cid Committed by Albert Astals Cid

Make Document::swapBackingFileArchive use swapBackingFile

parent 1ed2522b
......@@ -4446,19 +4446,6 @@ bool Document::swapBackingFile( const QString &newFileName, const QUrl &url )
bool Document::swapBackingFileArchive( const QString &newFileName, const QUrl &url )
{
if ( !d->m_generator )
return false;
Q_ASSERT( !d->m_generatorName.isEmpty() );
QHash< QString, GeneratorInfo >::iterator genIt = d->m_loadedGenerators.find( d->m_generatorName );
Q_ASSERT( genIt != d->m_loadedGenerators.end() );
if ( !genIt->generator->hasFeature( Generator::SwapBackingFile ) )
return false;
// Save metadata about the file we're about to close
d->saveDocumentInfo();
qCDebug(OkularCoreDebug) << "Swapping backing archive to" << newFileName;
ArchiveData *newArchive = DocumentPrivate::unpackDocumentArchive( newFileName );
......@@ -4467,89 +4454,15 @@ bool Document::swapBackingFileArchive( const QString &newFileName, const QUrl &u
const QString tempFileName = newArchive->document.fileName();
qCDebug(OkularCoreDebug) << "Swapping backing file to" << tempFileName;
QVector< Page * > newPagesVector;
Generator::SwapBackingFileResult result = genIt->generator->swapBackingFile( tempFileName, newPagesVector );
if (result != Generator::SwapBackingFileError)
{
QLinkedList< ObjectRect* > rectsToDelete;
QLinkedList< Annotation* > annotationsToDelete;
QSet< PagePrivate* > pagePrivatesToDelete;
if (result == Generator::SwapBackingFileReloadInternalData)
{
// Here we need to replace everything that the old generator
// had created with what the new one has without making it look like
// we have actually closed and opened the file again
// Simple sanity check
if (newPagesVector.count() != d->m_pagesVector.count())
return false;
// Update the undo stack contents
for (int i = 0; i < d->m_undoStack->count(); ++i)
{
// Trust me on the const_cast ^_^
QUndoCommand *uc = const_cast<QUndoCommand *>( d->m_undoStack->command( i ) );
if (OkularUndoCommand *ouc = dynamic_cast<OkularUndoCommand*>( uc )) ouc->refreshInternalPageReferences( newPagesVector );
else
{
qWarning() << "Unhandled undo command" << uc;
}
}
for (int i = 0; i < d->m_pagesVector.count(); ++i)
{
// switch the PagePrivate* from newPage to oldPage
// this way everyone still holding Page* doesn't get
// disturbed by it
Page *oldPage = d->m_pagesVector[i];
Page *newPage = newPagesVector[i];
newPage->d->adoptGeneratedContents(oldPage->d);
pagePrivatesToDelete << oldPage->d;
oldPage->d = newPage->d;
oldPage->d->m_page = oldPage;
oldPage->d->m_doc = d;
newPage->d = nullptr;
annotationsToDelete << oldPage->m_annotations;
rectsToDelete << oldPage->m_rects;
oldPage->m_annotations = newPage->m_annotations;
oldPage->m_rects = newPage->m_rects;
}
qDeleteAll( newPagesVector );
}
const bool success = swapBackingFile( tempFileName, url );
if ( success )
{
delete d->m_archiveData;
d->m_archiveData = newArchive;
d->m_url = url;
d->m_docFileName = tempFileName;
d->updateMetadataXmlNameAndDocSize();
d->m_bookmarkManager->setUrl( d->m_url );
if ( d->m_synctex_scanner )
{
synctex_scanner_free( d->m_synctex_scanner );
d->m_synctex_scanner = synctex_scanner_new_with_output_file( QFile::encodeName( newFileName ).constData(), nullptr, 1);
if ( !d->m_synctex_scanner && QFile::exists(newFileName + QLatin1String( "sync" ) ) )
{
d->loadSyncFile(newFileName);
}
}
foreachObserver( notifySetup( d->m_pagesVector, DocumentObserver::UrlChanged ) );
qDeleteAll( annotationsToDelete );
qDeleteAll( rectsToDelete );
qDeleteAll( pagePrivatesToDelete );
return true;
}
else
{
return false;
}
return success;
}
bool Document::canSaveChanges() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment