Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

part.h 14.4 KB
Newer Older
1 2 3 4 5 6 7
/***************************************************************************
 *   Copyright (C) 2002 by Wilco Greven <greven@kde.org>                   *
 *   Copyright (C) 2003-2004 by Christophe Devriese                        *
 *                         <Christophe.Devriese@student.kuleuven.ac.be>    *
 *   Copyright (C) 2003 by Andy Goossens <andygoossens@telenet.be>         *
 *   Copyright (C) 2003 by Laurent Montel <montel@kde.org>                 *
 *   Copyright (C) 2004 by Dominique Devriese <devriese@kde.org>           *
Albert Astals Cid's avatar
Albert Astals Cid committed
8
 *   Copyright (C) 2004-2007 by Albert Astals Cid <aacid@kde.org>          *
9 10 11 12 13 14 15
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/

16 17
#ifndef _PART_H_
#define _PART_H_
18

19 20 21 22 23
#include <QIcon>
#include <QList>
#include <QPointer>
#include <QProcess>
#include <QtDBus>
Lukáš Tinkl's avatar
Lukáš Tinkl committed
24
#include <QUrl>
25 26 27 28 29 30 31

#include <KCompressionDevice>
#include <KIO/Job>
#include <KMessageWidget>
#include <KParts/ReadWritePart>
#include <KPluginFactory>

32
#include "core/observer.h"
33
#include "core/document.h"
34
#include "kdocumentviewer.h"
35
#include "interfaces/viewerinterface.h"
36

37
#include "okularpart_export.h"
38

Kevin Ottens's avatar
Kevin Ottens committed
39 40
#include <config-okular.h>

41
class QAction;
42
class QWidget;
43
class QPrinter;
44
class QMenu;
45

46
class KConfigDialog;
Tobias Koenig's avatar
Tobias Koenig committed
47
class KConfigGroup;
Albert Astals Cid's avatar
Albert Astals Cid committed
48
class KDirWatch;
49
class KToggleAction;
50
class KToggleFullScreenAction;
51
class KSelectAction;
52
class KAboutData;
Frederik Gladhorn's avatar
Frederik Gladhorn committed
53
class QTemporaryFile;
Vishesh Handa's avatar
Vishesh Handa committed
54
class QAction;
Kevin Ottens's avatar
Kevin Ottens committed
55
class QJsonObject;
56
namespace KParts { class GUIActivateEvent; }
57

58
class FindBar;
Albert Astals Cid's avatar
Albert Astals Cid committed
59
class ThumbnailList;
Albert Astals Cid's avatar
Albert Astals Cid committed
60
class PageSizeLabel;
61
class PageView;
62
class PresentationWidget;
63
class ProgressWidget;
64
class SearchWidget;
Pino Toscano's avatar
Pino Toscano committed
65
class Sidebar;
Albert Astals Cid's avatar
Albert Astals Cid committed
66 67
class TOC;
class MiniBar;
Albert Astals Cid's avatar
Albert Astals Cid committed
68
class MiniBarLogic;
69
class FileKeeper;
70 71
class Reviews;
class BookmarkList;
72
class DrawingToolActions;
73
class Layers;
74

Kevin Ottens's avatar
Kevin Ottens committed
75 76 77 78
#if PURPOSE_FOUND
namespace Purpose { class Menu; }
#endif

79 80
namespace Okular
{
81 82

class BrowserExtension;
83
class ExportFormat;
84

85 86 87 88 89 90 91 92 93 94 95
/**
 * 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
Laurent Montel's avatar
Laurent Montel committed
96
    ViewerWidgetMode         // the part acts as a widget that can display all kinds of documents
97 98
};

99 100 101 102 103 104 105 106
/**
 * This is a "Part".  It that does all the real work in a KPart
 * application.
 *
 * @short Main Part
 * @author Wilco Greven <greven@kde.org>
 * @version 0.2
 */
