Make documentInfo be Hash based instead of XML based

This commit is contained in:
Albert Astals Cid 2014-05-11 11:17:49 +02:00
parent c5c3be9a1a
commit e9e3d4a435
31 changed files with 529 additions and 514 deletions

View File

@ -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<DocumentInfo::Key> 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<DocumentInfo::Key> &keys ) const
{
DocumentInfo result = d->m_documentInfo;
const QSet<DocumentInfo::Key> 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 **/

View File

@ -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<DocumentInfo::Key> &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.
*

View File

@ -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<DocumentInfo::Key> 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<QString, QString> values; // key -> value
QMap<QString, QString> titles; // key -> title For the custom keys
};
}
#endif

View File

@ -290,9 +290,9 @@ TextPage* Generator::textPage( Page* )
return 0;
}
const DocumentInfo * Generator::generateDocumentInfo()
DocumentInfo Generator::generateDocumentInfo(const QSet<DocumentInfo::Key> &keys) const
{
return 0;
return DocumentInfo();
}
const DocumentSynopsis * Generator::generateDocumentSynopsis()

View File

@ -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<DocumentInfo::Key> &keys ) const;
/**
* Returns the 'table of content' object of the document or 0 if

View File

@ -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<DocumentInfo::Key> 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<DocumentInfo::Key>() << 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

View File

@ -453,10 +453,10 @@ bool TextDocumentGenerator::print( QPrinter& printer )
return true;
}
const Okular::DocumentInfo* TextDocumentGenerator::generateDocumentInfo()
Okular::DocumentInfo TextDocumentGenerator::generateDocumentInfo( const QSet<DocumentInfo::Key> & /*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();
}

View File

@ -211,7 +211,7 @@ class OKULAR_EXPORT TextDocumentGenerator : public Generator, public Okular::Con
*/
TextDocumentSettings* generalSettings();
const Okular::DocumentInfo* generateDocumentInfo();
Okular::DocumentInfo generateDocumentInfo( const QSet<DocumentInfo::Key> &keys ) const;
const Okular::DocumentSynopsis* generateDocumentSynopsis();
protected:

View File

@ -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<Okular::DocumentInfo::Key> &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()

View File

@ -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<Okular::DocumentInfo::Key> &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;
};

View File

@ -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<Okular::DocumentInfo::Key> &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()

View File

@ -30,7 +30,7 @@ class DjVuGenerator : public Okular::Generator
bool loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector );
// document information
const Okular::DocumentInfo * generateDocumentInfo();
Okular::DocumentInfo generateDocumentInfo( const QSet<Okular::DocumentInfo::Key> &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;
};

View File

@ -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<Okular::DocumentInfo::Key> &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()

View File

@ -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<Okular::DocumentInfo::Key> &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;

View File

@ -9,8 +9,6 @@
#include "generator_fax.h"
#include "faxdocument.h"
#include <QtGui/QPainter>
#include <QtGui/QPrinter>
@ -52,13 +50,12 @@ FaxGenerator::~FaxGenerator()
bool FaxGenerator::loadDocument( const QString & fileName, QVector<Okular::Page*> & 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, QVector<Okular::Page*
Okular::Page * page = new Okular::Page( 0, m_img.width(), m_img.height(), Okular::Rotation0 );
pagesVector[0] = page;
m_docInfo = new Okular::DocumentInfo();
if ( type == FaxDocument::G3 )
m_docInfo->set( 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<Okular::DocumentInfo::Key> &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 )

View File

@ -14,6 +14,8 @@
#include <QtGui/QImage>
#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<Okular::Page*> & pagesVector );
const Okular::DocumentInfo * generateDocumentInfo();
Okular::DocumentInfo generateDocumentInfo( const QSet<Okular::DocumentInfo::Key> &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

View File

@ -186,9 +186,9 @@ void KIMGIOGenerator::slotTest()
kDebug() << "Test";
}
const Okular::DocumentInfo * KIMGIOGenerator::generateDocumentInfo()
Okular::DocumentInfo KIMGIOGenerator::generateDocumentInfo( const QSet<Okular::DocumentInfo::Key> &keys ) const
{
return &docInfo;
return docInfo;
}
#include "generator_kimgio.moc"

View File

@ -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<Okular::DocumentInfo::Key> &keys ) const;
protected:
bool doCloseDocument();

