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.6 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 202 203 204
        void slotGetNewStuff();
        void slotNewConfig();
        void slotShowMenu(const Okular::Page *page, const QPoint &point);
        void slotShowProperties();
        void slotShowEmbeddedFiles();
        void slotShowLeftPanel();
205
        void slotShowBottomBar();
206 207 208 209
        void slotShowPresentation();
        void slotHidePresentation();
        void slotExportAs(QAction *);
        bool slotImportPSFile();
210
        void slotAboutBackend();
211
        void slotReload();
212 213
        void close();
        void cannotQuit();
214 215
        void slotShowFindBar();
        void slotHideFindBar();
216
        void slotJobStarted(KIO::Job *job);
217
        void slotJobFinished(KJob *job);
218 219
        void loadCancelled(const QString &reason);
        void setWindowTitleFromDocument();
220 221
        // can be connected to widget elements
        void updateViewActions();
222
        void updateBookmarksActions();
223
        void enableTOC(bool enable);
224
        void slotRebuildBookmarkMenu();
225
        void enableLayers( bool enable );
226

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

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

239 240
        void moveSplitter( const int sideWidgetSize );

241
    private:
242 243
        bool aboutToShowContextMenu(QMenu *menu, QAction *action, QMenu *contextMenu);
        bool eventFilter(QObject * watched, QEvent * event) override;
Frederik Gladhorn's avatar
Frederik Gladhorn committed
244
        Document::OpenResult doOpenFile(const QMimeType &mime, const QString &fileNameToOpen, bool *isCompressedFile);
245

246
        void setupViewerActions();
247
        void setViewerShortcuts();
248 249
        void setupActions();

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

259
        static int numberOfParts;
Albert Astals Cid's avatar
Albert Astals Cid committed
260

Frederik Gladhorn's avatar
Frederik Gladhorn committed
261
        QTemporaryFile *m_tempfile;
262 263 264 265

        // the document
        Okular::Document * m_document;
        QString m_temporaryLocalFile;
266
        bool isDocumentArchive;
267 268

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

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

        // Remember the search history
        QStringList m_searchHistory;

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

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

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

350
        EmbedMode m_embedMode;
351

Lukáš Tinkl's avatar
Lukáš Tinkl committed
352
        QUrl m_realUrl;
353

354
        KXMLGUIClient *m_generatorGuiClient;
355
        FileKeeper *m_keeper;
356

357 358 359
        // Timer for m_infoMessage
        QTimer *m_infoTimer;

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

365 366
}

367 368
#endif

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