Commit 93c1d384 authored by Enrico Ros's avatar Enrico Ros

Implemented history (implementation is inside Document. actions (2) are in

 Part). Implemented 'history (xpdf's LinkAction) links'. History depth is
 100 steps by default (this is enough for sure, clicking 100 times on a
 button is not an easy task :-).

Minor issues (removed half TODOs in code, all FIXMEs are already removed):
Invoke mailer on 'mailto:' links inst instead of konqueror.
Actions cleanup: disable actions like 'print', 'preview', 'save to..', etc
 when there isn't an active document. Added history actions to the toolbar
 in place of the 'prev_page' and 'next_page' ones. Fixed open+open_recent
 action tooltip and behavior.
Move definition and implementation of PagePainter class to ui/pagepainter
 from core/page.
Valgrinded and leakchecked (2 memory leaks spotted and fixed (missing
 contents deletion in KPDFGeneratorThread and missing deletion of
 PixmapRequests on cancel in Document::requestPixmaps())).

svn path=/trunk/kdegraphics/kpdf/; revision=382960
parent e65c7058
...@@ -6,16 +6,13 @@ Legend: ...@@ -6,16 +6,13 @@ Legend:
MRG - MeRGed (code from a branch or a patch) MRG - MeRGed (code from a branch or a patch)
Status: Status:
-> 2005-01-20: Stable. Apart from a bad memory deallocation mechanism -> 2005-01-27: Stable and leakchecked. Usability: needs testing.
the core is ready for a public release. Usability: needs testing. -> 2005-01-20: Stable. Apart from a bad (but still safe) memory deallocation
next steps: empty the in-progress list and keep it empty until release. mechanism the core is ready for a public release.
In progress: In progress 3.4 features (deadline is 2k5-Feb-2):
-> save/restore history (partially committed)
-> new word highlighting for searches / other highlights -> new word highlighting for searches / other highlights
-> implement history (for actionNamed and restoring previous viewports on navigation)
High priority 3.4 features (deadline is 2k5-Feb-2):
- empty! -
More items (first items will enter 'In progress list' first): More items (first items will enter 'In progress list' first):
-> go to next/previous bookmark actions (showing in thumbnailslist rmb popup too) -> go to next/previous bookmark actions (showing in thumbnailslist rmb popup too)
...@@ -28,9 +25,8 @@ More items (first items will enter 'In progress list' first): ...@@ -28,9 +25,8 @@ More items (first items will enter 'In progress list' first):
-> show Viewport in ThumbnailsList (blended/contour) -> show Viewport in ThumbnailsList (blended/contour)
-> history as a toolbox child (collecting Doc's viewport changes notifications) -> history as a toolbox child (collecting Doc's viewport changes notifications)
-> Delay TOC (DocumentSynapsis) generation (and move it on thread) -> Delay TOC (DocumentSynapsis) generation (and move it on thread)
-> refactor ThumbnailsList to do internal rendering as pageview does (way -> refactor ThumbnailsList to do internal rendering as pageview does (way faster
faster than using QScrollView + inserted Widgets and saves 8% on document than using QScrollView + inserted Widgets and saves 8% on document loading)
loading)
-> move toolbar view actions in the PageView instead of the part. maybe.. or not... -> move toolbar view actions in the PageView instead of the part. maybe.. or not...
-> usability: layout 2PPV [1 2,3 4,5 6] -> [1,2 3,4 5]. add option for 'ebook' style alignment -> usability: layout 2PPV [1 2,3 4,5 6] -> [1,2 3,4 5]. add option for 'ebook' style alignment
-> usability: trigger redraw on 'filter text' on current page -> usability: trigger redraw on 'filter text' on current page
...@@ -69,7 +65,7 @@ More items (first items will enter 'In progress list' first): ...@@ -69,7 +65,7 @@ More items (first items will enter 'In progress list' first):
-> core: pdf forms support -> core: pdf forms support
-> add OCR for building TextPages out of pure graphical (aka scanned) pages -> add OCR for building TextPages out of pure graphical (aka scanned) pages
-> rotate the whole document / individual pages -> rotate the whole document / individual pages
-> presentation: implement transitions (6/11 done) -> presentation: implement missing transitions (6/11 done)
-> presentation: add some gfx tools (like a red pencil) -> presentation: add some gfx tools (like a red pencil)
-> presentation: save a flag (to the xml) to open a pdf in presentation mode -> presentation: save a flag (to the xml) to open a pdf in presentation mode
-> presentation: link following (difficult due to pagerects related to pageview pixmap only) -> presentation: link following (difficult due to pagerects related to pageview pixmap only)
...@@ -85,6 +81,8 @@ More items (first items will enter 'In progress list' first): ...@@ -85,6 +81,8 @@ More items (first items will enter 'In progress list' first):
-> export: export to other formats keeping formatting (a dream.. except for PNG :-) (PS is easy, we just have PSOutputDev that does it :-D) -> export: export to other formats keeping formatting (a dream.. except for PNG :-) (PS is easy, we just have PSOutputDev that does it :-D)
Done (newest features come first): Done (newest features come first):
-> FIX: complete valgrind check and leakfix (2 leaks were present) [27-Jan-04]
-> ADD: history (100 steps) and forward/back actions
-> ADD: rmb popup on thumbnailslist (the popup shared with pageView: same behavior) -> ADD: rmb popup on thumbnailslist (the popup shared with pageView: same behavior)
-> ADD: display 'current page' / 'total pages' with analog indicator, active labels, etc -> ADD: display 'current page' / 'total pages' with analog indicator, active labels, etc
-> CHG: Presentation mode is now Ctrl+Shift+p instead of F9 because it was colliding with Konqueror's toggle sidebar -> CHG: Presentation mode is now Ctrl+Shift+p instead of F9 because it was colliding with Konqueror's toggle sidebar
......
...@@ -47,10 +47,13 @@ class KPDFDocumentPrivate ...@@ -47,10 +47,13 @@ class KPDFDocumentPrivate
bool filterCase; bool filterCase;
// cached stuff // cached stuff
DocumentViewport viewport;
QString docFileName; QString docFileName;
QString xmlFileName; QString xmlFileName;
// viewport stuff
QValueList< DocumentViewport > viewportHistory;
QValueList< DocumentViewport >::iterator viewportIterator;
// observers / requests / allocator stuff // observers / requests / allocator stuff
QMap< int, DocumentObserver * > observers; QMap< int, DocumentObserver * > observers;
QValueList< PixmapRequest * > pixmapRequestsStack; QValueList< PixmapRequest * > pixmapRequestsStack;
...@@ -144,12 +147,12 @@ bool KPDFDocument::openDocument( const QString & docFile ) ...@@ -144,12 +147,12 @@ bool KPDFDocument::openDocument( const QString & docFile )
// 3. setup observers inernal lists and data // 3. setup observers inernal lists and data
processPageList( true ); processPageList( true );
// 4. set initial page (restoring previous page saved in xml) // 4. set initial page (restoring the page saved in xml if loaded)
DocumentViewport loadedViewport = d->viewport; DocumentViewport loadedViewport = (*d->viewportIterator);
if ( loadedViewport.pageNumber < 0 ) if ( loadedViewport.pageNumber != -1 )
loadedViewport.pageNumber = 0; (*d->viewportIterator) = DocumentViewport();
else else
d->viewport = DocumentViewport(); loadedViewport.pageNumber = 0;
setViewport( loadedViewport ); setViewport( loadedViewport );
// start bookmark saver timer // start bookmark saver timer
...@@ -212,7 +215,9 @@ void KPDFDocument::closeDocument() ...@@ -212,7 +215,9 @@ void KPDFDocument::closeDocument()
d->allocatedPixmapsFifo.clear(); d->allocatedPixmapsFifo.clear();
// reset internal variables // reset internal variables
d->viewport = DocumentViewport(); d->viewportHistory.clear();
d->viewportHistory.append( DocumentViewport() );
d->viewportIterator = d->viewportHistory.begin();
d->searchPage = -1; d->searchPage = -1;
d->allocatedPixmapsTotalMemory = 0; d->allocatedPixmapsTotalMemory = 0;
} }
...@@ -295,12 +300,12 @@ const KPDFPage * KPDFDocument::page( uint n ) const ...@@ -295,12 +300,12 @@ const KPDFPage * KPDFDocument::page( uint n ) const
const DocumentViewport & KPDFDocument::viewport() const const DocumentViewport & KPDFDocument::viewport() const
{ {
return d->viewport; return (*d->viewportIterator);
} }
uint KPDFDocument::currentPage() const uint KPDFDocument::currentPage() const
{ {
return d->viewport.pageNumber; return (*d->viewportIterator).pageNumber;
} }
uint KPDFDocument::pages() const uint KPDFDocument::pages() const
...@@ -313,6 +318,16 @@ bool KPDFDocument::okToPrint() const ...@@ -313,6 +318,16 @@ bool KPDFDocument::okToPrint() const
return generator ? generator->isAllowed( Generator::Print ) : false; return generator ? generator->isAllowed( Generator::Print ) : false;
} }
bool KPDFDocument::historyAtBegin() const
{
return d->viewportIterator == d->viewportHistory.begin();
}
bool KPDFDocument::historyAtEnd() const
{
return d->viewportIterator == --(d->viewportHistory.end());
}
QString KPDFDocument::getMetaData( const QString & key, const QString & option ) const QString KPDFDocument::getMetaData( const QString & key, const QString & option ) const
{ {
return generator ? generator->getMetaData( key, option ) : QString(); return generator ? generator->getMetaData( key, option ) : QString();
...@@ -320,8 +335,15 @@ QString KPDFDocument::getMetaData( const QString & key, const QString & option ) ...@@ -320,8 +335,15 @@ QString KPDFDocument::getMetaData( const QString & key, const QString & option )
void KPDFDocument::requestPixmaps( const QValueList< PixmapRequest * > & requests ) void KPDFDocument::requestPixmaps( const QValueList< PixmapRequest * > & requests )
{ {
if ( !generator || requests.isEmpty() ) if ( !generator )
{
// delete requests..
QValueList< PixmapRequest * >::const_iterator rIt = requests.begin(), rEnd = requests.end();
for ( ; rIt != rEnd; ++rIt )
delete *rIt;
// ..and return
return; return;
}
// 1. [CLEAN STACK] remove previous requests of requesterID // 1. [CLEAN STACK] remove previous requests of requesterID
int requesterID = requests.first()->id; int requesterID = requests.first()->id;
...@@ -329,7 +351,11 @@ void KPDFDocument::requestPixmaps( const QValueList< PixmapRequest * > & request ...@@ -329,7 +351,11 @@ void KPDFDocument::requestPixmaps( const QValueList< PixmapRequest * > & request
while ( sIt != sEnd ) while ( sIt != sEnd )
{ {
if ( (*sIt)->id == requesterID ) if ( (*sIt)->id == requesterID )
{
// delete request and remove it from stack
delete *sIt;
sIt = d->pixmapRequestsStack.remove( sIt ); sIt = d->pixmapRequestsStack.remove( sIt );
}
else else
++sIt; ++sIt;
} }
...@@ -342,7 +368,11 @@ void KPDFDocument::requestPixmaps( const QValueList< PixmapRequest * > & request ...@@ -342,7 +368,11 @@ void KPDFDocument::requestPixmaps( const QValueList< PixmapRequest * > & request
// set the 'page field' (see PixmapRequest) and check if it is valid // set the 'page field' (see PixmapRequest) and check if it is valid
PixmapRequest * request = *rIt; PixmapRequest * request = *rIt;
if ( !(request->page = pages_vector[ request->pageNumber ]) ) if ( !(request->page = pages_vector[ request->pageNumber ]) )
{
// skip requests referencing an invalid page (must not happen)
delete request;
continue; continue;
}
if ( !request->async ) if ( !request->async )
request->priority = 0; request->priority = 0;
...@@ -386,18 +416,18 @@ void KPDFDocument::requestTextPage( uint page ) ...@@ -386,18 +416,18 @@ void KPDFDocument::requestTextPage( uint page )
void KPDFDocument::setNextPage() void KPDFDocument::setNextPage()
{ {
// advance page and set viewport on observers // advance page and set viewport on observers
if ( d->viewport.pageNumber < (int)pages_vector.count() - 1 ) if ( (*d->viewportIterator).pageNumber < (int)pages_vector.count() - 1 )
setViewport( DocumentViewport( d->viewport.pageNumber + 1 ) ); setViewport( DocumentViewport( (*d->viewportIterator).pageNumber + 1 ) );
} }
void KPDFDocument::setPrevPage() void KPDFDocument::setPrevPage()
{ {
// go to previous page and set viewport on observers // go to previous page and set viewport on observers
if ( d->viewport.pageNumber > 0 ) if ( (*d->viewportIterator).pageNumber > 0 )
setViewport( DocumentViewport( d->viewport.pageNumber - 1 ) ); setViewport( DocumentViewport( (*d->viewportIterator).pageNumber - 1 ) );
} }
*/ */
void KPDFDocument::setViewportPage( int page, int id ) void KPDFDocument::setViewportPage( int page, int excludeId )
{ {
// clamp page in range [0 ... numPages-1] // clamp page in range [0 ... numPages-1]
if ( page < 0 ) if ( page < 0 )
...@@ -406,22 +436,39 @@ void KPDFDocument::setViewportPage( int page, int id ) ...@@ -406,22 +436,39 @@ void KPDFDocument::setViewportPage( int page, int id )
page = pages_vector.count() - 1; page = pages_vector.count() - 1;
// make a viewport from the page and broadcast it // make a viewport from the page and broadcast it
setViewport( DocumentViewport( page ), id ); setViewport( DocumentViewport( page ), excludeId );
} }
void KPDFDocument::setViewport( const DocumentViewport & viewport, int id ) void KPDFDocument::setViewport( const DocumentViewport & viewport, int excludeId )
{ {
// if already broadcasted, don't redo it // if already broadcasted, don't redo it
if ( viewport == d->viewport ) DocumentViewport & oldViewport = *d->viewportIterator;
if ( viewport == oldViewport )
kdDebug() << "setViewport with the same viewport." << endl; kdDebug() << "setViewport with the same viewport." << endl;
// set internal viewport // set internal viewport taking care of history
d->viewport = viewport; if ( oldViewport.pageNumber == viewport.pageNumber || oldViewport.pageNumber == -1 )
{
// if page is unchanged save the viewport at current position in queue
oldViewport = viewport;
}
else
{
// remove elements after viewportIterator in queue
d->viewportHistory.erase( ++d->viewportIterator, d->viewportHistory.end() );
// keep the list to a reasonable size by removing head when needed
if ( d->viewportHistory.count() >= 100 )
d->viewportHistory.pop_front();
// notify change to all other (different from id) viewports // add the item at the end of the queue
d->viewportIterator = d->viewportHistory.append( viewport );
}
// notify change to all other (different from id) observers
QMap< int, DocumentObserver * >::iterator it = d->observers.begin(), end = d->observers.end(); QMap< int, DocumentObserver * >::iterator it = d->observers.begin(), end = d->observers.end();
for ( ; it != end ; ++ it ) for ( ; it != end ; ++ it )
if ( it.key() != id ) if ( it.key() != excludeId )
(*it)->notifyViewportChanged(); (*it)->notifyViewportChanged();
// [MEM] raise position of currently viewed page in allocation queue // [MEM] raise position of currently viewed page in allocation queue
...@@ -446,6 +493,30 @@ void KPDFDocument::setViewport( const DocumentViewport & viewport, int id ) ...@@ -446,6 +493,30 @@ void KPDFDocument::setViewport( const DocumentViewport & viewport, int id )
} }
} }
void KPDFDocument::setPrevViewport()
// restore viewport from the history
{
if ( d->viewportIterator != d->viewportHistory.begin() )
{
// restore previous viewport and notify it to observers
--d->viewportIterator;
foreachObserver( notifyViewportChanged() );
}
}
void KPDFDocument::setNextViewport()
// restore next viewport from the history
{
QValueList< DocumentViewport >::iterator nextIterator = d->viewportIterator;
++nextIterator;
if ( nextIterator != d->viewportHistory.end() )
{
// restore next viewport and notify it to observers
++d->viewportIterator;
foreachObserver( notifyViewportChanged() );
}
}
bool KPDFDocument::findText( const QString & string, bool keepCase, bool findAhead ) bool KPDFDocument::findText( const QString & string, bool keepCase, bool findAhead )
{ {
// turn selection drawing off on filtered pages // turn selection drawing off on filtered pages
...@@ -460,7 +531,7 @@ bool KPDFDocument::findText( const QString & string, bool keepCase, bool findAhe ...@@ -460,7 +531,7 @@ bool KPDFDocument::findText( const QString & string, bool keepCase, bool findAhe
} }
// continue checking last SearchPage first (if it is the current page) // continue checking last SearchPage first (if it is the current page)
int currentPage = d->viewport.pageNumber; int currentPage = (*d->viewportIterator).pageNumber;
int pageCount = pages_vector.count(); int pageCount = pages_vector.count();
KPDFPage * foundPage = 0, KPDFPage * foundPage = 0,
* lastPage = (d->searchPage > -1) ? pages_vector[ d->searchPage ] : 0; * lastPage = (d->searchPage > -1) ? pages_vector[ d->searchPage ] : 0;
...@@ -622,21 +693,21 @@ void KPDFDocument::processLink( const KPDFLink * link ) ...@@ -622,21 +693,21 @@ void KPDFDocument::processLink( const KPDFLink * link )
setViewportPage( 0 ); setViewportPage( 0 );
break; break;
case KPDFLinkAction::PagePrev: case KPDFLinkAction::PagePrev:
if ( d->viewport.pageNumber > 0 ) if ( (*d->viewportIterator).pageNumber > 0 )
setViewportPage( d->viewport.pageNumber - 1 ); setViewportPage( (*d->viewportIterator).pageNumber - 1 );
break; break;
case KPDFLinkAction::PageNext: case KPDFLinkAction::PageNext:
if ( d->viewport.pageNumber < (int)pages_vector.count() - 1 ) if ( (*d->viewportIterator).pageNumber < (int)pages_vector.count() - 1 )
setViewportPage( d->viewport.pageNumber + 1 ); setViewportPage( (*d->viewportIterator).pageNumber + 1 );
break; break;
case KPDFLinkAction::PageLast: case KPDFLinkAction::PageLast:
setViewportPage( pages_vector.count() - 1 ); setViewportPage( pages_vector.count() - 1 );
break; break;
case KPDFLinkAction::HistoryBack: case KPDFLinkAction::HistoryBack:
{} //TODO setPrevViewport();
break; break;
case KPDFLinkAction::HistoryForward: case KPDFLinkAction::HistoryForward:
{} //TODO setNextViewport();
break; break;
case KPDFLinkAction::Quit: case KPDFLinkAction::Quit:
kapp->quit(); kapp->quit();
...@@ -652,17 +723,23 @@ void KPDFDocument::processLink( const KPDFLink * link ) ...@@ -652,17 +723,23 @@ void KPDFDocument::processLink( const KPDFLink * link )
case KPDFLink::Browse: { case KPDFLink::Browse: {
const KPDFLinkBrowse * browse = static_cast< const KPDFLinkBrowse * >( link ); const KPDFLinkBrowse * browse = static_cast< const KPDFLinkBrowse * >( link );
// get service for web browsing TODO: check for "mailto:" links // if the url is a mailto one, invoke mailer
KService::Ptr ptr = KServiceTypeProfile::preferredService("text/html", "Application"); if ( browse->url().startsWith( "mailto:", false ) )
KURL::List lst; kapp->invokeMailer( browse->url() );
// append 'url' parameter to the service and run it else
lst.append( browse->url() ); {
KRun::run( *ptr, lst ); // get service for web browsing
KService::Ptr ptr = KServiceTypeProfile::preferredService("text/html", "Application");
KURL::List lst;
// append 'url' parameter to the service and run it
lst.append( browse->url() );
KRun::run( *ptr, lst );
}
} break; } break;
case KPDFLink::Movie: case KPDFLink::Movie:
//const KPDFLinkMovie * browse = static_cast< const KPDFLinkMovie * >( link ); //const KPDFLinkMovie * browse = static_cast< const KPDFLinkMovie * >( link );
// TODO this // TODO this (Movie link)
break; break;
} }
} }
...@@ -738,7 +815,7 @@ void KPDFDocument::sendGeneratorRequest() ...@@ -738,7 +815,7 @@ void KPDFDocument::sendGeneratorRequest()
generator->generatePixmap( request ); generator->generatePixmap( request );
} }
void KPDFDocument::cleanupPixmapMemory( int /*bytesOffset*/ ) void KPDFDocument::cleanupPixmapMemory( int /*sure? bytesOffset*/ )
{ {
// [MEM] choose memory parameters based on configuration profile // [MEM] choose memory parameters based on configuration profile
int clipValue = -1; int clipValue = -1;
...@@ -901,7 +978,7 @@ void KPDFDocument::loadDocumentInfo() ...@@ -901,7 +978,7 @@ void KPDFDocument::loadDocumentInfo()
if ( infoElement.tagName() == "activePage" ) if ( infoElement.tagName() == "activePage" )
{ {
if ( infoElement.hasAttribute( "viewport" ) ) if ( infoElement.hasAttribute( "viewport" ) )
d->viewport = DocumentViewport( infoElement.attribute( "viewport" ) ); *d->viewportIterator = DocumentViewport( infoElement.attribute( "viewport" ) );
} }
infoNode = infoNode.nextSibling(); infoNode = infoNode.nextSibling();
} }
...@@ -984,7 +1061,6 @@ void KPDFDocument::saveDocumentInfo() const ...@@ -984,7 +1061,6 @@ void KPDFDocument::saveDocumentInfo() const
if ( d->docFileName.isNull() ) if ( d->docFileName.isNull() )
return; return;
//kdDebug() << "Using '" << d->xmlFileName << "' as document info file for saving." << endl;
QFile infoFile( d->xmlFileName ); QFile infoFile( d->xmlFileName );
if (infoFile.open( IO_WriteOnly | IO_Truncate) ) if (infoFile.open( IO_WriteOnly | IO_Truncate) )
{ {
...@@ -1012,10 +1088,21 @@ void KPDFDocument::saveDocumentInfo() const ...@@ -1012,10 +1088,21 @@ void KPDFDocument::saveDocumentInfo() const
QDomElement generalInfo = doc.createElement( "generalInfo" ); QDomElement generalInfo = doc.createElement( "generalInfo" );
root.appendChild( generalInfo ); root.appendChild( generalInfo );
// <general info><activePage />
QDomElement activePage = doc.createElement( "activePage" ); QDomElement activePage = doc.createElement( "activePage" );
activePage.setAttribute( "viewport", d->viewport.toString() ); activePage.setAttribute( "viewport", (*d->viewportIterator).toString() );
generalInfo.appendChild( activePage ); generalInfo.appendChild( activePage );
/*
// <general info><history> ... </history>
QDomElement historyNode = doc.createElement( "history" );
generalInfo.appendChild( historyNode );
for ( uint i = 0; i < 6 ; i++ )
{
QDomElement historyEntry = doc.createElement( "entry" );
historyEntry.setAttribute( "viewport", DocumentViewport().toString() );
historyNode.appendChild( historyEntry );
}
*/
// Save DOM to XML file // Save DOM to XML file
QString xml = doc.toString(); QString xml = doc.toString();
QTextStream os( &infoFile ); QTextStream os( &infoFile );
......
...@@ -68,11 +68,15 @@ class KPDFDocument : public QObject // only for a private slot.. ...@@ -68,11 +68,15 @@ class KPDFDocument : public QObject // only for a private slot..
uint currentPage() const; uint currentPage() const;
uint pages() const; uint pages() const;
bool okToPrint() const; bool okToPrint() const;
bool historyAtBegin() const;
bool historyAtEnd() const;
QString getMetaData( const QString & key, const QString & option = QString() ) const; QString getMetaData( const QString & key, const QString & option = QString() ) const;
// perform actions on document / pages // perform actions on document / pages
void setViewportPage( int page, int id = -1 ); void setViewportPage( int page, int excludeId = -1 );
void setViewport( const DocumentViewport & viewport, int id = -1 ); void setViewport( const DocumentViewport & viewport, int excludeId = -1 );
void setPrevViewport();
void setNextViewport();
void requestPixmaps( const QValueList< PixmapRequest * > & requests ); void requestPixmaps( const QValueList< PixmapRequest * > & requests );
void requestTextPage( uint page ); void requestTextPage( uint page );
bool findText( const QString & text = "", bool caseSensitive = false, bool findAhead = false ); bool findText( const QString & text = "", bool caseSensitive = false, bool findAhead = false );
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
// xpdf includes // xpdf includes
#include "xpdf/PSOutputDev.h" #include "xpdf/PSOutputDev.h"
#include "xpdf/TextOutputDev.h"
#include "xpdf/Link.h" #include "xpdf/Link.h"
#include "xpdf/ErrorCodes.h" #include "xpdf/ErrorCodes.h"
#include "xpdf/UnicodeMap.h" #include "xpdf/UnicodeMap.h"
...@@ -285,7 +286,6 @@ void PDFGenerator::generateSyncTextPage( KPDFPage * page ) ...@@ -285,7 +286,6 @@ void PDFGenerator::generateSyncTextPage( KPDFPage * page )
bool PDFGenerator::print( KPrinter& printer ) bool PDFGenerator::print( KPrinter& printer )
{ {
//FIXME (if needed) TAKE CARE OF THREADING, READY STATE AND SIMILAR STUFF
KTempFile tf( QString::null, ".ps" ); KTempFile tf( QString::null, ".ps" );
PSOutputDev *psOut = new PSOutputDev(tf.name().latin1(), pdfdoc->getXRef(), pdfdoc->getCatalog(), 1, pdfdoc->getNumPages(), psModePS); PSOutputDev *psOut = new PSOutputDev(tf.name().latin1(), pdfdoc->getXRef(), pdfdoc->getCatalog(), 1, pdfdoc->getNumPages(), psModePS);
...@@ -532,7 +532,7 @@ void PDFGenerator::addSynopsisChildren( QDomNode * parent, GList * items ) ...@@ -532,7 +532,7 @@ void PDFGenerator::addSynopsisChildren( QDomNode * parent, GList * items )
pageNumber = pdfdoc->findPage( ref.num, ref.gen ) - 1; pageNumber = pdfdoc->findPage( ref.num, ref.gen ) - 1;
} }
// set page as attribute to node // set page as attribute to node
// TODO add other attributes to the viewport // TODO add other attributes to the viewport (taken from link)
item.setAttribute( "Viewport", DocumentViewport( pageNumber ).toString() ); item.setAttribute( "Viewport", DocumentViewport( pageNumber ).toString() );
} }
} }
...@@ -690,6 +690,7 @@ struct PPGThreadPrivate ...@@ -690,6 +690,7 @@ struct PPGThreadPrivate
QImage * m_image; QImage * m_image;
TextPage * m_textPage; TextPage * m_textPage;
QValueList< KPDFPageRect * > m_rects; QValueList< KPDFPageRect * > m_rects;
bool m_rectsTaken;
}; };
PDFPixmapGeneratorThread::PDFPixmapGeneratorThread( PDFGenerator * gen ) PDFPixmapGeneratorThread::PDFPixmapGeneratorThread( PDFGenerator * gen )
...@@ -697,10 +698,24 @@ PDFPixmapGeneratorThread::PDFPixmapGeneratorThread( PDFGenerator * gen ) ...@@ -697,10 +698,24 @@ PDFPixmapGeneratorThread::PDFPixmapGeneratorThread( PDFGenerator * gen )
{ {
d->generator = gen; d->generator = gen;
d->currentRequest = 0; d->currentRequest = 0;
d->m_image = 0;
d->m_textPage = 0;
d->m_rectsTaken = true;
} }
PDFPixmapGeneratorThread::~PDFPixmapGeneratorThread() PDFPixmapGeneratorThread::~PDFPixmapGeneratorThread()
{ {
// delete internal objects if the class is deleted before the gui thread
// takes the data
delete d->m_image;
delete d->m_textPage;
if ( !d->m_rectsTaken && d->m_rects.count() )
{
QValueList< KPDFPageRect * >::iterator it = d->m_rects.begin(), end = d->m_rects.end();
for ( ; it != end; ++it )
delete *it;
}
// delete internal storage structure
delete d; delete d;
} }
...@@ -727,9 +742,7 @@ void PDFPixmapGeneratorThread::startGeneration( PixmapRequest * request ) ...@@ -727,9 +742,7 @@ void PDFPixmapGeneratorThread::startGeneration( PixmapRequest * request )
#endif #endif
// set generation parameters and run thread // set generation parameters and run thread
d->currentRequest = request; d->currentRequest = request;
// TODO map priorities embedded in request start( QThread::InheritPriority );
QThread::Priority prio = QThread::InheritPriority;
start( prio );
} }
void PDFPixmapGeneratorThread::endGeneration() void PDFPixmapGeneratorThread::endGeneration()
...@@ -749,16 +762,21 @@ void PDFPixmapGeneratorThread::endGeneration() ...@@ -749,16 +762,21 @@ void PDFPixmapGeneratorThread::endGeneration()
QImage * PDFPixmapGeneratorThread::takeImage() const QImage * PDFPixmapGeneratorThread::takeImage() const
{