From 0847edc4b7c1377bb4e83d279129be5af1b632c4 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Wed, 31 Jan 2007 21:10:00 +0000 Subject: [PATCH] Add a second parameter to requestTextPage/generateTextPage where you can specify whether the request should be synchronous or asynchronous svn path=/trunk/playground/graphics/okular/; revision=628893 --- core/document.cpp | 4 ++-- core/document.h | 2 +- core/generator.cpp | 25 +++++++++++++++++++------ core/generator.h | 7 ++++++- core/global.h | 9 +++++++++ 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index 24cffd4be..a8a6389cc 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -1320,7 +1320,7 @@ void Document::requestPixmaps( const QLinkedList< PixmapRequest * > & requests ) d->sendGeneratorRequest(); } -void Document::requestTextPage( uint page ) +void Document::requestTextPage( uint page, enum GenerationType type ) { Page * kp = d->m_pagesVector[ page ]; if ( !d->m_generator || !kp ) @@ -1328,7 +1328,7 @@ void Document::requestTextPage( uint page ) // Memory management for TextPages - d->m_generator->generateTextPage( kp ); + d->m_generator->generateTextPage( kp, type ); } void Document::addPageAnnotation( int page, Annotation * annotation ) diff --git a/core/document.h b/core/document.h index 7fc3d11af..0c76deb8f 100644 --- a/core/document.h +++ b/core/document.h @@ -309,7 +309,7 @@ class OKULAR_EXPORT Document : public QObject /** * Sends a request for text page generation for the given page @p number. */ - void requestTextPage( uint number ); + void requestTextPage( uint number, enum GenerationType type = Synchronous ); /** * Adds a new @p annotation to the given @p page. diff --git a/core/generator.cpp b/core/generator.cpp index 62ced4791..51b432d5c 100644 --- a/core/generator.cpp +++ b/core/generator.cpp @@ -134,6 +134,17 @@ void Generator::generatePixmap( PixmapRequest *request ) { d->createPixmapGenerationThread(); d->mPixmapGenerationThread->startGeneration( request ); + + /** + * We create the text page for every page that is visible to the + * user, so he can use the text extraction tools without a delay. + */ + if ( !request->page()->hasTextPage() && canGenerateTextPage() ) { + d->mTextPageReady = false; + d->createTextPageGenerationThread(); + d->mTextPageGenerationThread->startGeneration( request->page() ); + } + return; } @@ -149,15 +160,17 @@ bool Generator::canGenerateTextPage() const return d->mTextPageReady; } -void Generator::generateTextPage( Page *page ) +void Generator::generateTextPage( Page *page, enum GenerationType type ) { d->mTextPageReady = false; - if ( hasFeature( Threaded ) ) - { - d->createTextPageGenerationThread(); - d->mTextPageGenerationThread->startGeneration( page ); - return; + if ( type == Asynchronous ) { + if ( hasFeature( Threaded ) ) + { + d->createTextPageGenerationThread(); + d->mTextPageGenerationThread->startGeneration( page ); + return; + } } page->setTextPage( textPage( page ) ); diff --git a/core/generator.h b/core/generator.h index 06cb384cc..e0a81eb55 100644 --- a/core/generator.h +++ b/core/generator.h @@ -221,9 +221,14 @@ class OKULAR_EXPORT Generator : public QObject /** * This method can be called to trigger the generation of * a text page for the given @p page. + * + * The generation is done synchronous or asynchronous, depending + * on the @p type parameter and the capabilities of the + * generator (e.g. multithreading). + * * @see TextPage */ - virtual void generateTextPage( Page * page ); + virtual void generateTextPage( Page * page, enum GenerationType type = Synchronous ); /** * Returns the general information object of the document or 0 if diff --git a/core/global.h b/core/global.h index 57c4cda5f..deb23ad04 100644 --- a/core/global.h +++ b/core/global.h @@ -48,6 +48,15 @@ enum Rotation Rotation270 = 3 ///< Rotated 2700 degrees clockwise. }; +/** + * Describes the type of generation of objects + */ +enum GenerationType +{ + Synchronous, ///< Will create the object in a synchronous way + Asynchronous ///< Will create the object in an asynchronous way +}; + } #endif