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 10 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;
59
class FileKeeper;
60 61
class Reviews;
class BookmarkList;
62

63 64
namespace Okular
{
65 66

class BrowserExtension;
67
class ExportFormat;
68 69 70 71 72 73 74 75 76

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

Pino Toscano's avatar
Pino Toscano committed
84
    public:
85
        // Default constructor
86 87 88 89 90 91
        /**
         * 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'.
         **/
92
        Part(QWidget* parentWidget, QObject* parent, const QVariantList& args);
93 94 95 96 97 98

        // Destructor
        ~Part();

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

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

107 108
        KUrl realUrl() const;

109
        void showSourceLocation(const QString& fileName, int line, int column);
110 111
        void setWatchFileModeEnabled(bool enable);
        void setShowSourceLocationsGraphically(bool show);
112

113 114
    public slots:                // dbus
        Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page);
115
        Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc );
116 117
        Q_SCRIPTABLE uint pages();
        Q_SCRIPTABLE uint currentPage();
118
        Q_SCRIPTABLE QString currentDocument();
119
        Q_SCRIPTABLE QString documentMetaData( const QString &metaData ) const;
120 121 122 123 124 125 126
        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();
127
        Q_SCRIPTABLE void slotTogglePresentation();
128
        Q_SCRIPTABLE Q_NOREPLY void reload();
129

Pino Toscano's avatar
Pino Toscano committed
130
    signals:
131
        void enablePrintAction(bool enable);
132
        void openSourceReference(const QString& absFileName, int line, int column);
133
        void viewerMenuStateChange(bool enabled);
134 135 136 137 138 139

    protected:
        // reimplemented from KParts::ReadOnlyPart
        bool openFile();
        bool openUrl(const KUrl &url);
        bool closeUrl();
140
        void guiActivateEvent(KParts::GUIActivateEvent *event);
141 142 143 144

    protected slots:
        // connected to actions
        void openUrlFromDocument(const KUrl &url);
145
        void openUrlFromBookmarks(const KUrl &url);
146 147 148
        void slotGoToPage();
        void slotHistoryBack();
        void slotHistoryNext();
149
        void slotAddBookmark();
150 151 152
        void slotRenameBookmarkFromMenu();
        void slotRenameCurrentPageBookmark();
        void slotAboutToShowContextMenu(KMenu *menu, QAction *action, QMenu *contextMenu);
153 154 155
        void slotPreviousBookmark();
        void slotNextBookmark();
        void slotFindNext();
Pino Toscano's avatar
Pino Toscano committed
156
        void slotFindPrev();
157
        void slotSaveFileAs();
158
        void slotSaveCopyAs();
159 160
        void slotGetNewStuff();
        void slotNewConfig();
161
        void slotNewGeneratorConfig();
162 163 164 165
        void slotShowMenu(const Okular::Page *page, const QPoint &point);
        void slotShowProperties();
        void slotShowEmbeddedFiles();
        void slotShowLeftPanel();
166
        void slotShowBottomBar();
167 168 169 170
        void slotShowPresentation();
        void slotHidePresentation();
        void slotExportAs(QAction *);
        bool slotImportPSFile();
171
        void slotAboutBackend();
172
        void slotReload();
173 174
        void close();
        void cannotQuit();
175 176
        void slotShowFindBar();
        void slotHideFindBar();
177
        void slotJobStarted(KIO::Job *job);
178
        void slotJobFinished(KJob *job);
179 180
        void loadCancelled(const QString &reason);
        void setWindowTitleFromDocument();
181 182
        // can be connected to widget elements
        void updateViewActions();
183
        void updateBookmarksActions();
184
        void enableTOC(bool enable);
185
        void slotRebuildBookmarkMenu();
186 187 188 189

    public slots:
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
Pino Toscano's avatar
Pino Toscano committed
190
        void restoreDocument(const KConfigGroup &group);
Tobias Koenig's avatar
Tobias Koenig committed
191
        void saveDocumentRestoreInfo(KConfigGroup &group);
