1 | /*************************************************************************** |
2 | * Copyright (C) 2002 by Wilco Greven <greven@kde.org> * |
3 | * Copyright (C) 2003-2004 by Christophe Devriese * |
4 | * <Christophe.Devriese@student.kuleuven.ac.be> * |
5 | * Copyright (C) 2003 by Andy Goossens <andygoossens@telenet.be> * |
6 | * Copyright (C) 2003 by Laurent Montel <montel@kde.org> * |
7 | * Copyright (C) 2004 by Dominique Devriese <devriese@kde.org> * |
8 | * Copyright (C) 2004-2007 by Albert Astals Cid <aacid@kde.org> * |
9 | * * |
10 | * This program is free software; you can redistribute it and/or modify * |
11 | * it under the terms of the GNU General Public License as published by * |
12 | * the Free Software Foundation; either version 2 of the License, or * |
13 | * (at your option) any later version. * |
14 | ***************************************************************************/ |
15 | |
16 | #ifndef _PART_H_ |
17 | #define _PART_H_ |
18 | |
19 | #include <kparts/part.h> |
20 | #include <kpluginfactory.h> |
21 | #include <kmessagewidget.h> |
22 | #include <qicon.h> |
23 | #include <qlist.h> |
24 | #include <qpointer.h> |
25 | #include <qprocess.h> |
26 | #include "core/observer.h" |
27 | #include "core/document.h" |
28 | #include "kdocumentviewer.h" |
29 | #include "interfaces/viewerinterface.h" |
30 | |
31 | #include "okular_part_export.h" |
32 | |
33 | #include <QtDBus/QtDBus> |
34 | |
35 | class QAction; |
36 | class QWidget; |
37 | class QPrinter; |
38 | class ; |
39 | |
40 | class KUrl; |
41 | class KConfigDialog; |
42 | class KConfigGroup; |
43 | class KDirWatch; |
44 | class KToggleAction; |
45 | class KToggleFullScreenAction; |
46 | class KSelectAction; |
47 | class KAboutData; |
48 | class KTemporaryFile; |
49 | class KAction; |
50 | class ; |
51 | namespace KParts { class GUIActivateEvent; } |
52 | |
53 | class FindBar; |
54 | class ThumbnailList; |
55 | class PageSizeLabel; |
56 | class PageView; |
57 | class PresentationWidget; |
58 | class ProgressWidget; |
59 | class SearchWidget; |
60 | class ; |
61 | class TOC; |
62 | class MiniBar; |
63 | class MiniBarLogic; |
64 | class FileKeeper; |
65 | class Reviews; |
66 | class BookmarkList; |
67 | |
68 | namespace Okular |
69 | { |
70 | |
71 | class BrowserExtension; |
72 | class ExportFormat; |
73 | |
74 | /** |
75 | * Describes the possible embedding modes of the part |
76 | * |
77 | * @since 0.14 (KDE 4.8) |
78 | */ |
79 | enum EmbedMode |
80 | { |
81 | UnknownEmbedMode, |
82 | NativeShellMode, // embedded in the native Okular' shell |
83 | PrintPreviewMode, // embedded to show the print preview of a document |
84 | KHTMLPartMode, // embedded in KHTML |
85 | ViewerWidgetMode // the part acts as a widget that can display all kinds of documents |
86 | }; |
87 | |
88 | /** |
89 | * This is a "Part". It that does all the real work in a KPart |
90 | * application. |
91 | * |
92 | * @short Main Part |
93 | * @author Wilco Greven <greven@kde.org> |
94 | * @version 0.2 |
95 | */ |
96 | class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::DocumentObserver, public KDocumentViewer, public Okular::ViewerInterface |
97 | { |
98 | Q_OBJECT |
99 | Q_CLASSINFO("D-Bus Interface" , "org.kde.okular" ) |
100 | Q_INTERFACES(KDocumentViewer) |
101 | Q_INTERFACES(Okular::ViewerInterface) |
102 | |
103 | friend class PartTest; |
104 | |
105 | public: |
106 | // Default constructor |
107 | /** |
108 | * If one element of 'args' contains one of the strings "Print/Preview" or "ViewerWidget", |
109 | * the part will be set up in the corresponding mode. Additionally, it is possible to specify |
110 | * which config file should be used by adding a string containing "ConfigFileName=<file name>" |
111 | * to 'args'. |
112 | **/ |
113 | Part(QWidget* parentWidget, QObject* parent, const QVariantList& args, KComponentData componentData); |
114 | |
115 | // Destructor |
116 | ~Part(); |
117 | |
118 | // inherited from DocumentObserver |
119 | void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags ); |
120 | void notifyViewportChanged( bool smoothMove ); |
121 | void notifyPageChanged( int page, int flags ); |
122 | |
123 | bool openDocument(const KUrl& url, uint page); |
124 | void startPresentation(); |
125 | QStringList supportedMimeTypes() const; |
126 | |
127 | KUrl realUrl() const; |
128 | |
129 | void showSourceLocation(const QString& fileName, int line, int column, bool showGraphically = true); |
130 | void clearLastShownSourceLocation(); |
131 | bool isWatchFileModeEnabled() const; |
132 | void setWatchFileModeEnabled(bool enable); |
133 | bool areSourceLocationsShownGraphically() const; |
134 | void setShowSourceLocationsGraphically(bool show); |
135 | bool openNewFilesInTabs() const; |
136 | |
137 | public slots: // dbus |
138 | Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page); |
139 | Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc ); |
140 | Q_SCRIPTABLE uint pages(); |
141 | Q_SCRIPTABLE uint currentPage(); |
142 | Q_SCRIPTABLE QString currentDocument(); |
143 | Q_SCRIPTABLE QString documentMetaData( const QString &metaData ) const; |
144 | Q_SCRIPTABLE void slotPreferences(); |
145 | Q_SCRIPTABLE void slotFind(); |
146 | Q_SCRIPTABLE void slotPrintPreview(); |
147 | Q_SCRIPTABLE void slotPreviousPage(); |
148 | Q_SCRIPTABLE void slotNextPage(); |
149 | Q_SCRIPTABLE void slotGotoFirst(); |
150 | Q_SCRIPTABLE void slotGotoLast(); |
151 | Q_SCRIPTABLE void slotTogglePresentation(); |
152 | Q_SCRIPTABLE Q_NOREPLY void reload(); |
153 | Q_SCRIPTABLE Q_NOREPLY void enableStartWithPrint(); |
154 | |
155 | signals: |
156 | void enablePrintAction(bool enable); |
157 | void openSourceReference(const QString& absFileName, int line, int column); |
158 | void (bool enabled); |
159 | void enableCloseAction(bool enable); |
160 | void mimeTypeChanged(KMimeType::Ptr mimeType); |
161 | void urlsDropped( const KUrl::List& urls ); |
162 | |
163 | protected: |
164 | // reimplemented from KParts::ReadWritePart |
165 | bool openFile(); |
166 | bool openUrl(const KUrl &url); |
167 | void guiActivateEvent(KParts::GUIActivateEvent *event); |
168 | void displayInfoMessage( const QString &message, KMessageWidget::MessageType messageType = KMessageWidget::Information, int duration = -1 );; |
169 | public: |
170 | bool saveFile(); |
171 | bool queryClose(); |
172 | bool closeUrl(); |
173 | bool closeUrl(bool promptToSave); |
174 | void setReadWrite(bool readwrite); |
175 | bool saveAs(const KUrl & saveUrl); |
176 | |
177 | protected slots: |
178 | // connected to actions |
179 | void openUrlFromDocument(const KUrl &url); |
180 | void openUrlFromBookmarks(const KUrl &url); |
181 | void handleDroppedUrls( const KUrl::List& urls ); |
182 | void slotGoToPage(); |
183 | void slotHistoryBack(); |
184 | void slotHistoryNext(); |
185 | void slotAddBookmark(); |
186 | void (); |
187 | void slotRenameCurrentViewportBookmark(); |
188 | void (KMenu *, QAction *action, QMenu *); |
189 | void slotPreviousBookmark(); |
190 | void slotNextBookmark(); |
191 | void slotFindNext(); |
192 | void slotFindPrev(); |
193 | void slotSaveFileAs(); |
194 | void slotSaveCopyAs(); |
195 | void slotGetNewStuff(); |
196 | void slotNewConfig(); |
197 | void (const Okular::Page *page, const QPoint &point); |
198 | void slotShowProperties(); |
199 | void slotShowEmbeddedFiles(); |
200 | void slotShowLeftPanel(); |
201 | void slotShowBottomBar(); |
202 | void slotShowPresentation(); |
203 | void slotHidePresentation(); |
204 | void slotExportAs(QAction *); |
205 | bool slotImportPSFile(); |
206 | void slotAboutBackend(); |
207 | void slotReload(); |
208 | void close(); |
209 | void cannotQuit(); |
210 | void slotShowFindBar(); |
211 | void slotHideFindBar(); |
212 | void slotJobStarted(KIO::Job *job); |
213 | void slotJobFinished(KJob *job); |
214 | void loadCancelled(const QString &reason); |
215 | void setWindowTitleFromDocument(); |
216 | // can be connected to widget elements |
217 | void updateViewActions(); |
218 | void updateBookmarksActions(); |
219 | void enableTOC(bool enable); |
220 | void (); |
221 | |
222 | public slots: |
223 | // connected to Shell action (and browserExtension), not local one |
224 | void slotPrint(); |
225 | void restoreDocument(const KConfigGroup &group); |
226 | void saveDocumentRestoreInfo(KConfigGroup &group); |
227 | void slotFileDirty( const QString& ); |
228 | void slotDoFileDirty(); |
229 | void psTransformEnded(int, QProcess::ExitStatus); |
230 | KConfigDialog * slotGeneratorPreferences(); |
231 | |
232 | void errorMessage( const QString &message, int duration = 0 ); |
233 | void warningMessage( const QString &message, int duration = -1 ); |
234 | void noticeMessage( const QString &message, int duration = -1 ); |
235 | |
236 | private: |
237 | void setupViewerActions(); |
238 | void setViewerShortcuts(); |
239 | void setupActions(); |
240 | |
241 | void setupPrint( QPrinter &printer ); |
242 | void doPrint( QPrinter &printer ); |
243 | bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype ); |
244 | void ( bool unplugActions = true ); |
245 | void updateAboutBackendAction(); |
246 | void unsetDummyMode(); |
247 | void slotRenameBookmark( const DocumentViewport &viewport ); |
248 | void resetStartArguments(); |
249 | |
250 | static int numberOfParts; |
251 | |
252 | KTemporaryFile *m_tempfile; |
253 | |
254 | // the document |
255 | Okular::Document * m_document; |
256 | QString m_temporaryLocalFile; |
257 | bool isDocumentArchive; |
258 | |
259 | // main widgets |
260 | Sidebar *; |
261 | SearchWidget *m_searchWidget; |
262 | FindBar * m_findBar; |
263 | KMessageWidget * m_topMessage; |
264 | KMessageWidget * m_formsMessage; |
265 | KMessageWidget * m_infoMessage; |
266 | QPointer<ThumbnailList> m_thumbnailList; |
267 | QPointer<PageView> m_pageView; |
268 | QPointer<TOC> m_toc; |
269 | QPointer<MiniBarLogic> m_miniBarLogic; |
270 | QPointer<MiniBar> m_miniBar; |
271 | QPointer<MiniBar> m_pageNumberTool; |
272 | QPointer<QWidget> m_bottomBar; |
273 | QPointer<PresentationWidget> m_presentationWidget; |
274 | QPointer<ProgressWidget> m_progressWidget; |
275 | QPointer<PageSizeLabel> m_pageSizeLabel; |
276 | QPointer<Reviews> m_reviewsWidget; |
277 | QPointer<BookmarkList> m_bookmarkList; |
278 | |
279 | // document watcher (and reloader) variables |
280 | KDirWatch *m_watcher; |
281 | QTimer *m_dirtyHandler; |
282 | KUrl m_oldUrl; |
283 | Okular::DocumentViewport m_viewportDirty; |
284 | bool m_wasPresentationOpen; |
285 | int m_dirtyToolboxIndex; |
286 | bool ; |
287 | bool ; |
288 | bool m_fileWasRemoved; |
289 | Rotation ; |
290 | |
291 | // Remember the search history |
292 | QStringList m_searchHistory; |
293 | |
294 | // actions |
295 | KAction *m_gotoPage; |
296 | KAction *m_prevPage; |
297 | KAction *m_nextPage; |
298 | KAction *m_beginningOfDocument; |
299 | KAction *m_endOfDocument; |
300 | KAction *m_historyBack; |
301 | KAction *m_historyNext; |
302 | KAction *m_addBookmark; |
303 | KAction *m_renameBookmark; |
304 | KAction *m_prevBookmark; |
305 | KAction *m_nextBookmark; |
306 | KAction *m_copy; |
307 | KAction *m_selectAll; |
308 | KAction *m_find; |
309 | KAction *m_findNext; |
310 | KAction *m_findPrev; |
311 | KAction *m_saveAs; |
312 | KAction *m_saveCopyAs; |
313 | KAction *m_printPreview; |
314 | KAction *m_showProperties; |
315 | KAction *m_showEmbeddedFiles; |
316 | KAction *m_exportAs; |
317 | QAction *m_exportAsText; |
318 | QAction *m_exportAsDocArchive; |
319 | KAction *m_showPresentation; |
320 | KToggleAction* ; |
321 | KToggleAction* m_showLeftPanel; |
322 | KToggleAction* m_showBottomBar; |
323 | KToggleFullScreenAction* m_showFullScreenAction; |
324 | KAction *m_aboutBackend; |
325 | KAction *m_reload; |
326 | QMenu *; |
327 | KAction *m_closeFindBar; |
328 | |
329 | bool m_actionsSearched; |
330 | BrowserExtension *m_bExtension; |
331 | |
332 | QList<Okular::ExportFormat> m_exportFormats; |
333 | QList<QAction*> m_bookmarkActions; |
334 | bool m_cliPresentation; |
335 | bool m_cliPrint; |
336 | QString m_addBookmarkText; |
337 | QIcon m_addBookmarkIcon; |
338 | |
339 | EmbedMode m_embedMode; |
340 | |
341 | KUrl m_realUrl; |
342 | |
343 | KXMLGUIClient *m_generatorGuiClient; |
344 | FileKeeper *m_keeper; |
345 | |
346 | // Timer for m_infoMessage |
347 | QTimer *m_infoTimer; |
348 | |
349 | private slots: |
350 | void slotAnnotationPreferences(); |
351 | void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled); |
352 | }; |
353 | |
354 | class PartFactory : public KPluginFactory |
355 | { |
356 | Q_OBJECT |
357 | |
358 | public: |
359 | PartFactory(); |
360 | virtual ~PartFactory(); |
361 | |
362 | protected: |
363 | virtual QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword); |
364 | }; |
365 | |
366 | } |
367 | |
368 | #endif |
369 | |
370 | /* kate: replace-tabs on; indent-width 4; */ |
371 | |