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
remotes/origin/dont-use-docdata-for-annots-and-forms
Fabio D'Urso 12 years ago
parent 48a23fc443
commit 31efd827f9
  1. 47
      core/document.cpp
  2. 13
      core/document_p.h

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

@ -74,6 +74,15 @@ struct DoContinueDirectionMatchSearchStruct
int searchID; 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 class DocumentPrivate
{ {
public: public:
@ -114,8 +123,8 @@ class DocumentPrivate
void calculateMaxTextPages(); void calculateMaxTextPages();
qulonglong getTotalMemory(); qulonglong getTotalMemory();
qulonglong getFreeMemory( qulonglong *freeSwap = 0 ); qulonglong getFreeMemory( qulonglong *freeSwap = 0 );
void loadDocumentInfo(); void loadDocumentInfo( LoadDocumentInfoFlags loadWhat );
void loadDocumentInfo( QFile &infoFile ); void loadDocumentInfo( QFile &infoFile, LoadDocumentInfoFlags loadWhat );
void loadViewsInfo( View *view, const QDomElement &e ); void loadViewsInfo( View *view, const QDomElement &e );
void saveViewsInfo( View *view, QDomElement &e ) const; void saveViewsInfo( View *view, QDomElement &e ) const;
QString giveAbsolutePath( const QString & fileName ) const; QString giveAbsolutePath( const QString & fileName ) const;

Loading…
Cancel
Save