From e9e3d4a4353a247290d790b2104740913e0f0f7f Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sun, 11 May 2014 11:17:49 +0200 Subject: [PATCH] Make documentInfo be Hash based instead of XML based --- core/document.cpp | 161 +++++++++++------- core/document.h | 186 +++++++++++++-------- core/document_p.h | 11 +- core/generator.cpp | 4 +- core/generator.h | 5 +- core/script/kjs_document.cpp | 42 ++--- core/textdocumentgenerator.cpp | 8 +- core/textdocumentgenerator.h | 2 +- generators/chm/generator_chm.cpp | 19 +-- generators/chm/generator_chm.h | 3 +- generators/djvu/generator_djvu.cpp | 58 +++---- generators/djvu/generator_djvu.h | 3 +- generators/dvi/generator_dvi.cpp | 25 ++- generators/dvi/generator_dvi.h | 3 +- generators/fax/generator_fax.cpp | 29 ++-- generators/fax/generator_fax.h | 6 +- generators/kimgio/generator_kimgio.cpp | 4 +- generators/kimgio/generator_kimgio.h | 2 +- generators/plucker/generator_plucker.cpp | 4 +- generators/plucker/generator_plucker.h | 2 +- generators/poppler/generator_pdf.cpp | 76 ++++----- generators/poppler/generator_pdf.h | 4 +- generators/spectre/generator_ghostview.cpp | 42 ++--- generators/spectre/generator_ghostview.h | 3 +- generators/tiff/generator_tiff.cpp | 71 ++++---- generators/tiff/generator_tiff.h | 3 +- generators/xps/generator_xps.cpp | 41 ++--- generators/xps/generator_xps.h | 5 +- part.cpp | 27 +-- ui/presentationwidget.cpp | 13 +- ui/propertiesdialog.cpp | 181 +++++++++----------- 31 files changed, 529 insertions(+), 514 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index 99e05630e..721d36a50 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -2473,8 +2473,8 @@ void Document::closeDocument() d->m_pageSize = PageSize(); d->m_pageSizes.clear(); - delete d->m_documentInfo; - d->m_documentInfo = 0; + d->m_documentInfo = DocumentInfo(); + d->m_documentInfoAskedKeys.clear(); AudioPlayer::instance()->d->m_currentDocument = KUrl(); @@ -2574,42 +2574,59 @@ bool Document::canConfigurePrinter( ) const return 0; } -const DocumentInfo * Document::documentInfo() const +DocumentInfo Document::documentInfo() const { - if ( d->m_documentInfo ) - return d->m_documentInfo; - - if ( d->m_generator ) + QSet keys; + for (Okular::DocumentInfo::Key ks = Okular::DocumentInfo::Title; + ks < Okular::DocumentInfo::Invalid; + ks = Okular::DocumentInfo::Key( ks+1 ) ) { - DocumentInfo *info = new DocumentInfo(); - const DocumentInfo *tmp = d->m_generator->generateDocumentInfo(); - if ( tmp ) - *info = *tmp; + keys << ks; + } - info->set( DocumentInfo::FilePath, currentDocument().prettyUrl() ); - const QString pagesSize = d->pagesSizeString(); - if ( d->m_docSize != -1 ) + return documentInfo( keys ); +} + +DocumentInfo Document::documentInfo( const QSet &keys ) const +{ + DocumentInfo result = d->m_documentInfo; + const QSet missingKeys = keys - d->m_documentInfoAskedKeys; + + if ( d->m_generator && !missingKeys.isEmpty() ) + { + DocumentInfo info = d->m_generator->generateDocumentInfo( missingKeys ); + + if ( missingKeys.contains( DocumentInfo::FilePath ) ) + { + info.set( DocumentInfo::FilePath, currentDocument().prettyUrl() ); + } + + if ( d->m_docSize != -1 && missingKeys.contains( DocumentInfo::DocumentSize ) ) { const QString sizeString = KGlobal::locale()->formatByteSize( d->m_docSize ); - info->set( DocumentInfo::DocumentSize, sizeString ); + info.set( DocumentInfo::DocumentSize, sizeString ); } - if (!pagesSize.isEmpty()) + if ( missingKeys.contains( DocumentInfo::PagesSize ) ) { - info->set( DocumentInfo::PagesSize, pagesSize ); + const QString pagesSize = d->pagesSizeString(); + if ( !pagesSize.isEmpty() ) + { + info.set( DocumentInfo::PagesSize, pagesSize ); + } } - const DocumentInfo::Key keyPages = DocumentInfo::Pages; - const QString keyString = DocumentInfo::getKeyString( keyPages ); - - if ( info->get( keyString ).isEmpty() ) { - info->set( keyString, QString::number( this->pages() ), - DocumentInfo::getKeyTitle( keyPages ) ); + if ( missingKeys.contains( DocumentInfo::Pages ) && info.get( DocumentInfo::Pages ).isEmpty() ) { + info.set( DocumentInfo::Pages, QString::number( this->pages() ) ); } - d->m_documentInfo = info; - return info; + d->m_documentInfo.d->values.unite(info.d->values); + d->m_documentInfo.d->titles.unite(info.d->titles); + result.d->values.unite(info.d->values); + result.d->titles.unite(info.d->titles); } - else return NULL; + d->m_documentInfoAskedKeys += keys; + + return result; } const DocumentSynopsis * Document::documentSynopsis() const @@ -4641,52 +4658,51 @@ bool DocumentViewport::operator<( const DocumentViewport & vp ) const /** DocumentInfo **/ -DocumentInfo::DocumentInfo() - : QDomDocument( "DocumentInformation" ) +DocumentInfo::DocumentInfo() : d(new DocumentInfoPrivate()) { - QDomElement docElement = createElement( "DocumentInfo" ); - appendChild( docElement ); } -void DocumentInfo::set( const QString &key, const QString &value, - const QString &title ) +DocumentInfo::DocumentInfo(const DocumentInfo &info) : d(new DocumentInfoPrivate()) { - QDomElement docElement = documentElement(); - QDomElement element; + *this = info; +} - // check whether key already exists - QDomNodeList list = docElement.elementsByTagName( key ); - if ( list.count() > 0 ) - element = list.item( 0 ).toElement(); - else - element = createElement( key ); +DocumentInfo& DocumentInfo::operator=(const DocumentInfo &info) +{ + d->values = info.d->values; + d->titles = info.d->titles; + return *this; +} - element.setAttribute( "value", value ); - element.setAttribute( "title", title ); +DocumentInfo::~DocumentInfo() +{ + delete d; +} - if ( list.count() == 0 ) - docElement.appendChild( element ); +void DocumentInfo::set( const QString &key, const QString &value, const QString &title ) +{ + d->values[ key ] = value; + d->titles[ key ] = title; } void DocumentInfo::set( Key key, const QString &value ) { - const QString keyString = getKeyString( key ); - if ( !keyString.isEmpty() ) - set( keyString, value, getKeyTitle( key ) ); - else - kWarning(OkularDebug) << "Invalid key passed"; + d->values[ getKeyString( key ) ] = value; +} + +QStringList DocumentInfo::keys() const +{ + return d->values.keys(); +} + +QString DocumentInfo::get( Key key ) const +{ + return get( getKeyString( key ) ); } QString DocumentInfo::get( const QString &key ) const { - const QDomElement docElement = documentElement(); - - // check whether key already exists - const QDomNodeList list = docElement.elementsByTagName( key ); - if ( list.count() > 0 ) - return list.item( 0 ).toElement().attribute( "value" ); - else - return QString(); + return d->values[ key ]; } QString DocumentInfo::getKeyString( Key key ) //const @@ -4741,11 +4757,33 @@ QString DocumentInfo::getKeyString( Key key ) //const return "pageSize"; break; default: + kWarning() << "Unknown" << key; return QString(); break; } } +DocumentInfo::Key DocumentInfo::getKeyFromString( const QString &key ) //const +{ + if (key == "title") return Title; + else if (key == "subject") return Subject; + else if (key == "description") return Description; + else if (key == "author") return Author; + else if (key == "creator") return Creator; + else if (key == "producer") return Producer; + else if (key == "copyright") return Copyright; + else if (key == "pages") return Pages; + else if (key == "creationDate") return CreationDate; + else if (key == "modificationDate") return ModificationDate; + else if (key == "mimeType") return MimeType; + else if (key == "category") return Category; + else if (key == "keywords") return Keywords; + else if (key == "filePath") return FilePath; + else if (key == "documentSize") return DocumentSize; + else if (key == "pageSize") return PagesSize; + else return Invalid; +} + QString DocumentInfo::getKeyTitle( Key key ) //const { switch ( key ) { @@ -4803,6 +4841,15 @@ QString DocumentInfo::getKeyTitle( Key key ) //const } } +QString DocumentInfo::getKeyTitle( const QString &key ) const +{ + QString title = getKeyTitle ( getKeyFromString( key ) ); + if ( title.isEmpty() ) + title = d->titles[ key ]; + return title; +} + + /** DocumentSynopsis **/ diff --git a/core/document.h b/core/document.h index 06bac8a0f..21a49046a 100644 --- a/core/document.h +++ b/core/document.h @@ -36,7 +36,7 @@ namespace Okular { class Annotation; class BookmarkManager; -class DocumentInfo; +class DocumentInfoPrivate; class DocumentObserver; class DocumentPrivate; class DocumentSynopsis; @@ -63,6 +63,110 @@ class VisiblePageRect; #define SW_SEARCH_ID 3 #define PRESENTATION_SEARCH_ID 4 +/** + * The DocumentInfo structure can be filled in by generators to display + * metadata about the currently opened file. + */ +class OKULAR_EXPORT DocumentInfo +{ + friend class Document; + + public: + /** + * The list of predefined keys. + */ + enum Key { + Title, ///< The title of the document + Subject, ///< The subject of the document + Description, ///< The description of the document + Author, ///< The author of the document + Creator, ///< The creator of the document (this can be different from the author) + Producer, ///< The producer of the document (e.g. some software) + Copyright, ///< The copyright of the document + Pages, ///< The number of pages of the document + CreationDate, ///< The date of creation of the document + ModificationDate, ///< The date of last modification of the document + MimeType, ///< The mime type of the document + Category, ///< The category of the document + Keywords, ///< The keywords which describe the content of the document + FilePath, ///< The path of the file @since 0.10 (KDE 4.4) + DocumentSize, ///< The size of the document @since 0.10 (KDE 4.4) + PagesSize, ///< The size of the pages (if all pages have the same size) @since 0.10 (KDE 4.4) + CustomKeys, ///< All the custom keys the generator supports @since 0.21 + Invalid ///< An invalid key @since 0.21. It will always be the last element in the enum + }; + + /** + * Creates a new document info. + */ + DocumentInfo(); + DocumentInfo(const DocumentInfo &info); + DocumentInfo& operator=( const DocumentInfo& ); + + ~DocumentInfo(); + + /** + * Returns all the keys present in this DocumentInfo + * + * @since 0.21 + */ + QStringList keys() const; + + /** + * Returns the value for a given key or an null string when the + * key doesn't exist. + */ + QString get( Key key ) const; + + /** + * Returns the value for a given key or an null string when the + * key doesn't exist. + */ + QString get( const QString &key ) const; + + /** + * Sets a value for a custom key. The title should be an i18n'ed + * string, since it's used in the document information dialog. + */ + void set( const QString &key, const QString &value, + const QString &title = QString() ); + + /** + * Sets a value for a special key. The title should be an i18n'ed + * string, since it's used in the document information dialog. + */ + void set( Key key, const QString &value ); + + /** + * Returns the user visible string for the given key + * Takes into account keys added by the set() that takes a QString + * + * @since 0.21 + */ + QString getKeyTitle( const QString &key ) const; + + /** + * Returns the internal string for the given key + * @since 0.10 (KDE 4.4) + */ + static QString getKeyString( Key key ); + + /** + * Returns the user visible string for the given key + * @since 0.10 (KDE 4.4) + */ + static QString getKeyTitle( Key key ); + + /** + * Returns the Key from a string key + * @since 0.21 + */ + static Key getKeyFromString( const QString &key ); + + private: + DocumentInfoPrivate *d; +}; + /** * @short The Document. Heart of everything. Actions take place here. @@ -139,10 +243,15 @@ class OKULAR_EXPORT Document : public QObject bool isOpened() const; /** - * Returns the meta data of the document or 0 if no meta data - * are available. + * Returns the meta data of the document. */ - const DocumentInfo * documentInfo() const; + DocumentInfo documentInfo() const; + + /** + * Returns the asked set of meta data of the document. The result may contain more + * metadata than the one asked for. + */ + DocumentInfo documentInfo( const QSet &keys ) const; /** * Returns the table of content of the document or 0 if no @@ -1077,75 +1186,6 @@ class OKULAR_EXPORT DocumentViewport } autoFit; }; -/** - * @short A DOM tree containing information about the document. - * - * The DocumentInfo structure can be filled in by generators to display - * metadata about the currently opened file. - */ -class OKULAR_EXPORT DocumentInfo : public QDomDocument -{ - public: - /** - * The list of predefined keys. - */ - enum Key { - Title, ///< The title of the document - Subject, ///< The subject of the document - Description, ///< The description of the document - Author, ///< The author of the document - Creator, ///< The creator of the document (this can be different from the author) - Producer, ///< The producer of the document (e.g. some software) - Copyright, ///< The copyright of the document - Pages, ///< The number of pages of the document - CreationDate, ///< The date of creation of the document - ModificationDate, ///< The date of last modification of the document - MimeType, ///< The mime type of the document - Category, ///< The category of the document - Keywords, ///< The keywords which describe the content of the document - FilePath, ///< The path of the file @since 0.10 (KDE 4.4) - DocumentSize, ///< The size of the document @since 0.10 (KDE 4.4) - PagesSize ///< The size of the pages (if all pages have the same size) @since 0.10 (KDE 4.4) - }; - - /** - * Creates a new document info. - */ - DocumentInfo(); - - /** - * Sets a value for a special key. The title should be an i18n'ed - * string, since it's used in the document information dialog. - */ - void set( const QString &key, const QString &value, - const QString &title = QString() ); - - /** - * Sets the value for a predefined key. You should use this method - * whenever a predefined key exists for your value. - */ - void set( Key key, const QString &value ); - - /** - * Returns the value for a given key or an empty string when the - * key doesn't exist. - */ - QString get( const QString &key ) const; - - /** - * Returns the internal string for the given key - * @since 0.10 (KDE 4.4) - */ - static QString getKeyString( Key key ); - - /** - * Returns the user visible string for the given key - * @since 0.10 (KDE 4.4) - */ - static QString getKeyTitle( Key key ); - -}; - /** * @short A DOM tree that describes the Table of Contents. * diff --git a/core/document_p.h b/core/document_p.h index 08775da4c..a71912b2a 100644 --- a/core/document_p.h +++ b/core/document_p.h @@ -96,7 +96,6 @@ class DocumentPrivate m_scripter( 0 ), m_archiveData( 0 ), m_fontsCached( false ), - m_documentInfo( 0 ), m_annotationEditingEnabled ( true ), m_annotationBeingMoved( false ) { @@ -258,7 +257,8 @@ class DocumentPrivate QPointer< FontExtractionThread > m_fontThread; bool m_fontsCached; - DocumentInfo *m_documentInfo; + QSet m_documentInfoAskedKeys; + DocumentInfo m_documentInfo; FontInfo::List m_fontsCache; QSet< View * > m_views; @@ -272,6 +272,13 @@ class DocumentPrivate QDomNode m_prevPropsOfAnnotBeingModified; }; +class DocumentInfoPrivate +{ + public: + QMap values; // key -> value + QMap titles; // key -> title For the custom keys +}; + } #endif diff --git a/core/generator.cpp b/core/generator.cpp index ec1d1f76d..e74064e4d 100644 --- a/core/generator.cpp +++ b/core/generator.cpp @@ -290,9 +290,9 @@ TextPage* Generator::textPage( Page* ) return 0; } -const DocumentInfo * Generator::generateDocumentInfo() +DocumentInfo Generator::generateDocumentInfo(const QSet &keys) const { - return 0; + return DocumentInfo(); } const DocumentSynopsis * Generator::generateDocumentSynopsis() diff --git a/core/generator.h b/core/generator.h index 506f8a826..9a1d7b26f 100644 --- a/core/generator.h +++ b/core/generator.h @@ -308,10 +308,9 @@ class OKULAR_EXPORT Generator : public QObject virtual void generateTextPage( Page * page ); /** - * Returns the general information object of the document or 0 if - * no information are available. + * Returns the general information object of the document. */ - virtual const DocumentInfo * generateDocumentInfo(); + virtual DocumentInfo generateDocumentInfo( const QSet &keys ) const; /** * Returns the 'table of content' object of the document or 0 if diff --git a/core/script/kjs_document.cpp b/core/script/kjs_document.cpp index c3280cddb..4422953b0 100644 --- a/core/script/kjs_document.cpp +++ b/core/script/kjs_document.cpp @@ -135,12 +135,17 @@ static KJSObject docGetInfo( KJSContext *ctx, void *object ) DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); KJSObject obj; - const DocumentInfo *docinfo = doc->m_generator->generateDocumentInfo(); - if ( docinfo ) - { + QSet keys; + keys << DocumentInfo::Title + << DocumentInfo::Author + << DocumentInfo::Subject + << DocumentInfo::Keywords + << DocumentInfo::Creator + << DocumentInfo::Producer; + const DocumentInfo docinfo = doc->m_parent->documentInfo( keys ); #define KEY_GET( key, property ) \ do { \ - const QString data = docinfo->get( key ); \ + const QString data = docinfo.get( key ); \ if ( !data.isEmpty() ) \ { \ const KJSString newval( data ); \ @@ -148,14 +153,13 @@ do { \ obj.setProperty( ctx, QString( property ).toLower(), newval ); \ } \ } while ( 0 ); - KEY_GET( "title", "Title" ); - KEY_GET( "author", "Author" ); - KEY_GET( "subject", "Subject" ); - KEY_GET( "keywords", "Keywords" ); - KEY_GET( "creator", "Creator" ); - KEY_GET( "producer", "Producer" ); + KEY_GET( DocumentInfo::Title, "Title" ); + KEY_GET( DocumentInfo::Author, "Author" ); + KEY_GET( DocumentInfo::Subject, "Subject" ); + KEY_GET( DocumentInfo::Keywords, "Keywords" ); + KEY_GET( DocumentInfo::Creator, "Creator" ); + KEY_GET( DocumentInfo::Producer, "Producer" ); #undef KEY_GET - } return obj; } @@ -163,16 +167,16 @@ do { \ static KJSObject docGet ## name( KJSContext *, void *object ) \ { \ DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); \ - const DocumentInfo *docinfo = doc->m_generator->generateDocumentInfo(); \ - return KJSString( docinfo->get( key ) ); \ + const DocumentInfo docinfo = doc->m_parent->documentInfo(QSet() << key ); \ + return KJSString( docinfo.get( key ) ); \ } -DOCINFO_GET_METHOD( "author", Author ) -DOCINFO_GET_METHOD( "creator", Creator ) -DOCINFO_GET_METHOD( "keywords", Keywords ) -DOCINFO_GET_METHOD( "producer", Producer ) -DOCINFO_GET_METHOD( "title", Title ) -DOCINFO_GET_METHOD( "subject", Subject ) +DOCINFO_GET_METHOD( DocumentInfo::Author, Author ) +DOCINFO_GET_METHOD( DocumentInfo::Creator, Creator ) +DOCINFO_GET_METHOD( DocumentInfo::Keywords, Keywords ) +DOCINFO_GET_METHOD( DocumentInfo::Producer, Producer ) +DOCINFO_GET_METHOD( DocumentInfo::Title, Title ) +DOCINFO_GET_METHOD( DocumentInfo::Subject, Subject ) #undef DOCINFO_GET_METHOD diff --git a/core/textdocumentgenerator.cpp b/core/textdocumentgenerator.cpp index d598ccc8d..f018329a6 100644 --- a/core/textdocumentgenerator.cpp +++ b/core/textdocumentgenerator.cpp @@ -453,10 +453,10 @@ bool TextDocumentGenerator::print( QPrinter& printer ) return true; } -const Okular::DocumentInfo* TextDocumentGenerator::generateDocumentInfo() +Okular::DocumentInfo TextDocumentGenerator::generateDocumentInfo( const QSet & /*keys*/ ) const { - Q_D( TextDocumentGenerator ); - return &d->mDocumentInfo; + Q_D( const TextDocumentGenerator ); + return d->mDocumentInfo; } const Okular::DocumentSynopsis* TextDocumentGenerator::generateDocumentSynopsis() @@ -473,7 +473,7 @@ QVariant TextDocumentGeneratorPrivate::metaData( const QString &key, const QVari Q_UNUSED( option ) if ( key == "DocumentTitle" ) { - return mDocumentInfo.get( "title" ); + return mDocumentInfo.get( DocumentInfo::Title ); } return QVariant(); } diff --git a/core/textdocumentgenerator.h b/core/textdocumentgenerator.h index ec331d6d1..b03121b70 100644 --- a/core/textdocumentgenerator.h +++ b/core/textdocumentgenerator.h @@ -211,7 +211,7 @@ class OKULAR_EXPORT TextDocumentGenerator : public Generator, public Okular::Con */ TextDocumentSettings* generalSettings(); - const Okular::DocumentInfo* generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo( const QSet &keys ) const; const Okular::DocumentSynopsis* generateDocumentSynopsis(); protected: diff --git a/generators/chm/generator_chm.cpp b/generators/chm/generator_chm.cpp index 84b9dde76..fbdcea8e9 100644 --- a/generators/chm/generator_chm.cpp +++ b/generators/chm/generator_chm.cpp @@ -71,7 +71,6 @@ CHMGenerator::CHMGenerator( QObject *parent, const QVariantList &args ) m_syncGen=0; m_file=0; - m_docInfo=0; m_pixmapRequestZoom=1; m_request = 0; } @@ -163,8 +162,6 @@ bool CHMGenerator::loadDocument( const QString & fileName, QVector< Okular::Page bool CHMGenerator::doCloseDocument() { // delete the document information of the old document - delete m_docInfo; - m_docInfo=0; delete m_file; m_file=0; m_textpageAddedList.clear(); @@ -234,16 +231,14 @@ void CHMGenerator::slotCompleted() signalPixmapRequestDone( req ); } -const Okular::DocumentInfo * CHMGenerator::generateDocumentInfo() +Okular::DocumentInfo CHMGenerator::generateDocumentInfo( const QSet &keys ) const { - if (!m_docInfo) - { - m_docInfo=new Okular::DocumentInfo(); - - m_docInfo->set( Okular::DocumentInfo::MimeType, "application/x-chm" ); - m_docInfo->set( Okular::DocumentInfo::Title, m_file->title() ); - } - return m_docInfo; + Okular::DocumentInfo docInfo; + if ( keys.contains( Okular::DocumentInfo::MimeType ) ) + docInfo.set( Okular::DocumentInfo::MimeType, "application/x-chm" ); + if ( keys.contains( Okular::DocumentInfo::Title ) ) + docInfo.set( Okular::DocumentInfo::Title, m_file->title() ); + return docInfo; } const Okular::DocumentSynopsis * CHMGenerator::generateDocumentSynopsis() diff --git a/generators/chm/generator_chm.h b/generators/chm/generator_chm.h index 5d970097e..e9f2a8e8f 100644 --- a/generators/chm/generator_chm.h +++ b/generators/chm/generator_chm.h @@ -36,7 +36,7 @@ class CHMGenerator : public Okular::Generator ~CHMGenerator(); bool loadDocument( const QString & fileName, QVector< Okular::Page * > & pagesVector ); - const Okular::DocumentInfo * generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo( const QSet &keys ) const; const Okular::DocumentSynopsis * generateDocumentSynopsis(); bool canGeneratePixmap() const; @@ -64,7 +64,6 @@ class CHMGenerator : public Okular::Generator QString m_chmUrl; Okular::PixmapRequest* m_request; int m_pixmapRequestZoom; - Okular::DocumentInfo* m_docInfo; QBitArray m_textpageAddedList; QBitArray m_rectsGenerated; }; diff --git a/generators/djvu/generator_djvu.cpp b/generators/djvu/generator_djvu.cpp index c506ce3f0..b01175983 100644 --- a/generators/djvu/generator_djvu.cpp +++ b/generators/djvu/generator_djvu.cpp @@ -84,7 +84,7 @@ static KAboutData createAboutData() OKULAR_EXPORT_PLUGIN( DjVuGenerator, createAboutData() ) DjVuGenerator::DjVuGenerator( QObject *parent, const QVariantList &args ) - : Okular::Generator( parent, args ), m_docInfo( 0 ), m_docSyn( 0 ) + : Okular::Generator( parent, args ), m_docSyn( 0 ) { setFeature( TextExtraction ); setFeature( Threaded ); @@ -120,8 +120,6 @@ bool DjVuGenerator::doCloseDocument() m_djvu->closeFile(); userMutex()->unlock(); - delete m_docInfo; - m_docInfo = 0; delete m_docSyn; m_docSyn = 0; @@ -136,48 +134,34 @@ QImage DjVuGenerator::image( Okular::PixmapRequest *request ) return img; } -const Okular::DocumentInfo * DjVuGenerator::generateDocumentInfo() +Okular::DocumentInfo DjVuGenerator::generateDocumentInfo( const QSet &keys ) const { - if ( m_docInfo ) - return m_docInfo; + Okular::DocumentInfo docInfo; - m_docInfo = new Okular::DocumentInfo(); - - m_docInfo->set( Okular::DocumentInfo::MimeType, "image/vnd.djvu" ); + if ( keys.contains( Okular::DocumentInfo::MimeType ) ) + docInfo.set( Okular::DocumentInfo::MimeType, "image/vnd.djvu" ); if ( m_djvu ) { // compile internal structure reading properties from KDjVu - QString title = m_djvu->metaData( "title" ).toString(); - m_docInfo->set( Okular::DocumentInfo::Title, title.isEmpty() ? i18nc( "Unknown title", "Unknown" ) : title ); - QString author = m_djvu->metaData( "author" ).toString(); - m_docInfo->set( Okular::DocumentInfo::Author, author.isEmpty() ? i18nc( "Unknown author", "Unknown" ) : author ); - QString editor = m_djvu->metaData( "editor" ).toString(); - m_docInfo->set( "editor", editor.isEmpty() ? i18nc( "Unknown editor", "Unknown" ) : editor, i18n( "Editor" ) ); - QString publisher = m_djvu->metaData( "publisher" ).toString(); - m_docInfo->set( "publisher", publisher.isEmpty() ? i18nc( "Unknown publisher", "Unknown" ) : publisher, i18n( "Publisher" ) ); - QString year = m_djvu->metaData( "year" ).toString(); - m_docInfo->set( Okular::DocumentInfo::CreationDate, year.isEmpty() ? i18nc( "Unknown creation date", "Unknown" ) : year ); - QString volume = m_djvu->metaData( "volume" ).toString(); - m_docInfo->set( "volume", volume.isEmpty() ? i18nc( "Unknown volume information", "Unknown" ) : volume, i18n( "Volume" ) ); - QString doctype = m_djvu->metaData( "documentType" ).toString(); - m_docInfo->set( "documentType", doctype.isEmpty() ? i18nc( "Unknown type of document", "Unknown" ) : doctype, i18n( "Type of document" ) ); - QVariant numcomponents = m_djvu->metaData( "componentFile" ); - m_docInfo->set( "componentFile", numcomponents.type() != QVariant::Int ? i18nc( "Unknown number of component files", "Unknown" ) : numcomponents.toString(), i18n( "Component Files" ) ); - } - else - { - m_docInfo->set( Okular::DocumentInfo::Title, i18nc( "Unknown title", "Unknown" ) ); - m_docInfo->set( Okular::DocumentInfo::Author, i18nc( "Unknown author", "Unknown" ) ); - m_docInfo->set( "editor", i18nc( "Unknown editor", "Unknown" ), i18n( "Editor" ) ); - m_docInfo->set( "publisher", i18nc( "Unknown publisher", "Unknown" ), i18n( "Publisher" ) ); - m_docInfo->set( Okular::DocumentInfo::CreationDate, i18nc( "Unknown creation date", "Unknown" ) ); - m_docInfo->set( "volume", i18nc( "Unknown volume information", "Unknown" ), i18n( "Volume" ) ); - m_docInfo->set( "documentType", i18nc( "Unknown type of document", "Unknown" ), i18n( "Type of document" ) ); - m_docInfo->set( "componentFile", i18nc( "Unknown number of component files", "Unknown" ), i18n( "Component Files" ) ); + if ( keys.contains( Okular::DocumentInfo::Author ) ) + docInfo.set( Okular::DocumentInfo::Title, m_djvu->metaData( "title" ).toString() ); + if ( keys.contains( Okular::DocumentInfo::Author ) ) + docInfo.set( Okular::DocumentInfo::Author, m_djvu->metaData( "author" ).toString() ); + if ( keys.contains( Okular::DocumentInfo::CreationDate ) ) + docInfo.set( Okular::DocumentInfo::CreationDate, m_djvu->metaData( "year" ).toString() ); + if ( keys.contains( Okular::DocumentInfo::CustomKeys ) ) + { + docInfo.set( "editor", m_djvu->metaData( "editor" ).toString(), i18n( "Editor" ) ); + docInfo.set( "publisher", m_djvu->metaData( "publisher" ).toString(), i18n( "Publisher" ) ); + docInfo.set( "volume", m_djvu->metaData( "volume" ).toString(), i18n( "Volume" ) ); + docInfo.set( "documentType", m_djvu->metaData( "documentType" ).toString(), i18n( "Type of document" ) ); + QVariant numcomponents = m_djvu->metaData( "componentFile" ); + docInfo.set( "componentFile", numcomponents.type() != QVariant::Int ? i18nc( "Unknown number of component files", "Unknown" ) : numcomponents.toString(), i18n( "Component Files" ) ); + } } - return m_docInfo; + return docInfo; } const Okular::DocumentSynopsis * DjVuGenerator::generateDocumentSynopsis() diff --git a/generators/djvu/generator_djvu.h b/generators/djvu/generator_djvu.h index 93ee4dea8..f056fecf3 100644 --- a/generators/djvu/generator_djvu.h +++ b/generators/djvu/generator_djvu.h @@ -30,7 +30,7 @@ class DjVuGenerator : public Okular::Generator bool loadDocument( const QString & fileName, QVector & pagesVector ); // document information - const Okular::DocumentInfo * generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo( const QSet &keys ) const; const Okular::DocumentSynopsis * generateDocumentSynopsis(); // printing @@ -51,7 +51,6 @@ class DjVuGenerator : public Okular::Generator KDjVu *m_djvu; - Okular::DocumentInfo *m_docInfo; Okular::DocumentSynopsis *m_docSyn; }; diff --git a/generators/dvi/generator_dvi.cpp b/generators/dvi/generator_dvi.cpp index 166a9054a..a26c6ebef 100644 --- a/generators/dvi/generator_dvi.cpp +++ b/generators/dvi/generator_dvi.cpp @@ -63,7 +63,7 @@ static KAboutData createAboutData() OKULAR_EXPORT_PLUGIN( DviGenerator, createAboutData() ) DviGenerator::DviGenerator( QObject *parent, const QVariantList &args ) : Okular::Generator( parent, args ), - m_fontExtracted( false ), m_docInfo( 0 ), m_docSynopsis( 0 ), m_dviRenderer( 0 ) + m_fontExtracted( false ), m_docSynopsis( 0 ), m_dviRenderer( 0 ) { setFeature( Threaded ); setFeature( TextExtraction ); @@ -130,8 +130,6 @@ bool DviGenerator::loadDocument( const QString & fileName, QVector< Okular::Page bool DviGenerator::doCloseDocument() { - delete m_docInfo; - m_docInfo = 0; delete m_docSynopsis; m_docSynopsis = 0; delete m_dviRenderer; @@ -335,14 +333,12 @@ Okular::TextPage *DviGenerator::extractTextFromPage( dviPageInfo *pageInfo ) return ktp; } -const Okular::DocumentInfo *DviGenerator::generateDocumentInfo() +Okular::DocumentInfo DviGenerator::generateDocumentInfo( const QSet &keys ) const { - if ( m_docInfo ) - return m_docInfo; + Okular::DocumentInfo docInfo; - m_docInfo = new Okular::DocumentInfo(); - - m_docInfo->set( Okular::DocumentInfo::MimeType, "application/x-dvi" ); + if ( keys.contains( Okular::DocumentInfo::MimeType ) ) + docInfo.set( Okular::DocumentInfo::MimeType, "application/x-dvi" ); QMutexLocker lock( userMutex() ); @@ -351,12 +347,13 @@ const Okular::DocumentInfo *DviGenerator::generateDocumentInfo() dvifile *dvif = m_dviRenderer->dviFile; // read properties from dvif - //m_docInfo->set( "filename", dvif->filename, i18n("Filename") ); - m_docInfo->set( "generatorDate", dvif->generatorString, - i18n("Generator/Date") ); - m_docInfo->set( Okular::DocumentInfo::Pages, QString::number( dvif->total_pages ) ); + //docInfo.set( "filename", dvif->filename, i18n("Filename") ); + if ( keys.contains( Okular::DocumentInfo::CustomKeys ) ) + docInfo.set( "generatorDate", dvif->generatorString, i18n("Generator/Date") ); + if ( keys.contains( Okular::DocumentInfo::Pages ) ) + docInfo.set( Okular::DocumentInfo::Pages, QString::number( dvif->total_pages ) ); } - return m_docInfo; + return docInfo; } const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis() diff --git a/generators/dvi/generator_dvi.h b/generators/dvi/generator_dvi.h index d7bf8fd48..1fac6b365 100644 --- a/generators/dvi/generator_dvi.h +++ b/generators/dvi/generator_dvi.h @@ -31,7 +31,7 @@ class DviGenerator : public Okular::Generator bool loadDocument( const QString & fileName, QVector< Okular::Page * > & pagesVector ); // document information - const Okular::DocumentInfo *generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo( const QSet &keys ) const; // table of contents const Okular::DocumentSynopsis *generateDocumentSynopsis(); @@ -52,7 +52,6 @@ class DviGenerator : public Okular::Generator double m_resolution; bool m_fontExtracted; - Okular::DocumentInfo *m_docInfo; Okular::DocumentSynopsis *m_docSynopsis; dviRenderer *m_dviRenderer; diff --git a/generators/fax/generator_fax.cpp b/generators/fax/generator_fax.cpp index 38873ef67..078f18cb1 100644 --- a/generators/fax/generator_fax.cpp +++ b/generators/fax/generator_fax.cpp @@ -9,8 +9,6 @@ #include "generator_fax.h" -#include "faxdocument.h" - #include #include @@ -52,13 +50,12 @@ FaxGenerator::~FaxGenerator() bool FaxGenerator::loadDocument( const QString & fileName, QVector & pagesVector ) { - FaxDocument::DocumentType type; if ( fileName.toLower().endsWith( ".g3" ) ) - type = FaxDocument::G3; + m_type = FaxDocument::G3; else - type = FaxDocument::G4; + m_type = FaxDocument::G4; - FaxDocument faxDocument( fileName, type ); + FaxDocument faxDocument( fileName, m_type ); if ( !faxDocument.load() ) { @@ -73,20 +70,12 @@ bool FaxGenerator::loadDocument( const QString & fileName, QVectorset( Okular::DocumentInfo::MimeType, "image/fax-g3" ); - else - m_docInfo->set( Okular::DocumentInfo::MimeType, "image/fax-g4" ); - return true; } bool FaxGenerator::doCloseDocument() { m_img = QImage(); - delete m_docInfo; - m_docInfo = 0; return true; } @@ -102,9 +91,17 @@ QImage FaxGenerator::image( Okular::PixmapRequest * request ) return m_img.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); } -const Okular::DocumentInfo * FaxGenerator::generateDocumentInfo() +Okular::DocumentInfo FaxGenerator::generateDocumentInfo( const QSet &keys ) const { - return m_docInfo; + Okular::DocumentInfo docInfo; + if ( keys.contains( Okular::DocumentInfo::MimeType ) ) + { + if ( m_type == FaxDocument::G3 ) + docInfo.set( Okular::DocumentInfo::MimeType, "image/fax-g3" ); + else + docInfo.set( Okular::DocumentInfo::MimeType, "image/fax-g4" ); + } + return docInfo; } bool FaxGenerator::print( QPrinter& printer ) diff --git a/generators/fax/generator_fax.h b/generators/fax/generator_fax.h index 1cb7d223f..66d83c817 100644 --- a/generators/fax/generator_fax.h +++ b/generators/fax/generator_fax.h @@ -14,6 +14,8 @@ #include +#include "faxdocument.h" + class FaxGenerator : public Okular::Generator { Q_OBJECT @@ -24,7 +26,7 @@ class FaxGenerator : public Okular::Generator bool loadDocument( const QString & fileName, QVector & pagesVector ); - const Okular::DocumentInfo * generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo( const QSet &keys ) const; bool print( QPrinter& printer ); @@ -34,7 +36,7 @@ class FaxGenerator : public Okular::Generator private: QImage m_img; - Okular::DocumentInfo *m_docInfo; + FaxDocument::DocumentType m_type; }; #endif diff --git a/generators/kimgio/generator_kimgio.cpp b/generators/kimgio/generator_kimgio.cpp index f856434fe..5dc9011e4 100644 --- a/generators/kimgio/generator_kimgio.cpp +++ b/generators/kimgio/generator_kimgio.cpp @@ -186,9 +186,9 @@ void KIMGIOGenerator::slotTest() kDebug() << "Test"; } -const Okular::DocumentInfo * KIMGIOGenerator::generateDocumentInfo() +Okular::DocumentInfo KIMGIOGenerator::generateDocumentInfo( const QSet &keys ) const { - return &docInfo; + return docInfo; } #include "generator_kimgio.moc" diff --git a/generators/kimgio/generator_kimgio.h b/generators/kimgio/generator_kimgio.h index faebd8572..a33bf0b18 100644 --- a/generators/kimgio/generator_kimgio.h +++ b/generators/kimgio/generator_kimgio.h @@ -30,7 +30,7 @@ class KIMGIOGenerator : public Okular::Generator bool print( QPrinter& printer ); // [INHERITED] document information - const Okular::DocumentInfo * generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo( const QSet &keys ) const; protected: bool doCloseDocument(); diff --git a/generators/plucker/generator_plucker.cpp b/generators/plucker/generator_plucker.cpp index 4ffdead26..3a91ae7c2 100644 --- a/generators/plucker/generator_plucker.cpp +++ b/generators/plucker/generator_plucker.cpp @@ -126,9 +126,9 @@ bool PluckerGenerator::doCloseDocument() return true; } -const Okular::DocumentInfo* PluckerGenerator::generateDocumentInfo() +Okular::DocumentInfo PluckerGenerator::generateDocumentInfo( const QSet & /*keys*/ ) const { - return &mDocumentInfo; + return mDocumentInfo; } QImage PluckerGenerator::image( Okular::PixmapRequest *request ) diff --git a/generators/plucker/generator_plucker.h b/generators/plucker/generator_plucker.h index 8dac4b830..ff96fbbfc 100644 --- a/generators/plucker/generator_plucker.h +++ b/generators/plucker/generator_plucker.h @@ -31,7 +31,7 @@ class PluckerGenerator : public Okular::Generator bool loadDocument( const QString & fileName, QVector & pagesVector ); // [INHERITED] document information - const Okular::DocumentInfo * generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo( const QSet &keys ) const; // [INHERITED] perform actions on document / pages QImage image( Okular::PixmapRequest *request ); diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index c978b09f8..d61b996ac 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -421,7 +421,7 @@ static void PDFGeneratorPopplerDebugFunction(const QString &message, const QVari PDFGenerator::PDFGenerator( QObject *parent, const QVariantList &args ) : Generator( parent, args ), pdfdoc( 0 ), - docInfoDirty( true ), docSynopsisDirty( true ), + docSynopsisDirty( true ), docEmbeddedFilesDirty( true ), nextFontPage( 0 ), annotProxy( 0 ), synctex_scanner( 0 ) { @@ -539,7 +539,6 @@ bool PDFGenerator::doCloseDocument() delete pdfdoc; pdfdoc = 0; userMutex()->unlock(); - docInfoDirty = true; docSynopsisDirty = true; docSyn.clear(); docEmbeddedFilesDirty = true; @@ -619,64 +618,47 @@ void PDFGenerator::loadPages(QVector &pagesVector, int rotation, } } -const Okular::DocumentInfo * PDFGenerator::generateDocumentInfo() +Okular::DocumentInfo PDFGenerator::generateDocumentInfo( const QSet &keys ) const { - if ( docInfoDirty ) + Okular::DocumentInfo docInfo; + docInfo.set( Okular::DocumentInfo::MimeType, "application/pdf" ); + + userMutex()->lock(); + + + if ( pdfdoc ) { - userMutex()->lock(); - - docInfo.set( Okular::DocumentInfo::MimeType, "application/pdf" ); - - if ( pdfdoc ) - { - // compile internal structure reading properties from PDFDoc + // compile internal structure reading properties from PDFDoc + if ( keys.contains( Okular::DocumentInfo::Title ) ) docInfo.set( Okular::DocumentInfo::Title, pdfdoc->info("Title") ); + if ( keys.contains( Okular::DocumentInfo::Subject ) ) docInfo.set( Okular::DocumentInfo::Subject, pdfdoc->info("Subject") ); + if ( keys.contains( Okular::DocumentInfo::Author ) ) docInfo.set( Okular::DocumentInfo::Author, pdfdoc->info("Author") ); + if ( keys.contains( Okular::DocumentInfo::Keywords ) ) docInfo.set( Okular::DocumentInfo::Keywords, pdfdoc->info("Keywords") ); + if ( keys.contains( Okular::DocumentInfo::Creator ) ) docInfo.set( Okular::DocumentInfo::Creator, pdfdoc->info("Creator") ); + if ( keys.contains( Okular::DocumentInfo::Producer ) ) docInfo.set( Okular::DocumentInfo::Producer, pdfdoc->info("Producer") ); - docInfo.set( Okular::DocumentInfo::CreationDate, - KGlobal::locale()->formatDateTime( pdfdoc->date("CreationDate"), KLocale::LongDate, true ) ); - docInfo.set( Okular::DocumentInfo::ModificationDate, - KGlobal::locale()->formatDateTime( pdfdoc->date("ModDate"), KLocale::LongDate, true ) ); - + if ( keys.contains( Okular::DocumentInfo::CreationDate ) ) + docInfo.set( Okular::DocumentInfo::CreationDate, KGlobal::locale()->formatDateTime( pdfdoc->date("CreationDate"), KLocale::LongDate, true ) ); + if ( keys.contains( Okular::DocumentInfo::ModificationDate ) ) + docInfo.set( Okular::DocumentInfo::ModificationDate, KGlobal::locale()->formatDateTime( pdfdoc->date("ModDate"), KLocale::LongDate, true ) ); + if ( keys.contains( Okular::DocumentInfo::CustomKeys ) ) + { int major, minor; pdfdoc->getPdfVersion(&major, &minor); - docInfo.set( "format", i18nc( "PDF v. ", "PDF v. %1.%2", - major, minor ), i18n( "Format" ) ); - docInfo.set( "encryption", pdfdoc->isEncrypted() ? i18n( "Encrypted" ) : i18n( "Unencrypted" ), - i18n("Security") ); - docInfo.set( "optimization", pdfdoc->isLinearized() ? i18n( "Yes" ) : i18n( "No" ), - i18n("Optimized") ); - - docInfo.set( Okular::DocumentInfo::Pages, QString::number( pdfdoc->numPages() ) ); + docInfo.set( "format", i18nc( "PDF v. ", "PDF v. %1.%2", major, minor ), i18n( "Format" ) ); + docInfo.set( "encryption", pdfdoc->isEncrypted() ? i18n( "Encrypted" ) : i18n( "Unencrypted" ), i18n("Security") ); + docInfo.set( "optimization", pdfdoc->isLinearized() ? i18n( "Yes" ) : i18n( "No" ), i18n("Optimized") ); } - else - { - // TODO not sure one can reach here, check and if it is not possible, remove the code - docInfo.set( Okular::DocumentInfo::Title, i18n("Unknown") ); - docInfo.set( Okular::DocumentInfo::Subject, i18n("Unknown") ); - docInfo.set( Okular::DocumentInfo::Author, i18n("Unknown") ); - docInfo.set( Okular::DocumentInfo::Keywords, i18n("Unknown") ); - docInfo.set( Okular::DocumentInfo::Creator, i18n("Unknown") ); - docInfo.set( Okular::DocumentInfo::Producer, i18n("Unknown") ); - docInfo.set( Okular::DocumentInfo::CreationDate, i18n("Unknown Date") ); - docInfo.set( Okular::DocumentInfo::ModificationDate, i18n("Unknown Date") ); - docInfo.set( "format", "PDF", i18n( "Format" ) ); - docInfo.set( "encryption", i18n( "Unknown Encryption" ), i18n( "Security" ) ); - docInfo.set( "optimization", i18n( "Unknown Optimization" ), i18n( "Optimized" ) ); - - docInfo.set( Okular::DocumentInfo::Pages, i18n("Unknown") ); - } - userMutex()->unlock(); - - // if pdfdoc is valid then we cached good info -> don't cache them again - if ( pdfdoc ) - docInfoDirty = false; + docInfo.set( Okular::DocumentInfo::Pages, QString::number( pdfdoc->numPages() ) ); } - return &docInfo; + userMutex()->unlock(); + + return docInfo; } const Okular::DocumentSynopsis * PDFGenerator::generateDocumentSynopsis() diff --git a/generators/poppler/generator_pdf.h b/generators/poppler/generator_pdf.h index 1a34bb79e..2faa0d8c0 100644 --- a/generators/poppler/generator_pdf.h +++ b/generators/poppler/generator_pdf.h @@ -64,7 +64,7 @@ class PDFGenerator : public Okular::Generator, public Okular::ConfigInterface, p Okular::Document::OpenResult loadDocumentFromDataWithPassword( const QByteArray & fileData, QVector & pagesVector, const QString & password ); void loadPages(QVector &pagesVector, int rotation=-1, bool clear=false); // [INHERITED] document information - const Okular::DocumentInfo * generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo( const QSet &keys ) const; const Okular::DocumentSynopsis * generateDocumentSynopsis(); Okular::FontInfo::List fontsForPage( int page ); const QList * embeddedFiles() const; @@ -137,8 +137,6 @@ class PDFGenerator : public Okular::Generator, public Okular::ConfigInterface, p // misc variables for document info and synopsis caching - bool docInfoDirty; - Okular::DocumentInfo docInfo; bool docSynopsisDirty; Okular::DocumentSynopsis docSyn; mutable bool docEmbeddedFilesDirty; diff --git a/generators/spectre/generator_ghostview.cpp b/generators/spectre/generator_ghostview.cpp index 7b0146a12..b84e1e4e9 100644 --- a/generators/spectre/generator_ghostview.cpp +++ b/generators/spectre/generator_ghostview.cpp @@ -54,7 +54,6 @@ OKULAR_EXPORT_PLUGIN(GSGenerator, createAboutData()) GSGenerator::GSGenerator( QObject *parent, const QVariantList &args ) : Okular::Generator( parent, args ), m_internalDocument(0), - m_docInfo(0), m_request(0) { setFeature( PrintPostscript ); @@ -182,9 +181,6 @@ bool GSGenerator::doCloseDocument() spectre_document_free(m_internalDocument); m_internalDocument = 0; - delete m_docInfo; - m_docInfo = 0; - return true; } @@ -265,28 +261,34 @@ bool GSGenerator::canGeneratePixmap() const return !m_request; } -const Okular::DocumentInfo * GSGenerator::generateDocumentInfo() +Okular::DocumentInfo GSGenerator::generateDocumentInfo( const QSet &keys ) const { - if (!m_docInfo) + Okular::DocumentInfo docInfo; + if ( keys.contains( Okular::DocumentInfo::Title ) ) + docInfo.set( Okular::DocumentInfo::Title, spectre_document_get_title(m_internalDocument) ); + if ( keys.contains( Okular::DocumentInfo::Author ) ) + docInfo.set( Okular::DocumentInfo::Author, spectre_document_get_for(m_internalDocument) ); + if ( keys.contains( Okular::DocumentInfo::Creator ) ) + docInfo.set( Okular::DocumentInfo::Creator, spectre_document_get_creator(m_internalDocument) ); + if ( keys.contains( Okular::DocumentInfo::CreationDate ) ) + docInfo.set( Okular::DocumentInfo::CreationDate, spectre_document_get_creation_date(m_internalDocument) ); + if ( keys.contains( Okular::DocumentInfo::CustomKeys ) ) + docInfo.set( "dscversion", spectre_document_get_format(m_internalDocument), i18n("Document version") ); + + if ( keys.contains( Okular::DocumentInfo::MimeType ) ) { - m_docInfo = new Okular::DocumentInfo(); - - m_docInfo->set( Okular::DocumentInfo::Title, spectre_document_get_title(m_internalDocument) ); - m_docInfo->set( Okular::DocumentInfo::Author, spectre_document_get_for(m_internalDocument) ); - m_docInfo->set( Okular::DocumentInfo::Creator, spectre_document_get_creator(m_internalDocument) ); - m_docInfo->set( Okular::DocumentInfo::CreationDate, spectre_document_get_creation_date(m_internalDocument) ); - m_docInfo->set( "dscversion", spectre_document_get_format(m_internalDocument), i18n("Document version") ); - int languageLevel = spectre_document_get_language_level(m_internalDocument); - if (languageLevel > 0) m_docInfo->set( "langlevel", QString::number(languageLevel), i18n("Language Level") ); + if (languageLevel > 0) docInfo.set( "langlevel", QString::number(languageLevel), i18n("Language Level") ); if (spectre_document_is_eps(m_internalDocument)) - m_docInfo->set( Okular::DocumentInfo::MimeType, "image/x-eps" ); + docInfo.set( Okular::DocumentInfo::MimeType, "image/x-eps" ); else - m_docInfo->set( Okular::DocumentInfo::MimeType, "application/postscript" ); - - m_docInfo->set( Okular::DocumentInfo::Pages, QString::number(spectre_document_get_n_pages(m_internalDocument)) ); + docInfo.set( Okular::DocumentInfo::MimeType, "application/postscript" ); } - return m_docInfo; + + if ( keys.contains( Okular::DocumentInfo::Pages ) ) + docInfo.set( Okular::DocumentInfo::Pages, QString::number(spectre_document_get_n_pages(m_internalDocument)) ); + + return docInfo; } Okular::Rotation GSGenerator::orientation(SpectreOrientation pageOrientation) const diff --git a/generators/spectre/generator_ghostview.h b/generators/spectre/generator_ghostview.h index ab9c33d90..914a51810 100644 --- a/generators/spectre/generator_ghostview.h +++ b/generators/spectre/generator_ghostview.h @@ -26,7 +26,7 @@ class GSGenerator : public Okular::Generator, public Okular::ConfigInterface bool loadDocument( const QString & fileName, QVector< Okular::Page * > & pagesVector ); // Document description and Table of contents - const Okular::DocumentInfo * generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo( const QSet &keys ) const; const Okular::DocumentSynopsis * generateDocumentSynopsis() { return 0L; } const Okular::DocumentFonts * generateDocumentFonts() { return 0L; } @@ -59,7 +59,6 @@ class GSGenerator : public Okular::Generator, public Okular::ConfigInterface // backendish stuff SpectreDocument *m_internalDocument; - Okular::DocumentInfo *m_docInfo; Okular::PixmapRequest *m_request; diff --git a/generators/tiff/generator_tiff.cpp b/generators/tiff/generator_tiff.cpp index bc692dec3..31b2e3e09 100644 --- a/generators/tiff/generator_tiff.cpp +++ b/generators/tiff/generator_tiff.cpp @@ -178,7 +178,7 @@ OKULAR_EXPORT_PLUGIN( TIFFGenerator, createAboutData() ) TIFFGenerator::TIFFGenerator( QObject *parent, const QVariantList &args ) : Okular::Generator( parent, args ), - d( new Private ), m_docInfo( 0 ) + d( new Private ) { setFeature( Threaded ); setFeature( PrintNative ); @@ -194,7 +194,6 @@ TIFFGenerator::~TIFFGenerator() d->tiff = 0; } - delete m_docInfo; delete d; } @@ -245,8 +244,6 @@ bool TIFFGenerator::doCloseDocument() delete d->dev; d->dev = 0; d->data.clear(); - delete m_docInfo; - m_docInfo = 0; m_pageMapping.clear(); } @@ -304,40 +301,52 @@ QImage TIFFGenerator::image( Okular::PixmapRequest * request ) return img; } -const Okular::DocumentInfo * TIFFGenerator::generateDocumentInfo() +Okular::DocumentInfo TIFFGenerator::generateDocumentInfo( const QSet &keys ) const { - if ( !d->tiff ) - return 0; + Okular::DocumentInfo docInfo; + if ( d->tiff ) + { + if ( keys.contains( Okular::DocumentInfo::MimeType ) ) + docInfo.set( Okular::DocumentInfo::MimeType, "image/tiff" ); - if ( m_docInfo ) - return m_docInfo; + if ( keys.contains( Okular::DocumentInfo::Description ) ) + { + char* buffer = 0; + TIFFGetField( d->tiff, TIFFTAG_IMAGEDESCRIPTION, &buffer ); + docInfo.set( Okular::DocumentInfo::Description, buffer ? QString::fromLatin1( buffer ) : QString() ); + } - m_docInfo = new Okular::DocumentInfo(); + if ( keys.contains( Okular::DocumentInfo::Producer ) ) + { + char* buffer = 0; + TIFFGetField( d->tiff, TIFFTAG_SOFTWARE, &buffer ); + docInfo.set( Okular::DocumentInfo::Producer, buffer ? QString::fromLatin1( buffer ) : QString() ); + } - m_docInfo->set( Okular::DocumentInfo::MimeType, "image/tiff" ); + if ( keys.contains( Okular::DocumentInfo::Copyright ) ) + { + char* buffer = 0; + TIFFGetField( d->tiff, TIFFTAG_COPYRIGHT, &buffer ); + docInfo.set( Okular::DocumentInfo::Copyright, buffer ? QString::fromLatin1( buffer ) : QString() ); + } - char* buffer = 0; - TIFFGetField( d->tiff, TIFFTAG_IMAGEDESCRIPTION, &buffer ); - m_docInfo->set( Okular::DocumentInfo::Description, buffer ? QString::fromLatin1( buffer ) : i18nc( "Unknown description", "Unknown" ) ); + if ( keys.contains( Okular::DocumentInfo::Author ) ) + { + char* buffer = 0; + TIFFGetField( d->tiff, TIFFTAG_ARTIST, &buffer ); + docInfo.set( Okular::DocumentInfo::Author, buffer ? QString::fromLatin1( buffer ) : QString() ); + } - buffer = 0; - TIFFGetField( d->tiff, TIFFTAG_SOFTWARE, &buffer ); - m_docInfo->set( Okular::DocumentInfo::Producer, buffer ? QString::fromLatin1( buffer ) : i18nc( "Unknown producer", "Unknown" ) ); + if ( keys.contains( Okular::DocumentInfo::CreationDate ) ) + { + char* buffer = 0; + TIFFGetField( d->tiff, TIFFTAG_DATETIME, &buffer ); + QDateTime date = convertTIFFDateTime( buffer ); + docInfo.set( Okular::DocumentInfo::CreationDate, date.isValid() ? KGlobal::locale()->formatDateTime( date, KLocale::LongDate, true ) : QString() ); + } + } - buffer = 0; - TIFFGetField( d->tiff, TIFFTAG_COPYRIGHT, &buffer ); - m_docInfo->set( Okular::DocumentInfo::Copyright, buffer ? QString::fromLatin1( buffer ) : i18nc( "Unknown copyright statement", "Unknown" ) ); - - buffer = 0; - TIFFGetField( d->tiff, TIFFTAG_ARTIST, &buffer ); - m_docInfo->set( Okular::DocumentInfo::Author, buffer ? QString::fromLatin1( buffer ) : i18nc( "Unknown author", "Unknown" ) ); - - buffer = 0; - TIFFGetField( d->tiff, TIFFTAG_DATETIME, &buffer ); - QDateTime date = convertTIFFDateTime( buffer ); - m_docInfo->set( Okular::DocumentInfo::CreationDate, date.isValid() ? KGlobal::locale()->formatDateTime( date, KLocale::LongDate, true ) : i18nc( "Unknown creation date", "Unknown" ) ); - - return m_docInfo; + return docInfo; } void TIFFGenerator::loadPages( QVector & pagesVector ) diff --git a/generators/tiff/generator_tiff.h b/generators/tiff/generator_tiff.h index 9ad1de613..04917c232 100644 --- a/generators/tiff/generator_tiff.h +++ b/generators/tiff/generator_tiff.h @@ -24,7 +24,7 @@ class TIFFGenerator : public Okular::Generator bool loadDocument( const QString & fileName, QVector & pagesVector ); bool loadDocumentFromData( const QByteArray & fileData, QVector< Okular::Page * > & pagesVector ); - const Okular::DocumentInfo * generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo( const QSet &keys ) const; bool print( QPrinter& printer ); @@ -40,7 +40,6 @@ class TIFFGenerator : public Okular::Generator void loadPages( QVector & pagesVector ); int mapPage( int page ) const; - Okular::DocumentInfo * m_docInfo; QHash< int, int > m_pageMapping; }; diff --git a/generators/xps/generator_xps.cpp b/generators/xps/generator_xps.cpp index 2399a9656..d86dbcb6e 100644 --- a/generators/xps/generator_xps.cpp +++ b/generators/xps/generator_xps.cpp @@ -1892,7 +1892,7 @@ XpsPage* XpsDocument::page(int pageNum) const return m_pages.at(pageNum); } -XpsFile::XpsFile() : m_docInfo( 0 ) +XpsFile::XpsFile() { } @@ -1996,14 +1996,11 @@ bool XpsFile::loadDocument(const QString &filename) return true; } -const Okular::DocumentInfo * XpsFile::generateDocumentInfo() +Okular::DocumentInfo XpsFile::generateDocumentInfo() const { - if ( m_docInfo ) - return m_docInfo; + Okular::DocumentInfo docInfo; - m_docInfo = new Okular::DocumentInfo(); - - m_docInfo->set( Okular::DocumentInfo::MimeType, "application/oxps" ); + docInfo.set( Okular::DocumentInfo::MimeType, "application/oxps" ); if ( ! m_corePropertiesFileName.isEmpty() ) { const KZipFileEntry* corepropsFile = static_cast(m_xpsArchive->directory()->entry(m_corePropertiesFileName)); @@ -2018,25 +2015,25 @@ const Okular::DocumentInfo * XpsFile::generateDocumentInfo() if ( xml.isStartElement() ) { if (xml.name() == "title") { - m_docInfo->set( Okular::DocumentInfo::Title, xml.readElementText() ); + docInfo.set( Okular::DocumentInfo::Title, xml.readElementText() ); } else if (xml.name() == "subject") { - m_docInfo->set( Okular::DocumentInfo::Subject, xml.readElementText() ); + docInfo.set( Okular::DocumentInfo::Subject, xml.readElementText() ); } else if (xml.name() == "description") { - m_docInfo->set( Okular::DocumentInfo::Description, xml.readElementText() ); + docInfo.set( Okular::DocumentInfo::Description, xml.readElementText() ); } else if (xml.name() == "creator") { - m_docInfo->set( Okular::DocumentInfo::Creator, xml.readElementText() ); + docInfo.set( Okular::DocumentInfo::Creator, xml.readElementText() ); } else if (xml.name() == "category") { - m_docInfo->set( Okular::DocumentInfo::Category, xml.readElementText() ); + docInfo.set( Okular::DocumentInfo::Category, xml.readElementText() ); } else if (xml.name() == "created") { QDateTime createdDate = QDateTime::fromString( xml.readElementText(), "yyyy-MM-ddThh:mm:ssZ" ); - m_docInfo->set( Okular::DocumentInfo::CreationDate, KGlobal::locale()->formatDateTime( createdDate, KLocale::LongDate, true ) ); + docInfo.set( Okular::DocumentInfo::CreationDate, KGlobal::locale()->formatDateTime( createdDate, KLocale::LongDate, true ) ); } else if (xml.name() == "modified") { QDateTime modifiedDate = QDateTime::fromString( xml.readElementText(), "yyyy-MM-ddThh:mm:ssZ" ); - m_docInfo->set( Okular::DocumentInfo::ModificationDate, KGlobal::locale()->formatDateTime( modifiedDate, KLocale::LongDate, true ) ); + docInfo.set( Okular::DocumentInfo::ModificationDate, KGlobal::locale()->formatDateTime( modifiedDate, KLocale::LongDate, true ) ); } else if (xml.name() == "keywords") { - m_docInfo->set( Okular::DocumentInfo::Keywords, xml.readElementText() ); + docInfo.set( Okular::DocumentInfo::Keywords, xml.readElementText() ); } else if (xml.name() == "revision") { - m_docInfo->set( "revision", xml.readElementText(), i18n( "Revision" ) ); + docInfo.set( "revision", xml.readElementText(), i18n( "Revision" ) ); } } } @@ -2048,19 +2045,13 @@ const Okular::DocumentInfo * XpsFile::generateDocumentInfo() kDebug(XpsDebug) << "No core properties filename"; } - m_docInfo->set( Okular::DocumentInfo::Pages, QString::number(numPages()) ); + docInfo.set( Okular::DocumentInfo::Pages, QString::number(numPages()) ); - return m_docInfo; + return docInfo; } bool XpsFile::closeDocument() { - - if ( m_docInfo ) - delete m_docInfo; - - m_docInfo = 0; - qDeleteAll( m_documents ); m_documents.clear(); @@ -2159,7 +2150,7 @@ Okular::TextPage* XpsGenerator::textPage( Okular::Page * page ) return xpsPage->textPage(); } -const Okular::DocumentInfo * XpsGenerator::generateDocumentInfo() +Okular::DocumentInfo XpsGenerator::generateDocumentInfo( const QSet &keys ) const { kDebug(XpsDebug) << "generating document metadata"; diff --git a/generators/xps/generator_xps.h b/generators/xps/generator_xps.h index 4c56e8c73..398eb3fb4 100644 --- a/generators/xps/generator_xps.h +++ b/generators/xps/generator_xps.h @@ -235,7 +235,7 @@ public: bool loadDocument( const QString & fileName ); bool closeDocument(); - const Okular::DocumentInfo * generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo() const; QImage thumbnail(); @@ -287,7 +287,6 @@ private: bool m_thumbnailIsLoaded; QString m_corePropertiesFileName; - Okular::DocumentInfo * m_docInfo; QString m_signatureOrigin; @@ -307,7 +306,7 @@ class XpsGenerator : public Okular::Generator bool loadDocument( const QString & fileName, QVector & pagesVector ); - const Okular::DocumentInfo * generateDocumentInfo(); + Okular::DocumentInfo generateDocumentInfo( const QSet &keys ) const; const Okular::DocumentSynopsis * generateDocumentSynopsis(); Okular::ExportFormat::List exportFormats() const; diff --git a/part.cpp b/part.cpp index d9f168202..6a639fcc4 100644 --- a/part.cpp +++ b/part.cpp @@ -1160,19 +1160,8 @@ QString Part::currentDocument() QString Part::documentMetaData( const QString &metaData ) const { - const Okular::DocumentInfo * info = m_document->documentInfo(); - if ( info ) - { - QDomElement docElement = info->documentElement(); - for ( QDomNode node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) - { - const QDomElement element = node.toElement(); - if ( metaData.compare( element.tagName(), Qt::CaseInsensitive ) == 0 ) - return element.attribute( "value" ); - } - } - - return QString(); + const Okular::DocumentInfo info = m_document->documentInfo(); + return info.get( metaData ); } @@ -2537,14 +2526,12 @@ void Part::slotAboutBackend() if ( aboutData.programIconName().isEmpty() || aboutData.programIconName() == aboutData.appName() ) { - if ( const Okular::DocumentInfo *documentInfo = m_document->documentInfo() ) + const Okular::DocumentInfo documentInfo = m_document->documentInfo(QSet() << DocumentInfo::MimeType); + const QString mimeTypeName = documentInfo.get(DocumentInfo::MimeType); + if ( !mimeTypeName.isEmpty() ) { - const QString mimeTypeName = documentInfo->get("mimeType"); - if ( !mimeTypeName.isEmpty() ) - { - if ( KMimeType::Ptr type = KMimeType::mimeType( mimeTypeName ) ) - aboutData.setProgramIconName( type->iconName() ); - } + if ( KMimeType::Ptr type = KMimeType::mimeType( mimeTypeName ) ) + aboutData.setProgramIconName( type->iconName() ); } } diff --git a/ui/presentationwidget.cpp b/ui/presentationwidget.cpp index 4aaec2a27..d99464768 100644 --- a/ui/presentationwidget.cpp +++ b/ui/presentationwidget.cpp @@ -353,14 +353,11 @@ void PresentationWidget::notifySetup( const QVector< Okular::Page * > & pageSet, // get metadata from the document m_metaStrings.clear(); - const Okular::DocumentInfo * info = m_document->documentInfo(); - if ( info ) - { - if ( !info->get( "title" ).isNull() ) - m_metaStrings += i18n( "Title: %1", info->get( "title" ) ); - if ( !info->get( "author" ).isNull() ) - m_metaStrings += i18n( "Author: %1", info->get( "author" ) ); - } + const Okular::DocumentInfo info = m_document->documentInfo( QSet() << Okular::DocumentInfo::Title << Okular::DocumentInfo::Author ); + if ( !info.get( Okular::DocumentInfo::Title ).isNull() ) + m_metaStrings += i18n( "Title: %1", info.get( Okular::DocumentInfo::Title ) ); + if ( !info.get( Okular::DocumentInfo::Author ).isNull() ) + m_metaStrings += i18n( "Author: %1", info.get( Okular::DocumentInfo::Author ) ); m_metaStrings += i18n( "Pages: %1", m_document->pages() ); m_metaStrings += i18n( "Click to begin" ); diff --git a/ui/propertiesdialog.cpp b/ui/propertiesdialog.cpp index 485c2de3c..933100c24 100644 --- a/ui/propertiesdialog.cpp +++ b/ui/propertiesdialog.cpp @@ -41,71 +41,55 @@ PropertiesDialog::PropertiesDialog(QWidget *parent, Okular::Document *doc) m_fontModel( 0 ), m_fontInfo( 0 ), m_fontProgressBar( 0 ), m_fontScanStarted( false ) { - setFaceType( Tabbed ); - setCaption( i18n( "Unknown File" ) ); - setButtons( Ok ); + setFaceType( Tabbed ); + setCaption( i18n( "Unknown File" ) ); + setButtons( Ok ); - // PROPERTIES - QFrame *page = new QFrame(); - KPageWidgetItem *item = addPage( page, i18n( "&Properties" ) ); - item->setIcon( KIcon( "document-properties" ) ); + // PROPERTIES + QFrame *page = new QFrame(); + KPageWidgetItem *item = addPage( page, i18n( "&Properties" ) ); + item->setIcon( KIcon( "document-properties" ) ); - // get document info, if not present display blank data and a warning - const Okular::DocumentInfo * info = doc->documentInfo(); - if ( !info ) { - QVBoxLayout *layout = new QVBoxLayout( page ); - layout->addWidget( new QLabel( i18n( "No document opened." ), page ) ); - return; - } + // get document info + const Okular::DocumentInfo info = doc->documentInfo(); + QFormLayout *layout = new QFormLayout( page ); - QFormLayout *layout = new QFormLayout( page ); + // mime name based on mimetype id + QString mimeName = info.get( Okular::DocumentInfo::MimeType ).section( '/', -1 ).toUpper(); + setCaption( i18n( "%1 Properties", mimeName ) ); - // mime name based on mimetype id - QString mimeName = info->get( "mimeType" ).section( '/', -1 ).toUpper(); - setCaption( i18n( "%1 Properties", mimeName ) ); + int valMaxWidth = 100; - QDomElement docElement = info->documentElement(); - - int valMaxWidth = 100; - - /* obtains the properties list, conveniently ordered */ - QStringList orderedProperties; - orderedProperties << Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::FilePath ) - << Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::PagesSize ) - << Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::DocumentSize ); - for (Okular::DocumentInfo::Key ks = Okular::DocumentInfo::Title; - ks <= Okular::DocumentInfo::Keywords; - ks = Okular::DocumentInfo::Key( ks+1 ) ) { - orderedProperties << Okular::DocumentInfo::getKeyString( ks ); - } - for ( QDomNode node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { - const QDomElement element = node.toElement(); - - const QString titleString = element.attribute( "title" ); - const QString valueString = element.attribute( "value" ); - if ( titleString.isEmpty() || valueString.isEmpty() ) - continue; - if ( !orderedProperties.contains( element.tagName() ) ) { - orderedProperties << element.tagName(); + /* obtains the properties list, conveniently ordered */ + QStringList orderedProperties; + orderedProperties << Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::FilePath ) + << Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::PagesSize ) + << Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::DocumentSize ); + for (Okular::DocumentInfo::Key ks = Okular::DocumentInfo::Title; + ks <= Okular::DocumentInfo::Keywords; + ks = Okular::DocumentInfo::Key( ks+1 ) ) + { + orderedProperties << Okular::DocumentInfo::getKeyString( ks ); + } + foreach( const QString &ks, info.keys()) { + if ( !orderedProperties.contains( ks ) ) { + orderedProperties << ks; + } } - } - QDomNodeList list; - - for ( QStringList::Iterator it = orderedProperties.begin(); - it != orderedProperties.end(); ++it ) { - list = docElement.elementsByTagName( (*it) ); - if ( list.count() == 1 ) { - - QDomElement element = list.at(0).toElement(); - const QString titleString = element.attribute( "title" ); - const QString valueString = element.attribute( "value" ); - if ( titleString.isEmpty() || valueString.isEmpty() ) + for ( QStringList::Iterator it = orderedProperties.begin(); + it != orderedProperties.end(); + ++it ) + { + const QString key = *it; + const QString titleString = info.getKeyTitle( key ); + const QString valueString = info.get( key ); + if ( titleString.isNull() || valueString.isNull() ) continue; // create labels and layout them QWidget *value = NULL; - if ( element.tagName() == Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::MimeType ) ) { + if ( key == Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::MimeType ) ) { /// for mime type fields, show icon as well value = new QWidget( page ); /// place icon left of mime type's name @@ -138,53 +122,52 @@ PropertiesDialog::PropertiesDialog(QWidget *parent, Okular::Document *doc) // refine maximum width of 'value' labels valMaxWidth = qMax( valMaxWidth, fontMetrics().width( valueString ) ); } - } - // FONTS - QVBoxLayout *page2Layout = 0; - if ( doc->canProvideFontInformation() ) { - // create fonts tab and layout it - QFrame *page2 = new QFrame(); - m_fontPage = addPage(page2, i18n("&Fonts")); - m_fontPage->setIcon( KIcon( "preferences-desktop-font" ) ); - page2Layout = new QVBoxLayout(page2); - page2Layout->setMargin(marginHint()); - page2Layout->setSpacing(spacingHint()); - // add a tree view - QTreeView *view = new QTreeView(page2); - view->setContextMenuPolicy(Qt::CustomContextMenu); - connect(view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showFontsMenu(QPoint))); - page2Layout->addWidget(view); - view->setRootIsDecorated(false); - view->setAlternatingRowColors(true); - view->setSortingEnabled( true ); - // creating a proxy model so we can sort the data - QSortFilterProxyModel *proxymodel = new QSortFilterProxyModel(view); - proxymodel->setDynamicSortFilter( true ); - proxymodel->setSortCaseSensitivity( Qt::CaseInsensitive ); - m_fontModel = new FontsListModel(view); - proxymodel->setSourceModel(m_fontModel); - view->setModel(proxymodel); - view->sortByColumn( 0, Qt::AscendingOrder ); - m_fontInfo = new QLabel( this ); - page2Layout->addWidget( m_fontInfo ); - m_fontInfo->setText( i18n( "Reading font information..." ) ); - m_fontInfo->hide(); - m_fontProgressBar = new QProgressBar( this ); - page2Layout->addWidget( m_fontProgressBar ); - m_fontProgressBar->setRange( 0, 100 ); - m_fontProgressBar->setValue( 0 ); - m_fontProgressBar->hide(); - } + // FONTS + QVBoxLayout *page2Layout = 0; + if ( doc->canProvideFontInformation() ) { + // create fonts tab and layout it + QFrame *page2 = new QFrame(); + m_fontPage = addPage(page2, i18n("&Fonts")); + m_fontPage->setIcon( KIcon( "preferences-desktop-font" ) ); + page2Layout = new QVBoxLayout(page2); + page2Layout->setMargin(marginHint()); + page2Layout->setSpacing(spacingHint()); + // add a tree view + QTreeView *view = new QTreeView(page2); + view->setContextMenuPolicy(Qt::CustomContextMenu); + connect(view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showFontsMenu(QPoint))); + page2Layout->addWidget(view); + view->setRootIsDecorated(false); + view->setAlternatingRowColors(true); + view->setSortingEnabled( true ); + // creating a proxy model so we can sort the data + QSortFilterProxyModel *proxymodel = new QSortFilterProxyModel(view); + proxymodel->setDynamicSortFilter( true ); + proxymodel->setSortCaseSensitivity( Qt::CaseInsensitive ); + m_fontModel = new FontsListModel(view); + proxymodel->setSourceModel(m_fontModel); + view->setModel(proxymodel); + view->sortByColumn( 0, Qt::AscendingOrder ); + m_fontInfo = new QLabel( this ); + page2Layout->addWidget( m_fontInfo ); + m_fontInfo->setText( i18n( "Reading font information..." ) ); + m_fontInfo->hide(); + m_fontProgressBar = new QProgressBar( this ); + page2Layout->addWidget( m_fontProgressBar ); + m_fontProgressBar->setRange( 0, 100 ); + m_fontProgressBar->setValue( 0 ); + m_fontProgressBar->hide(); + } - // current width: left columnt + right column + dialog borders - int width = layout->minimumSize().width() + valMaxWidth + 2 * marginHint() + spacingHint() + 30; - if ( page2Layout ) - width = qMax( width, page2Layout->sizeHint().width() + marginHint() + spacingHint() + 31 ); - // stay inside the 2/3 of the screen width - QRect screenContainer = KGlobalSettings::desktopGeometry( this ); - width = qMin( width, 2*screenContainer.width()/3 ); - resize(width, 1); + // current width: left columnt + right column + dialog borders + int width = layout->minimumSize().width() + valMaxWidth + 2 * marginHint() + spacingHint() + 30; + if ( page2Layout ) + width = qMax( width, page2Layout->sizeHint().width() + marginHint() + spacingHint() + 31 ); + // stay inside the 2/3 of the screen width + QRect screenContainer = KGlobalSettings::desktopGeometry( this ); + width = qMin( width, 2*screenContainer.width()/3 ); + resize(width, 1); connect( pageWidget(), SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), this, SLOT(pageChanged(KPageWidgetItem*,KPageWidgetItem*)) );