107
class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::DocumentObserver, public KDocumentViewer, public Okular::ViewerInterface
108
{
109
    Q_OBJECT
Pino Toscano's avatar
Pino Toscano committed
110 111
    Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
    Q_INTERFACES(KDocumentViewer)
112
    Q_INTERFACES(Okular::ViewerInterface)
113

114
    friend class PartTest;
115

Pino Toscano's avatar
Pino Toscano committed
116
    public:
117
        // Default constructor
118 119 120 121 122 123
        /**
         * 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'.
         **/
124
        Part(QWidget* parentWidget, QObject* parent, const QVariantList& args);
125 126 127 128 129

        // Destructor
        ~Part();

        // inherited from DocumentObserver
130 131 132
        void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags ) override;
        void notifyViewportChanged( bool smoothMove ) override;
        void notifyPageChanged( int page, int flags ) override;
133

134 135 136
        bool openDocument(const QUrl &url, uint page) override;
        void startPresentation() override;
        QStringList supportedMimeTypes() const override;
137

Lukáš Tinkl's avatar
Lukáš Tinkl committed
138
        QUrl realUrl() const;
139

140 141 142 143 144 145 146
        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;
147

148
    public Q_SLOTS:                // dbus
149
        Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page) override;
150
        Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc );
151 152
        Q_SCRIPTABLE uint pages();
        Q_SCRIPTABLE uint currentPage();
153
        Q_SCRIPTABLE QString currentDocument();
154
        Q_SCRIPTABLE QString documentMetaData( const QString &metaData ) const;
155 156 157 158 159 160 161
        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();
162
        Q_SCRIPTABLE void slotTogglePresentation();
163
        Q_SCRIPTABLE Q_NOREPLY void reload();
164
        Q_SCRIPTABLE Q_NOREPLY void enableStartWithPrint();
165

166
    Q_SIGNALS:
167
        void enablePrintAction(bool enable);
168
        void openSourceReference(const QString& absFileName, int line, int column);
169
        void viewerMenuStateChange(bool enabled);
170
        void enableCloseAction(bool enable);
Frederik Gladhorn's avatar
Frederik Gladhorn committed
171
        void mimeTypeChanged(QMimeType mimeType);
Vishesh Handa's avatar
Vishesh Handa committed
172
        void urlsDropped( const QList<QUrl>& urls );
173
        void fitWindowToPage( const QSize& pageViewPortSize, const QSize& pageSize );
174 175

    protected:
176
        // reimplemented from KParts::ReadWritePart
177 178 179
        bool openFile() override;
        bool openUrl(const QUrl &url) override;
        void guiActivateEvent(KParts::GUIActivateEvent *event) override;
Frederik Gladhorn's avatar
Frederik Gladhorn committed
180
        void displayInfoMessage( const QString &message, KMessageWidget::MessageType messageType = KMessageWidget::Information, int duration = -1 );
181
    public:
182 183 184 185 186
        bool queryClose() override;
        bool closeUrl() override;
        bool closeUrl(bool promptToSave) override;
        void setReadWrite(bool readwrite) override;
        bool saveAs(const QUrl & saveUrl) override;
187

188
    protected Q_SLOTS:
189
        // connected to actions
Lukáš Tinkl's avatar
Lukáš Tinkl committed
190 191
        void openUrlFromDocument(const QUrl &url);
        void openUrlFromBookmarks(const QUrl &url);
Vishesh Handa's avatar
Vishesh Handa committed
192
        void handleDroppedUrls( const QList<QUrl>& urls );
193 194 195
        void slotGoToPage();
        void slotHistoryBack();
        void slotHistoryNext();
196
        void slotAddBookmark();
197
        void slotRenameBookmarkFromMenu();
198
        void slotRemoveBookmarkFromMenu();
199
        void slotRenameCurrentViewportBookmark();
200 201 202
        void slotPreviousBookmark();
        void slotNextBookmark();
        void slotFindNext();
Pino Toscano's avatar
Pino Toscano committed
203
        void slotFindPrev();
204
        bool slotSaveFileAs(bool showOkularArchiveAsDefaultFormat = false);
205 206 207
        void slotGetNewStuff();
        void slotNewConfig();
        void slotShowMenu(const Okular::Page *page, const QPoint &point);
Albert Astals Cid's avatar
Albert Astals Cid committed
208
        void slotShowTOCMenu(const Okular::DocumentViewport &vp, const QPoint &point, const QString &title);
209 210 211
        void slotShowProperties();
        void slotShowEmbeddedFiles();
        void slotShowLeftPanel();
