stop gracefully the font extraction thread when closing a document or the properties dialog; make the thread deleting itself when finished

svn path=/trunk/KDE/kdegraphics/okular/; revision=685437
remotes/origin/KDE/4.0
Pino Toscano 19 years ago
parent ff308d7f83
commit 964424d62f
  1. 23
      core/document.cpp
  2. 6
      core/document.h
  3. 11
      core/generator_p.cpp
  4. 2
      core/generator_p.h
  5. 5
      ui/propertiesdialog.cpp
  6. 1
      ui/propertiesdialog.h

@ -120,7 +120,6 @@ class Okular::DocumentPrivate
m_saveBookmarksTimer( 0 ),
m_generator( 0 ),
m_generatorsLoaded( false ),
m_fontThread( 0 ),
m_fontsCached( false )
{
}
@ -207,7 +206,7 @@ class Okular::DocumentPrivate
// cache of the mimetype we support
QStringList m_supportedMimeTypes;
FontExtractionThread * m_fontThread;
QPointer< FontExtractionThread > m_fontThread;
bool m_fontsCached;
FontInfo::List m_fontsCache;
};
@ -718,7 +717,6 @@ void DocumentPrivate::fontReadingProgress( int page )
if ( page == (int)m_parent->pages() )
{
emit m_parent->fontReadingEnded();
delete m_fontThread;
m_fontThread = 0;
m_fontsCached = true;
}
@ -990,6 +988,14 @@ void Document::setupGui( KActionCollection *ac, QToolBox *tBox )
void Document::closeDocument()
{
if ( d->m_fontThread )
{
disconnect( d->m_fontThread, 0, this, 0 );
d->m_fontThread->stopExtraction();
d->m_fontThread->wait();
d->m_fontThread = 0;
}
// close the current document and save document info if a document is still opened
if ( d->m_generator && d->m_pagesVector.size() > 0 )
{
@ -1230,6 +1236,17 @@ void Document::startFontReading()
d->m_fontThread->startExtraction( /*d->m_generator->hasFeature( Generator::Threaded )*/true );
}
void Document::stopFontReading()
{
if ( !d->m_fontThread )
return;
disconnect( d->m_fontThread, 0, this, 0 );
d->m_fontThread->stopExtraction();
d->m_fontThread = 0;
d->m_fontsCache.clear();
}
bool Document::canProvideFontInformation() const
{
return d->m_generator ? d->m_generator->hasFeature( Generator::FontInfo ) : false;

@ -146,6 +146,12 @@ class OKULAR_EXPORT Document : public QObject
*/
void startFontReading();
/**
* Force the termination of the reading of the informations about the
* fonts in the document, if running.
*/
void stopFontReading();
/**
* Whether the current document can provide information about the
* fonts used in it.

@ -89,7 +89,7 @@ void TextPageGenerationThread::run()
FontExtractionThread::FontExtractionThread( Generator *generator, int pages )
: mGenerator( generator ), mNumOfPages( pages )
: mGenerator( generator ), mNumOfPages( pages ), mGoOn( true )
{
}
@ -97,17 +97,24 @@ void FontExtractionThread::startExtraction( bool async )
{
if ( async )
{
connect( this, SIGNAL( finished() ), this, SLOT( deleteLater() ) );
start( QThread::InheritPriority );
}
else
{
run();
deleteLater();
}
}
void FontExtractionThread::stopExtraction()
{
mGoOn = false;
}
void FontExtractionThread::run()
{
for ( int i = 1; i <= mNumOfPages; ++i )
for ( int i = 1; i <= mNumOfPages && mGoOn; ++i )
{
FontInfo::List list = mGenerator->fontsForPage( i );
foreach ( const FontInfo& fi, list )

@ -112,6 +112,7 @@ class FontExtractionThread : public QThread
FontExtractionThread( Generator *generator, int pages );
void startExtraction( bool async );
void stopExtraction();
Q_SIGNALS:
void gotFont( const Okular::FontInfo& );
@ -123,6 +124,7 @@ class FontExtractionThread : public QThread
private:
Generator *mGenerator;
int mNumOfPages;
bool mGoOn;
};
}

@ -135,6 +135,11 @@ PropertiesDialog::PropertiesDialog(QWidget *parent, Okular::Document *doc)
this, SLOT( pageChanged( KPageWidgetItem *, KPageWidgetItem * ) ) );
}
PropertiesDialog::~PropertiesDialog()
{
m_document->stopFontReading();
}
void PropertiesDialog::pageChanged( KPageWidgetItem *current, KPageWidgetItem * )
{
if ( current == m_fontPage && !m_fontScanStarted )

@ -31,6 +31,7 @@ class PropertiesDialog : public KPageDialog
public:
PropertiesDialog( QWidget *parent, Okular::Document *doc );
virtual ~PropertiesDialog();
private slots:
void pageChanged( KPageWidgetItem *, KPageWidgetItem * );

Loading…
Cancel
Save