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

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

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

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

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

65 66
namespace Okular
{
67 68

class BrowserExtension;
69
class ExportFormat;
70

71 72 73 74 75 76 77 78 79 80 81 82 83 84
/**
 * 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
};

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

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

        // Destructor
        ~Part();

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

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

123 124
        KUrl realUrl() const;

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

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

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

    protected:
155
        // reimplemented from KParts::ReadWritePart
156 157
        bool openFile();
        bool openUrl(const KUrl &url);
158
        void guiActivateEvent(KParts::GUIActivateEvent *event);
159 160 161 162 163 164 165
    public:
        bool saveFile();
        bool queryClose();
        bool closeUrl();
        bool closeUrl(bool promptToSave);
        void setReadWrite(bool readwrite);
        bool saveAs(const KUrl & saveUrl);
166 167 168 169

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

    public slots:
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
Pino Toscano's avatar
Pino Toscano committed
215
        void restoreDocument(const KConfigGroup &group);
Tobias Koenig's avatar
Tobias Koenig committed
216
        void saveDocumentRestoreInfo(KConfigGroup &group);
217 218
        void slotFileDirty( const QString& );
        void slotDoFileDirty();
219
        void psTransformEnded(int, QProcess::ExitStatus);
220 221

    private:
222
        void setupViewerActions();
223
        void setViewerShortcuts();
224 225
        void setupActions();

John Layt's avatar
John Layt committed
226 227
        void setupPrint( QPrinter &printer );
        void doPrint( QPrinter &printer );
228
        bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype );
229
        void rebuildBookmarkMenu( bool unplugActions = true );
230
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
231
        void unsetDummyMode();
232
        void slotRenameBookmark( const DocumentViewport &viewport );
Albert Astals Cid's avatar
Albert Astals Cid committed
233

234 235 236 237 238
        KTemporaryFile *m_tempfile;

        // the document
        Okular::Document * m_document;
        QString m_temporaryLocalFile;
239
        bool isDocumentArchive;
240 241

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

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
265
        int m_dirtyToolboxIndex;
266
        bool m_wasSidebarVisible;
267
        bool m_wasSidebarCollapsed;
268
        bool m_fileWasRemoved;
269
        Rotation m_dirtyPageRotation;
270 271 272 273 274

        // Remember the search history
        QStringList m_searchHistory;

        // actions
275 276 277
        KAction *m_gotoPage;
        KAction *m_prevPage;
        KAction *m_nextPage;
278 279
        KAction *m_beginningOfDocument;
        KAction *m_endOfDocument;
280 281 282
        KAction *m_historyBack;
        KAction *m_historyNext;
        KAction *m_addBookmark;
283
        KAction *m_renameBookmark;
284 285 286 287 288 289
        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
290
        KAction *m_findPrev;
291 292 293 294 295 296
        KAction *m_saveAs;
        KAction *m_saveCopyAs;
        KAction *m_printPreview;
        KAction *m_showProperties;
        KAction *m_showEmbeddedFiles;
        KAction *m_exportAs;
297
        QAction *m_exportAsText;
298
        QAction *m_exportAsDocArchive;
299
        KAction *m_showPresentation;
300 301
        KToggleAction* m_showMenuBarAction;
        KToggleAction* m_showLeftPanel;
302
        KToggleAction* m_showBottomBar;
303
        KToggleFullScreenAction* m_showFullScreenAction;
304 305
        KAction *m_aboutBackend;
        KAction *m_reload;
306
        QMenu *m_exportAsMenu;
Jiri Baum's avatar
Jiri Baum committed
307
        KAction *m_closeFindBar;
308 309 310 311 312

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
313
        QList<QAction*> m_bookmarkActions;
314
        bool m_cliPresentation;
315
        QString m_addBookmarkText;
316
        QIcon m_addBookmarkIcon;
317

318
        EmbedMode m_embedMode;
319

320 321
        KUrl m_realUrl;

322
        KXMLGUIClient *m_generatorGuiClient;
323
        FileKeeper *m_keeper;
324

325 326
    private slots:
        void slotGeneratorPreferences();
Michel Ludwig's avatar
Michel Ludwig committed
327
        void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
328
};
Wilco Greven's avatar
Wilco Greven committed
329

330 331 332 333 334 335 336 337 338 339 340 341
class PartFactory : public KPluginFactory
{
    Q_OBJECT

    public:
        PartFactory();
        virtual ~PartFactory();

    protected:
        virtual QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword);
};

342 343
}

344 345
#endif

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