From 8def2109ec2ce61b81e76ad6dbf2754a875ef8da Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 28 Oct 2006 19:18:36 +0000 Subject: [PATCH] change the metaData() function of the Generator to use QVariant as type for the returned value and for the 'option' parameter, this gives more flexibility svn path=/trunk/playground/graphics/okular/; revision=599847 --- core/document.cpp | 4 ++-- core/document.h | 2 +- core/generator.cpp | 4 ++-- core/generator.h | 3 ++- generators/chm/generator_chm.cpp | 10 +++++----- generators/chm/generator_chm.h | 2 +- generators/poppler/generator_pdf.cpp | 12 ++++++------ generators/poppler/generator_pdf.h | 2 +- part.cpp | 6 +++--- ui/presentationwidget.cpp | 2 +- ui/toc.cpp | 2 +- 11 files changed, 25 insertions(+), 24 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index 9ba6464dc..0714c5bc5 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -641,9 +641,9 @@ bool Document::historyAtEnd() const return d->viewportIterator == --(d->viewportHistory.end()); } -QString Document::getMetaData( const QString & key, const QString & option ) const +QVariant Document::getMetaData( const QString & key, const QVariant & option ) const { - return generator ? generator->metaData( key, option ) : QString(); + return generator ? generator->metaData( key, option ) : QVariant(); } int Document::rotation() const diff --git a/core/document.h b/core/document.h index 6404e7801..f65a48128 100644 --- a/core/document.h +++ b/core/document.h @@ -115,7 +115,7 @@ class OKULAR_EXPORT Document : public QObject bool exportTo( const QString& fileName, const ExportFormat& format ) const; bool historyAtBegin() const; bool historyAtEnd() const; - QString getMetaData( const QString & key, const QString & option = QString() ) const; + QVariant getMetaData( const QString & key, const QVariant & option = QVariant() ) const; int rotation() const; QSizeF allPagesSize() const; QString pageSizeString(int page) const; diff --git a/core/generator.cpp b/core/generator.cpp index f249f729c..0fa104ee7 100644 --- a/core/generator.cpp +++ b/core/generator.cpp @@ -125,9 +125,9 @@ bool Generator::print( KPrinter& ) return false; } -QString Generator::metaData( const QString&, const QString& ) const +QVariant Generator::metaData( const QString&, const QVariant& ) const { - return QString(); + return QVariant(); } bool Generator::reparseConfig() diff --git a/core/generator.h b/core/generator.h index ca35ff8c6..9ee201ea4 100644 --- a/core/generator.h +++ b/core/generator.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -283,7 +284,7 @@ class OKULAR_EXPORT Generator : public QObject * This method returns the meta data of the given @p key with the given @p option * of the document. */ - virtual QString metaData( const QString &key, const QString &option ) const; + virtual QVariant metaData( const QString &key, const QVariant &option ) const; /** * This method is called to tell the generator to re-parse its configuration. diff --git a/generators/chm/generator_chm.cpp b/generators/chm/generator_chm.cpp index c5ee1f903..73ec57434 100644 --- a/generators/chm/generator_chm.cpp +++ b/generators/chm/generator_chm.cpp @@ -306,7 +306,7 @@ void CHMGenerator::additionalRequestData() } else { - Okular::DocumentViewport viewport(metaData( "NamedViewport", '/' + url )); + Okular::DocumentViewport viewport( metaData( "NamedViewport", '/' + url ).toString() ); objRects.push_back( new Okular::ObjectRect ( Okular::NormalizedRect(r,xScale,yScale), false, @@ -371,12 +371,12 @@ bool CHMGenerator::supportsSearching() const return true; } -QString CHMGenerator::metaData( const QString &key, const QString &option ) const +QVariant CHMGenerator::metaData( const QString &key, const QVariant &option ) const { - if ( key == "NamedViewport" && !option.isEmpty() ) + if ( key == "NamedViewport" && !option.toString().isEmpty() ) { Okular::DocumentViewport viewport; - viewport.pageNumber = m_file->getPageNum( option ) -1; + viewport.pageNumber = m_file->getPageNum( option.toString() ) -1; if ( viewport.pageNumber >= 0 ) return viewport.toString(); } @@ -384,7 +384,7 @@ QString CHMGenerator::metaData( const QString &key, const QString &option ) cons { return m_file->Title(); } - return QString(); + return QVariant(); } /* diff --git a/generators/chm/generator_chm.h b/generators/chm/generator_chm.h index be086c96e..75f72288e 100644 --- a/generators/chm/generator_chm.h +++ b/generators/chm/generator_chm.h @@ -45,7 +45,7 @@ class CHMGenerator : public Okular::Generator bool supportsSearching() const; - QString metaData( const QString & key, const QString & option ) const; + QVariant metaData( const QString & key, const QVariant & option ) const; public slots: void slotCompleted(); diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index 8d2f5862e..ac050322c 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -687,21 +687,21 @@ bool PDFGenerator::print( KPrinter& printer ) return false; } -QString PDFGenerator::metaData( const QString & key, const QString & option ) const +QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) const { if ( key == "StartFullScreen" ) { // asking for the 'start in fullscreen mode' (pdf property) if ( pdfdoc->pageMode() == Poppler::Document::FullScreen ) - return "yes"; + return true; } - else if ( key == "NamedViewport" && !option.isEmpty() ) + else if ( key == "NamedViewport" && !option.toString().isEmpty() ) { // asking for the page related to a 'named link destination'. the // option is the link name. @see addSynopsisChildren. Okular::DocumentViewport viewport; docLock.lock(); - Poppler::LinkDestination *ld = pdfdoc->linkDestination( option ); + Poppler::LinkDestination *ld = pdfdoc->linkDestination( option.toString() ); docLock.unlock(); if ( ld ) { @@ -721,9 +721,9 @@ QString PDFGenerator::metaData( const QString & key, const QString & option ) co else if ( key == "OpenTOC" ) { if ( pdfdoc->pageMode() == Poppler::Document::UseOutlines ) - return "yes"; + return true; } - return QString(); + return QVariant(); } bool PDFGenerator::reparseConfig() diff --git a/generators/poppler/generator_pdf.h b/generators/poppler/generator_pdf.h index 8d3680779..9d3ae0ff3 100644 --- a/generators/poppler/generator_pdf.h +++ b/generators/poppler/generator_pdf.h @@ -78,7 +78,7 @@ class PDFGenerator : public Okular::Generator bool print( KPrinter& printer ); // [INHERITED] reply to some metadata requests - QString metaData( const QString & key, const QString & option ) const; + QVariant metaData( const QString & key, const QVariant & option ) const; // [INHERITED] reparse configuration bool reparseConfig(); diff --git a/part.cpp b/part.cpp index de978c331..5e58549f0 100644 --- a/part.cpp +++ b/part.cpp @@ -623,12 +623,12 @@ bool Part::openFile() m_watcher->addFile(m_file); // if the 'OpenTOC' flag is set, start presentation - if ( m_document->getMetaData( "OpenTOC" ) == "yes" && m_toolBox->isItemEnabled( 0 ) ) + if ( m_document->getMetaData( "OpenTOC" ).toBool() && m_toolBox->isItemEnabled( 0 ) ) { m_toolBox->setCurrentIndex( 0 ); } // if the 'StartFullScreen' flag is set, start presentation - if ( m_document->getMetaData( "StartFullScreen" ) == "yes" ) + if ( m_document->getMetaData( "StartFullScreen" ).toBool() ) { KMessageBox::information( m_presentationWidget, i18n("The document is going to be launched on presentation mode because the file requested it."), QString::null, "autoPresentationWarning" ); slotShowPresentation(); @@ -653,7 +653,7 @@ bool Part::openUrl(const KUrl &url) m_viewportDirty.pageNumber = -1; // if the document have a 'DocumentTitle' flag set (and it is not empty), set it as title - QString title = m_document->getMetaData( "DocumentTitle" ); + QString title = m_document->getMetaData( "DocumentTitle" ).toString(); if ( !title.isEmpty() && !title.trimmed().isEmpty() ) { emit setWindowCaption( title ); diff --git a/ui/presentationwidget.cpp b/ui/presentationwidget.cpp index 58e42b9e8..bd987cf69 100644 --- a/ui/presentationwidget.cpp +++ b/ui/presentationwidget.cpp @@ -65,7 +65,7 @@ PresentationWidget::PresentationWidget( QWidget * parent, Okular::Document * doc setAttribute( Qt::WA_DeleteOnClose ); setAttribute( Qt::WA_OpaquePaintEvent ); setObjectName( "presentationWidget" ); - QString caption = doc->getMetaData( "DocumentTitle" ); + QString caption = doc->getMetaData( "DocumentTitle" ).toString(); if ( caption.trimmed().isEmpty() ) caption = doc->currentDocument().fileName(); setWindowTitle( KInstance::makeStdCaption( caption ) ); diff --git a/ui/toc.cpp b/ui/toc.cpp index 97bfc4c2c..0eb5c0f96 100644 --- a/ui/toc.cpp +++ b/ui/toc.cpp @@ -213,7 +213,7 @@ Okular::DocumentViewport TOC::getViewport( const QDomElement &e ) const { // if the node references a viewport, get the reference and set it const QString & page = e.attribute( "ViewportName" ); - const QString & viewport = m_document->getMetaData( "NamedViewport", page ); + QString viewport = m_document->getMetaData( "NamedViewport", page ).toString(); if ( !viewport.isNull() ) return Okular::DocumentViewport( viewport ); }