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 9.05 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

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

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

Pino Toscano's avatar
porting  
Pino Toscano committed
35
class KUrl;
Tobias Koenig's avatar
Tobias Koenig committed
36
class KConfigGroup;
Albert Astals Cid's avatar
Albert Astals Cid committed
37
class KDirWatch;
38
class KToggleAction;
39
class KToggleFullScreenAction;
40
class KSelectAction;
41
class KAboutData;
Leandro Emanuel López's avatar
Leandro Emanuel López committed
42
class KTemporaryFile;
43
class KAction;
44

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

60 61
namespace Okular
{
62 63

class BrowserExtension;
64
class ExportFormat;
65 66 67 68 69 70 71 72 73

/**
 * 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
 */
74
class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, public KDocumentViewer
75
{
76
    Q_OBJECT
Pino Toscano's avatar
Pino Toscano committed
77 78
    Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
    Q_INTERFACES(KDocumentViewer)
79

Pino Toscano's avatar
Pino Toscano committed
80
    public:
81 82 83 84
        enum EmbedMode
        {
            UnknownEmbedMode,
            NativeShellMode,         // embedded in the native Okular' shell
85 86
            PrintPreviewMode,        // embedded to show the print preview of a document
            KHTMLPartMode            // embedded in KHTML
87 88
        };

89
        // Default constructor
90
        Part(QWidget* parentWidget, QObject* parent, const QVariantList& args);
91 92 93 94 95 96

        // Destructor
        ~Part();

        // inherited from DocumentObserver
        uint observerId() const { return PART_ID; }
97
        void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags );
98
        void notifyViewportChanged( bool smoothMove );
99
        void notifyPageChanged( int page, int flags );
100 101 102

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

105 106
        KUrl realUrl() const;

107 108
    public slots:                // dbus
        Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page);
109
        Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc );
110 111
        Q_SCRIPTABLE uint pages();
        Q_SCRIPTABLE uint currentPage();
112
        Q_SCRIPTABLE QString currentDocument();
113
        Q_SCRIPTABLE QString documentMetaData( const QString &metaData ) const;
114 115 116 117 118 119 120
        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();
121
        Q_SCRIPTABLE void slotTogglePresentation();
122
        Q_SCRIPTABLE Q_NOREPLY void reload();
123

Pino Toscano's avatar
Pino Toscano committed
124
    signals:
125 126 127 128 129 130 131 132 133 134 135
        void enablePrintAction(bool enable);

    protected:
        // reimplemented from KParts::ReadOnlyPart
        bool openFile();
        bool openUrl(const KUrl &url);
        bool closeUrl();

    protected slots:
        // connected to actions
        void openUrlFromDocument(const KUrl &url);
136
        void openUrlFromBookmarks(const KUrl &url);
137 138 139
        void slotGoToPage();
        void slotHistoryBack();
        void slotHistoryNext();
140
        void slotAddBookmark();
141
        void slotRenameBookmark();
142 143 144
        void slotPreviousBookmark();
        void slotNextBookmark();
        void slotFindNext();
Pino Toscano's avatar
Pino Toscano committed
145
        void slotFindPrev();
146
        void slotSaveFileAs();
147
        void slotSaveCopyAs();
148 149
        void slotGetNewStuff();
        void slotNewConfig();
150
        void slotNewGeneratorConfig();
151 152 153 154
        void slotShowMenu(const Okular::Page *page, const QPoint &point);
        void slotShowProperties();
        void slotShowEmbeddedFiles();
        void slotShowLeftPanel();
155
        void slotShowBottomBar();
156 157 158 159
        void slotShowPresentation();
        void slotHidePresentation();
        void slotExportAs(QAction *);
        bool slotImportPSFile();
160
        void slotAboutBackend();
161
        void slotReload();
162 163
        void close();
        void cannotQuit();
164 165
        void slotShowFindBar();
        void slotHideFindBar();
166
        void slotJobStarted(KIO::Job *job);
167
        void slotJobFinished(KJob *job);
168 169
        void loadCancelled(const QString &reason);
        void setWindowTitleFromDocument();
