part.h 11.6 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;
Tobias Koenig's avatar
Tobias Koenig committed
40
class KConfigGroup;
Albert Astals Cid's avatar
Albert Astals Cid committed
41
class KDirWatch;
42
class KToggleAction;
43
class KToggleFullScreenAction;
44
class KSelectAction;
45
class KAboutData;
Leandro Emanuel López's avatar
Leandro Emanuel López committed
46
class KTemporaryFile;
47
class KAction;
48
class KMenu;
49
namespace KParts { class GUIActivateEvent; }
50

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

67 68
namespace Okular
{
69 70

class BrowserExtension;
71
class ExportFormat;
72

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

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

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

        // Destructor
        ~Part();

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

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

126 127
        KUrl realUrl() const;

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

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

Pino Toscano's avatar
Pino Toscano committed
153
    signals:
154
        void enablePrintAction(bool enable);
155
        void openSourceReference(const QString& absFileName, int line, int column);
156
        void viewerMenuStateChange(bool enabled);
157
        void enableCloseAction(bool enable);
158 159

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

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

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

    private:
226
        void setupViewerActions();
227
        void setViewerShortcuts();
228 229
        void setupActions();

John Layt's avatar
John Layt committed
230 231
        void setupPrint( QPrinter &printer );
        void doPrint( QPrinter &printer );
232
        bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype );
233
        void rebuildBookmarkMenu( bool unplugActions = true );
234
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
235
        void unsetDummyMode();
236
        void slotRenameBookmark( const DocumentViewport &viewport );
237
        void resetStartArguments();
238 239
        
        static int numberOfParts;
Albert Astals Cid's avatar
Albert Astals Cid committed
240

241 242 243 244 245
        KTemporaryFile *m_tempfile;

        // the document
        Okular::Document * m_document;
        QString m_temporaryLocalFile;
246
        bool isDocumentArchive;
247 248

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

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
270
        KUrl m_oldUrl;
271 272
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
273
        int m_dirtyToolboxIndex;
274
        bool m_wasSidebarVisible;
275
        bool m_wasSidebarCollapsed;
276
        bool m_fileWasRemoved;
277
        Rotation m_dirtyPageRotation;
278 279 280 281 282

        // Remember the search history
        QStringList m_searchHistory;

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

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
321
        QList<QAction*> m_bookmarkActions;
322
        bool m_cliPresentation;
323
        bool m_cliPrint;
324
        QString m_addBookmarkText;
325
        QIcon m_addBookmarkIcon;
326

327
        EmbedMode m_embedMode;
328

329 330
        KUrl m_realUrl;

331
        KXMLGUIClient *m_generatorGuiClient;
332
        FileKeeper *m_keeper;
333

334 335
    private slots:
        void slotGeneratorPreferences();
336
        void slotAnnotationPreferences();
Michel Ludwig's avatar
Michel Ludwig committed
337
        void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
338
};
Wilco Greven's avatar
Wilco Greven committed
339

340 341 342 343 344 345 346 347 348 349 350 351
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);
};

352 353
}

354 355
#endif

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