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 <KCompressionDevice>
23
#include <qicon.h>
24
#include <qlist.h>
25
#include <qpointer.h>
26
#include <qprocess.h>
Lukáš Tinkl's avatar
Lukáš Tinkl committed
27
#include <QUrl>
28
#include <kio/job.h>
29
#include "core/observer.h"
30
#include "core/document.h"
31
#include "kdocumentviewer.h"
32
#include "interfaces/viewerinterface.h"
33

34
#include "okularpart_export.h"
35

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

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

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

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

71 72
namespace Okular
{
73 74

class BrowserExtension;
75
class ExportFormat;
76

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

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

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

        // Destructor
        ~Part();

        // inherited from DocumentObserver
Laurent Montel's avatar
Laurent Montel committed
122 123 124
        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;
125

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

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

Laurent Montel's avatar
Laurent Montel committed
132 133 134 135 136 137 138
        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;
139

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

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

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

181
    protected Q_SLOTS:
182
        // connected to actions
Lukáš Tinkl's avatar
Lukáš Tinkl committed
183 184
        void openUrlFromDocument(const QUrl &url);
        void openUrlFromBookmarks(const QUrl &url);
Vishesh Handa's avatar
Vishesh Handa committed
185
        void handleDroppedUrls( const QList<QUrl>& urls );
186 187 188
        void slotGoToPage();
        void slotHistoryBack();
        void slotHistoryNext();
189
        void slotAddBookmark();
190
        void slotRenameBookmarkFromMenu();
191
        void slotRenameCurrentViewportBookmark();
Vishesh Handa's avatar
Vishesh Handa committed
192
        void slotAboutToShowContextMenu(QMenu *menu, QAction *action, QMenu *contextMenu);
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:
Frederik Gladhorn's avatar
Frederik Gladhorn committed
242
        Document::OpenResult doOpenFile(const QMimeType &mime, const QString &fileNameToOpen, bool *isCompressedFile);
243

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

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

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

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

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

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

        // Remember the search history
        QStringList m_searchHistory;

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

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

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

348
        EmbedMode m_embedMode;
349

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

352
        KXMLGUIClient *m_generatorGuiClient;
353
        FileKeeper *m_keeper;
354

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

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

363 364
}

365 366
#endif

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