Convert 'struct DocumentInfo' into a QDomDocument for more flexible information

passing.

svn path=/trunk/kdegraphics/kpdf/; revision=375065
This commit is contained in:
Tobias Koenig 2005-01-02 22:37:52 +00:00
parent 833ae4800f
commit b10d10a2bd
9 changed files with 122 additions and 310 deletions

View file

@ -709,5 +709,47 @@ void KPDFDocument::slotGeneratedContents( int id, int pageNumber )
d->observers[ id ]->observer->notifyPixmapChanged( pageNumber );
}
/** DocumentInfo **/
DocumentInfo::DocumentInfo()
: QDomDocument( "DocumentInformation" )
{
QDomElement docElement = createElement( "DocumentInfo" );
appendChild( docElement );
}
void DocumentInfo::set( const QString &key, const QString &value,
const QString &title )
{
QDomElement docElement = documentElement();
QDomElement element;
// check whether key already exists
QDomNodeList list = docElement.elementsByTagName( key );
if ( list.count() > 0 )
element = list.item( 0 ).toElement();
else
element = createElement( key );
element.setAttribute( "value", value );
element.setAttribute( "title", title );
if ( list.count() == 0 )
docElement.appendChild( element );
}
QString DocumentInfo::get( const QString &key ) const
{
QDomElement docElement = documentElement();
QDomElement element;
// check whether key already exists
QDomNodeList list = docElement.elementsByTagName( key );
if ( list.count() > 0 )
return list.item( 0 ).toElement().attribute( "value" );
else
return QString();
}
#include "document.moc"
#include "generator.moc"

View file

