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 12.9 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

39
class QAction;
40
class QWidget;
41
class QPrinter;
42
class QMenu;
43

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

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

72 73
namespace Okular
{
74 75

class BrowserExtension;
76
class ExportFormat;
77

78 79 80 81 82 83 84 85 86 87 88
/**
 * 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
89
    ViewerWidgetMode         // the part acts as a widget that can display all kinds of documents
90 91
};

92 93 94 95 96 97 98 99
/**
 * 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
 */
100
class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::DocumentObserver, public KDocumentViewer, public Okular::ViewerInterface
101
{
102
    Q_OBJECT
Pino Toscano's avatar
Pino Toscano committed
103 104
    Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
    Q_INTERFACES(KDocumentViewer)
105
    Q_INTERFACES(Okular::ViewerInterface)
106

107
    friend class PartTest;
108

Pino Toscano's avatar
Pino Toscano committed
109
    public:
110
        // Default constructor
111 112 113 114 115 116
        /**
         * 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'.
         **/
117
        Part(QWidget* parentWidget, QObject* parent, const QVariantList& args);
118 119 120 121 122

        // Destructor
        ~Part();

        // inherited from DocumentObserver
123 124 125
        void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags ) override;
        void notifyViewportChanged( bool smoothMove ) override;
        void notifyPageChanged( int page, int flags ) override;
126

127 128 129
        bool openDocument(const QUrl &url, uint page) override;
        void startPresentation() override;
        QStringList supportedMimeTypes() const override;
130

Lukáš Tinkl's avatar
Lukáš Tinkl committed
131
        QUrl realUrl() const;
132

133 134 135 136 137 138 139
        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;
140

141
    public Q_SLOTS:                // dbus
142
        Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page) override;
143
        Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc );
144 145
        Q_SCRIPTABLE uint pages();
        Q_SCRIPTABLE uint currentPage();
146
        Q_SCRIPTABLE QString currentDocument();
147
        Q_SCRIPTABLE QString documentMetaData( const QString &metaData ) const;
148 149 150 151 152 153 154
        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();
155
        Q_SCRIPTABLE void slotTogglePresentation();
156
        Q_SCRIPTABLE Q_NOREPLY void reload();
157
        Q_SCRIPTABLE Q_NOREPLY void enableStartWithPrint();
158

159
    Q_SIGNALS:
160
        void enablePrintAction(bool enable);
161
        void openSourceReference(const QString& absFileName, int line, int column);
162
        void viewerMenuStateChange(bool enabled);
163
        void enableCloseAction(bool enable);
Frederik Gladhorn's avatar
Frederik Gladhorn committed
164
        void mimeTypeChanged(QMimeType mimeType);
Vishesh Handa's avatar
Vishesh Handa committed
165
        void urlsDropped( const QList<QUrl>& urls );
166
        void fitWindowToPage( const QSize& pageViewPortSize, const QSize& pageSize );
167 168

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

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

228
    public Q_SLOTS:
229 230 231 232
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
        void slotFileDirty( const QString& );
        void slotDoFileDirty();
233
        void psTransformEnded(int, QProcess::ExitStatus);
234
        KConfigDialog * slotGeneratorPreferences();
235

236 237 238 239
        void errorMessage( const QString &message, int duration = 0 );
        void warningMessage( const QString &message, int duration = -1 );
        void noticeMessage( const QString &message, int duration = -1 );

240 241
        void moveSplitter( const int sideWidgetSize );

242
    private:
243
        bool aboutToShowContextMenu(QMenu *menu, QAction *action, QMenu *contextMenu);
244
        void showMenu(const Okular::Page *page, const QPoint &point, const QString &bookmarkTitle = QString(), const Okular::DocumentViewport &vp = DocumentViewport());
245
        bool eventFilter(QObject * watched, QEvent * event) override;
Frederik Gladhorn's avatar
Frederik Gladhorn committed
246
        Document::OpenResult doOpenFile(const QMimeType &mime, const QString &fileNameToOpen, bool *isCompressedFile);
247

248
        void setupViewerActions();
249
        void setViewerShortcuts();
250 251
        void setupActions();

