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.7 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
#include <kparts/readwritepart.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>
Lukáš Tinkl's avatar
Lukáš Tinkl committed
26
#include <QUrl>
27
#include <kio/job.h>
28
#include "core/observer.h"
29
#include "core/document.h"
30
#include "kdocumentviewer.h"
31
#include "interfaces/viewerinterface.h"
32

33
#include "okularpart_export.h"
34

Pino Toscano's avatar
Pino Toscano committed
35
#include <QtDBus/QtDBus>
36

37
class QAction;
38
class QWidget;
39
class QPrinter;
40
class QMenu;
41

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

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

70 71
namespace Okular
{
72 73

class BrowserExtension;
74
class ExportFormat;
75

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

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

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

        // Destructor
        ~Part();

        // inherited from DocumentObserver
Laurent Montel's avatar
Laurent Montel committed
121 122 123
        void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags ) Q_DECL_OVERRIDE;
        void notifyViewportChanged( bool smoothMove ) Q_DECL_OVERRIDE;
        void notifyPageChanged( int page, int flags ) Q_DECL_OVERRIDE;
124

Laurent Montel's avatar
Laurent Montel committed
125 126 127
        bool openDocument(const QUrl &url, uint page) Q_DECL_OVERRIDE;
        void startPresentation() Q_DECL_OVERRIDE;
        QStringList supportedMimeTypes() const Q_DECL_OVERRIDE;
128

Lukáš Tinkl's avatar
Lukáš Tinkl committed
129
        QUrl realUrl() const;
130

Laurent Montel's avatar
Laurent Montel committed
131 132 133 134 135 136 137
        void showSourceLocation(const QString& fileName, int line, int column, bool showGraphically = true) Q_DECL_OVERRIDE;
        void clearLastShownSourceLocation() Q_DECL_OVERRIDE;
        bool isWatchFileModeEnabled() const Q_DECL_OVERRIDE;
        void setWatchFileModeEnabled(bool enable) Q_DECL_OVERRIDE;
        bool areSourceLocationsShownGraphically() const Q_DECL_OVERRIDE;
        void setShowSourceLocationsGraphically(bool show) Q_DECL_OVERRIDE;
        bool openNewFilesInTabs() const Q_DECL_OVERRIDE;
138

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

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

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

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

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

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

238 239
        void moveSplitter( const int sideWidgetSize );

240
    private:
Frederik Gladhorn's avatar
Frederik Gladhorn committed
241
        Document::OpenResult doOpenFile(const QMimeType &mime, const QString &fileNameToOpen, bool *isCompressedFile);
242

243
        void setupViewerActions();
244
        void setViewerShortcuts();
245 246
        void setupActions();

John Layt's avatar
John Layt committed
247 248
        void setupPrint( QPrinter &printer );
        void doPrint( QPrinter &printer );
249
        bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype );
250
        void rebuildBookmarkMenu( bool unplugActions = true );
251
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
252
        void unsetDummyMode();
253
        void slotRenameBookmark( const DocumentViewport &viewport );
254
        void resetStartArguments();
255 256
        
        static int numberOfParts;
Albert Astals Cid's avatar
Albert Astals Cid committed
257

Frederik Gladhorn's avatar
Frederik Gladhorn committed
258
        QTemporaryFile *m_tempfile;
259 260 261 262

        // the document
        Okular::Document * m_document;
        QString m_temporaryLocalFile;
263
        bool isDocumentArchive;
264 265

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

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

        // Remember the search history
        QStringList m_searchHistory;

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

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
341
        QList<QAction*> m_bookmarkActions;
342
        bool m_cliPresentation;
343
        bool m_cliPrint;
344
        QString m_addBookmarkText;
345
        QIcon m_addBookmarkIcon;
346

347
        EmbedMode m_embedMode;
348

Lukáš Tinkl's avatar
Lukáš Tinkl committed
349
        QUrl m_realUrl;
350

351
        KXMLGUIClient *m_generatorGuiClient;
352
        FileKeeper *m_keeper;
353

354 355 356
        // Timer for m_infoMessage
        QTimer *m_infoTimer;

357
    private slots:
358
        void slotAnnotationPreferences();
Michel Ludwig's avatar
Michel Ludwig committed
359
        void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
360
};
Wilco Greven's avatar
Wilco Greven committed
361

362 363
}

364 365
#endif

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