2004-09-08 12:41:14 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
|
2004-09-23 21:33:53 +00:00
|
|
|
* Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es> *
|
2004-09-08 12:41:14 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2004-10-06 00:05:49 +00:00
|
|
|
// qt/kde/system includes
|
|
|
|
#include <qdir.h>
|
2004-09-08 12:41:14 +00:00
|
|
|
#include <qfile.h>
|
2004-10-06 00:05:49 +00:00
|
|
|
#include <qfileinfo.h>
|
2005-01-03 00:28:46 +00:00
|
|
|
#include <qtextstream.h>
|
2004-09-08 12:41:14 +00:00
|
|
|
#include <qvaluevector.h>
|
2004-12-24 10:24:10 +00:00
|
|
|
#include <qtimer.h>
|
2004-09-15 20:45:00 +00:00
|
|
|
#include <qmap.h>
|
2004-09-12 23:19:18 +00:00
|
|
|
#include <kdebug.h>
|
2004-09-16 21:04:49 +00:00
|
|
|
#include <klocale.h>
|
|
|
|
#include <kfinddialog.h>
|
|
|
|
#include <kmessagebox.h>
|
2004-10-06 00:05:49 +00:00
|
|
|
#include <kapplication.h>
|
|
|
|
#include <kuserprofile.h>
|
2004-12-10 16:04:45 +00:00
|
|
|
#include <kmimetype.h>
|
|
|
|
#include <krun.h>
|
2005-01-03 00:28:46 +00:00
|
|
|
#include <kstandarddirs.h>
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
// local includes
|
|
|
|
#include "document.h"
|
2005-01-02 14:55:14 +00:00
|
|
|
#include "observer.h"
|
2004-09-08 12:41:14 +00:00
|
|
|
#include "page.h"
|
2004-12-10 16:04:45 +00:00
|
|
|
#include "link.h"
|
2005-01-02 14:37:49 +00:00
|
|
|
#include "generator_pdf/generator_pdf.h" // PDF generator
|
2005-01-02 14:55:14 +00:00
|
|
|
#include "conf/settings.h"
|
2004-09-09 13:25:40 +00:00
|
|
|
|
2004-12-21 12:38:52 +00:00
|
|
|
// structures used internally by KPDFDocument for local variables storage
|
2004-09-09 13:25:40 +00:00
|
|
|
class KPDFDocumentPrivate
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
public:
|
|
|
|
// find related
|
|
|
|
QString searchText;
|
|
|
|
bool searchCase;
|
|
|
|
int searchPage;
|
|
|
|
// filtering related
|
|
|
|
QString filterText;
|
|
|
|
bool filterCase;
|
|
|
|
|
|
|
|
// cached stuff
|
|
|
|
int currentPage;
|
|
|
|
|
2004-12-24 10:24:10 +00:00
|
|
|
// memory check/free timer
|
|
|
|
QTimer * memCheckTimer;
|
|
|
|
|
2005-01-03 00:28:46 +00:00
|
|
|
// bookmark saver timer
|
|
|
|
QTimer * saveBookmarksTimer;
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
// observers related (note: won't delete oservers)
|
2004-12-21 12:38:52 +00:00
|
|
|
QMap< int, class ObserverData* > observers;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ObserverData
|
|
|
|
{
|
|
|
|
// public data fields
|
|
|
|
KPDFDocumentObserver * observer;
|
|
|
|
QMap< int, int > pageMemory;
|
|
|
|
int totalMemory;
|
|
|
|
// public constructor: initialize data
|
|
|
|
ObserverData( KPDFDocumentObserver * obs ) : observer( obs ), totalMemory( 0 ) {};
|
2004-09-08 12:41:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define foreachObserver( cmd ) {\
|
2004-12-21 12:38:52 +00:00
|
|
|
QMap< int, ObserverData * >::iterator it = d->observers.begin(), end = d->observers.end();\
|
|
|
|
for ( ; it != end ; ++ it ) { (*it)->observer-> cmd ; } }
|
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
KPDFDocument::KPDFDocument()
|
2004-12-10 16:04:45 +00:00
|
|
|
: generator( 0 ), d( new KPDFDocumentPrivate )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-09-09 13:25:40 +00:00
|
|
|
d->currentPage = -1;
|
2004-09-17 17:58:42 +00:00
|
|
|
d->searchPage = -1;
|
2004-12-24 10:24:10 +00:00
|
|
|
d->memCheckTimer = new QTimer( this );
|
|
|
|
connect( d->memCheckTimer, SIGNAL( timeout() ), this, SLOT( slotCheckMemory() ) );
|
2005-01-03 00:28:46 +00:00
|
|
|
d->saveBookmarksTimer = new QTimer( this );
|
2005-01-03 00:45:47 +00:00
|
|
|
connect( d->saveBookmarksTimer, SIGNAL( timeout() ), this, SLOT( saveDocumentInfo() ) );
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
2004-09-12 23:19:18 +00:00
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
KPDFDocument::~KPDFDocument()
|
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
closeDocument();
|
2004-09-08 12:41:14 +00:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2004-10-27 14:07:24 +00:00
|
|
|
|
2004-09-17 17:58:42 +00:00
|
|
|
bool KPDFDocument::openDocument( const QString & docFile )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
|
|
|
// docFile is always local so we can use QFile on it
|
|
|
|
QFile fileReadTest( docFile );
|
|
|
|
if ( !fileReadTest.open( IO_ReadOnly ) )
|
2005-01-03 00:28:46 +00:00
|
|
|
{
|
|
|
|
documentFileName = QString::null;
|
2004-09-08 12:41:14 +00:00
|
|
|
return false;
|
2005-01-03 00:28:46 +00:00
|
|
|
}
|
2004-09-08 12:41:14 +00:00
|
|
|
fileReadTest.close();
|
|
|
|
|
2004-12-21 12:38:52 +00:00
|
|
|
// create the generator based on the file's mimetype
|
|
|
|
KMimeType::Ptr mime = KMimeType::findByPath( docFile );
|
|
|
|
QString mimeName = mime->name();
|
|
|
|
if ( mimeName == "application/pdf" )
|
|
|
|
generator = new PDFGenerator();
|
2004-12-22 18:21:36 +00:00
|
|
|
else if ( mimeName == "application/postscript" )
|
|
|
|
kdError() << "PS generator not available" << endl;
|
2004-12-21 12:38:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
kdWarning() << "Unknown mimetype '" << mimeName << "'." << endl;
|
|
|
|
return false;
|
|
|
|
}
|
2004-12-22 18:21:36 +00:00
|
|
|
// get notification of completed jobs
|
|
|
|
connect( generator, SIGNAL( contentsChanged( int, int ) ),
|
|
|
|
this, SLOT( slotGeneratedContents( int, int ) ) );
|
2004-12-21 12:38:52 +00:00
|
|
|
|
2004-12-22 18:21:36 +00:00
|
|
|
// ask generator to open the document and return if unsuccessfull
|
2004-12-10 16:04:45 +00:00
|
|
|
documentFileName = docFile;
|
|
|
|
bool openOk = generator->loadDocument( docFile, pages_vector );
|
|
|
|
if ( !openOk )
|
|
|
|
return false;
|
2004-09-08 12:41:14 +00:00
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
// filter pages, setup observers and set the first page as current
|
|
|
|
if ( pages_vector.size() > 0 )
|
2004-09-11 15:59:32 +00:00
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
processPageList( true );
|
2004-11-09 17:20:19 +00:00
|
|
|
setCurrentPage( 0 );
|
2004-09-11 15:59:32 +00:00
|
|
|
}
|
2005-01-03 00:45:47 +00:00
|
|
|
|
|
|
|
loadDocumentInfo();
|
|
|
|
|
|
|
|
// start bookmark saver timer
|
|
|
|
d->saveBookmarksTimer->start( 5 * 60 * 1000 );
|
|
|
|
|
|
|
|
// start memory check timer
|
|
|
|
d->memCheckTimer->start( 2000 );
|
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-09-17 17:58:42 +00:00
|
|
|
void KPDFDocument::closeDocument()
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2005-01-03 00:28:46 +00:00
|
|
|
saveDocumentInfo();
|
|
|
|
|
2004-12-24 10:24:10 +00:00
|
|
|
// stop memory check timer
|
|
|
|
d->memCheckTimer->stop();
|
|
|
|
|
2005-01-03 00:24:59 +00:00
|
|
|
// delete contents generator
|
|
|
|
delete generator;
|
|
|
|
generator = 0;
|
|
|
|
|
|
|
|
// send an empty list to observers (to free their data)
|
|
|
|
foreachObserver( pageSetup( QValueVector< KPDFPage * >(), true ) );
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
// delete pages and clear 'pages_vector' container
|
|
|
|
for ( uint i = 0; i < pages_vector.count() ; i++ )
|
|
|
|
delete pages_vector[i];
|
|
|
|
pages_vector.clear();
|
|
|
|
|
2004-12-22 18:21:36 +00:00
|
|
|
// clear memory management data
|
|
|
|
QMap< int, ObserverData * >::iterator oIt = d->observers.begin(), oEnd = d->observers.end();
|
|
|
|
for ( ; oIt != oEnd ; ++oIt )
|
|
|
|
{
|
|
|
|
ObserverData * observerData = *oIt;
|
|
|
|
observerData->pageMemory.clear();
|
|
|
|
observerData->totalMemory = 0;
|
|
|
|
}
|
|
|
|
|
2004-09-17 17:58:42 +00:00
|
|
|
// reset internal variables
|
|
|
|
d->currentPage = -1;
|
|
|
|
d->searchPage = -1;
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
void KPDFDocument::addObserver( KPDFDocumentObserver * pObserver )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-12-17 17:14:46 +00:00
|
|
|
// keep the pointer to the observer in a map
|
2004-12-21 12:38:52 +00:00
|
|
|
d->observers[ pObserver->observerId() ] = new ObserverData( pObserver );
|
2004-12-17 17:14:46 +00:00
|
|
|
|
|
|
|
// if the observer is added while a document is already opened, tell it
|
|
|
|
if ( !pages_vector.isEmpty() )
|
|
|
|
pObserver->pageSetup( pages_vector, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void KPDFDocument::removeObserver( KPDFDocumentObserver * pObserver )
|
|
|
|
{
|
|
|
|
// remove observer from the map. it won't receive notifications anymore
|
2004-12-21 12:38:52 +00:00
|
|
|
if ( d->observers.contains( pObserver->observerId() ) )
|
|
|
|
{
|
|
|
|
// free observer data
|
|
|
|
int observerId = pObserver->observerId();
|
|
|
|
QValueVector<KPDFPage*>::iterator it = pages_vector.begin(), end = pages_vector.end();
|
|
|
|
for ( ; it != end; ++it )
|
|
|
|
(*it)->deletePixmap( observerId );
|
2004-12-24 10:24:10 +00:00
|
|
|
|
2004-12-21 12:38:52 +00:00
|
|
|
// delete observer
|
|
|
|
delete d->observers[ observerId ];
|
|
|
|
d->observers.remove( observerId );
|
|
|
|
}
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
void KPDFDocument::reparseConfig()
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
// reparse generator config and if something changed clear KPDFPages
|
|
|
|
if ( generator && generator->reparseConfig() )
|
2004-11-09 17:20:19 +00:00
|
|
|
{
|
2004-11-12 10:58:33 +00:00
|
|
|
// invalidate pixmaps and send reload signals to observers
|
2004-12-10 16:04:45 +00:00
|
|
|
QValueVector<KPDFPage*>::iterator it = pages_vector.begin(), end = pages_vector.end();
|
2004-11-12 10:58:33 +00:00
|
|
|
for ( ; it != end; ++it )
|
2004-12-10 16:04:45 +00:00
|
|
|
(*it)->deletePixmapsAndRects();
|
2004-11-12 10:58:33 +00:00
|
|
|
foreachObserver( notifyPixmapsCleared() );
|
2004-11-09 17:20:19 +00:00
|
|
|
}
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
|
2004-12-11 17:25:03 +00:00
|
|
|
const DocumentInfo * KPDFDocument::documentInfo() const
|
2004-12-05 22:47:32 +00:00
|
|
|
{
|
2004-12-11 17:25:03 +00:00
|
|
|
return generator ? generator->documentInfo() : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const DocumentSynopsis * KPDFDocument::documentSynopsis() const
|
|
|
|
{
|
|
|
|
return generator ? generator->documentSynopsis() : NULL;
|
2004-12-05 22:47:32 +00:00
|
|
|
}
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
const KPDFPage * KPDFDocument::page( uint n ) const
|
2004-12-05 22:47:32 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
return ( n < pages_vector.count() ) ? pages_vector[n] : 0;
|
2004-12-05 22:47:32 +00:00
|
|
|
}
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
uint KPDFDocument::currentPage() const
|
2004-12-05 22:47:32 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
return d->currentPage;
|
2004-12-05 22:47:32 +00:00
|
|
|
}
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
uint KPDFDocument::pages() const
|
2004-12-05 22:47:32 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
return pages_vector.size();
|
2004-12-05 22:47:32 +00:00
|
|
|
}
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
bool KPDFDocument::okToPrint() const
|
2004-09-09 13:25:40 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
return generator ? generator->allowed( Generator::Print ) : false;
|
2004-09-09 13:25:40 +00:00
|
|
|
}
|
|
|
|
|
2005-01-01 15:44:44 +00:00
|
|
|
QString KPDFDocument::getMetaData( const QString &key ) const
|
|
|
|
{
|
|
|
|
return generator ? generator->getMetaData( key ) : QString();
|
|
|
|
}
|
2004-11-09 17:20:19 +00:00
|
|
|
|
2004-12-28 18:50:11 +00:00
|
|
|
void KPDFDocument::requestPixmaps( const QValueList< PixmapRequest * > & requests, bool async )
|
2004-09-15 20:45:00 +00:00
|
|
|
{
|
2004-12-22 18:21:36 +00:00
|
|
|
if ( !generator )
|
2004-09-15 20:45:00 +00:00
|
|
|
return;
|
|
|
|
|
2004-12-22 18:21:36 +00:00
|
|
|
QValueList< PixmapRequest * >::const_iterator rIt = requests.begin(), rEnd = requests.end();
|
|
|
|
for ( ; rIt != rEnd; ++rIt )
|
2004-12-21 12:38:52 +00:00
|
|
|
{
|
2004-12-22 18:21:36 +00:00
|
|
|
// set the 'page field' (see PixmapRequest) and check if request is valid
|
|
|
|
PixmapRequest * request = *rIt;
|
|
|
|
request->page = pages_vector[ request->pageNumber ];
|
|
|
|
if ( !request->page || request->page->width() < 1 || request->page->height() < 1 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// 1. Update statistics (pageMemory / totalMemory) adding this pixmap
|
|
|
|
ObserverData * obs = d->observers[ request->id ];
|
2004-12-24 10:24:10 +00:00
|
|
|
int pageNumber = request->pageNumber;
|
2004-12-22 18:21:36 +00:00
|
|
|
if ( obs->pageMemory.contains( pageNumber ) )
|
|
|
|
obs->totalMemory -= obs->pageMemory[ pageNumber ];
|
|
|
|
int pixmapMemory = 4 * request->width * request->height / 1024;
|
|
|
|
obs->pageMemory[ pageNumber ] = pixmapMemory;
|
|
|
|
obs->totalMemory += pixmapMemory;
|
|
|
|
|
|
|
|
// 2. Perform pre-cleaning if needed
|
|
|
|
mCleanupMemory( request->id );
|
|
|
|
|
|
|
|
// 3. Enqueue to Generator (that takes ownership of request)
|
2004-12-28 18:50:11 +00:00
|
|
|
generator->requestPixmap( request, Settings::disableThreading() ? false : async );
|
2004-12-21 12:38:52 +00:00
|
|
|
}
|
2004-09-15 20:45:00 +00:00
|
|
|
}
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
void KPDFDocument::requestTextPage( uint page )
|
2004-10-09 08:10:56 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
KPDFPage * kp = pages_vector[ page ];
|
|
|
|
if ( !generator || !kp )
|
|
|
|
return;
|
|
|
|
|
2004-12-21 12:38:52 +00:00
|
|
|
// Memory management for TextPages
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
generator->requestTextPage( kp );
|
2004-10-09 08:10:56 +00:00
|
|
|
}
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
void KPDFDocument::setCurrentPage( int page, const QRect & viewport )
|
2004-09-09 13:25:40 +00:00
|
|
|
{
|
2004-10-10 13:21:30 +00:00
|
|
|
if ( page < 0 )
|
2004-10-09 08:10:56 +00:00
|
|
|
page = 0;
|
2004-12-10 16:04:45 +00:00
|
|
|
else if ( page > (int)pages_vector.count() )
|
|
|
|
page = pages_vector.count() - 1;
|
|
|
|
if ( page == d->currentPage )
|
2004-09-08 12:41:14 +00:00
|
|
|
return;
|
|
|
|
d->currentPage = page;
|
2004-10-10 13:21:30 +00:00
|
|
|
foreachObserver( pageSetCurrent( page, viewport ) );
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
void KPDFDocument::findText( const QString & string, bool keepCase )
|
2004-09-16 21:04:49 +00:00
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
// turn selection drawing off on filtered pages
|
|
|
|
if ( !d->filterText.isEmpty() )
|
|
|
|
unHilightPages();
|
|
|
|
|
|
|
|
// save params for the 'find next' case
|
|
|
|
if ( !string.isEmpty() )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
d->searchText = string;
|
|
|
|
d->searchCase = keepCase;
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-16 21:04:49 +00:00
|
|
|
// continue checking last SearchPage first (if it is the current page)
|
|
|
|
int currentPage = d->currentPage;
|
2004-12-10 16:04:45 +00:00
|
|
|
int pageCount = pages_vector.count();
|
2004-09-17 17:58:42 +00:00
|
|
|
KPDFPage * foundPage = 0,
|
2004-12-10 16:04:45 +00:00
|
|
|
* lastPage = (d->searchPage > -1) ? pages_vector[ d->searchPage ] : 0;
|
2004-09-17 17:58:42 +00:00
|
|
|
if ( lastPage && d->searchPage == currentPage )
|
|
|
|
if ( lastPage->hasText( d->searchText, d->searchCase, false ) )
|
|
|
|
foundPage = lastPage;
|
2004-09-16 21:04:49 +00:00
|
|
|
else
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-11-06 00:56:55 +00:00
|
|
|
lastPage->clearAttribute( KPDFPage::Highlight );
|
2004-09-16 21:04:49 +00:00
|
|
|
currentPage++;
|
|
|
|
pageCount--;
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-16 21:04:49 +00:00
|
|
|
if ( !foundPage )
|
|
|
|
// loop through the whole document
|
|
|
|
for ( int i = 0; i < pageCount; i++ )
|
2004-09-13 08:51:36 +00:00
|
|
|
{
|
2004-09-16 21:04:49 +00:00
|
|
|
if ( currentPage >= pageCount )
|
|
|
|
{
|
|
|
|
if ( KMessageBox::questionYesNo(0, i18n("End of document reached.\nContinue from the beginning?")) == KMessageBox::Yes )
|
|
|
|
currentPage = 0;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2004-12-10 16:04:45 +00:00
|
|
|
KPDFPage * page = pages_vector[ currentPage ];
|
2004-09-16 21:04:49 +00:00
|
|
|
if ( !page->hasSearchPage() )
|
2004-10-09 08:10:56 +00:00
|
|
|
requestTextPage( page->number() );
|
2004-09-17 17:58:42 +00:00
|
|
|
if ( page->hasText( d->searchText, d->searchCase, true ) )
|
2004-09-16 21:04:49 +00:00
|
|
|
{
|
|
|
|
foundPage = page;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
currentPage++;
|
2004-09-13 08:51:36 +00:00
|
|
|
}
|
|
|
|
|
2004-09-16 21:04:49 +00:00
|
|
|
if ( foundPage )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
int pageNumber = foundPage->number();
|
|
|
|
d->searchPage = pageNumber;
|
2004-11-06 00:56:55 +00:00
|
|
|
foundPage->setAttribute( KPDFPage::Highlight );
|
2004-11-09 17:20:19 +00:00
|
|
|
setCurrentPage( pageNumber );
|
2004-09-17 17:58:42 +00:00
|
|
|
foreachObserver( notifyPixmapChanged( pageNumber ) );
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
2004-09-16 21:04:49 +00:00
|
|
|
else
|
2004-09-17 17:58:42 +00:00
|
|
|
KMessageBox::information( 0, i18n("No matches found for '%1'.").arg(d->searchText) );
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
void KPDFDocument::findTextAll( const QString & pattern, bool keepCase )
|
|
|
|
{
|
2004-12-13 18:21:37 +00:00
|
|
|
// if pattern is null, clear 'hilighted' attribute in all pages
|
|
|
|
if ( pattern.isEmpty() )
|
|
|
|
unHilightPages();
|
|
|
|
|
|
|
|
// cache search pattern and perform a linear search/mark
|
2004-11-09 17:20:19 +00:00
|
|
|
d->filterText = pattern;
|
|
|
|
d->filterCase = keepCase;
|
|
|
|
processPageList( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
void KPDFDocument::toggleBookmark( int n )
|
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
KPDFPage * page = ( n < (int)pages_vector.count() ) ? pages_vector[ n ] : 0;
|
2004-11-09 17:20:19 +00:00
|
|
|
if ( page )
|
|
|
|
{
|
|
|
|
page->toggleAttribute( KPDFPage::Bookmark );
|
|
|
|
foreachObserver( notifyPixmapChanged( n ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KPDFDocument::processLink( const KPDFLink * link )
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-10-06 00:05:49 +00:00
|
|
|
if ( !link )
|
|
|
|
return;
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
switch( link->linkType() )
|
2004-10-06 00:05:49 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
case KPDFLink::Goto: {
|
|
|
|
const KPDFLinkGoto * go = static_cast< const KPDFLinkGoto * >( link );
|
|
|
|
KPDFLinkGoto::Viewport destVp = go->destViewport();
|
|
|
|
|
|
|
|
// first open filename if link is pointing outside this document
|
|
|
|
if ( go->isExternal() && !openRelativeFile( go->fileName() ) )
|
2004-10-06 00:05:49 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
kdWarning() << "Link: Error opening '" << go->fileName() << "'." << endl;
|
2004-10-06 00:05:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
// note: if external file is opened, 'link' doesn't exist anymore!
|
2004-12-11 17:25:03 +00:00
|
|
|
setCurrentPage( destVp.page ); //TODO implement and use Viewport
|
2004-12-10 16:04:45 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case KPDFLink::Execute: {
|
|
|
|
const KPDFLinkExecute * exe = static_cast< const KPDFLinkExecute * >( link );
|
|
|
|
QString fileName = exe->fileName();
|
|
|
|
if ( fileName.endsWith( ".pdf" ) || fileName.endsWith( ".PDF" ) )
|
2004-10-09 08:10:56 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
openRelativeFile( fileName );
|
|
|
|
return;
|
2004-10-09 08:10:56 +00:00
|
|
|
}
|
2004-12-10 16:04:45 +00:00
|
|
|
|
|
|
|
// Albert: the only pdf i have that has that kind of link don't define
|
|
|
|
// an application and use the fileName as the file to open
|
|
|
|
fileName = giveAbsolutePath( fileName );
|
|
|
|
KMimeType::Ptr mime = KMimeType::findByPath( fileName );
|
|
|
|
// Check executables
|
|
|
|
if ( KRun::isExecutableFile( fileName, mime->name() ) )
|
2004-10-09 08:10:56 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
// Don't have any pdf that uses this code path, just a guess on how it should work
|
|
|
|
if ( !exe->parameters().isEmpty() )
|
|
|
|
{
|
|
|
|
fileName = giveAbsolutePath( exe->parameters() );
|
|
|
|
mime = KMimeType::findByPath( fileName );
|
|
|
|
if ( KRun::isExecutableFile( fileName, mime->name() ) )
|
|
|
|
{
|
|
|
|
// this case is a link pointing to an executable with a parameter
|
|
|
|
// that also is an executable, possibly a hand-crafted pdf
|
|
|
|
KMessageBox::information( 0, i18n("The pdf file is trying to execute an external application and for your safety kpdf does not allow that.") );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// this case is a link pointing to an executable with no parameters
|
|
|
|
// core developers find unacceptable executing it even after asking the user
|
|
|
|
KMessageBox::information( 0, i18n("The pdf file is trying to execute an external application and for your safety kpdf does not allow that.") );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::Ptr ptr = KServiceTypeProfile::preferredService( mime->name(), "Application" );
|
|
|
|
if ( ptr )
|
|
|
|
{
|
|
|
|
KURL::List lst;
|
|
|
|
lst.append( fileName );
|
|
|
|
KRun::run( *ptr, lst );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
KMessageBox::information( 0, i18n( "No application found for opening file of mimetype %1." ).arg( mime->name() ) );
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case KPDFLink::Action: {
|
|
|
|
const KPDFLinkAction * action = static_cast< const KPDFLinkAction * >( link );
|
|
|
|
switch( action->actionType() )
|
|
|
|
{
|
|
|
|
case KPDFLinkAction::PageFirst:
|
|
|
|
setCurrentPage( 0 );
|
|
|
|
break;
|
|
|
|
case KPDFLinkAction::PagePrev:
|
|
|
|
if ( d->currentPage > 0 )
|
|
|
|
setCurrentPage( d->currentPage - 1 );
|
|
|
|
break;
|
|
|
|
case KPDFLinkAction::PageNext:
|
|
|
|
if ( d->currentPage < (int)pages_vector.count() - 1 )
|
|
|
|
setCurrentPage( d->currentPage + 1 );
|
|
|
|
break;
|
|
|
|
case KPDFLinkAction::PageLast:
|
|
|
|
setCurrentPage( pages_vector.count() - 1 );
|
|
|
|
break;
|
|
|
|
case KPDFLinkAction::HistoryBack:
|
|
|
|
{} //TODO
|
|
|
|
break;
|
|
|
|
case KPDFLinkAction::HistoryForward:
|
|
|
|
{} //TODO
|
|
|
|
break;
|
|
|
|
case KPDFLinkAction::Quit:
|
|
|
|
kapp->quit();
|
|
|
|
break;
|
2005-01-01 21:50:34 +00:00
|
|
|
case KPDFLinkAction::Find:
|
|
|
|
emit linkFind();
|
|
|
|
break;
|
|
|
|
case KPDFLinkAction::GoToPage:
|
|
|
|
emit linkGoToPage();
|
|
|
|
break;
|
2004-12-10 16:04:45 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case KPDFLink::Browse: {
|
|
|
|
const KPDFLinkBrowse * browse = static_cast< const KPDFLinkBrowse * >( link );
|
2004-12-17 17:14:46 +00:00
|
|
|
// get service for web browsing TODO: check for "mailto:" links
|
2004-12-10 16:04:45 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
case KPDFLink::Movie:
|
|
|
|
// TODO this
|
|
|
|
break;
|
2004-10-06 00:05:49 +00:00
|
|
|
}
|
2004-09-09 13:25:40 +00:00
|
|
|
}
|
2004-11-09 17:20:19 +00:00
|
|
|
|
2004-12-10 16:04:45 +00:00
|
|
|
bool KPDFDocument::print( KPrinter &printer )
|
2004-11-09 17:20:19 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
return generator ? generator->print( printer ) : false;
|
2004-11-09 17:20:19 +00:00
|
|
|
}
|
2004-12-10 16:04:45 +00:00
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
|
2004-12-22 18:21:36 +00:00
|
|
|
void KPDFDocument::mCleanupMemory( int observerId )
|
|
|
|
{
|
|
|
|
// get observer data for given id
|
|
|
|
ObserverData * obs = d->observers[ observerId ];
|
|
|
|
|
|
|
|
// choose memory parameters based on configuration profile
|
2004-12-24 10:24:10 +00:00
|
|
|
int clipValue = 0;
|
2004-12-22 18:21:36 +00:00
|
|
|
int memoryToFree = 0;
|
|
|
|
switch ( Settings::memoryLevel() )
|
|
|
|
{
|
|
|
|
case Settings::EnumMemoryLevel::Low:
|
|
|
|
memoryToFree = obs->totalMemory;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Settings::EnumMemoryLevel::Normal:
|
2004-12-24 10:24:10 +00:00
|
|
|
clipValue = obs->totalMemory - mFreeMemory() / 3;
|
|
|
|
if ( observerId == THUMBNAILS_ID )
|
|
|
|
memoryToFree = obs->totalMemory - mTotalMemory() / 20;
|
|
|
|
else
|
|
|
|
memoryToFree = obs->totalMemory - mTotalMemory() / 5;
|
2004-12-22 18:21:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Settings::EnumMemoryLevel::Aggressive:
|
2004-12-24 10:24:10 +00:00
|
|
|
clipValue = obs->totalMemory - mFreeMemory() / 2;
|
2004-12-22 18:21:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-12-24 10:24:10 +00:00
|
|
|
if ( clipValue > memoryToFree )
|
|
|
|
memoryToFree = clipValue;
|
|
|
|
|
2004-12-22 18:21:36 +00:00
|
|
|
// free memory. remove older data until we free enough memory
|
|
|
|
int freed = 0;
|
|
|
|
if ( memoryToFree > 0 )
|
|
|
|
{
|
|
|
|
QMap< int, int >::iterator it = obs->pageMemory.begin(), end = obs->pageMemory.end();
|
|
|
|
while ( (it != end) && (memoryToFree > 0) )
|
|
|
|
{
|
|
|
|
int freeNumber = it.key();
|
|
|
|
if ( obs->observer->canUnloadPixmap( freeNumber ) )
|
|
|
|
{
|
|
|
|
// update mem stats
|
|
|
|
memoryToFree -= it.data();
|
|
|
|
obs->totalMemory -= it.data();
|
|
|
|
obs->pageMemory.remove( it );
|
|
|
|
// delete pixmap
|
|
|
|
pages_vector[ freeNumber ]->deletePixmap( observerId );
|
|
|
|
freed++;
|
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
2004-12-28 16:06:11 +00:00
|
|
|
//kdDebug() << "Id:" << observerId << " [" << obs->totalMemory << "kB] Removed " << freed << " pages. " << obs->pageMemory.count() << " pages kept in memory." << endl;
|
2004-12-22 18:21:36 +00:00
|
|
|
}
|
|
|
|
|
2004-12-21 12:38:52 +00:00
|
|
|
int KPDFDocument::mTotalMemory()
|
|
|
|
{
|
2004-12-22 18:21:36 +00:00
|
|
|
static int cachedValue = 0;
|
|
|
|
if ( cachedValue )
|
|
|
|
return cachedValue;
|
|
|
|
|
2004-12-21 12:38:52 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
// if /proc/meminfo doesn't exist, return 128MB
|
|
|
|
QFile memFile( "/proc/meminfo" );
|
|
|
|
if ( !memFile.open( IO_ReadOnly ) )
|
2004-12-22 18:21:36 +00:00
|
|
|
return (cachedValue = 131072);
|
2004-12-21 12:38:52 +00:00
|
|
|
|
|
|
|
// read /proc/meminfo and sum up the contents of 'MemFree', 'Buffers'
|
|
|
|
// and 'Cached' fields. consider swapped memory as used memory.
|
|
|
|
QTextStream readStream( &memFile );
|
|
|
|
while ( !readStream.atEnd() )
|
|
|
|
{
|
|
|
|
QString entry = readStream.readLine();
|
|
|
|
if ( entry.startsWith( "MemTotal:" ) )
|
2004-12-22 18:21:36 +00:00
|
|
|
return (cachedValue = entry.section( ' ', -2, -2 ).toInt());
|
2004-12-21 12:38:52 +00:00
|
|
|
}
|
|
|
|
#endif
|
2004-12-22 18:21:36 +00:00
|
|
|
return (cachedValue = 131072);
|
2004-12-21 12:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int KPDFDocument::mFreeMemory()
|
|
|
|
{
|
|
|
|
#ifdef __linux__
|
2004-12-24 10:24:10 +00:00
|
|
|
// if /proc/meminfo doesn't exist, return MEMORY FULL
|
2004-12-21 12:38:52 +00:00
|
|
|
QFile memFile( "/proc/meminfo" );
|
|
|
|
if ( !memFile.open( IO_ReadOnly ) )
|
2004-12-24 10:24:10 +00:00
|
|
|
return 0;
|
2004-12-21 12:38:52 +00:00
|
|
|
|
|
|
|
// read /proc/meminfo and sum up the contents of 'MemFree', 'Buffers'
|
|
|
|
// and 'Cached' fields. consider swapped memory as used memory.
|
|
|
|
int memoryFree = 0;
|
|
|
|
QString entry;
|
|
|
|
QTextStream readStream( &memFile );
|
|
|
|
while ( !readStream.atEnd() )
|
|
|
|
{
|
|
|
|
entry = readStream.readLine();
|
|
|
|
if ( entry.startsWith( "MemFree:" ) ||
|
|
|
|
entry.startsWith( "Buffers:" ) ||
|
|
|
|
entry.startsWith( "Cached:" ) ||
|
|
|
|
entry.startsWith( "SwapFree:" ) )
|
|
|
|
memoryFree += entry.section( ' ', -2, -2 ).toInt();
|
|
|
|
if ( entry.startsWith( "SwapTotal:" ) )
|
|
|
|
memoryFree -= entry.section( ' ', -2, -2 ).toInt();
|
|
|
|
}
|
|
|
|
memFile.close();
|
|
|
|
return memoryFree;
|
|
|
|
#else
|
2004-12-24 10:24:10 +00:00
|
|
|
// tell the memory is full.. will act as in LOW profile
|
|
|
|
return 0;
|
2004-12-21 12:38:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-01-03 00:28:46 +00:00
|
|
|
void KPDFDocument::loadDocumentInfo()
|
|
|
|
{
|
|
|
|
QFile fileReadTest( documentFileName );
|
|
|
|
fileReadTest.open( IO_ReadOnly );
|
|
|
|
|
|
|
|
QString fileName = documentFileName.contains('/') ? documentFileName.section('/', -1, -1) : documentFileName;
|
|
|
|
fileName = "kpdf/" + QString::number(fileReadTest.size()) + "." + fileName + ".xml";
|
|
|
|
fileReadTest.close();
|
|
|
|
QString localFN = locateLocal( "data", fileName );
|
|
|
|
kdDebug() << "Using '" << localFN << "' as document info file." << endl;
|
|
|
|
QFile infoFile( localFN );
|
|
|
|
if (infoFile.exists() && infoFile.open( IO_ReadOnly ) )
|
|
|
|
{
|
|
|
|
QDomDocument doc( "documentInfo" );
|
|
|
|
if ( !doc.setContent( &infoFile ) )
|
|
|
|
{
|
|
|
|
kdDebug() << "Could not set content" << endl;
|
|
|
|
infoFile.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDomElement root = doc.documentElement();
|
|
|
|
if (root.tagName() != "documentInfo") return;
|
|
|
|
|
|
|
|
QDomNode bookMarkList = root.firstChild();
|
|
|
|
if (bookMarkList.isElement() && bookMarkList.toElement().tagName() != "bookmarkList") return;
|
|
|
|
|
|
|
|
QDomNode n = bookMarkList.firstChild();
|
|
|
|
|
|
|
|
QDomElement e;
|
|
|
|
int pageNumber;
|
|
|
|
bool ok;
|
|
|
|
while ( !n.isNull() )
|
|
|
|
{
|
|
|
|
if ( n.isElement() )
|
|
|
|
{
|
|
|
|
e = n.toElement();
|
|
|
|
if (e.tagName() != "page") return;
|
|
|
|
|
|
|
|
pageNumber = e.text().toInt(&ok);
|
|
|
|
if (ok) toggleBookmark( pageNumber );
|
|
|
|
}
|
|
|
|
n = n.nextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
infoFile.close();
|
|
|
|
}
|
|
|
|
|
2004-10-17 18:40:02 +00:00
|
|
|
QString KPDFDocument::giveAbsolutePath( const QString & fileName )
|
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
if ( documentFileName.isEmpty() )
|
|
|
|
return QString::null;
|
2004-10-17 18:40:02 +00:00
|
|
|
|
|
|
|
// convert the pdf fileName to absolute using current pdf path
|
2004-12-10 16:04:45 +00:00
|
|
|
QFileInfo currentInfo( documentFileName );
|
|
|
|
return currentInfo.dir().absFilePath( fileName );
|
2004-10-17 18:40:02 +00:00
|
|
|
}
|
|
|
|
|
2004-10-06 00:05:49 +00:00
|
|
|
bool KPDFDocument::openRelativeFile( const QString & fileName )
|
|
|
|
{
|
2004-10-17 18:40:02 +00:00
|
|
|
QString absFileName = giveAbsolutePath( fileName );
|
|
|
|
if ( absFileName.isNull() )
|
2004-10-06 00:05:49 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
kdDebug() << "openDocument: '" << absFileName << "'" << endl;
|
|
|
|
|
|
|
|
// open the absolute filename
|
|
|
|
return openDocument( absFileName );
|
|
|
|
}
|
|
|
|
|
2004-09-17 17:58:42 +00:00
|
|
|
void KPDFDocument::processPageList( bool documentChanged )
|
2004-09-09 13:25:40 +00:00
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
if ( d->filterText.length() < 3 )
|
|
|
|
unHilightPages();
|
|
|
|
else
|
2004-09-16 21:27:34 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
uint pageCount = pages_vector.count();
|
2004-09-15 20:45:00 +00:00
|
|
|
for ( uint i = 0; i < pageCount ; i++ )
|
2004-09-16 21:27:34 +00:00
|
|
|
{
|
2004-12-10 16:04:45 +00:00
|
|
|
KPDFPage * page = pages_vector[ i ];
|
2004-11-06 00:56:55 +00:00
|
|
|
page->clearAttribute( KPDFPage::Highlight );
|
|
|
|
if ( d->filterText.length() > 2 )
|
2004-09-16 21:27:34 +00:00
|
|
|
{
|
|
|
|
if ( !page->hasSearchPage() )
|
2004-12-10 16:04:45 +00:00
|
|
|
requestTextPage( i );
|
2004-11-06 00:56:55 +00:00
|
|
|
if ( page->hasText( d->filterText, d->filterCase, true ) )
|
|
|
|
page->setAttribute( KPDFPage::Highlight );
|
2004-09-16 21:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
// send the list to observers
|
2004-12-10 16:04:45 +00:00
|
|
|
foreachObserver( pageSetup( pages_vector, documentChanged ) );
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2004-09-17 17:58:42 +00:00
|
|
|
void KPDFDocument::unHilightPages()
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-10-24 07:53:00 +00:00
|
|
|
if ( d->filterText.isEmpty() )
|
2004-09-08 12:41:14 +00:00
|
|
|
return;
|
|
|
|
|
2004-11-06 00:56:55 +00:00
|
|
|
d->filterText = QString::null;
|
2004-12-10 16:04:45 +00:00
|
|
|
QValueVector<KPDFPage*>::iterator it = pages_vector.begin(), end = pages_vector.end();
|
2004-09-17 17:58:42 +00:00
|
|
|
for ( ; it != end; ++it )
|
|
|
|
{
|
|
|
|
KPDFPage * page = *it;
|
2004-11-06 00:56:55 +00:00
|
|
|
if ( page->attributes() & KPDFPage::Highlight )
|
2004-09-17 17:58:42 +00:00
|
|
|
{
|
2004-11-06 00:56:55 +00:00
|
|
|
page->clearAttribute( KPDFPage::Highlight );
|
2004-09-17 17:58:42 +00:00
|
|
|
foreachObserver( notifyPixmapChanged( page->number() ) );
|
|
|
|
}
|
|
|
|
}
|
2004-09-08 12:41:14 +00:00
|
|
|
}
|
2004-12-22 18:21:36 +00:00
|
|
|
|
2004-12-24 10:24:10 +00:00
|
|
|
|
2005-01-03 00:28:46 +00:00
|
|
|
void KPDFDocument::saveDocumentInfo() const
|
|
|
|
{
|
|
|
|
if (documentFileName.isNull()) return;
|
|
|
|
|
|
|
|
QFile fileReadTest( documentFileName );
|
|
|
|
fileReadTest.open( IO_ReadOnly );
|
|
|
|
|
|
|
|
QString fileName = documentFileName.contains('/') ? documentFileName.section('/', -1, -1) : documentFileName;
|
|
|
|
fileName = "kpdf/" + QString::number(fileReadTest.size()) + "." + fileName + ".xml";
|
|
|
|
fileReadTest.close();
|
|
|
|
QString localFN = locateLocal( "data", fileName );
|
|
|
|
kdDebug() << "Using '" << localFN << "' as document info file for saving." << endl;
|
|
|
|
QFile infoFile( localFN );
|
|
|
|
if (infoFile.open( IO_WriteOnly | IO_Truncate) )
|
|
|
|
{
|
|
|
|
QDomDocument doc( "documentInfo" );
|
|
|
|
QDomElement root = doc.createElement( "documentInfo" );
|
|
|
|
doc.appendChild( root );
|
|
|
|
|
|
|
|
QDomElement bookmarkList = doc.createElement( "bookmarkList" );
|
|
|
|
root.appendChild( bookmarkList );
|
|
|
|
|
|
|
|
for ( uint i = 0; i < pages_vector.count() ; i++ )
|
|
|
|
{
|
|
|
|
if (pages_vector[i]->attributes() & KPDFPage::Bookmark)
|
|
|
|
{
|
|
|
|
QDomElement page = doc.createElement( "page" );
|
|
|
|
page.appendChild( doc.createTextNode( QString::number(i) ) );
|
|
|
|
|
|
|
|
bookmarkList.appendChild( page );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString xml = doc.toString();
|
|
|
|
QTextStream os( &infoFile );
|
|
|
|
os << xml;
|
|
|
|
}
|
|
|
|
infoFile.close();
|
|
|
|
}
|
|
|
|
|
2004-12-24 10:24:10 +00:00
|
|
|
void KPDFDocument::slotCheckMemory()
|
|
|
|
{
|
|
|
|
// perform the memory check for 'free mem dependant' profiles only
|
|
|
|
if ( Settings::memoryLevel() == Settings::EnumMemoryLevel::Low )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// for each observer going over 1MB of memory, invoke the manager
|
|
|
|
QMap< int, ObserverData * >::iterator it = d->observers.begin(), end = d->observers.end();
|
|
|
|
for ( ; it != end ; ++ it )
|
|
|
|
if ( (*it)->totalMemory > 1024 )
|
|
|
|
mCleanupMemory( it.key() /*observerId*/ );
|
|
|
|
}
|
|
|
|
|
2004-12-22 18:21:36 +00:00
|
|
|
void KPDFDocument::slotGeneratedContents( int id, int pageNumber )
|
|
|
|
{
|
2004-12-24 10:24:10 +00:00
|
|
|
// notify an observer that its pixmap changed
|
2004-12-22 18:21:36 +00:00
|
|
|
if ( d->observers.contains( id ) )
|
|
|
|
d->observers[ id ]->observer->notifyPixmapChanged( pageNumber );
|
|
|
|
}
|
|
|
|
|
2005-01-02 22:37:52 +00:00
|
|
|
/** DocumentInfo **/
|
|
|
|
|
|
|
|
DocumentInfo::DocumentInfo()
|
|
|
|
: QDomDocument( "DocumentInformation" )
|
|
|
|
{
|
|
|
|
QDomElement docElement = createElement( "DocumentInfo" );
|
|
|
|
appendChild( docElement );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentInfo::set( const QString &key, const QString &value,
|
|
|
|
const QString &title )
|
|
|
|
{
|
|
|
|
QDomElement docElement = documentElement();
|
|
|
|
QDomElement element;
|
|
|
|
|
|
|
|
// check whether key already exists
|
|
|
|
QDomNodeList list = docElement.elementsByTagName( key );
|
|
|
|
if ( list.count() > 0 )
|
|
|
|
element = list.item( 0 ).toElement();
|
|
|
|
else
|
|
|
|
element = createElement( key );
|
|
|
|
|
|
|
|
element.setAttribute( "value", value );
|
|
|
|
element.setAttribute( "title", title );
|
|
|
|
|
|
|
|
if ( list.count() == 0 )
|
|
|
|
docElement.appendChild( element );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DocumentInfo::get( const QString &key ) const
|
|
|
|
{
|
|
|
|
QDomElement docElement = documentElement();
|
|
|
|
QDomElement element;
|
|
|
|
|
|
|
|
// check whether key already exists
|
|
|
|
QDomNodeList list = docElement.elementsByTagName( key );
|
|
|
|
if ( list.count() > 0 )
|
|
|
|
return list.item( 0 ).toElement().attribute( "value" );
|
|
|
|
else
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2004-12-22 18:21:36 +00:00
|
|
|
#include "document.moc"
|
2005-01-02 14:19:33 +00:00
|
|
|
#include "generator.moc"
|