Small addition to the Ganarator API: bool closeDocument().

Now every generator has to implement this one and put (if necessary) all the code for cleaning up all the stuff related to the currently open document.
For now the return value it is not read, but generators as strongly suggested to return tru o false, whether all the operations in there went fine.

svn path=/trunk/playground/graphics/okular/; revision=562210
This commit is contained in:
Pino Toscano 2006-07-14 10:54:29 +00:00
parent 9b55ffedd4
commit b6d7a36eda
16 changed files with 87 additions and 30 deletions

View file

@ -317,9 +317,12 @@ void KPDFDocument::setupGUI(KActionCollection* ac, QToolBox* tBox )
void KPDFDocument::closeDocument()
{
// save document info if a document is still opened
// close the current document and save document info if a document is still opened
if ( generator && pages_vector.size() > 0 )
{
generator->closeDocument();
saveDocumentInfo();
}
// stop timers
if ( d->memCheckTimer )

View file

@ -65,6 +65,8 @@ class OKULAR_EXPORT Generator : public QObject
/** virtual methods to reimplement **/
// load a document and fill up the pagesVector
virtual bool loadDocument( const QString & fileName, QVector< KPDFPage * > & pagesVector ) = 0;
// the current document is no more useful, close it
virtual bool closeDocument() = 0;
// page contents generation
virtual bool canGeneratePixmap( bool async ) = 0;

View file

@ -45,10 +45,6 @@ bool CHMGenerator::loadDocument( const QString & fileName, QVector< KPDFPage * >
m_file=new CHMFile (fileName);
m_file->ParseAndFillTopicsTree (&m_docSyn);
// delete the document information of the old document
delete m_docInfo;
m_docInfo=0;
QPrinter p;
p.setPageSize(static_cast< QPrinter::PageSize >( KGlobal::locale()->pageSize() ));
p.setFullPage(true);
@ -74,6 +70,15 @@ bool CHMGenerator::loadDocument( const QString & fileName, QVector< KPDFPage * >
return true;
}
bool CHMGenerator::closeDocument()
{
// delete the document information of the old document
delete m_docInfo;
m_docInfo=0;
return true;
}
void CHMGenerator::preparePageForSyncOperation( int zoom , const QString & url)
{
KUrl pAddress= "ms-its:" + m_fileName + "::" + url;

View file

@ -28,6 +28,7 @@ class CHMGenerator : public Generator
public:
CHMGenerator(KPDFDocument * doc );
bool loadDocument( const QString & fileName, QVector< KPDFPage * > & pagesVector );
bool closeDocument();
const DocumentInfo * generateDocumentInfo();
const DocumentSynopsis * generateDocumentSynopsis();

View file

@ -61,11 +61,6 @@ DjVuGenerator::DjVuGenerator( KPDFDocument * doc ) : Generator ( doc ),
bool DjVuGenerator::loadDocument( const QString & fileName, QVector< KPDFPage * > & pagesVector )
{
delete m_docInfo;
m_docInfo = 0;
delete m_docSyn;
m_docSyn = 0;
if ( !m_djvu->openFile( fileName ) )
return false;
@ -75,6 +70,18 @@ bool DjVuGenerator::loadDocument( const QString & fileName, QVector< KPDFPage *
return true;
}
bool DjVuGenerator::closeDocument()
{
delete m_docInfo;
m_docInfo = 0;
delete m_docSyn;
m_docSyn = 0;
ready = false;
return true;
}
bool DjVuGenerator::canGeneratePixmap( bool /*async*/ )
{
return ready;

View file

@ -21,6 +21,7 @@ class DjVuGenerator : public Generator
public:
DjVuGenerator( KPDFDocument * doc );
bool loadDocument( const QString & fileName, QVector<KPDFPage*> & pagesVector );
bool closeDocument();
// pixmap generation
bool canGeneratePixmap( bool async );

View file

@ -39,13 +39,6 @@ bool DviGenerator::loadDocument( const QString & fileName, QVector< KPDFPage * >
//kDebug() << "file: " << qPrintable( fileName ) << endl;
KUrl base( fileName );
delete m_docInfo;
m_docInfo = 0;
delete m_docSynopsis;
m_docSynopsis = 0;
delete m_dviRenderer;
m_dviRenderer = new dviRenderer();
if ( ! m_dviRenderer->setFile( fileName, base ) )
return false;
@ -59,6 +52,20 @@ bool DviGenerator::loadDocument( const QString & fileName, QVector< KPDFPage * >
return true;
}
bool DviGenerator::closeDocument()
{
delete m_docInfo;
m_docInfo = 0;
delete m_docSynopsis;
m_docSynopsis = 0;
delete m_dviRenderer;
m_dviRenderer = 0;
ready = false;
return true;
}
bool DviGenerator::canGeneratePixmap ( bool /*async*/ )
{
return ready;

View file

@ -23,6 +23,7 @@ class DviGenerator : public Generator
public:
DviGenerator( KPDFDocument * doc );
bool loadDocument( const QString & fileName, QVector< KPDFPage * > & pagesVector );
bool closeDocument();
bool canGeneratePixmap( bool async );
void generatePixmap( PixmapRequest * request );

View file

@ -217,6 +217,11 @@ bool GSGenerator::loadDocument( const QString & fileName, QVector< KPDFPage * >
return loadDocumentWithDSC(name,pagesVector,ps);
}
bool GSGenerator::closeDocument()
{
return true;
}
void GSGenerator::slotPixmapGenerated(const QImage* img)
{
kWarning() << "SlotSyncGenerated! - finished m_sRequest id=" << m_sRequest->id << " " <<m_sRequest->width << "x" << m_sRequest->height << "@" << m_sRequest->pageNumber << " async == " << m_sRequest->async << endl;

View file

@ -26,6 +26,7 @@ class GSGenerator : public Generator
/** virtual methods to reimplement **/
// load a document and fill up the pagesVector
bool loadDocument( const QString & fileName, QVector< KPDFPage * > & pagesVector );
bool closeDocument();
// Document description and Table of contents
const DocumentInfo * generateDocumentInfo();

View file

@ -24,7 +24,6 @@ KIMGIOGenerator::KIMGIOGenerator( KPDFDocument * document ) : Generator( documen
KIMGIOGenerator::~KIMGIOGenerator()
{
delete m_pix;
}
bool KIMGIOGenerator::loadDocument( const QString & fileName, QVector<KPDFPage*> & pagesVector )
@ -39,6 +38,14 @@ bool KIMGIOGenerator::loadDocument( const QString & fileName, QVector<KPDFPage*>
return true;
}
bool KIMGIOGenerator::closeDocument()
{
delete m_pix;
m_pix = 0;
return true;
}
bool KIMGIOGenerator::canGeneratePixmap( bool /* async */ )
{
return true;

View file

@ -21,6 +21,7 @@ class KIMGIOGenerator : public Generator
// [INHERITED] load a document and fill up the pagesVector
bool loadDocument( const QString & fileName, QVector<KPDFPage*> & pagesVector );
bool closeDocument();
// [INHERITED] perform actions on document / pages
bool canGeneratePixmap( bool async );

View file

@ -199,16 +199,12 @@ PDFGenerator::PDFGenerator( KPDFDocument * doc )
PDFGenerator::~PDFGenerator()
{
// first stop and delete the generator thread
// stop and delete the generator thread
if ( generatorThread )
{
generatorThread->wait();
delete generatorThread;
}
// remove other internal objects
docLock.lock();
delete pdfdoc;
docLock.unlock();
}
void PDFGenerator::setOrientation(QVector<KPDFPage*> & pagesVector, int orientation)
@ -298,6 +294,17 @@ bool PDFGenerator::loadDocument( const QString & filePath, QVector<KPDFPage*> &
return true;
}
bool PDFGenerator::closeDocument()
{
// remove internal objects
docLock.lock();
delete pdfdoc;
pdfdoc = 0;
docLock.unlock();
return true;
}
void PDFGenerator::loadPages(QVector<KPDFPage*> &pagesVector, int rotation, bool clear)
{
// TODO XPDF 3.01 check

View file

@ -50,6 +50,7 @@ class PDFGenerator : public Generator
// [INHERITED] load a document and fill up the pagesVector
bool loadDocument( const QString & fileName, QVector<KPDFPage*> & pagesVector );
bool closeDocument();
void loadPages(QVector<KPDFPage*> &pagesVector, int rotation=-1, bool clear=false);
// [INHERITED] document information
const DocumentInfo * generateDocumentInfo();

View file

@ -165,6 +165,19 @@ TIFFGenerator::~TIFFGenerator()
}
bool TIFFGenerator::loadDocument( const QString & fileName, QVector<KPDFPage*> & pagesVector )
{
d->tiff = TIFFOpen( QFile::encodeName( fileName ), "r" );
if ( !d->tiff )
return false;
loadPages( pagesVector, 0 );
ready = true;
return true;
}
bool TIFFGenerator::closeDocument()
{
// closing the old document
if ( d->tiff )
@ -175,13 +188,7 @@ bool TIFFGenerator::loadDocument( const QString & fileName, QVector<KPDFPage*> &
m_docInfo = 0;
}
d->tiff = TIFFOpen( QFile::encodeName( fileName ), "r" );
if ( !d->tiff )
return false;
loadPages( pagesVector, 0 );
ready = true;
ready = false;
return true;
}

View file

@ -22,6 +22,7 @@ class TIFFGenerator : public Generator
virtual ~TIFFGenerator();
bool loadDocument( const QString & fileName, QVector<KPDFPage*> & pagesVector );
bool closeDocument();
bool canGeneratePixmap( bool async );
void generatePixmap( PixmapRequest * request );