212
        void slotShowBottomBar();
213 214 215 216
        void slotShowPresentation();
        void slotHidePresentation();
        void slotExportAs(QAction *);
        bool slotImportPSFile();
217
        void slotAboutBackend();
218
        void slotReload();
219 220
        void close();
        void cannotQuit();
221 222
        void slotShowFindBar();
        void slotHideFindBar();
223
        void slotJobStarted(KIO::Job *job);
224
        void slotJobFinished(KJob *job);
225 226
        void loadCancelled(const QString &reason);
        void setWindowTitleFromDocument();
227 228
        // can be connected to widget elements
        void updateViewActions();
229
        void updateBookmarksActions();
230
        void enableTOC(bool enable);
231
        void slotRebuildBookmarkMenu();
232
        void enableLayers( bool enable );
233

234
    public Q_SLOTS:
235
        bool saveFile() override;
236 237 238
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
        void slotFileDirty( const QString& );
239
        bool slotAttemptReload( bool oneShot = false, const QUrl &newUrl = QUrl() );
240
        void psTransformEnded(int, QProcess::ExitStatus);
241
        KConfigDialog * slotGeneratorPreferences();
242

243 244 245 246
        void errorMessage( const QString &message, int duration = 0 );
        void warningMessage( const QString &message, int duration = -1 );
        void noticeMessage( const QString &message, int duration = -1 );

247 248
        void moveSplitter( const int sideWidgetSize );

249
    private:
250
        bool aboutToShowContextMenu(QMenu *menu, QAction *action, QMenu *contextMenu);
251
        void showMenu(const Okular::Page *page, const QPoint &point, const QString &bookmarkTitle = QString(), const Okular::DocumentViewport &vp = DocumentViewport());
252
        bool eventFilter(QObject * watched, QEvent * event) override;
Frederik Gladhorn's avatar
Frederik Gladhorn committed
253
        Document::OpenResult doOpenFile(const QMimeType &mime, const QString &fileNameToOpen, bool *isCompressedFile);
254
        bool openUrl( const QUrl &url, bool swapInsteadOfOpening );
255

256
        void setupViewerActions();
257
        void setViewerShortcuts();
258 259
        void setupActions();

John Layt's avatar
John Layt committed
260 261
        void setupPrint( QPrinter &printer );
        void doPrint( QPrinter &printer );
262
        bool handleCompressed(QString &destpath, const QString &path, KCompressionDevice::CompressionType compressionType );
263
        void rebuildBookmarkMenu( bool unplugActions = true );
264
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
265
        void unsetDummyMode();
266
        void slotRenameBookmark( const DocumentViewport &viewport );
267
        void slotRemoveBookmark( const DocumentViewport &viewport );
268
        void resetStartArguments();
269
        void checkNativeSaveDataLoss(bool *out_wontSaveForms, bool *out_wontSaveAnnotations) const;
270 271 272 273 274 275 276 277 278

        enum SaveAsFlag
        {
            NoSaveAsFlags = 0,         ///< No options
            SaveAsOkularArchive = 1,   ///< Save as Okular Archive (.okular) instead of document's native format
            SaveAsDontShowWarning = 2, ///< Don't show warning for unsupported save features
        };
        Q_DECLARE_FLAGS( SaveAsFlags, SaveAsFlag )

279
        bool saveAs( const QUrl & saveUrl, SaveAsFlags flags );
280

281 282 283
        void setFileToWatch( const QString &filePath );
        void unsetFileToWatch();

Kevin Ottens's avatar
Kevin Ottens committed
284 285 286 287
#if PURPOSE_FOUND
        void slotShareActionFinished(const QJsonObject &output, int error, const QString &message);
#endif

288
        static int numberOfParts;
Albert Astals Cid's avatar
Albert Astals Cid committed
289

Frederik Gladhorn's avatar
Frederik Gladhorn committed
290
        QTemporaryFile *m_tempfile;
291 292 293 294

        // the document
        Okular::Document * m_document;
        QString m_temporaryLocalFile;
295
        bool isDocumentArchive;
296
        bool m_swapInsteadOfOpening; // if set, the next open operation will replace the backing file (used when reloading just saved files)
297 298

        // main widgets
