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.5 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

68 69
namespace Okular
{
70 71

class BrowserExtension;
72
class ExportFormat;
73

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

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

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

        // Destructor
        ~Part();

        // inherited from DocumentObserver
Laurent Montel's avatar
Laurent Montel committed
119 120 121
        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;
122

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

Lukáš Tinkl's avatar
Lukáš Tinkl committed
127
        QUrl realUrl() const;
128

Laurent Montel's avatar
Laurent Montel committed
129 130 131 132 133 134 135
        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;
136

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

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

    protected:
165
        // reimplemented from KParts::ReadWritePart
Frederik Gladhorn's avatar
Frederik Gladhorn committed
166 167 168 169
        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 );
170
    public:
Frederik Gladhorn's avatar
Frederik Gladhorn committed
171 172 173 174 175 176
        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;
177 178 179

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

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

231 232 233 234
        void errorMessage( const QString &message, int duration = 0 );
        void warningMessage( const QString &message, int duration = -1 );
        void noticeMessage( const QString &message, int duration = -1 );

235 236
        void moveSplitter( const int sideWidgetSize );

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

240
        void setupViewerActions();
241
        void setViewerShortcuts();
242 243
        void setupActions();

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

Frederik Gladhorn's avatar
Frederik Gladhorn committed
255
        QTemporaryFile *m_tempfile;
256 257 258 259

        // the document
        Okular::Document * m_document;
        QString m_temporaryLocalFile;
260
        bool isDocumentArchive;
261 262

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

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
Lukáš Tinkl's avatar
Lukáš Tinkl committed
285
        QUrl m_oldUrl;
286 287
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
288
        int m_dirtyToolboxIndex;
289
        bool m_wasSidebarVisible;
290
        bool m_wasSidebarCollapsed;
291
        bool m_fileWasRemoved;
292
        Rotation m_dirtyPageRotation;
293 294 295 296 297

        // Remember the search history
        QStringList m_searchHistory;

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

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
336
        QList<QAction*> m_bookmarkActions;
337
        bool m_cliPresentation;
338
        bool m_cliPrint;
339
        QString m_addBookmarkText;
340
        QIcon m_addBookmarkIcon;
341

342
        EmbedMode m_embedMode;
343

Lukáš Tinkl's avatar
Lukáš Tinkl committed
344
        QUrl m_realUrl;
345

346
        KXMLGUIClient *m_generatorGuiClient;
347
        FileKeeper *m_keeper;
348

349 350 351
        // Timer for m_infoMessage
        QTimer *m_infoTimer;

352
    private slots:
353
        void slotAnnotationPreferences();
Michel Ludwig's avatar
Michel Ludwig committed
354
        void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
355
};
Wilco Greven's avatar
Wilco Greven committed
356

357 358
}

359 360
#endif

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