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.3 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>
Frederik Gladhorn's avatar
Frederik Gladhorn committed
26
#include <kurl.h>
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 34
#include "okular_part_export.h"

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

Pino Toscano's avatar
porting  
Pino Toscano committed
42
class KUrl;
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;
Leandro Emanuel López's avatar
Leandro Emanuel López committed
50
class KTemporaryFile;
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

69 70
namespace Okular
{
71 72

class BrowserExtension;
73
class ExportFormat;
74

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

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

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

        // Destructor
        ~Part();

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

        bool openDocument(const KUrl& url, uint page);
        void startPresentation();
126
        QStringList supportedMimeTypes() const;
127

128 129
        KUrl realUrl() const;

130 131
        void showSourceLocation(const QString& fileName, int line, int column, bool showGraphically = true);
        void clearLastShownSourceLocation();
132
        bool isWatchFileModeEnabled() const;
133
        void setWatchFileModeEnabled(bool enable);
134
        bool areSourceLocationsShownGraphically() const;
135
        void setShowSourceLocationsGraphically(bool show);
136
        bool openNewFilesInTabs() const;
137

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

Pino Toscano's avatar
Pino Toscano committed
156
    signals:
157
        void enablePrintAction(bool enable);
158
        void openSourceReference(const QString& absFileName, int line, int column);
159
        void viewerMenuStateChange(bool enabled);
160
        void enableCloseAction(bool enable);
Jonathan Doman's avatar
Jonathan Doman committed
161
        void mimeTypeChanged(KMimeType::Ptr mimeType);
Vishesh Handa's avatar
Vishesh Handa committed
162
        void urlsDropped( const QList<QUrl>& urls );
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 180

    protected slots:
        // connected to actions
        void openUrlFromDocument(const KUrl &url);
181
        void openUrlFromBookmarks(const KUrl &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

    public slots:
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
Pino Toscano's avatar
Pino Toscano committed
226
        void restoreDocument(const KConfigGroup &group);
Tobias Koenig's avatar
Tobias Koenig committed
227
        void saveDocumentRestoreInfo(KConfigGroup &group);
228 229
        void slotFileDirty( const QString& );
        void slotDoFileDirty();
230
        void psTransformEnded(int, QProcess::ExitStatus);
231
        KConfigDialog * slotGeneratorPreferences();
232

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

237
    private:
238 239
        Document::OpenResult doOpenFile(const KMimeType::Ptr &mime, const QString &fileNameToOpen, bool *isCompressedFile);

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

255 256 257 258 259
        KTemporaryFile *m_tempfile;

        // 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;
285
        KUrl 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

344 345
        KUrl m_realUrl;

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; */