View File

@ -126,9 +126,9 @@ bool PluckerGenerator::doCloseDocument()
return true;
}
const Okular::DocumentInfo* PluckerGenerator::generateDocumentInfo()
Okular::DocumentInfo PluckerGenerator::generateDocumentInfo( const QSet<Okular::DocumentInfo::Key> & /*keys*/ ) const
{
return &mDocumentInfo;
return mDocumentInfo;
}
QImage PluckerGenerator::image( Okular::PixmapRequest *request )

View File

@ -31,7 +31,7 @@ class PluckerGenerator : public Okular::Generator
bool loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector );
// [INHERITED] document information
const Okular::DocumentInfo * generateDocumentInfo();
Okular::DocumentInfo generateDocumentInfo( const QSet<Okular::DocumentInfo::Key> &keys ) const;
// [INHERITED] perform actions on document / pages
QImage image( Okular::PixmapRequest *request );

View File

@ -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<Okular::Page*> &pagesVector, int rotation,
}
}
const Okular::DocumentInfo * PDFGenerator::generateDocumentInfo()
Okular::DocumentInfo PDFGenerator::generateDocumentInfo( const QSet<Okular::DocumentInfo::Key> &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. <version>", "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. <version>", "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()

View File

@ -64,7 +64,7 @@ class PDFGenerator : public Okular::Generator, public Okular::ConfigInterface, p
Okular::Document::OpenResult loadDocumentFromDataWithPassword( const QByteArray & fileData, QVector<Okular::Page*> & pagesVector, const QString & password );
void loadPages(QVector<Okular::Page*> &pagesVector, int rotation=-1, bool clear=false);
// [INHERITED] document information
const Okular::DocumentInfo * generateDocumentInfo();
Okular::DocumentInfo generateDocumentInfo( const QSet<Okular::DocumentInfo::Key> &keys ) const;
const Okular::DocumentSynopsis * generateDocumentSynopsis();
Okular::FontInfo::List fontsForPage( int page );
const QList<Okular::EmbeddedFile*> * 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;

View File

@ -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<Okular::DocumentInfo::Key> &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

View File

@ -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<Okular::DocumentInfo::Key> &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;

View File

@ -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<Okular::DocumentInfo::Key> &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<Okular::Page*> & pagesVector )

View File

@ -24,7 +24,7 @@ class TIFFGenerator : public Okular::Generator
bool loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector );
bool loadDocumentFromData( const QByteArray & fileData, QVector< Okular::Page * > & pagesVector );
const Okular::DocumentInfo * generateDocumentInfo();
Okular::DocumentInfo generateDocumentInfo( const QSet<Okular::DocumentInfo::Key> &keys ) const;
bool print( QPrinter& printer );
@ -40,7 +40,6 @@ class TIFFGenerator : public Okular::Generator
void loadPages( QVector<Okular::Page*> & pagesVector );
int mapPage( int page ) const;
Okular::DocumentInfo * m_docInfo;
QHash< int, int > m_pageMapping;
};

View File

@ -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<const KZipFileEntry *>(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<Okular::DocumentInfo::Key> &keys ) const
{
kDebug(XpsDebug) << "generating document metadata";

View File

@ -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<Okular::Page*> & pagesVector );
const Okular::DocumentInfo * generateDocumentInfo();
Okular::DocumentInfo generateDocumentInfo( const QSet<Okular::DocumentInfo::Key> &keys ) const;
const Okular::DocumentSynopsis * generateDocumentSynopsis();
Okular::ExportFormat::List exportFormats() const;

View File

@ -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::Key>() << 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() );
}
}

View File

@ -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::Key>() << 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" );

View File

@ -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*)) );