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.9 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

30 31
#include "okular_part_export.h"

Pino Toscano's avatar
Pino Toscano committed
32
#include <QtDBus/QtDBus>
33

34
class QAction;
35
class QWidget;
36
class QPrinter;
37
class QMenu;
38

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

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

68 69
namespace Okular
{
70 71

class BrowserExtension;
72
class ExportFormat;
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
Laurent Montel's avatar
Laurent Montel committed
85
    ViewerWidgetMode         // the part acts as a widget that can display all kinds of documents
86 87
};

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

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

        // Destructor
        ~Part();

        // inherited from DocumentObserver
119
        void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags );
120
        void notifyViewportChanged( bool smoothMove );
121
        void notifyPageChanged( int page, int flags );
122 123 124

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

127 128
        KUrl realUrl() const;

129 130
        void showSourceLocation(const QString& fileName, int line, int column, bool showGraphically = true);
        void clearLastShownSourceLocation();
131
        bool isWatchFileModeEnabled() const;
132
        void setWatchFileModeEnabled(bool enable);
133
        bool areSourceLocationsShownGraphically() const;
134
        void setShowSourceLocationsGraphically(bool show);
135
        bool openNewFilesInTabs() const;
136

137 138
    public slots:                // dbus
        Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page);
139
        Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc );
140 141
        Q_SCRIPTABLE uint pages();
        Q_SCRIPTABLE uint currentPage();
142
        Q_SCRIPTABLE QString currentDocument();
143
        Q_SCRIPTABLE QString documentMetaData( const QString &metaData ) const;
144 145 146 147 148 149 150
        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();
151
        Q_SCRIPTABLE void slotTogglePresentation();
152
        Q_SCRIPTABLE Q_NOREPLY void reload();
153
        Q_SCRIPTABLE Q_NOREPLY void enableStartWithPrint();
154

Pino Toscano's avatar
Pino Toscano committed
155
    signals:
156
        void enablePrintAction(bool enable);
157
        void openSourceReference(const QString& absFileName, int line, int column);
158
        void viewerMenuStateChange(bool enabled);
159
        void enableCloseAction(bool enable);
Jonathan Doman's avatar
Jonathan Doman committed
160
        void mimeTypeChanged(KMimeType::Ptr mimeType);
161
        void urlsDropped( const KUrl::List& urls );
162 163

    protected:
164
        // reimplemented from KParts::ReadWritePart
165 166
        bool openFile();
        bool openUrl(const KUrl &url);
167
        void guiActivateEvent(KParts::GUIActivateEvent *event);
168 169 170 171 172 173 174
    public:
        bool saveFile();
        bool queryClose();
        bool closeUrl();
        bool closeUrl(bool promptToSave);
        void setReadWrite(bool readwrite);
        bool saveAs(const KUrl & saveUrl);
175 176 177 178

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

    public slots:
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
Pino Toscano's avatar
Pino Toscano committed
224
        void restoreDocument(const KConfigGroup &group);
Tobias Koenig's avatar
Tobias Koenig committed
225
        void saveDocumentRestoreInfo(KConfigGroup &group);
226 227
        void slotFileDirty( const QString& );
        void slotDoFileDirty();
228
        void psTransformEnded(int, QProcess::ExitStatus);
229
        KConfigDialog * slotGeneratorPreferences();
230 231

    private:
232
        void setupViewerActions();
233
        void setViewerShortcuts();
234 235
        void setupActions();

John Layt's avatar
John Layt committed
236 237
        void setupPrint( QPrinter &printer );
        void doPrint( QPrinter &printer );
238
        bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype );
239
        void rebuildBookmarkMenu( bool unplugActions = true );
240
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
241
        void unsetDummyMode();
242
        void slotRenameBookmark( const DocumentViewport &viewport );
243
        void resetStartArguments();
244 245
        
        static int numberOfParts;
Albert Astals Cid's avatar
Albert Astals Cid committed
246

247 248 249 250 251
        KTemporaryFile *m_tempfile;

        // the document
        Okular::Document * m_document;
        QString m_temporaryLocalFile;
252
        bool isDocumentArchive;
253 254

        // main widgets
Pino Toscano's avatar
Pino Toscano committed
255
        Sidebar *m_sidebar;
256
        SearchWidget *m_searchWidget;
257
        FindBar * m_findBar;
258
        PageViewTopMessage * m_topMessage;
259
        PageViewTopMessage * m_formsMessage;
260 261 262
        QPointer<ThumbnailList> m_thumbnailList;
        QPointer<PageView> m_pageView;
        QPointer<TOC> m_toc;
Albert Astals Cid's avatar
Albert Astals Cid committed
263
        QPointer<MiniBarLogic> m_miniBarLogic;
264
        QPointer<MiniBar> m_miniBar;
265
        QPointer<MiniBar> m_pageNumberTool;
266
        QPointer<QWidget> m_bottomBar;
267 268 269
        QPointer<PresentationWidget> m_presentationWidget;
        QPointer<ProgressWidget> m_progressWidget;
        QPointer<PageSizeLabel> m_pageSizeLabel;
270 271
        QPointer<Reviews> m_reviewsWidget;
        QPointer<BookmarkList> m_bookmarkList;
272 273 274 275

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
276
        KUrl m_oldUrl;
277 278
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
279
        int m_dirtyToolboxIndex;
280
        bool m_wasSidebarVisible;
281
        bool m_wasSidebarCollapsed;
282
        bool m_fileWasRemoved;
283
        Rotation m_dirtyPageRotation;
284 285 286 287 288

        // Remember the search history
        QStringList m_searchHistory;

        // actions
289 290 291
        KAction *m_gotoPage;
        KAction *m_prevPage;
        KAction *m_nextPage;
292 293
        KAction *m_beginningOfDocument;
        KAction *m_endOfDocument;
294 295 296
        KAction *m_historyBack;
        KAction *m_historyNext;
        KAction *m_addBookmark;
297
        KAction *m_renameBookmark;
298 299 300 301 302 303
        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
304
        KAction *m_findPrev;
305 306 307 308 309 310
        KAction *m_saveAs;
        KAction *m_saveCopyAs;
        KAction *m_printPreview;
        KAction *m_showProperties;
        KAction *m_showEmbeddedFiles;
        KAction *m_exportAs;
311
        QAction *m_exportAsText;
312
        QAction *m_exportAsDocArchive;
313
        KAction *m_showPresentation;
314 315
        KToggleAction* m_showMenuBarAction;
        KToggleAction* m_showLeftPanel;
316
        KToggleAction* m_showBottomBar;
317
        KToggleFullScreenAction* m_showFullScreenAction;
318 319
        KAction *m_aboutBackend;
        KAction *m_reload;
320
        QMenu *m_exportAsMenu;
Jiri Baum's avatar
Jiri Baum committed
321
        KAction *m_closeFindBar;
322 323 324 325 326

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
327
        QList<QAction*> m_bookmarkActions;
328
        bool m_cliPresentation;
329
        bool m_cliPrint;
330
        QString m_addBookmarkText;
331
        QIcon m_addBookmarkIcon;
332

333
        EmbedMode m_embedMode;
334

335 336
        KUrl m_realUrl;

337
        KXMLGUIClient *m_generatorGuiClient;
338
        FileKeeper *m_keeper;
339

340
    private slots:
341
        void slotAnnotationPreferences();
Michel Ludwig's avatar
Michel Ludwig committed
342
        void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
343
};
Wilco Greven's avatar
Wilco Greven committed
344

345 346 347 348 349 350 351 352 353 354 355 356
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);
};

357 358
}

359 360
#endif

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