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.2 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;
51
class KAction;
52
class KMenu;
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

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 OKULAR_PART_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
121
        void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags );
122
        void notifyViewportChanged( bool smoothMove );
123
        void notifyPageChanged( int page, int flags );
124 125 126

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

129 130
        KUrl realUrl() const;

131 132
        void showSourceLocation(const QString& fileName, int line, int column, bool showGraphically = true);
        void clearLastShownSourceLocation();
133
        bool isWatchFileModeEnabled() const;
134
        void setWatchFileModeEnabled(bool enable);
135
        bool areSourceLocationsShownGraphically() const;
136
        void setShowSourceLocationsGraphically(bool show);
137
        bool openNewFilesInTabs() const;
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);
Jonathan Doman's avatar
Jonathan Doman committed
162
        void mimeTypeChanged(KMimeType::Ptr mimeType);
163
        void urlsDropped( const KUrl::List& urls );
164 165

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

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

    public slots:
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
Pino Toscano's avatar
Pino Toscano committed
227
        void restoreDocument(const KConfigGroup &group);
Tobias Koenig's avatar
Tobias Koenig committed
228
        void saveDocumentRestoreInfo(KConfigGroup &group);
229 230
        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
    private:
239
        void setupViewerActions();
240
        void setViewerShortcuts();
241 242
        void setupActions();

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

254 255 256 257 258
        KTemporaryFile *m_tempfile;

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

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

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
284
        KUrl m_oldUrl;
285 286
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
287
        int m_dirtyToolboxIndex;
288
        bool m_wasSidebarVisible;
289
        bool m_wasSidebarCollapsed;
290
        bool m_fileWasRemoved;
291
        Rotation m_dirtyPageRotation;
292 293 294 295 296

        // Remember the search history
        QStringList m_searchHistory;

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

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

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

341
        EmbedMode m_embedMode;
342

343 344
        KUrl m_realUrl;

345
        KXMLGUIClient *m_generatorGuiClient;
346
        FileKeeper *m_keeper;
347

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

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

356 357
}

358 359
#endif

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