@ -106,24 +106,24 @@ class KPDFDocument : public QObject // only for a private slot..
*
* The Info structure can be filled in by generators to display metadata
* about the currently opened file.
* FUTURE: use a Dom tree so every generator can have different fields for
* its metadata and renew the display widget to use the dynamic format.
*/
struct DocumentInfo
class DocumentInfo : public QDomDocument
{
QString author,
creationDate,
modificationDate,
creator,
keywords,
producer,
subject,
title,
mimeType,
format,
formatVersion,
encryption,
optimization;
public:
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() );
/**
* Returns the value for a given key or an empty string when the
* key doesn't exist.
*/
QString get( const QString &key ) const;
};
/**

View file

@ -138,28 +138,31 @@ const DocumentInfo * PDFGenerator::documentInfo()
{
docLock.lock();
// compile internal structure reading properties from PDFDoc
docInfo.author = getDocumentInfo("Author");
docInfo.creationDate = getDocumentDate("CreationDate");
docInfo.modificationDate = getDocumentDate("ModDate");
docInfo.creator = getDocumentInfo("Creator");
docInfo.keywords = getDocumentInfo("Keywords");
docInfo.producer = getDocumentInfo("Producer");
docInfo.subject = getDocumentInfo("Subject");
docInfo.title = getDocumentInfo("Title");
docInfo.mimeType = "application/pdf";
docInfo.format = "PDF";
docInfo.set( "title", getDocumentInfo("Title"), i18n("Title") );
docInfo.set( "subject", getDocumentInfo("Subject"), i18n("Subject") );
docInfo.set( "author", getDocumentInfo("Author"), i18n("Author") );
docInfo.set( "keywords", getDocumentInfo("Keywords"), i18n("Keywords") );
docInfo.set( "creator", getDocumentInfo("Creator"), i18n("Creator") );
docInfo.set( "producer", getDocumentInfo("Producer"), i18n("Producer") );
docInfo.set( "creationDate", getDocumentDate("CreationDate"), i18n("Created") );
docInfo.set( "modificationDate", getDocumentDate("ModDate"), i18n("Modified") );
docInfo.set( "mimeType", "application/pdf" );
if ( pdfdoc )
{
docInfo.formatVersion = QString::number( pdfdoc->getPDFVersion() );
docInfo.encryption = pdfdoc->isEncrypted() ? i18n( "Encrypted" ) : i18n( "Unencrypted" );
docInfo.optimization = pdfdoc->isLinearized() ? i18n( "Yes" ) : i18n( "No" );
docInfo.set( "format", i18n( "PDF v. <version>", "PDF v. %1" )
.arg( QString::number( pdfdoc->getPDFVersion() ) ), 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
{
docInfo.formatVersion = i18n( "Unknown Version" );
docInfo.encryption = i18n( "Unknown Encryption" );
docInfo.optimization = i18n( "Unknown Optimization" );
docInfo.set( "format", "PDF", i18n( "Format" ) );
docInfo.set( "encryption", i18n( "Unknown Encryption" ), i18n( "Security" ) );
docInfo.set( "optimization", i18n( "Unknown Optimization" ), i18n( "Optimized" ) );
}
docInfo.set( "pages", QString::number( pdfdoc->getCatalog()->getNumPages() ), i18n("Pages") );
docLock.unlock();
// if pdfdoc is valid then we cached good info -> don't cache them again

View file

@ -606,7 +606,7 @@ void Part::slotShowMenu(const KPDFPage *page, const QPoint &point)
void Part::slotShowProperties()
{
propertiesDialog *d = new propertiesDialog(widget(), m_document);
PropertiesDialog *d = new PropertiesDialog(widget(), m_document);
d->exec();
delete d;
}

View file

@ -3,7 +3,7 @@ INCLUDES = -I$(srcdir)/.. -I$(top_builddir)/kpdf $(all_includes)
METASOURCES = AUTO
libkpdfui_la_SOURCES = pageview.cpp pageviewutils.cpp thumbnaillist.cpp \
toc.cpp searchwidget.cpp properties.ui \
toc.cpp searchwidget.cpp \
propertiesdialog.cpp presentationwidget.cpp
noinst_LTLIBRARIES = libkpdfui.la

View file

@ -140,10 +140,10 @@ void PresentationWidget::pageSetup( const QValueVector<KPDFPage*> & pageSet, boo
const DocumentInfo * info = m_document->documentInfo();
if ( info )
{
if ( !info->title.isNull() )
m_metaStrings += i18n( "Title: %1" ).arg( info->title );
if ( !info->title.isNull() )
m_metaStrings += i18n( "Author: %1" ).arg( info->author );
if ( !info->get( "title" ).isNull() )
m_metaStrings += i18n( "Title: %1" ).arg( info->get( "title" ) );
if ( !info->get( "author" ).isNull() )
m_metaStrings += i18n( "Author: %1" ).arg( info->get( "author" ) );
}
m_metaStrings += i18n( "Pages: %1" ).arg( m_document->pages() );
m_metaStrings += i18n( "Click to begin" );

View file

@ -1,248 +0,0 @@
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>properties</class>
<widget class="QWidget">
<property name="name">
<cstring>properties</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>124</width>
<height>324</height>
</rect>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel" row="9" column="0">
<property name="name">
<cstring>textLabel1_3_2_3_6</cstring>
</property>
<property name="text">
<string>Format:</string>
</property>
</widget>
<widget class="QLabel" row="8" column="0">
<property name="name">
<cstring>textLabel1_3_2_3_5</cstring>
</property>
<property name="text">
<string>Security:</string>
</property>
</widget>
<widget class="QLabel" row="11" column="0">
<property name="name">
<cstring>textLabel1_3_2_3_8</cstring>
</property>
<property name="text">
<string>Optimized:</string>
</property>
</widget>
<spacer row="12" column="0">
<property name="name">
<cstring>spacer3</cstring>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
<spacer row="6" column="2">
<property name="name">
<cstring>spacer4</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QLabel" row="5" column="0">
<property name="name">
<cstring>textLabel1_3_2_3_2</cstring>
</property>
<property name="text">
<string>Producer:</string>
</property>
</widget>
<widget class="QLabel" row="2" column="0">
<property name="name">
<cstring>textLabel1_3_2</cstring>
</property>
<property name="text">
<string>Author:</string>
</property>
</widget>
<widget class="QLabel" row="6" column="1">
<property name="name">
<cstring>createdValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="9" column="1">
<property name="name">
<cstring>versionValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="2" column="1">
<property name="name">
<cstring>authorValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="6" column="0">
<property name="name">
<cstring>textLabel1_3_2_3_3</cstring>
</property>
<property name="text">
<string>Created:</string>
</property>
</widget>
<widget class="QLabel" row="3" column="0">
<property name="name">
<cstring>textLabel1_3_2_2</cstring>
</property>
<property name="text">
<string>Keywords:</string>
</property>
</widget>
<widget class="QLabel" row="5" column="1">
<property name="name">
<cstring>producerValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="3" column="1">
<property name="name">
<cstring>keywordsValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="7" column="1">
<property name="name">
<cstring>modifiedValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="4" column="1">
<property name="name">
<cstring>creatorValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="10" column="0">
<property name="name">
<cstring>textLabel1_3_2_3_7</cstring>
</property>
<property name="text">
<string>Pages:</string>
</property>
</widget>
<widget class="QLabel" row="11" column="1">
<property name="name">
<cstring>optimizedValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="10" column="1">
<property name="name">
<cstring>pagesValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="8" column="1">
<property name="name">
<cstring>securityValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="7" column="0">
<property name="name">
<cstring>textLabel1_3_2_3_4</cstring>
</property>
<property name="text">
<string>Modified:</string>
</property>
</widget>
<widget class="QLabel" row="4" column="0">
<property name="name">
<cstring>textLabel1_3_2_3</cstring>
</property>
<property name="text">
<string>Creator:</string>
</property>
</widget>
<widget class="QLabel" row="0" column="0">
<property name="name">
<cstring>textLabel1</cstring>
</property>
<property name="text">
<string>Title:</string>
</property>
</widget>
<widget class="QLabel" row="1" column="0">
<property name="name">
<cstring>textLabel1_3</cstring>
</property>
<property name="text">
<string>Subject:</string>
</property>
</widget>
<widget class="QLabel" row="1" column="1">
<property name="name">
<cstring>subjectValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" row="0" column="1" rowspan="1" colspan="2">
<property name="name">
<cstring>titleValue</cstring>
</property>
<property name="text">
<string></string>
</property>
</widget>
</grid>
</widget>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View file

@ -9,39 +9,54 @@
// qt/kde includes
#include <klocale.h>
#include <qlayout.h>
#include <qlabel.h>
// local includes
#include "propertiesdialog.h"
#include "properties.h"
#include "core/document.h"
propertiesDialog::propertiesDialog(QWidget *parent, KPDFDocument *doc) : KDialogBase(parent, 0, true, i18n( "Unknown File" ), Ok)
PropertiesDialog::PropertiesDialog(QWidget *parent, KPDFDocument *doc)
: KDialogBase( Plain, i18n( "Unknown File" ), Ok, Ok, parent, 0, true, true )
{
// embed the properties widget (TODO switch to a dynamic generated one)
properties *p = new properties(this);
setMainWidget(p);
QWidget *page = plainPage();
QGridLayout *layout = new QGridLayout( page, 2, 2, marginHint(), spacingHint() );
// get document info, if not present display blank data and a warning
const DocumentInfo * info = doc->documentInfo();
if ( !info )
{
p->titleValue->setText( i18n( "No document opened!" ) );
if ( !info ) {
layout->addWidget( new QLabel( i18n( "No document opened!" ), page ), 0, 0 );
return;
}
// mime name based on mimetype id
QString mimeName = info->mimeType.section( '/', -1 ).upper();
QString mimeName = info->get( "mimeType" ).section( '/', -1 ).upper();
setCaption( i18n("%1 Properties").arg( mimeName ) );
// fill in document property values
p->pagesValue->setText( QString::number( doc->pages() ) );
p->authorValue->setText( info->author );
p->titleValue->setText( info->title );
p->subjectValue->setText( info->subject );
p->keywordsValue->setText( info->keywords );
p->producerValue->setText( info->producer );
p->creatorValue->setText( info->creator );
p->optimizedValue->setText( info->optimization );
p->securityValue->setText( info->encryption );
p->versionValue->setText( info->format + " v." + info->formatVersion );
p->createdValue->setText( info->creationDate );
p->modifiedValue->setText( info->modificationDate );
QDomElement docElement = info->documentElement();
int row = 0;
for ( QDomNode node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
QDomElement element = node.toElement();
if ( !element.attribute( "title" ).isEmpty() ) {
QLabel *key = new QLabel( i18n( "%1:" ).arg( element.attribute( "title" ) ), page );
QLabel *value = new QLabel( element.attribute( "value" ), page );
layout->addWidget( key, row, 0, AlignRight );
layout->addWidget( value, row, 1 );
row++;
}
}
// add the number of pages if the generator hasn't done it already
QDomNodeList list = docElement.elementsByTagName( "pages" );
if ( list.count() == 0 ) {
QLabel *key = new QLabel( i18n( "Pages:" ), page );
QLabel *value = new QLabel( QString::number( doc->pages() ), page );
layout->addWidget( key, row, 0 );
layout->addWidget( value, row, 1 );
}
}

View file

@ -14,10 +14,10 @@
class KPDFDocument;
class propertiesDialog : public KDialogBase
class PropertiesDialog : public KDialogBase
{
public:
propertiesDialog(QWidget *parent, KPDFDocument *doc);
PropertiesDialog( QWidget *parent, KPDFDocument *doc );
};
#endif