John Layt's avatar
John Layt committed
252 253
        void setupPrint( QPrinter &printer );
        void doPrint( QPrinter &printer );
254
        bool handleCompressed(QString &destpath, const QString &path, KCompressionDevice::CompressionType compressionType );
255
        void rebuildBookmarkMenu( bool unplugActions = true );
256
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
257
        void unsetDummyMode();
258
        void slotRenameBookmark( const DocumentViewport &viewport );
259
        void resetStartArguments();
260

261
        static int numberOfParts;
Albert Astals Cid's avatar
Albert Astals Cid committed
262

Frederik Gladhorn's avatar
Frederik Gladhorn committed
263
        QTemporaryFile *m_tempfile;
264 265 266 267

        // the document
        Okular::Document * m_document;
        QString m_temporaryLocalFile;
268
        bool isDocumentArchive;
269 270

        // main widgets
Pino Toscano's avatar
Pino Toscano committed
271
        Sidebar *m_sidebar;
272
        SearchWidget *m_searchWidget;
273
        FindBar * m_findBar;
274 275
        KMessageWidget * m_topMessage;
        KMessageWidget * m_formsMessage;
276
        KMessageWidget * m_infoMessage;
277 278 279
        QPointer<ThumbnailList> m_thumbnailList;
        QPointer<PageView> m_pageView;
        QPointer<TOC> m_toc;
Albert Astals Cid's avatar
Albert Astals Cid committed
280
        QPointer<MiniBarLogic> m_miniBarLogic;
281
        QPointer<MiniBar> m_miniBar;
282
        QPointer<MiniBar> m_pageNumberTool;
283
        QPointer<QWidget> m_bottomBar;
284 285 286
        QPointer<PresentationWidget> m_presentationWidget;
        QPointer<ProgressWidget> m_progressWidget;
        QPointer<PageSizeLabel> m_pageSizeLabel;
287 288
        QPointer<Reviews> m_reviewsWidget;
        QPointer<BookmarkList> m_bookmarkList;
289
        QPointer<Layers> m_layers;
290 291 292 293

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
Lukáš Tinkl's avatar
Lukáš Tinkl committed
294
        QUrl m_oldUrl;
295 296
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
297
        QWidget *m_dirtyToolboxItem;
298
        bool m_wasSidebarVisible;
299
        bool m_wasSidebarCollapsed;
300
        bool m_fileWasRemoved;
301
        Rotation m_dirtyPageRotation;
302 303 304 305 306

        // Remember the search history
        QStringList m_searchHistory;

        // actions
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
        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;
        QAction *m_saveAs;
        QAction *m_saveCopyAs;
        QAction *m_printPreview;
        QAction *m_showProperties;
        QAction *m_showEmbeddedFiles;
        QAction *m_exportAs;
329
        QAction *m_exportAsText;
330
        QAction *m_exportAsDocArchive;
331
        QAction *m_showPresentation;
332 333
        KToggleAction* m_showMenuBarAction;
        KToggleAction* m_showLeftPanel;
334
        KToggleAction* m_showBottomBar;
335
        KToggleFullScreenAction* m_showFullScreenAction;
336 337
        QAction *m_aboutBackend;
        QAction *m_reload;
338
        QMenu *m_exportAsMenu;
339
        QAction *m_closeFindBar;
340
        DrawingToolActions *m_presentationDrawingActions;
341 342 343 344 345

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
346
        QList<QAction*> m_bookmarkActions;
347
        bool m_cliPresentation;
348
        bool m_cliPrint;
349
        QString m_addBookmarkText;
350
        QIcon m_addBookmarkIcon;
351

352
        EmbedMode m_embedMode;
353

Lukáš Tinkl's avatar
Lukáš Tinkl committed
354
        QUrl m_realUrl;
355

356
        KXMLGUIClient *m_generatorGuiClient;
357
        FileKeeper *m_keeper;
358

359 360 361
        // Timer for m_infoMessage
        QTimer *m_infoTimer;

362
    private Q_SLOTS:
363
        void slotAnnotationPreferences();
Michel Ludwig's avatar
Michel Ludwig committed
364
        void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
365
};
Wilco Greven's avatar
Wilco Greven committed
366

367 368
}

369 370
#endif

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