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;
|
2014-05-10 09:35:33 +00:00
|
|
|
class QFile;
|
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
|
|
|
|
{
|
|
|
|
QSet< int > *pagesToNotify;
|
|
|
|
RegularAreaRect *match;
|
|
|
|
int currentPage;
|
|
|
|
int searchID;
|
|
|
|
};
|
|
|
|
|
2014-05-11 13:55:46 +00:00
|
|
|
enum LoadDocumentInfoFlag
|
|
|
|
{
|
|
|
|
LoadNone = 0,
|
|
|
|
LoadPageInfo = 1, // Load annotations and forms
|
|
|
|
LoadGeneralInfo = 2, // History, rotation, ...
|
|
|
|
LoadAllInfo = 0xff
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(LoadDocumentInfoFlags, LoadDocumentInfoFlag)
|
|
|
|
|
2007-09-14 15:17:36 +00:00
|
|
|
class DocumentPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DocumentPrivate( Document *parent )
|
|
|
|
: m_parent( parent ),
|
|
|
|
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-23 21:43:44 +00:00
|
|
|
m_annotationEditingEnabled ( true ),
|
2014-09-09 14:08:32 +00:00
|
|
|
m_annotationBeingMoved( false ),
|
|
|
|
m_docdataMigrationNeeded( 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
|
2014-05-11 14:36:28 +00:00
|
|
|
bool updateMetadataXmlNameAndDocSize();
|
2007-09-14 15:17:36 +00:00
|
|
|
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 );
|
2014-09-09 14:08:32 +00:00
|
|
|
bool loadDocumentInfo( LoadDocumentInfoFlags loadWhat );
|
|
|
|
bool loadDocumentInfo( QFile &infoFile, LoadDocumentInfoFlags loadWhat );
|
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 );
|
2014-05-09 17:56:16 +00:00
|
|
|
Document::OpenResult openDocumentInternal( const KService::Ptr& offer, bool isstdin, const QString& docFile, const QByteArray& filedata, const QString& password );
|
2014-05-10 10:32:12 +00:00
|
|
|
static ArchiveData *unpackDocumentArchive( const QString &archivePath );
|
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 );
|
2014-05-11 13:06:27 +00:00
|
|
|
void notifyFormChanges( 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;
|
2014-08-08 20:35:53 +00:00
|
|
|
OKULAR_EXPORT static QString docDataFileName(const KUrl &url, qint64 document_size);
|
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);
|
2014-05-09 22:49:01 +00:00
|
|
|
void doContinueAllDocumentSearch(void *pagesToNotifySet, void *pageMatchesMap, int currentPage, int searchID);
|
|
|
|
void doContinueGooglesDocumentSearch(void *pagesToNotifySet, void *pageMatchesMap, int currentPage, int searchID, const QStringList & words);
|
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;
|
|
|
|
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;
|
2014-05-11 09:17:49 +00:00
|
|
|
QSet<DocumentInfo::Key> m_documentInfoAskedKeys;
|
|
|
|
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-13 18:10:55 +00:00
|
|
|
bool m_annotationBeingMoved; // is an annotation currently being moved?
|
2014-05-11 11:37:22 +00:00
|
|
|
bool m_metadataLoadingCompleted;
|
2013-04-05 22:22:48 +00:00
|
|
|
|
|
|
|
QUndoStack *m_undoStack;
|
|
|
|
QDomNode m_prevPropsOfAnnotBeingModified;
|
2014-09-09 14:08:32 +00:00
|
|
|
|
|
|
|
// Since 0.21, we no longer support saving annotations and form data in
|
|
|
|
// the docdata/ directory and we ask the user to migrate them to an
|
|
|
|
// external file as soon as possible, otherwise the document will be
|
|
|
|
// shown in read-only mode. This flag is set if the docdata/ XML file
|
|
|
|
// for the current document contains any annotation or form.
|
|
|
|
bool m_docdataMigrationNeeded;
|
2013-04-05 22:22:48 +00:00
|
|
|
};
|
|
|
|
|
2014-05-11 09:17:49 +00:00
|
|
|
class DocumentInfoPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QMap<QString, QString> values; // key -> value
|
|
|
|
QMap<QString, QString> titles; // key -> title For the custom keys
|
|
|
|
};
|
|
|
|
|
2007-09-14 15:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2012-09-24 22:14:10 +00:00
|
|
|
|
|
|
|
/* kate: replace-tabs on; indent-width 4; */
|