Commit "Document information" patch by Luigi Toscano, 8 months without a nack from any devel and i like it, so let's commit it

Luigi's mail says
********
The attached patch changes a bit the handling of document informations 
and the informations shown in the info page.
- document path is added to the information and a button allows you to 
toggle between to file name (default) and the complete path;
- the number of the page is added to the information set by 
documentInfo() and not by the properties dialog (so the latter will not 
modify datas);
- the order of the information shown is the fixed now (see 
orderedProperties).
*********

Then there are a few things of my own since some const here and there and adding three values to Key enum

Also it fixes wish 208999
BUGS: 208999

svn path=/trunk/KDE/kdegraphics/okular/; revision=1049872
This commit is contained in:
Albert Astals Cid 2009-11-16 00:46:33 +00:00
parent f18659612f
commit b9d749bc0d
5 changed files with 263 additions and 82 deletions

View File

@ -1868,6 +1868,10 @@ void Document::closeDocument()
d->m_allocatedTextPagesFifo.clear();
d->m_pageSize = PageSize();
d->m_pageSizes.clear();
delete d->m_documentInfo;
d->m_documentInfo = 0;
AudioPlayer::instance()->d->m_currentDocument = KUrl();
}
@ -1975,23 +1979,37 @@ bool Document::canConfigurePrinter( ) const
const DocumentInfo * Document::documentInfo() const
{
if ( d->m_documentInfo )
return d->m_documentInfo;
if ( d->m_generator )
{
const DocumentInfo *infoConst = d->m_generator->generateDocumentInfo();
if ( !infoConst )
return 0;
DocumentInfo *info = new DocumentInfo();
const DocumentInfo *tmp = d->m_generator->generateDocumentInfo();
if ( tmp )
*info = *tmp;
DocumentInfo *info = const_cast< DocumentInfo * >( infoConst );
QString pagesSize = d->pagesSizeString();
info->set( DocumentInfo::FilePath, currentDocument().url() );
const QString pagesSize = d->pagesSizeString();
if ( d->m_docSize != -1 )
{
QString sizeString = KGlobal::locale()->formatByteSize( d->m_docSize );
info->set( "documentSize", sizeString, i18n( "File Size" ) );
const QString sizeString = KGlobal::locale()->formatByteSize( d->m_docSize );
info->set( DocumentInfo::DocumentSize, sizeString );
}
if (!pagesSize.isEmpty())
{
info->set( "pagesSize", pagesSize, i18n("Page Size") );
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 ) );
}
d->m_documentInfo = info;
return info;
}
else return NULL;
@ -3729,67 +3747,141 @@ void DocumentInfo::set( const QString &key, const QString &value,
docElement.appendChild( element );
}
void DocumentInfo::set( enum Key key, const QString &value )
void DocumentInfo::set( Key key, const QString &value )
{
switch ( key ) {
case Title:
set( "title", value, i18n( "Title" ) );
break;
case Subject:
set( "subject", value, i18n( "Subject" ) );
break;
case Description:
set( "description", value, i18n( "Description" ) );
break;
case Author:
set( "author", value, i18n( "Author" ) );
break;
case Creator:
set( "creator", value, i18n( "Creator" ) );
break;
case Producer:
set( "producer", value, i18n( "Producer" ) );
break;
case Copyright:
set( "copyright", value, i18n( "Copyright" ) );
break;
case Pages:
set( "pages", value, i18n( "Pages" ) );
break;
case CreationDate:
set( "creationDate", value, i18n( "Created" ) );
break;
case ModificationDate:
set( "modificationDate", value, i18n( "Modified" ) );
break;
case MimeType:
set( "mimeType", value, i18n( "Mime Type" ) );
break;
case Category:
set( "category", value, i18n( "Category" ) );
break;
case Keywords:
set( "keywords", value, i18n( "Keywords" ) );
break;
default:
kWarning(OkularDebug) << "Invalid key passed";
break;
}
const QString keyString = getKeyString( key );
if ( !keyString.isEmpty() )
set( keyString, value, getKeyTitle( key ) );
else
kWarning(OkularDebug) << "Invalid key passed";
}
QString DocumentInfo::get( const QString &key ) const
{
QDomElement docElement = documentElement();
QDomElement element;
const QDomElement docElement = documentElement();
// check whether key already exists
QDomNodeList list = docElement.elementsByTagName( key );
const QDomNodeList list = docElement.elementsByTagName( key );
if ( list.count() > 0 )
return list.item( 0 ).toElement().attribute( "value" );
else
return QString();
}
QString DocumentInfo::getKeyString( Key key ) //const
{
switch ( key ) {
case Title:
return "title";
break;
case Subject:
return "subject";
break;
case Description:
return "description";
break;
case Author:
return "author";
break;
case Creator:
return "creator";
break;
case Producer:
return "producer";
break;
case Copyright:
return "copyright";
break;
case Pages:
return "pages";
break;
case CreationDate:
return "creationDate";
break;
case ModificationDate:
return "modificationDate";
break;
case MimeType:
return "mimeType";
break;
case Category:
return "category";
break;
case Keywords:
return "keywords";
break;
case FilePath:
return "filePath";
break;
case DocumentSize:
return "documentSize";
break;
case PagesSize:
return "pageSize";
break;
default:
return QString();
break;
}
}
QString DocumentInfo::getKeyTitle( Key key ) //const
{
switch ( key ) {
case Title:
return i18n( "Title" );
break;
case Subject:
return i18n( "Subject" );
break;
case Description:
return i18n( "Description" );
break;
case Author:
return i18n( "Author" );
break;
case Creator:
return i18n( "Creator" );
break;
case Producer:
return i18n( "Producer" );
break;
case Copyright:
return i18n( "Copyright" );
break;
case Pages:
return i18n( "Pages" );
break;
case CreationDate:
return i18n( "Created" );
break;
case ModificationDate:
return i18n( "Modified" );
break;
case MimeType:
return i18n( "Mime Type" );
break;
case Category:
return i18n( "Category" );
break;
case Keywords:
return i18n( "Keywords" );
break;
case FilePath:
return i18n( "File Path" );
break;
case DocumentSize:
return i18n( "File Size" );
break;
case PagesSize:
return i18n("Page Size");
break;
default:
return QString();
break;
}
}
/** DocumentSynopsis **/