170 171
        // can be connected to widget elements
        void updateViewActions();
172
        void updateBookmarksActions();
173
        void enableTOC(bool enable);
174
        void slotRebuildBookmarkMenu();
175 176 177 178

    public slots:
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
Pino Toscano's avatar
Pino Toscano committed
179
        void restoreDocument(const KConfigGroup &group);
Tobias Koenig's avatar
Tobias Koenig committed
180
        void saveDocumentRestoreInfo(KConfigGroup &group);
181 182
        void slotFileDirty( const QString& );
        void slotDoFileDirty();
183
        void psTransformEnded(int, QProcess::ExitStatus);
184 185

    private:
John Layt's avatar
John Layt committed
186 187
        void setupPrint( QPrinter &printer );
        void doPrint( QPrinter &printer );
188
        bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype );
189
        void rebuildBookmarkMenu( bool unplugActions = true );
190
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
191 192
        void unsetDummyMode();

193 194 195 196 197 198 199
        KTemporaryFile *m_tempfile;

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

        // main widgets
Pino Toscano's avatar
Pino Toscano committed
200
        Sidebar *m_sidebar;
201
        SearchWidget *m_searchWidget;
202
        FindBar * m_findBar;
203
        PageViewTopMessage * m_topMessage;
204
        PageViewTopMessage * m_formsMessage;
205 206 207 208
        QPointer<ThumbnailList> m_thumbnailList;
        QPointer<PageView> m_pageView;
        QPointer<TOC> m_toc;
        QPointer<MiniBar> m_miniBar;
209
        QPointer<QWidget> m_bottomBar;
210 211 212
        QPointer<PresentationWidget> m_presentationWidget;
        QPointer<ProgressWidget> m_progressWidget;
        QPointer<PageSizeLabel> m_pageSizeLabel;
213 214
        QPointer<Reviews> m_reviewsWidget;
        QPointer<BookmarkList> m_bookmarkList;
215 216 217 218 219 220

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
221
        int m_dirtyToolboxIndex;
222
        bool m_wasSidebarVisible;
223
        bool m_fileWasRemoved;
224
        Rotation m_dirtyPageRotation;
225 226 227 228 229

        // Remember the search history
        QStringList m_searchHistory;

        // actions
230 231 232
        KAction *m_gotoPage;
        KAction *m_prevPage;
        KAction *m_nextPage;
233 234
        KAction *m_beginningOfDocument;
        KAction *m_endOfDocument;
235 236 237
        KAction *m_historyBack;
        KAction *m_historyNext;
        KAction *m_addBookmark;
238
        KAction *m_renameBookmark;
239 240 241 242 243 244
        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
245
        KAction *m_findPrev;
246 247 248 249 250 251
        KAction *m_saveAs;
        KAction *m_saveCopyAs;
        KAction *m_printPreview;
        KAction *m_showProperties;
        KAction *m_showEmbeddedFiles;
        KAction *m_exportAs;
252
        QAction *m_exportAsText;
253
        QAction *m_exportAsDocArchive;
254
        KAction *m_showPresentation;
255 256
        KToggleAction* m_showMenuBarAction;
        KToggleAction* m_showLeftPanel;
257
        KToggleAction* m_showBottomBar;
258
        KToggleFullScreenAction* m_showFullScreenAction;
259 260
        KAction *m_aboutBackend;
        KAction *m_reload;
261
        QMenu *m_exportAsMenu;
Jiri Baum's avatar
Jiri Baum committed
262
        KAction *m_closeFindBar;
263 264 265 266 267

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
268
        QList<QAction*> m_bookmarkActions;
269
        bool m_cliPresentation;
270
        QString m_addBookmarkText;
271
        QIcon m_addBookmarkIcon;
272

273
        EmbedMode m_embedMode;
274

275 276
        KUrl m_realUrl;

277
        KXMLGUIClient *m_generatorGuiClient;
278
        FileKeeper *m_keeper;
279

280 281
    private slots:
        void slotGeneratorPreferences();
282
};
Wilco Greven's avatar
Wilco Greven committed
283

284 285
}

286 287
#endif

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