2007-09-14 15:17:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it> *
|
|
|
|
* Copyright (C) 2004-2007 by Albert Astals Cid <aacid@kde.org> *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _OKULAR_DOCUMENT_P_H_
|
|
|
|
#define _OKULAR_DOCUMENT_P_H_
|
|
|
|
|
|
|
|
#include "document.h"
|
|
|
|
|
|
|
|
// qt/kde/system includes
|
|
|
|
#include <QtCore/QHash>
|
|
|
|
#include <QtCore/QLinkedList>
|
|
|
|
#include <QtCore/QMap>
|
|
|
|
#include <QtCore/QMutex>
|
2008-09-21 22:44:42 +00:00
|
|
|
#include <QtCore/QPointer>
|
2007-09-14 15:17:36 +00:00
|
|
|
|
2007-12-02 20:57:24 +00:00
|
|
|
#include <kcomponentdata.h>
|
2007-09-14 15:17:36 +00:00
|
|
|
#include <kservicetypetrader.h>
|
|
|
|
|
|
|
|
// local includes
|
|
|
|
#include "fontinfo.h"
|
|
|
|
#include "generator.h"
|
|
|
|
|
2013-04-05 22:22:48 +00:00
|
|
|
class QUndoStack;
|
2008-02-01 00:43:45 +00:00
|
|
|
class QEventLoop;
|
2007-09-14 15:17:36 +00:00
|
|
|
class QTimer;
|
|
|
|
class KTemporaryFile;
|
|
|
|
|
|
|
|
struct AllocatedPixmap;
|
2008-11-15 14:15:31 +00:00
|
|
|
struct ArchiveData;
|
2007-09-14 15:17:36 +00:00
|
|
|
struct RunningSearch;
|
|
|
|
|
2007-11-25 12:49:30 +00:00
|
|
|
namespace Okular {
|
|
|
|
class ConfigInterface;
|
2013-07-30 15:00:32 +00:00
|
|
|
class PageController;
|
2008-03-11 23:40:59 +00:00
|
|
|
class SaveInterface;
|
2008-04-13 22:31:59 +00:00
|
|
|
class Scripter;
|
2008-04-27 11:05:59 +00:00
|
|
|
class View;
|
2007-11-25 12:49:30 +00:00
|
|
|
}
|
|
|
|
|
2007-09-14 15:17:36 +00:00
|
|
|
struct GeneratorInfo
|
|
|
|
{
|
2007-12-02 20:57:24 +00:00
|
|
|
GeneratorInfo( const KComponentData &_data )
|
2008-03-11 23:40:59 +00:00
|
|
|
: generator( 0 ), data( _data ),
|
|
|
|
config( 0 ), save( 0 ),
|
|
|
|
configChecked( false ), saveChecked( false )
|
2007-09-14 15:17:36 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
Okular::Generator * generator;
|
2007-12-02 20:57:24 +00:00
|
|
|
KComponentData data;
|
2007-09-14 15:17:36 +00:00
|
|
|
QString catalogName;
|
2007-11-25 12:49:30 +00:00
|
|
|
Okular::ConfigInterface * config;
|
2008-03-11 23:40:59 +00:00
|
|
|
Okular::SaveInterface * save;
|
2007-11-25 12:49:30 +00:00
|
|
|
bool configChecked : 1;
|
2008-03-11 23:40:59 +00:00
|
|
|
bool saveChecked : 1;
|
2007-09-14 15:17:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace Okular {
|
|
|
|
|
|
|
|
class FontExtractionThread;
|
|
|
|
|
2012-09-24 22:14:10 +00:00
|
|
|
struct DoContinueDirectionMatchSearchStruct
|
|
|
|
{
|
|
|
|
bool forward;
|
|
|
|
QSet< int > *pagesToNotify;
|
|
|
|
RegularAreaRect *match;
|
|
|
|
int currentPage;
|
|
|
|
int searchID;
|
|
|
|
QString text;
|
|
|
|
Qt::CaseSensitivity caseSensitivity;
|
|
|
|
bool moveViewport;
|
|
|
|
QColor color;
|
|
|
|
bool noDialogs;
|
|
|
|
int pagesDone;
|
|
|
|
};
|
|
|
|
|
2007-09-14 15:17:36 +00:00
|
|
|
class DocumentPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DocumentPrivate( Document *parent )
|
|
|
|
: m_parent( parent ),
|
|
|
|
m_lastSearchID( -1 ),
|
|
|
|
m_tempFile( 0 ),
|
|
|
|
m_docSize( -1 ),
|
|
|
|
m_allocatedPixmapsTotalMemory( 0 ),
|
2008-10-04 19:13:33 +00:00
|
|
|
m_maxAllocatedTextPages( 0 ),
|
2007-09-14 15:17:36 +00:00
|
|
|
m_warnedOutOfMemory( false ),
|
|
|
|
m_rotation( Rotation0 ),
|
|
|
|
m_exportCached( false ),
|
|
|
|
m_bookmarkManager( 0 ),
|
|
|
|
m_memCheckTimer( 0 ),
|
|
|
|
m_saveBookmarksTimer( 0 ),
|
|
|
|
m_generator( 0 ),
|
|
|
|
m_generatorsLoaded( false ),
|
2013-07-30 15:00:32 +00:00
|
|
|
m_pageController( 0 ),
|
2008-02-01 00:43:45 +00:00
|
|
|
m_closingLoop( 0 ),
|
2008-04-13 22:31:59 +00:00
|
|
|
m_scripter( 0 ),
|
2008-11-15 14:15:31 +00:00
|
|
|
m_archiveData( 0 ),
|
2009-11-16 00:46:33 +00:00
|
|
|
m_fontsCached( false ),
|
2012-05-13 18:10:55 +00:00
|
|
|
m_documentInfo( 0 ),
|
2012-05-23 21:43:44 +00:00
|
|
|
m_annotationEditingEnabled ( true ),
|
2012-05-13 18:10:55 +00:00
|
|
|
m_annotationBeingMoved( false )
|
2007-09-14 15:17:36 +00:00
|
|
|
{
|
2008-05-04 15:10:32 +00:00
|
|
|
calculateMaxTextPages();
|
2007-09-14 15:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// private methods
|
|
|
|
QString pagesSizeString() const;
|
2012-12-31 10:14:54 +00:00
|
|
|
QString namePaperSize(double inchesWidth, double inchesHeight) const;
|
2007-09-14 15:17:36 +00:00
|
|
|
QString localizedSize(const QSizeF &size) const;
|
2012-07-01 23:19:32 +00:00
|
|
|
qulonglong calculateMemoryToFree();
|
|
|
|
void cleanupPixmapMemory();
|
|
|
|
void cleanupPixmapMemory( qulonglong memoryToFree );
|
2013-02-24 21:58:53 +00:00
|
|
|
AllocatedPixmap * searchLowestPriorityPixmap( bool unloadableOnly = false, bool thenRemoveIt = false, DocumentObserver *observer = 0 /* any */ );
|
2008-05-04 15:10:32 +00:00
|
|
|
void calculateMaxTextPages();
|
2007-09-14 15:17:36 +00:00
|
|
|
qulonglong getTotalMemory();
|
2012-06-24 21:53:01 +00:00
|
|
|
qulonglong getFreeMemory( qulonglong *freeSwap = 0 );
|
2007-09-14 15:17:36 +00:00
|
|
|
void loadDocumentInfo();
|
2008-11-15 00:34:03 +00:00
|
|
|
void loadDocumentInfo( const QString &fileName );
|
2008-05-31 21:13:15 +00:00
|
|
|
void loadViewsInfo( View *view, const QDomElement &e );
|
|
|
|
void saveViewsInfo( View *view, QDomElement &e ) const;
|
2007-09-14 15:17:36 +00:00
|
|
|
QString giveAbsolutePath( const QString & fileName ) const;
|
|
|
|
bool openRelativeFile( const QString & fileName );
|
2007-12-02 20:57:24 +00:00
|
|
|
Generator * loadGeneratorLibrary( const KService::Ptr &service );
|
2007-09-14 15:17:36 +00:00
|
|
|
void loadAllGeneratorLibraries();
|
|
|
|
void loadServiceList( const KService::List& offers );
|
|
|
|
void unloadGenerator( const GeneratorInfo& info );
|
|
|
|
void cacheExportFormats();
|
2007-11-01 16:15:34 +00:00
|
|
|
void setRotationInternal( int r, bool notify );
|
2007-11-25 12:49:30 +00:00
|
|
|
ConfigInterface* generatorConfig( GeneratorInfo& info );
|
2008-03-11 23:40:59 +00:00
|
|
|
SaveInterface* generatorSave( GeneratorInfo& info );
|
2008-11-09 14:21:20 +00:00
|
|
|
bool openDocumentInternal( const KService::Ptr& offer, bool isstdin, const QString& docFile, const QByteArray& filedata );
|
2008-11-15 14:15:31 +00:00
|
|
|
bool savePageDocumentInfo( KTemporaryFile *infoFile, int what ) const;
|
2009-05-13 14:24:30 +00:00
|
|
|
DocumentViewport nextDocumentViewport() const;
|
2012-05-23 21:43:44 +00:00
|
|
|
void notifyAnnotationChanges( int page );
|
2012-05-14 13:51:58 +00:00
|
|
|
bool canAddAnnotationsNatively() const;
|
2012-03-09 13:59:24 +00:00
|
|
|
bool canModifyExternalAnnotations() const;
|
|
|
|
bool canRemoveExternalAnnotations() const;
|
2012-05-14 13:51:58 +00:00
|
|
|
void warnLimitedAnnotSupport();
|
2007-09-14 15:17:36 +00:00
|
|
|
|
2013-04-05 22:22:48 +00:00
|
|
|
// Methods that implement functionality needed by undo commands
|
|
|
|
void performAddPageAnnotation( int page, Annotation *annotation );
|
|
|
|
void performRemovePageAnnotation( int page, Annotation * annotation );
|
|
|
|
void performModifyPageAnnotation( int page, Annotation * annotation, bool appearanceChanged );
|
|
|
|
void performSetAnnotationContents( const QString & newContents, Annotation *annot, int pageNumber );
|
|
|
|
|
2007-09-14 15:17:36 +00:00
|
|
|
// private slots
|
|
|
|
void saveDocumentInfo() const;
|
|
|
|
void slotTimedMemoryCheck();
|
2012-09-25 09:09:34 +00:00
|
|
|
void sendGeneratorPixmapRequest();
|
2009-06-30 17:21:55 +00:00
|
|
|
void rotationFinished( int page, Okular::Page *okularPage );
|
2007-09-14 15:17:36 +00:00
|
|
|
void fontReadingProgress( int page );
|
|
|
|
void fontReadingGotFont( const Okular::FontInfo& font );
|
|
|
|
void slotGeneratorConfigChanged( const QString& );
|
2008-03-07 15:50:48 +00:00
|
|
|
void refreshPixmaps( int );
|
2008-05-04 15:02:35 +00:00
|
|
|
void _o_configChanged();
|
2012-09-24 22:14:10 +00:00
|
|
|
void doContinueDirectionMatchSearch(void *doContinueDirectionMatchSearchStruct);
|
2007-09-14 15:17:36 +00:00
|
|
|
void doContinueAllDocumentSearch(void *pagesToNotifySet, void *pageMatchesMap, int currentPage, int searchID, const QString & text, int caseSensitivity, const QColor & color);
|
2008-10-19 10:07:48 +00:00
|
|
|
void doContinueGooglesDocumentSearch(void *pagesToNotifySet, void *pageMatchesMap, int currentPage, int searchID, const QStringList & words, int caseSensitivity, const QColor & color, bool matchAll);
|
2007-09-14 15:17:36 +00:00
|
|
|
|
2010-04-15 22:26:58 +00:00
|
|
|
void doProcessSearchMatch( RegularAreaRect *match, RunningSearch *search, QSet< int > *pagesToNotify, int currentPage, int searchID, bool moveViewport, const QColor & color );
|
|
|
|
|
2007-09-14 15:29:16 +00:00
|
|
|
// generators stuff
|
|
|
|
/**
|
|
|
|
* This method is used by the generators to signal the finish of
|
|
|
|
* the pixmap generation @p request.
|
|
|
|
*/
|
|
|
|
void requestDone( PixmapRequest * request );
|
2008-05-04 15:10:32 +00:00
|
|
|
void textGenerationDone( Page *page );
|
2008-05-18 23:06:21 +00:00
|
|
|
/**
|
|
|
|
* Sets the bounding box of the given @p page (in terms of upright orientation, i.e., Rotation0).
|
|
|
|
*/
|
|
|
|
void setPageBoundingBox( int page, const NormalizedRect& boundingBox );
|
2007-09-14 22:16:00 +00:00
|
|
|
/**
|
|
|
|
* Request a particular metadata of the Document itself (ie, not something
|
|
|
|
* depending on the document type/backend).
|
|
|
|
*/
|
|
|
|
QVariant documentMetaData( const QString &key, const QVariant &option ) const;
|
2007-09-14 15:29:16 +00:00
|
|
|
|
2013-12-29 22:27:30 +00:00
|
|
|
/**
|
|
|
|
* Return whether the normalized rectangle @p rectOfInterest on page number @p rectPage
|
|
|
|
* is fully visible.
|
|
|
|
*/
|
|
|
|
bool isNormalizedRectangleFullyVisible( const Okular::NormalizedRect & rectOfInterest, int rectPage );
|
|
|
|
|
2007-09-14 15:17:36 +00:00
|
|
|
// member variables
|
|
|
|
Document *m_parent;
|
2008-09-21 22:44:42 +00:00
|
|
|
QPointer<QWidget> m_widget;
|
2007-09-14 15:17:36 +00:00
|
|
|
|
|
|
|
// find descriptors, mapped by ID (we handle multiple searches)
|
|
|
|
QMap< int, RunningSearch * > m_searches;
|
|
|
|
int m_lastSearchID;
|
|
|
|
bool m_searchCancelled;
|
|
|
|
|
|
|
|
// needed because for remote documents docFileName is a local file and
|
|
|
|
// we want the remote url when the document refers to relativeNames
|
|
|
|
KUrl m_url;
|
|
|
|
|
|
|
|
// cached stuff
|
|
|
|
QString m_docFileName;
|
|
|
|
QString m_xmlFileName;
|
|
|
|
KTemporaryFile *m_tempFile;
|
2007-09-30 10:49:38 +00:00
|
|
|
qint64 m_docSize;
|
2007-09-14 15:17:36 +00:00
|
|
|
|
|
|
|
// viewport stuff
|
|
|
|
QLinkedList< DocumentViewport > m_viewportHistory;
|
|
|
|
QLinkedList< DocumentViewport >::iterator m_viewportIterator;
|
|
|
|
DocumentViewport m_nextDocumentViewport; // see Link::Goto for an explanation
|
2009-05-13 14:24:30 +00:00
|
|
|
QString m_nextDocumentDestination;
|
2007-09-14 15:17:36 +00:00
|
|
|
|
|
|
|
// observers / requests / allocator stuff
|
2013-02-24 21:58:53 +00:00
|
|
|
QSet< DocumentObserver * > m_observers;
|
2007-09-14 15:17:36 +00:00
|
|
|
QLinkedList< PixmapRequest * > m_pixmapRequestsStack;
|
2008-02-01 00:43:45 +00:00
|
|
|
QLinkedList< PixmapRequest * > m_executingPixmapRequests;
|
2007-09-14 15:17:36 +00:00
|
|
|
QMutex m_pixmapRequestsMutex;
|
2012-07-01 23:05:02 +00:00
|
|
|
QLinkedList< AllocatedPixmap * > m_allocatedPixmaps;
|
2007-09-14 15:17:36 +00:00
|
|
|
qulonglong m_allocatedPixmapsTotalMemory;
|
2008-05-04 15:10:32 +00:00
|
|
|
QList< int > m_allocatedTextPagesFifo;
|
|
|
|
int m_maxAllocatedTextPages;
|
2007-09-14 15:17:36 +00:00
|
|
|
bool m_warnedOutOfMemory;
|
|
|
|
|
|
|
|
// the rotation applied to the document
|
|
|
|
Rotation m_rotation;
|
|
|
|
|
|
|
|
// the current size of the pages (if available), and the cache of the
|
|
|
|
// available page sizes
|
|
|
|
PageSize m_pageSize;
|
|
|
|
PageSize::List m_pageSizes;
|
|
|
|
|
|
|
|
// cache of the export formats
|
|
|
|
bool m_exportCached;
|
|
|
|
ExportFormat::List m_exportFormats;
|
|
|
|
ExportFormat m_exportToText;
|
|
|
|
|
|
|
|
// our bookmark manager
|
|
|
|
BookmarkManager *m_bookmarkManager;
|
|
|
|
|
|
|
|
// timers (memory checking / info saver)
|
|
|
|
QTimer *m_memCheckTimer;
|
|
|
|
QTimer *m_saveBookmarksTimer;
|
|
|
|
|
|
|
|
QHash<QString, GeneratorInfo> m_loadedGenerators;
|
|
|
|
Generator * m_generator;
|
|
|
|
QString m_generatorName;
|
|
|
|
bool m_generatorsLoaded;
|
|
|
|
QVector< Page * > m_pagesVector;
|
|
|
|
QVector< VisiblePageRect * > m_pageRects;
|
|
|
|
|
|
|
|
// cache of the mimetype we support
|
|
|
|
QStringList m_supportedMimeTypes;
|
|
|
|
|
2013-07-30 15:00:32 +00:00
|
|
|
PageController *m_pageController;
|
2008-02-01 00:43:45 +00:00
|
|
|
QEventLoop *m_closingLoop;
|
|
|
|
|
2008-04-13 22:31:59 +00:00
|
|
|
Scripter *m_scripter;
|
|
|
|
|
2008-11-15 14:15:31 +00:00
|
|
|
ArchiveData *m_archiveData;
|
2012-06-07 15:05:00 +00:00
|
|
|
QString m_archivedFileName;
|
2008-11-15 14:15:31 +00:00
|
|
|
|
2007-09-14 15:17:36 +00:00
|
|
|
QPointer< FontExtractionThread > m_fontThread;
|
|
|
|
bool m_fontsCached;
|
2009-11-16 00:46:33 +00:00
|
|
|
DocumentInfo *m_documentInfo;
|
2007-09-14 15:17:36 +00:00
|
|
|
FontInfo::List m_fontsCache;
|
2008-04-27 11:05:59 +00:00
|
|
|
|
|
|
|
QSet< View * > m_views;
|
2012-05-13 18:10:55 +00:00
|
|
|
|
2012-05-23 21:43:44 +00:00
|
|
|
bool m_annotationEditingEnabled;
|
2012-05-30 16:38:51 +00:00
|
|
|
bool m_annotationsNeedSaveAs;
|
2012-05-13 18:10:55 +00:00
|
|
|
bool m_annotationBeingMoved; // is an annotation currently being moved?
|
2012-05-14 13:51:58 +00:00
|
|
|
bool m_showWarningLimitedAnnotSupport;
|
2013-04-05 22:22:48 +00:00
|
|
|
|
|
|
|
QUndoStack *m_undoStack;
|
|
|
|
QDomNode m_prevPropsOfAnnotBeingModified;
|
|
|
|
};
|
|
|
|
|
2007-09-14 15:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2012-09-24 22:14:10 +00:00
|
|
|
|
|
|
|
/* kate: replace-tabs on; indent-width 4; */
|