View File

@ -829,7 +829,10 @@ class OKULAR_EXPORT DocumentInfo : public QDomDocument
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
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)
};
/**
@ -848,13 +851,26 @@ class OKULAR_EXPORT DocumentInfo : public QDomDocument
* Sets the value for a predefined key. You should use this method
* whenever a predefined key exists for your value.
*/
void set( enum Key, const QString &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 );
};
/**
@ -981,3 +997,5 @@ Q_DECLARE_METATYPE( Okular::DocumentInfo::Key )
Q_DECLARE_OPERATORS_FOR_FLAGS( Okular::Document::PixmapRequestFlags )
#endif
/* kate: replace-tabs on; indent-width 4; */

View File

@ -84,7 +84,8 @@ class DocumentPrivate
m_closingLoop( 0 ),
m_scripter( 0 ),
m_archiveData( 0 ),
m_fontsCached( false )
m_fontsCached( false ),
m_documentInfo( 0 )
{
calculateMaxTextPages();
}
@ -220,6 +221,7 @@ class DocumentPrivate
QPointer< FontExtractionThread > m_fontThread;
bool m_fontsCached;
DocumentInfo *m_documentInfo;
FontInfo::List m_fontsCache;
QSet< View * > m_views;

View File

@ -16,6 +16,7 @@
#include <qheaderview.h>
#include <qmenu.h>
#include <qprogressbar.h>
#include <qpushbutton.h>
#include <qsortfilterproxymodel.h>
#include <qtreeview.h>
#include <qtimer.h>
@ -25,6 +26,7 @@
#include <kmessagebox.h>
#include <ksqueezedtextlabel.h>
#include <kglobalsettings.h>
#include <kurl.h>
// local includes
#include "core/document.h"
@ -57,6 +59,8 @@ PropertiesDialog::PropertiesDialog(QWidget *parent, Okular::Document *doc)
return;
}
m_showingTitle = true;
// mime name based on mimetype id
QString mimeName = info->get( "mimeType" ).section( '/', -1 ).toUpper();
setCaption( i18n( "%1 Properties", mimeName ) );
@ -65,35 +69,69 @@ PropertiesDialog::PropertiesDialog(QWidget *parent, Okular::Document *doc)
int row = 0;
int valMaxWidth = 100;
for ( QDomNode node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
QDomElement element = node.toElement();
QString titleString = element.attribute( "title" );
QString valueString = element.attribute( "value" );
const QString filePathKey = Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::FilePath );
/* obtains the properties list, conveniently ordered */
QStringList orderedProperties;
orderedProperties << filePathKey
<< 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;
// create labels and layout them
QLabel *key = new QLabel( i18n( "%1:", titleString ), page );
QLabel *value = new KSqueezedTextLabel( valueString, page );
value->setTextInteractionFlags( Qt::TextSelectableByMouse );
layout->addWidget( key, row, 0, Qt::AlignRight );
layout->addWidget( value, row, 1 );
row++;
// refine maximum width of 'value' labels
valMaxWidth = qMax( valMaxWidth, fontMetrics().width( valueString ) );
if ( !orderedProperties.contains( titleString ) )
orderedProperties << titleString;
}
// 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 );
value->setTextInteractionFlags( Qt::TextSelectableByMouse );
QDomNodeList list;
for ( QStringList::Iterator it = orderedProperties.begin();
it != orderedProperties.end(); ++it ) {
list = docElement.elementsByTagName( (*it) );
if ( list.count() == 1 ) {
layout->addWidget( key, row, 0, Qt::AlignRight );
layout->addWidget( value, row, 1 );
QDomElement element = list.at(0).toElement();
const QString titleString = element.attribute( "title" );
const QString valueString = element.attribute( "value" );
if ( titleString.isEmpty() || valueString.isEmpty() )
continue;
// create labels and layout them
KSqueezedTextLabel *value = new KSqueezedTextLabel( valueString, page );
QWidget *key;
if ( element.tagName() == filePathKey ) {
m_toggleTitlePath = new QPushButton( page );
setToggleTitlePathText();
m_toggleTitlePath->setFlat( true );
connect( m_toggleTitlePath, SIGNAL( clicked() ), this, SLOT( filePathViewChanged() ) );
key = m_toggleTitlePath;
m_filePathNameLabel = value;
m_filePathName = valueString;
KUrl vurl( valueString );
value->setText( vurl.fileName() );
} else {
key = new QLabel( i18n( "%1:", titleString ), page );
}
value->setTextInteractionFlags( Qt::TextSelectableByMouse );
layout->addWidget( key, row, 0, Qt::AlignRight );
layout->addWidget( value, row, 1 );
row++;
// refine maximum width of 'value' labels
valMaxWidth = qMax( valMaxWidth, fontMetrics().width( valueString ) );
}
}
// FONTS
@ -166,6 +204,29 @@ void PropertiesDialog::pageChanged( KPageWidgetItem *current, KPageWidgetItem *
}
}
void PropertiesDialog::setToggleTitlePathText()
{
QString text;
if (m_showingTitle)
{
text = i18nc( "%1 is \"Title\"", "%1:", Okular::DocumentInfo::getKeyTitle( Okular::DocumentInfo::Title ) );
}
else
{
text = i18nc( "%1 is \"File Path\"", "%1:", Okular::DocumentInfo::getKeyTitle( Okular::DocumentInfo::FilePath ) );
}
m_toggleTitlePath->setText( text );
}
void PropertiesDialog::filePathViewChanged()
{
m_showingTitle = !m_showingTitle;
setToggleTitlePathText();
QString tmp(m_filePathName);
m_filePathName = m_filePathNameLabel->text();
m_filePathNameLabel->setText( tmp );
}
void PropertiesDialog::slotFontReadingProgress( int page )
{
m_fontProgressBar->setValue( m_fontProgressBar->maximum() * ( page + 1 ) / m_document->pages() );

View File

@ -20,6 +20,7 @@
class QLabel;
class QProgressBar;
class FontsListModel;
class KSqueezedTextLabel;
namespace Okular {
class Document;
@ -35,18 +36,25 @@ class PropertiesDialog : public KPageDialog
private slots:
void pageChanged( KPageWidgetItem *, KPageWidgetItem * );
void filePathViewChanged();
void slotFontReadingProgress( int page );
void slotFontReadingEnded();
void reallyStartFontReading();
void showFontsMenu(const QPoint &pos);
private:
void setToggleTitlePathText();
Okular::Document * m_document;
KPageWidgetItem * m_fontPage;
FontsListModel * m_fontModel;
QLabel * m_fontInfo;
QProgressBar * m_fontProgressBar;
bool m_fontScanStarted;
bool m_showingTitle;
QString m_filePathName;
KSqueezedTextLabel *m_filePathNameLabel;
QPushButton *m_toggleTitlePath;
};
class FontsListModel