part.h 10.8 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/part.h>
20
#include <qicon.h>
21
#include <qlist.h>
22
#include <qpointer.h>
23
#include <qprocess.h>
24
#include "core/observer.h"
25
#include "core/document.h"
26
#include "kdocumentviewer.h"
27
#include "interfaces/viewerinterface.h"
28

Pino Toscano's avatar
Pino Toscano committed
29
#include <QtDBus/QtDBus>
30

31
class QAction;
32
class QWidget;
33
class QPrinter;
34
class QMenu;
35

Pino Toscano's avatar
porting  
Pino Toscano committed
36
class KUrl;
Tobias Koenig's avatar
Tobias Koenig committed
37
class KConfigGroup;
Albert Astals Cid's avatar
Albert Astals Cid committed
38
class KDirWatch;
39
class KToggleAction;
40
class KToggleFullScreenAction;
41
class KSelectAction;
42
class KAboutData;
Leandro Emanuel López's avatar
Leandro Emanuel López committed
43
class KTemporaryFile;
44
class KAction;
45
class KMenu;
46
namespace KParts { class GUIActivateEvent; }
47

48
class FindBar;
Albert Astals Cid's avatar
Albert Astals Cid committed
49
class ThumbnailList;
Albert Astals Cid's avatar
Albert Astals Cid committed
50
class PageSizeLabel;
51
class PageView;
52
class PageViewTopMessage;
53
class PresentationWidget;
54
class ProgressWidget;
55
class SearchWidget;
Pino Toscano's avatar
Pino Toscano committed
56
class Sidebar;
Albert Astals Cid's avatar
Albert Astals Cid committed
57 58
class TOC;
class MiniBar;
Albert Astals Cid's avatar
Albert Astals Cid committed
59
class MiniBarLogic;
60
class FileKeeper;
61 62
class Reviews;
class BookmarkList;
63

64 65
namespace Okular
{
66 67

class BrowserExtension;
68
class ExportFormat;
69

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

84 85 86 87 88 89 90 91
/**
 * 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
 */
92
class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, public KDocumentViewer, public Okular::ViewerInterface
93
{
94
    Q_OBJECT
Pino Toscano's avatar
Pino Toscano committed
95 96
    Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
    Q_INTERFACES(KDocumentViewer)
97
    Q_INTERFACES(Okular::ViewerInterface)
98

Pino Toscano's avatar
Pino Toscano committed
99
    public:
100
        // Default constructor
101 102 103 104 105 106
        /**
         * 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'.
         **/
107
        Part(QWidget* parentWidget, QObject* parent, const QVariantList& args);
108 109 110 111 112 113

        // Destructor
        ~Part();

        // inherited from DocumentObserver
        uint observerId() const { return PART_ID; }
114
        void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags );
115
        void notifyViewportChanged( bool smoothMove );
116
        void notifyPageChanged( int page, int flags );
117 118 119

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

122 123
        KUrl realUrl() const;

124 125
        void showSourceLocation(const QString& fileName, int line, int column, bool showGraphically = true);
        void clearLastShownSourceLocation();
126
        bool isWatchFileModeEnabled() const;
127
        void setWatchFileModeEnabled(bool enable);
128
        bool areSourceLocationsShownGraphically() const;
129
        void setShowSourceLocationsGraphically(bool show);
130

131 132
    public slots:                // dbus
        Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page);
133
        Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc );
134 135
        Q_SCRIPTABLE uint pages();
        Q_SCRIPTABLE uint currentPage();
136
        Q_SCRIPTABLE QString currentDocument();
137
        Q_SCRIPTABLE QString documentMetaData( const QString &metaData ) const;
138 139 140 141 142 143 144
        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();
145
        Q_SCRIPTABLE void slotTogglePresentation();
146
        Q_SCRIPTABLE Q_NOREPLY void reload();
147

Pino Toscano's avatar
Pino Toscano committed
148
    signals:
149
        void enablePrintAction(bool enable);
150
        void openSourceReference(const QString& absFileName, int line, int column);
151
        void viewerMenuStateChange(bool enabled);
152 153 154 155 156 157

    protected:
        // reimplemented from KParts::ReadOnlyPart
        bool openFile();
        bool openUrl(const KUrl &url);
        bool closeUrl();
158
        void guiActivateEvent(KParts::GUIActivateEvent *event);
159 160 161 162

    protected slots:
        // connected to actions
        void openUrlFromDocument(const KUrl &url);
163
        void openUrlFromBookmarks(const KUrl &url);
164 165 166
        void slotGoToPage();
        void slotHistoryBack();
        void slotHistoryNext();
167
        void slotAddBookmark();
168
        void slotRenameBookmarkFromMenu();
169
        void slotRenameCurrentViewportBookmark();
170
        void slotAboutToShowContextMenu(KMenu *menu, QAction *action, QMenu *contextMenu);
171 172 173
        void slotPreviousBookmark();
        void slotNextBookmark();
        void slotFindNext();
Pino Toscano's avatar
Pino Toscano committed
174
        void slotFindPrev();
175
        void slotSaveFileAs();
176
        void slotSaveCopyAs();
177 178
        void slotGetNewStuff();
        void slotNewConfig();
179
        void slotNewGeneratorConfig();
180 181 182 183
        void slotShowMenu(const Okular::Page *page, const QPoint &point);
        void slotShowProperties();
        void slotShowEmbeddedFiles();
        void slotShowLeftPanel();
184
        void slotShowBottomBar();