192 193
        void slotFileDirty( const QString& );
        void slotDoFileDirty();
194
        void psTransformEnded(int, QProcess::ExitStatus);
195 196

    private:
197
        void setupViewerActions();
198
        void setViewerShortcuts();
199 200
        void setupActions();

John Layt's avatar
John Layt committed
201 202
        void setupPrint( QPrinter &printer );
        void doPrint( QPrinter &printer );
203
        bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype );
204
        void rebuildBookmarkMenu( bool unplugActions = true );
205
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
206
        void unsetDummyMode();
207
        void slotRenameBookmark( int page );
Albert Astals Cid's avatar
Albert Astals Cid committed
208

209 210 211 212 213 214 215
        KTemporaryFile *m_tempfile;

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

        // main widgets
Pino Toscano's avatar
Pino Toscano committed
216
        Sidebar *m_sidebar;
217
        SearchWidget *m_searchWidget;
218
        FindBar * m_findBar;
219
        PageViewTopMessage * m_topMessage;
220
        PageViewTopMessage * m_formsMessage;
221 222 223 224
        QPointer<ThumbnailList> m_thumbnailList;
        QPointer<PageView> m_pageView;
        QPointer<TOC> m_toc;
        QPointer<MiniBar> m_miniBar;
225
        QPointer<QWidget> m_bottomBar;
226 227 228
        QPointer<PresentationWidget> m_presentationWidget;
        QPointer<ProgressWidget> m_progressWidget;
        QPointer<PageSizeLabel> m_pageSizeLabel;
229 230
        QPointer<Reviews> m_reviewsWidget;
        QPointer<BookmarkList> m_bookmarkList;
231 232 233 234 235 236

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
237
        int m_dirtyToolboxIndex;
238
        bool m_wasSidebarVisible;
239
        bool m_fileWasRemoved;
240
        Rotation m_dirtyPageRotation;
241 242 243 244 245

        // Remember the search history
        QStringList m_searchHistory;

        // actions
246 247 248
        KAction *m_gotoPage;
        KAction *m_prevPage;
        KAction *m_nextPage;
249 250
        KAction *m_beginningOfDocument;
        KAction *m_endOfDocument;
251 252 253
        KAction *m_historyBack;
        KAction *m_historyNext;
        KAction *m_addBookmark;
254
        KAction *m_renameBookmark;
255 256 257 258 259 260
        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
261
        KAction *m_findPrev;
262 263 264 265 266 267
        KAction *m_saveAs;
        KAction *m_saveCopyAs;
        KAction *m_printPreview;
        KAction *m_showProperties;
        KAction *m_showEmbeddedFiles;
        KAction *m_exportAs;
268
        QAction *m_exportAsText;
269
        QAction *m_exportAsDocArchive;
270
        KAction *m_showPresentation;
271 272
        KToggleAction* m_showMenuBarAction;
        KToggleAction* m_showLeftPanel;
273
        KToggleAction* m_showBottomBar;
274
        KToggleFullScreenAction* m_showFullScreenAction;
275 276
        KAction *m_aboutBackend;
        KAction *m_reload;
277
        QMenu *m_exportAsMenu;
Jiri Baum's avatar
Jiri Baum committed
278
        KAction *m_closeFindBar;
279 280 281 282 283

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
284
        QList<QAction*> m_bookmarkActions;
285
        bool m_cliPresentation;
286
        QString m_addBookmarkText;
287
        QIcon m_addBookmarkIcon;
288

289
        EmbedMode m_embedMode;
290

291 292
        KUrl m_realUrl;

293
        KXMLGUIClient *m_generatorGuiClient;
294
        FileKeeper *m_keeper;
295

296 297
    private slots:
        void slotGeneratorPreferences();
Michel Ludwig's avatar
Michel Ludwig committed
298
        void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
299
};
Wilco Greven's avatar
Wilco Greven committed
300

301 302
}

303 304
#endif

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