compile
[kdegraphics.git] / okular / core / document_p.h
blobe386586398f37fd42b0081137725ada2be8e6ae4
1 /***************************************************************************
2 * Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it> *
3 * Copyright (C) 2004-2007 by Albert Astals Cid <aacid@kde.org> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
11 #ifndef _OKULAR_DOCUMENT_P_H_
12 #define _OKULAR_DOCUMENT_P_H_
14 #include "document.h"
16 // qt/kde/system includes
17 #include <QtCore/QHash>
18 #include <QtCore/QLinkedList>
19 #include <QtCore/QMap>
20 #include <QtCore/QMutex>
21 #include <QtCore/QPointer>
23 #include <kcomponentdata.h>
24 #include <kservicetypetrader.h>
26 // local includes
27 #include "fontinfo.h"
28 #include "generator.h"
30 class QEventLoop;
31 class QTimer;
32 class KTemporaryFile;
34 struct AllocatedPixmap;
35 struct RunningSearch;
37 namespace Okular {
38 class ConfigInterface;
39 class SaveInterface;
40 class Scripter;
41 class View;
44 struct GeneratorInfo
46 GeneratorInfo( const KComponentData &_data )
47 : generator( 0 ), data( _data ),
48 config( 0 ), save( 0 ),
49 configChecked( false ), saveChecked( false )
52 Okular::Generator * generator;
53 KComponentData data;
54 QString catalogName;
55 Okular::ConfigInterface * config;
56 Okular::SaveInterface * save;
57 bool configChecked : 1;
58 bool saveChecked : 1;
61 namespace Okular {
63 class FontExtractionThread;
65 class DocumentPrivate
67 public:
68 DocumentPrivate( Document *parent )
69 : m_parent( parent ),
70 m_lastSearchID( -1 ),
71 m_tempFile( 0 ),
72 m_docSize( -1 ),
73 m_allocatedPixmapsTotalMemory( 0 ),
74 m_warnedOutOfMemory( false ),
75 m_rotation( Rotation0 ),
76 m_exportCached( false ),
77 m_bookmarkManager( 0 ),
78 m_memCheckTimer( 0 ),
79 m_saveBookmarksTimer( 0 ),
80 m_generator( 0 ),
81 m_generatorsLoaded( false ),
82 m_closingLoop( 0 ),
83 m_scripter( 0 ),
84 m_fontsCached( false )
86 calculateMaxTextPages();
89 // private methods
90 QString pagesSizeString() const;
91 QString localizedSize(const QSizeF &size) const;
92 void cleanupPixmapMemory( qulonglong bytesOffset = 0 );
93 void calculateMaxTextPages();
94 qulonglong getTotalMemory();
95 qulonglong getFreeMemory();
96 void loadDocumentInfo();
97 void loadViewsInfo( View *view, const QDomElement &e );
98 void saveViewsInfo( View *view, QDomElement &e ) const;
99 QString giveAbsolutePath( const QString & fileName ) const;
100 bool openRelativeFile( const QString & fileName );
101 Generator * loadGeneratorLibrary( const KService::Ptr &service );
102 void loadAllGeneratorLibraries();
103 void loadServiceList( const KService::List& offers );
104 void unloadGenerator( const GeneratorInfo& info );
105 void cacheExportFormats();
106 void setRotationInternal( int r, bool notify );
107 ConfigInterface* generatorConfig( GeneratorInfo& info );
108 SaveInterface* generatorSave( GeneratorInfo& info );
110 // private slots
111 void saveDocumentInfo() const;
112 void slotTimedMemoryCheck();
113 void sendGeneratorRequest();
114 void rotationFinished( int page );
115 void fontReadingProgress( int page );
116 void fontReadingGotFont( const Okular::FontInfo& font );
117 void slotGeneratorConfigChanged( const QString& );
118 void refreshPixmaps( int );
119 void _o_configChanged();
120 void doContinueNextMatchSearch(void *pagesToNotifySet, void * match, int currentPage, int searchID, const QString & text, int caseSensitivity, bool moveViewport, const QColor & color, bool noDialogs, int donePages);
121 void doContinuePrevMatchSearch(void *pagesToNotifySet, void * theMatch, int currentPage, int searchID, const QString & text, int theCaseSensitivity, bool moveViewport, const QColor & color, bool noDialogs, int donePages);
122 void doContinueAllDocumentSearch(void *pagesToNotifySet, void *pageMatchesMap, int currentPage, int searchID, const QString & text, int caseSensitivity, const QColor & color);
123 void doContinueGooglesDocumentSearch(void *pagesToNotifySet, void *pageMatchesMap, int currentPage, int searchID, const QString & text, int caseSensitivity, const QColor & color, bool matchAll);
125 // generators stuff
127 * This method is used by the generators to signal the finish of
128 * the pixmap generation @p request.
130 void requestDone( PixmapRequest * request );
131 void textGenerationDone( Page *page );
133 * Sets the bounding box of the given @p page (in terms of upright orientation, i.e., Rotation0).
135 void setPageBoundingBox( int page, const NormalizedRect& boundingBox );
137 * Request a particular metadata of the Document itself (ie, not something
138 * depending on the document type/backend).
140 QVariant documentMetaData( const QString &key, const QVariant &option ) const;
142 // member variables
143 Document *m_parent;
144 QPointer<QWidget> m_widget;
146 // find descriptors, mapped by ID (we handle multiple searches)
147 QMap< int, RunningSearch * > m_searches;
148 int m_lastSearchID;
149 bool m_searchCancelled;
151 // needed because for remote documents docFileName is a local file and
152 // we want the remote url when the document refers to relativeNames
153 KUrl m_url;
155 // cached stuff
156 QString m_docFileName;
157 QString m_xmlFileName;
158 KTemporaryFile *m_tempFile;
159 qint64 m_docSize;
161 // viewport stuff
162 QLinkedList< DocumentViewport > m_viewportHistory;
163 QLinkedList< DocumentViewport >::iterator m_viewportIterator;
164 DocumentViewport m_nextDocumentViewport; // see Link::Goto for an explanation
166 // observers / requests / allocator stuff
167 QMap< int, DocumentObserver * > m_observers;
168 QLinkedList< PixmapRequest * > m_pixmapRequestsStack;
169 QLinkedList< PixmapRequest * > m_executingPixmapRequests;
170 QMutex m_pixmapRequestsMutex;
171 QLinkedList< AllocatedPixmap * > m_allocatedPixmapsFifo;
172 qulonglong m_allocatedPixmapsTotalMemory;
173 QList< int > m_allocatedTextPagesFifo;
174 int m_maxAllocatedTextPages;
175 bool m_warnedOutOfMemory;
177 // the rotation applied to the document
178 Rotation m_rotation;
180 // the current size of the pages (if available), and the cache of the
181 // available page sizes
182 PageSize m_pageSize;
183 PageSize::List m_pageSizes;
185 // cache of the export formats
186 bool m_exportCached;
187 ExportFormat::List m_exportFormats;
188 ExportFormat m_exportToText;
190 // our bookmark manager
191 BookmarkManager *m_bookmarkManager;
193 // timers (memory checking / info saver)
194 QTimer *m_memCheckTimer;
195 QTimer *m_saveBookmarksTimer;
197 QHash<QString, GeneratorInfo> m_loadedGenerators;
198 Generator * m_generator;
199 QString m_generatorName;
200 bool m_generatorsLoaded;
201 QVector< Page * > m_pagesVector;
202 QVector< VisiblePageRect * > m_pageRects;
204 // cache of the mimetype we support
205 QStringList m_supportedMimeTypes;
207 QEventLoop *m_closingLoop;
209 Scripter *m_scripter;
211 QPointer< FontExtractionThread > m_fontThread;
212 bool m_fontsCached;
213 FontInfo::List m_fontsCache;
215 QSet< View * > m_views;
220 #endif