185 186 187 188
        void slotShowPresentation();
        void slotHidePresentation();
        void slotExportAs(QAction *);
        bool slotImportPSFile();
189
        void slotAboutBackend();
190
        void slotReload();
191 192
        void close();
        void cannotQuit();
193 194
        void slotShowFindBar();
        void slotHideFindBar();
195
        void slotJobStarted(KIO::Job *job);
196
        void slotJobFinished(KJob *job);
197 198
        void loadCancelled(const QString &reason);
        void setWindowTitleFromDocument();
199 200
        // can be connected to widget elements
        void updateViewActions();
201
        void updateBookmarksActions();
202
        void enableTOC(bool enable);
203
        void slotRebuildBookmarkMenu();
204 205 206 207

    public slots:
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
Pino Toscano's avatar
Pino Toscano committed
208
        void restoreDocument(const KConfigGroup &group);
Tobias Koenig's avatar
Tobias Koenig committed
209
        void saveDocumentRestoreInfo(KConfigGroup &group);
210 211
        void slotFileDirty( const QString& );
        void slotDoFileDirty();
212
        void psTransformEnded(int, QProcess::ExitStatus);
213 214

    private:
215
        void setupViewerActions();
216
        void setViewerShortcuts();
217 218
        void setupActions();

John Layt's avatar
John Layt committed
219 220
        void setupPrint( QPrinter &printer );
        void doPrint( QPrinter &printer );
221
        bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype );
222
        void rebuildBookmarkMenu( bool unplugActions = true );
223
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
224
        void unsetDummyMode();
225
        void slotRenameBookmark( const DocumentViewport &viewport );
Albert Astals Cid's avatar
Albert Astals Cid committed
226

227 228 229 230 231 232 233
        KTemporaryFile *m_tempfile;

        // the document
        Okular::Document * m_document;
        QString m_temporaryLocalFile;

        // main widgets
Pino Toscano's avatar
Pino Toscano committed
234
        Sidebar *m_sidebar;
235
        SearchWidget *m_searchWidget;
236
        FindBar * m_findBar;
237
        PageViewTopMessage * m_topMessage;
238
        PageViewTopMessage * m_formsMessage;
239 240 241
        QPointer<ThumbnailList> m_thumbnailList;
        QPointer<PageView> m_pageView;
        QPointer<TOC> m_toc;
Albert Astals Cid's avatar
Albert Astals Cid committed
242
        QPointer<MiniBarLogic> m_miniBarLogic;
243
        QPointer<MiniBar> m_miniBar;
244
        QPointer<MiniBar> m_pageNumberTool;
245
        QPointer<QWidget> m_bottomBar;
246 247 248
        QPointer<PresentationWidget> m_presentationWidget;
        QPointer<ProgressWidget> m_progressWidget;
        QPointer<PageSizeLabel> m_pageSizeLabel;
249 250
        QPointer<Reviews> m_reviewsWidget;
        QPointer<BookmarkList> m_bookmarkList;
251 252 253 254 255 256

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
257
        int m_dirtyToolboxIndex;
258
        bool m_wasSidebarVisible;
259
        bool m_wasSidebarCollapsed;
260
        bool m_fileWasRemoved;
261
        Rotation m_dirtyPageRotation;
262 263 264 265 266

        // Remember the search history
        QStringList m_searchHistory;

        // actions
267 268 269
        KAction *m_gotoPage;
        KAction *m_prevPage;
        KAction *m_nextPage;
270 271
        KAction *m_beginningOfDocument;
        KAction *m_endOfDocument;
272 273 274
        KAction *m_historyBack;
        KAction *m_historyNext;
        KAction *m_addBookmark;
275
        KAction *m_renameBookmark;
276 277 278 279 280 281
        KAction *m_prevBookmark;
        KAction *m_nextBookmark;
        KAction *m_copy;
        KAction *m_selectAll;
        KAction *m_find;
        KAction *m_findNext;
Pino Toscano's avatar
Pino Toscano committed
282
        KAction *m_findPrev;
283 284 285 286 287 288
        KAction *m_saveAs;
        KAction *m_saveCopyAs;
        KAction *m_printPreview;
        KAction *m_showProperties;
        KAction *m_showEmbeddedFiles;
        KAction *m_exportAs;
289
        QAction *m_exportAsText;
290
        QAction *m_exportAsDocArchive;
291
        KAction *m_showPresentation;
292 293
        KToggleAction* m_showMenuBarAction;
        KToggleAction* m_showLeftPanel;
294
        KToggleAction* m_showBottomBar;
295
        KToggleFullScreenAction* m_showFullScreenAction;
296 297
        KAction *m_aboutBackend;
        KAction *m_reload;
298
        QMenu *m_exportAsMenu;
Jiri Baum's avatar
Jiri Baum committed
299
        KAction *m_closeFindBar;
300 301 302 303 304

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
305
        QList<QAction*> m_bookmarkActions;
306
        bool m_cliPresentation;
307
        QString m_addBookmarkText;
308
        QIcon m_addBookmarkIcon;
309

310
        EmbedMode m_embedMode;
311

312 313
        KUrl m_realUrl;

314
        KXMLGUIClient *m_generatorGuiClient;
315
        FileKeeper *m_keeper;
316

317 318
    private slots:
        void slotGeneratorPreferences();
Michel Ludwig's avatar
Michel Ludwig committed
319
        void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
320
};
Wilco Greven's avatar
Wilco Greven committed
321

322 323
}

324 325
#endif

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