Load and store generalInfo metadata for .okular archives too

generalInfo metadata is everything but annots and forms, which are
stored within the .okular archive itself
This commit is contained in:
Fabio D'Urso 2014-05-11 15:55:46 +02:00
parent 48a23fc443
commit 31efd827f9
2 changed files with 37 additions and 23 deletions

View file

@ -606,7 +606,7 @@ qulonglong DocumentPrivate::getFreeMemory( qulonglong *freeSwap )
#endif
}
void DocumentPrivate::loadDocumentInfo()
void DocumentPrivate::loadDocumentInfo( LoadDocumentInfoFlags loadWhat )
// note: load data and stores it internally (document or pages). observers
// are still uninitialized at this point so don't access them
{
@ -615,10 +615,10 @@ void DocumentPrivate::loadDocumentInfo()
return;
QFile infoFile( m_xmlFileName );
loadDocumentInfo( infoFile );
loadDocumentInfo( infoFile, loadWhat );
}
void DocumentPrivate::loadDocumentInfo( QFile &infoFile )
void DocumentPrivate::loadDocumentInfo( QFile &infoFile, LoadDocumentInfoFlags loadWhat )
{
if ( !infoFile.exists() || !infoFile.open( QIODevice::ReadOnly ) )
return;
@ -646,7 +646,7 @@ void DocumentPrivate::loadDocumentInfo( QFile &infoFile )
QString catName = topLevelNode.toElement().tagName();
// Restore page attributes (bookmark, annotations, ...) from the DOM
if ( catName == "pageList" )
if ( catName == "pageList" && ( loadWhat & LoadPageInfo ) )
{
QDomNode pageNode = topLevelNode.firstChild();
while ( pageNode.isElement() )
@ -667,7 +667,7 @@ void DocumentPrivate::loadDocumentInfo( QFile &infoFile )
}
// Restore 'general info' from the DOM
else if ( catName == "generalInfo" )
else if ( catName == "generalInfo" && ( loadWhat & LoadGeneralInfo ) )
{
QDomNode infoNode = topLevelNode.firstChild();
while ( infoNode.isElement() )
@ -1196,19 +1196,23 @@ void DocumentPrivate::saveDocumentInfo() const
doc.appendChild( root );
// 2.1. Save page attributes (bookmark state, annotations, ... ) to DOM
QDomElement pageList = doc.createElement( "pageList" );
root.appendChild( pageList );
// OriginalAnnotationPageItems and OriginalFormFieldPageItems tell to
// store the same unmodified annotation list and form contents that we
// read when we opened the file and ignore any change made by the user.
// Since we don't store annotations and forms docdata/ any more, this is
// necessary to preserve annotations/forms that previous Okular version
// had stored there.
const PageItems saveWhat = AllPageItems | OriginalAnnotationPageItems | OriginalFormFieldPageItems;
// <page list><page number='x'>.... </page> save pages that hold data
QVector< Page * >::const_iterator pIt = m_pagesVector.constBegin(), pEnd = m_pagesVector.constEnd();
for ( ; pIt != pEnd; ++pIt )
(*pIt)->d->saveLocalContents( pageList, doc, saveWhat );
// -> skipped for archives, because they store such info in their internal metadata.xml
if ( !m_archiveData )
{
QDomElement pageList = doc.createElement( "pageList" );
root.appendChild( pageList );
// OriginalAnnotationPageItems and OriginalFormFieldPageItems tell to
// store the same unmodified annotation list and form contents that we
// read when we opened the file and ignore any change made by the user.
// Since we don't store annotations and forms docdata/ any more, this is
// necessary to preserve annotations/forms that previous Okular version
// had stored there.
const PageItems saveWhat = AllPageItems | OriginalAnnotationPageItems | OriginalFormFieldPageItems;
// <page list><page number='x'>.... </page> save pages that hold data
QVector< Page * >::const_iterator pIt = m_pagesVector.constBegin(), pEnd = m_pagesVector.constEnd();
for ( ; pIt != pEnd; ++pIt )
(*pIt)->d->saveLocalContents( pageList, doc, saveWhat );
}
// 2.2. Save document info (current viewport, history, ... ) to DOM
QDomElement generalInfo = doc.createElement( "generalInfo" );
@ -2097,7 +2101,7 @@ Document::OpenResult Document::openDocument( const QString & docFile, const KUrl
// determine the related "xml document-info" filename
d->m_url = url;
d->m_docFileName = docFile;
if ( url.isLocalFile() && !d->m_archiveData )
if ( url.isLocalFile() )
{
QString fn = url.fileName();
document_size = fileReadTest.size();
@ -2223,11 +2227,12 @@ Document::OpenResult Document::openDocument( const QString & docFile, const KUrl
// 2. load Additional Data (bookmarks, local annotations and metadata) about the document
if ( d->m_archiveData )
{
d->loadDocumentInfo( d->m_archiveData->metadataFile );
d->loadDocumentInfo( d->m_archiveData->metadataFile, LoadPageInfo );
d->loadDocumentInfo( LoadGeneralInfo );
}
else
{
d->loadDocumentInfo();
d->loadDocumentInfo( LoadAllInfo );
}
d->m_metadataLoadingCompleted = true;

View file

@ -74,6 +74,15 @@ struct DoContinueDirectionMatchSearchStruct
int searchID;
};
enum LoadDocumentInfoFlag
{
LoadNone = 0,
LoadPageInfo = 1, // Load annotations and forms
LoadGeneralInfo = 2, // History, rotation, ...
LoadAllInfo = 0xff
};
Q_DECLARE_FLAGS(LoadDocumentInfoFlags, LoadDocumentInfoFlag)
class DocumentPrivate
{
public:
@ -114,8 +123,8 @@ class DocumentPrivate
void calculateMaxTextPages();
qulonglong getTotalMemory();
qulonglong getFreeMemory( qulonglong *freeSwap = 0 );
void loadDocumentInfo();
void loadDocumentInfo( QFile &infoFile );
void loadDocumentInfo( LoadDocumentInfoFlags loadWhat );
void loadDocumentInfo( QFile &infoFile, LoadDocumentInfoFlags loadWhat );
void loadViewsInfo( View *view, const QDomElement &e );
void saveViewsInfo( View *view, QDomElement &e ) const;
QString giveAbsolutePath( const QString & fileName ) const;