forked from KDE/okular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
part.h
426 lines (372 loc) · 15.2 KB
/
part.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/***************************************************************************
* Copyright (C) 2002 by Wilco Greven <[email protected]> *
* Copyright (C) 2003-2004 by Christophe Devriese *
* <[email protected]> *
* Copyright (C) 2003 by Andy Goossens <[email protected]> *
* Copyright (C) 2003 by Laurent Montel <[email protected]> *
* Copyright (C) 2004 by Dominique Devriese <[email protected]> *
* Copyright (C) 2004-2007 by Albert Astals Cid <[email protected]> *
* Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group *
* company, [email protected]. Work sponsored by the *
* LiMux project of the city of Munich *
* *
* 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 _PART_H_
#define _PART_H_
#include <QIcon>
#include <QList>
#include <QPointer>
#include <QProcess>
#include <QtDBus> // krazy:exclude=includes
#include <QUrl>
#include <KCompressionDevice>
#include <KIO/Job>
#include <KMessageWidget>
#include <KParts/ReadWritePart>
#include <KPluginFactory>
#include "core/observer.h"
#include "core/document.h"
#include "kdocumentviewer.h"
#include "interfaces/viewerinterface.h"
#include "okularpart_export.h"
#include <config-okular.h>
class QAction;
class QWidget;
class QPrinter;
class QMenu;
class KConfigDialog;
class KDirWatch;
class KToggleAction;
class KToggleFullScreenAction;
class QTemporaryFile;
class QAction;
class QJsonObject;
namespace KParts { class GUIActivateEvent; }
class FindBar;
class ThumbnailList;
class PageSizeLabel;
class PageView;
class PresentationWidget;
class ProgressWidget;
class SearchWidget;
class Sidebar;
class TOC;
class MiniBar;
class MiniBarLogic;
class FileKeeper;
class Reviews;
class BookmarkList;
class DrawingToolActions;
class Layers;
class SignaturePanel;
#if PURPOSE_FOUND
namespace Purpose { class Menu; }
#endif
namespace Okular
{
class BrowserExtension;
class ExportFormat;
/**
* Describes the possible embedding modes of the part
*
* @since 0.14 (KDE 4.8)
*/
enum EmbedMode
{
UnknownEmbedMode,
NativeShellMode, // embedded in the native Okular' shell
PrintPreviewMode, // embedded to show the print preview of a document
KHTMLPartMode, // embedded in KHTML
ViewerWidgetMode // the part acts as a widget that can display all kinds of documents
};
/**
* This is a "Part". It that does all the real work in a KPart
* application.
*
* @short Main Part
* @author Wilco Greven <[email protected]>
* @version 0.2
*/
class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::DocumentObserver, public KDocumentViewer, public Okular::ViewerInterface
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
Q_INTERFACES(KDocumentViewer)
Q_INTERFACES(Okular::ViewerInterface)
friend class PartTest;
public:
// Default constructor
/**
* If one element of 'args' contains one of the strings "Print/Preview" or "ViewerWidget",
* the part will be set up in the corresponding mode. Additionally, it is possible to specify
* which config file should be used by adding a string containing "ConfigFileName=<file name>"
* to 'args'.
**/
Part(QWidget* parentWidget, QObject* parent, const QVariantList& args);
// Destructor
~Part();
// inherited from DocumentObserver
void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags ) override;
void notifyViewportChanged( bool smoothMove ) override;
void notifyPageChanged( int page, int flags ) override;
bool openDocument(const QUrl &url, uint page) override;
void startPresentation() override;
QStringList supportedMimeTypes() const override;
QUrl realUrl() const;
void showSourceLocation(const QString& fileName, int line, int column, bool showGraphically = true) override;
void clearLastShownSourceLocation() override;
bool isWatchFileModeEnabled() const override;
void setWatchFileModeEnabled(bool enable) override;
bool areSourceLocationsShownGraphically() const override;
void setShowSourceLocationsGraphically(bool show) override;
bool openNewFilesInTabs() const override;
public Q_SLOTS: // dbus
Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page) override;
Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc );
Q_SCRIPTABLE uint pages();
Q_SCRIPTABLE uint currentPage();
Q_SCRIPTABLE QString currentDocument();
Q_SCRIPTABLE QString documentMetaData( const QString &metaData ) const;
Q_SCRIPTABLE void slotPreferences();
Q_SCRIPTABLE void slotFind();
Q_SCRIPTABLE void slotPrintPreview();
Q_SCRIPTABLE void slotPreviousPage();
Q_SCRIPTABLE void slotNextPage();
Q_SCRIPTABLE void slotGotoFirst();
Q_SCRIPTABLE void slotGotoLast();
Q_SCRIPTABLE void slotTogglePresentation();
Q_SCRIPTABLE void slotToggleChangeColors();
Q_SCRIPTABLE void slotSetChangeColors(bool active);
Q_SCRIPTABLE Q_NOREPLY void reload();
Q_SCRIPTABLE Q_NOREPLY void enableStartWithPrint();
Q_SCRIPTABLE Q_NOREPLY void enableExitAfterPrint();
Q_SCRIPTABLE Q_NOREPLY void enableStartWithFind(const QString &text);
Q_SIGNALS:
void enablePrintAction(bool enable);
void openSourceReference(const QString& absFileName, int line, int column);
void viewerMenuStateChange(bool enabled);
void enableCloseAction(bool enable);
void mimeTypeChanged(QMimeType mimeType);
void urlsDropped( const QList<QUrl>& urls );
void fitWindowToPage( const QSize& pageViewPortSize, const QSize& pageSize );
protected:
// reimplemented from KParts::ReadWritePart
bool openFile() override;
bool openUrl(const QUrl &url) override;
void guiActivateEvent(KParts::GUIActivateEvent *event) override;
void displayInfoMessage( const QString &message, KMessageWidget::MessageType messageType = KMessageWidget::Information, int duration = -1 );
public:
bool queryClose() override;
bool closeUrl() override;
bool closeUrl(bool promptToSave) override;
void setReadWrite(bool readwrite) override;
bool saveAs(const QUrl & saveUrl) override;
protected Q_SLOTS:
// connected to actions
void openUrlFromDocument(const QUrl &url);
void openUrlFromBookmarks(const QUrl &url);
void handleDroppedUrls( const QList<QUrl>& urls );
void slotGoToPage();
void slotHistoryBack();
void slotHistoryNext();
void slotAddBookmark();
void slotRenameBookmarkFromMenu();
void slotRemoveBookmarkFromMenu();
void slotRenameCurrentViewportBookmark();
void slotPreviousBookmark();
void slotNextBookmark();
void slotFindNext();
void slotFindPrev();
bool slotSaveFileAs(bool showOkularArchiveAsDefaultFormat = false);
void slotGetNewStuff();
void slotNewConfig();
void slotShowMenu(const Okular::Page *page, const QPoint &point);
void slotShowTOCMenu(const Okular::DocumentViewport &vp, const QPoint &point, const QString &title);
void slotShowProperties();
void slotShowEmbeddedFiles();
void slotShowLeftPanel();
void slotShowBottomBar();
void slotShowPresentation();
void slotHidePresentation();
void slotExportAs(QAction *);
bool slotImportPSFile();
void slotAboutBackend();
void slotReload();
void close();
void cannotQuit();
void slotShowFindBar();
void slotHideFindBar();
void slotJobStarted(KIO::Job *job);
void slotJobFinished(KJob *job);
void loadCancelled(const QString &reason);
void setWindowTitleFromDocument();
// can be connected to widget elements
void updateViewActions();
void updateBookmarksActions();
void enableTOC(bool enable);
void slotRebuildBookmarkMenu();
void enableLayers( bool enable );
void showSidebarSignaturesItem( bool show );
public Q_SLOTS:
bool saveFile() override;
// connected to Shell action (and browserExtension), not local one
void slotPrint();
void slotFileDirty( const QString& );
bool slotAttemptReload( bool oneShot = false, const QUrl &newUrl = QUrl() );
void psTransformEnded(int, QProcess::ExitStatus);
KConfigDialog * slotGeneratorPreferences();
void errorMessage( const QString &message, int duration = 0 );
void warningMessage( const QString &message, int duration = -1 );
void noticeMessage( const QString &message, int duration = -1 );
void moveSplitter( const int sideWidgetSize );
private:
bool aboutToShowContextMenu(QMenu *menu, QAction *action, QMenu *contextMenu);
void showMenu(const Okular::Page *page, const QPoint &point, const QString &bookmarkTitle = QString(), const Okular::DocumentViewport &vp = DocumentViewport(), bool showTOCActions = false);
bool eventFilter(QObject * watched, QEvent * event) override;
Document::OpenResult doOpenFile(const QMimeType &mime, const QString &fileNameToOpen, bool *isCompressedFile);
bool openUrl( const QUrl &url, bool swapInsteadOfOpening );
void setupViewerActions();
void setViewerShortcuts();
void setupActions();
void setupPrint( QPrinter &printer );
bool doPrint( QPrinter &printer );
bool handleCompressed(QString &destpath, const QString &path, KCompressionDevice::CompressionType compressionType );
void rebuildBookmarkMenu( bool unplugActions = true );
void updateAboutBackendAction();
void unsetDummyMode();
void slotRenameBookmark( const DocumentViewport &viewport );
void slotRemoveBookmark( const DocumentViewport &viewport );
void resetStartArguments();
void checkNativeSaveDataLoss(bool *out_wontSaveForms, bool *out_wontSaveAnnotations) const;
enum SaveAsFlag
{
NoSaveAsFlags = 0, ///< No options
SaveAsOkularArchive = 1 ///< Save as Okular Archive (.okular) instead of document's native format
};
Q_DECLARE_FLAGS( SaveAsFlags, SaveAsFlag )
bool saveAs( const QUrl & saveUrl, SaveAsFlags flags );
void setFileToWatch( const QString &filePath );
void unsetFileToWatch();
#if PURPOSE_FOUND
void slotShareActionFinished(const QJsonObject &output, int error, const QString &message);
#endif
static int numberOfParts;
QTemporaryFile *m_tempfile;
// the document
Okular::Document * m_document;
QDateTime m_fileLastModified;
QString m_temporaryLocalFile;
bool isDocumentArchive;
bool m_documentOpenWithPassword;
bool m_swapInsteadOfOpening; // if set, the next open operation will replace the backing file (used when reloading just saved files)
// main widgets
Sidebar *m_sidebar;
SearchWidget *m_searchWidget;
FindBar * m_findBar;
KMessageWidget * m_migrationMessage;
KMessageWidget * m_topMessage;
KMessageWidget * m_formsMessage;
KMessageWidget * m_infoMessage;
KMessageWidget * m_signatureMessage;
QPointer<ThumbnailList> m_thumbnailList;
QPointer<PageView> m_pageView;
QPointer<TOC> m_toc;
QPointer<MiniBarLogic> m_miniBarLogic;
QPointer<MiniBar> m_miniBar;
QPointer<MiniBar> m_pageNumberTool;
QPointer<QWidget> m_bottomBar;
QPointer<PresentationWidget> m_presentationWidget;
QPointer<ProgressWidget> m_progressWidget;
QPointer<PageSizeLabel> m_pageSizeLabel;
QPointer<Reviews> m_reviewsWidget;
QPointer<BookmarkList> m_bookmarkList;
QPointer<Layers> m_layers;
QPointer<SignaturePanel> m_signaturePanel;
// document watcher (and reloader) variables
KDirWatch *m_watcher;
QString m_watchedFilePath, m_watchedFileSymlinkTarget;
QTimer *m_dirtyHandler;
QUrl m_oldUrl;
Okular::DocumentViewport m_viewportDirty;
bool m_isReloading;
bool m_wasPresentationOpen;
QWidget *m_dirtyToolboxItem;
bool m_wasSidebarVisible;
bool m_wasSidebarCollapsed;
bool m_fileWasRemoved;
Rotation m_dirtyPageRotation;
// Remember the search history
QStringList m_searchHistory;
// actions
QAction *m_gotoPage;
QAction *m_prevPage;
QAction *m_nextPage;
QAction *m_beginningOfDocument;
QAction *m_endOfDocument;
QAction *m_historyBack;
QAction *m_historyNext;
QAction *m_addBookmark;
QAction *m_renameBookmark;
QAction *m_prevBookmark;
QAction *m_nextBookmark;
QAction *m_copy;
QAction *m_selectAll;
QAction *m_selectCurrentPage;
QAction *m_find;
QAction *m_findNext;
QAction *m_findPrev;
QAction *m_save;
QAction *m_saveAs;
QAction *m_saveCopyAs;
QAction *m_printPreview;
QAction *m_showProperties;
QAction *m_showEmbeddedFiles;
QAction *m_exportAs;
QAction *m_exportAsText;
QAction *m_exportAsDocArchive;
#if PURPOSE_FOUND
QAction *m_share;
#endif
QAction *m_showPresentation;
KToggleAction* m_showMenuBarAction;
KToggleAction* m_showLeftPanel;
KToggleAction* m_showBottomBar;
QAction* m_showSignaturePanel;
KToggleFullScreenAction* m_showFullScreenAction;
QAction *m_aboutBackend;
QAction *m_reload;
QMenu *m_exportAsMenu;
#if PURPOSE_FOUND
Purpose::Menu *m_shareMenu;
#endif
QAction *m_closeFindBar;
DrawingToolActions *m_presentationDrawingActions;
bool m_actionsSearched;
BrowserExtension *m_bExtension;
QList<Okular::ExportFormat> m_exportFormats;
QList<QAction*> m_bookmarkActions;
bool m_cliPresentation;
bool m_cliPrint;
bool m_cliPrintAndExit;
QString m_addBookmarkText;
QIcon m_addBookmarkIcon;
EmbedMode m_embedMode;
QUrl m_realUrl;
KXMLGUIClient *m_generatorGuiClient;
FileKeeper *m_keeper;
// Timer for m_infoMessage
QTimer *m_infoTimer;
QString m_registerDbusName;
// String to search in document startup
QString m_textToFindOnOpen;
private Q_SLOTS:
void slotAnnotationPreferences();
void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
};
}
#endif
/* kate: replace-tabs on; indent-width 4; */