Pino Toscano's avatar
Pino Toscano committed
299
        Sidebar *m_sidebar;
300
        SearchWidget *m_searchWidget;
301
        FindBar * m_findBar;
302
        KMessageWidget * m_migrationMessage;
303 304
        KMessageWidget * m_topMessage;
        KMessageWidget * m_formsMessage;
305
        KMessageWidget * m_infoMessage;
306 307 308
        QPointer<ThumbnailList> m_thumbnailList;
        QPointer<PageView> m_pageView;
        QPointer<TOC> m_toc;
Albert Astals Cid's avatar
Albert Astals Cid committed
309
        QPointer<MiniBarLogic> m_miniBarLogic;
310
        QPointer<MiniBar> m_miniBar;
311
        QPointer<MiniBar> m_pageNumberTool;
312
        QPointer<QWidget> m_bottomBar;
313 314 315
        QPointer<PresentationWidget> m_presentationWidget;
        QPointer<ProgressWidget> m_progressWidget;
        QPointer<PageSizeLabel> m_pageSizeLabel;
316 317
        QPointer<Reviews> m_reviewsWidget;
        QPointer<BookmarkList> m_bookmarkList;
318
        QPointer<Layers> m_layers;
319 320 321

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
322
        QString m_watchedFilePath, m_watchedFileSymlinkTarget;
323
        QTimer *m_dirtyHandler;
Lukáš Tinkl's avatar
Lukáš Tinkl committed
324
        QUrl m_oldUrl;
325
        Okular::DocumentViewport m_viewportDirty;
326
        bool m_isReloading;
327
        bool m_wasPresentationOpen;
328
        QWidget *m_dirtyToolboxItem;
329
        bool m_wasSidebarVisible;
330
        bool m_wasSidebarCollapsed;
331
        bool m_fileWasRemoved;
332
        Rotation m_dirtyPageRotation;
333 334 335 336 337

        // Remember the search history
        QStringList m_searchHistory;

        // actions
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
        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_find;
        QAction *m_findNext;
        QAction *m_findPrev;
354
        QAction *m_save;
355 356 357 358 359 360
        QAction *m_saveAs;
        QAction *m_saveCopyAs;
        QAction *m_printPreview;
        QAction *m_showProperties;
        QAction *m_showEmbeddedFiles;
        QAction *m_exportAs;
361
        QAction *m_exportAsText;
362
        QAction *m_exportAsDocArchive;
Kevin Ottens's avatar
Kevin Ottens committed
363 364 365
#if PURPOSE_FOUND
        QAction *m_share;
#endif
366
        QAction *m_showPresentation;
367 368
        KToggleAction* m_showMenuBarAction;
        KToggleAction* m_showLeftPanel;
369
        KToggleAction* m_showBottomBar;
370
        KToggleFullScreenAction* m_showFullScreenAction;
371 372
        QAction *m_aboutBackend;
        QAction *m_reload;
373
        QMenu *m_exportAsMenu;
Kevin Ottens's avatar
Kevin Ottens committed
374 375 376
#if PURPOSE_FOUND
        Purpose::Menu *m_shareMenu;
#endif
377
        QAction *m_closeFindBar;
378
        DrawingToolActions *m_presentationDrawingActions;
379 380 381 382 383

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
384
        QList<QAction*> m_bookmarkActions;
385
        bool m_cliPresentation;
386
        bool m_cliPrint;
387
        QString m_addBookmarkText;
388
        QIcon m_addBookmarkIcon;
389

390
        EmbedMode m_embedMode;
391

Lukáš Tinkl's avatar
Lukáš Tinkl committed
392
        QUrl m_realUrl;
393

394
        KXMLGUIClient *m_generatorGuiClient;
395
        FileKeeper *m_keeper;
396

397 398 399
        // Timer for m_infoMessage
        QTimer *m_infoTimer;

Albert Astals Cid's avatar
Albert Astals Cid committed
400 401
        QString m_registerDbusName;

402
    private Q_SLOTS:
403
        void slotAnnotationPreferences();
Michel Ludwig's avatar
Michel Ludwig committed
404
        void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
405
};
Wilco Greven's avatar
Wilco Greven committed
406

407 408
}

409 410
#endif

411
/* kate: replace-tabs on; indent-width 4; */