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

31 32
#include "okular_part_export.h"

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

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

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

53
class FindBar;
Albert Astals Cid's avatar
Albert Astals Cid committed
54
class ThumbnailList;
Albert Astals Cid's avatar
Albert Astals Cid committed
55
class PageSizeLabel;
56
class PageView;
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
class Layers;
68

69 70
namespace Okular
{
71 72

class BrowserExtension;
73
class ExportFormat;
74

75 76 77 78 79 80 81 82 83 84 85
/**
 * 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
86
    ViewerWidgetMode         // the part acts as a widget that can display all kinds of documents
87 88
};

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

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

        // Destructor
        ~Part();

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

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

128 129
        KUrl realUrl() const;

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

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

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

    protected:
166
        // reimplemented from KParts::ReadWritePart
167 168
        bool openFile();
        bool openUrl(const KUrl &url);
169
        void guiActivateEvent(KParts::GUIActivateEvent *event);
170
        void displayInfoMessage( const QString &message, KMessageWidget::MessageType messageType = KMessageWidget::Information, int duration = -1 );;
171 172 173 174 175 176 177
    public:
        bool saveFile();
        bool queryClose();
        bool closeUrl();
        bool closeUrl(bool promptToSave);
        void setReadWrite(bool readwrite);
        bool saveAs(const KUrl & saveUrl);
178 179 180 181

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

    public slots:
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
        void slotFileDirty( const QString& );
        void slotDoFileDirty();
230
        void psTransformEnded(int, QProcess::ExitStatus);
231
        KConfigDialog * slotGeneratorPreferences();
232

233 234 235 236
        void errorMessage( const QString &message, int duration = 0 );
        void warningMessage( const QString &message, int duration = -1 );
        void noticeMessage( const QString &message, int duration = -1 );

237 238
        void moveSplitter( const int sideWidgetSize );

239
    private:
240 241
        Document::OpenResult doOpenFile(const KMimeType::Ptr &mime, const QString &fileNameToOpen, bool *isCompressedFile);

242
        void setupViewerActions();
243
        void setViewerShortcuts();
244 245
        void setupActions();

John Layt's avatar
John Layt committed
246 247
        void setupPrint( QPrinter &printer );
        void doPrint( QPrinter &printer );
248
        bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype );
249
        void rebuildBookmarkMenu( bool unplugActions = true );
250
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
251
        void unsetDummyMode();
252
        void slotRenameBookmark( const DocumentViewport &viewport );
253
        void resetStartArguments();
254 255
        
        static int numberOfParts;
Albert Astals Cid's avatar
Albert Astals Cid committed
256

257 258 259 260 261
        KTemporaryFile *m_tempfile;

        // the document
        Okular::Document * m_document;
        QString m_temporaryLocalFile;
262
        bool isDocumentArchive;
263 264

        // main widgets
Pino Toscano's avatar
Pino Toscano committed
265
        Sidebar *m_sidebar;
266
        SearchWidget *m_searchWidget;
267
        FindBar * m_findBar;
268 269
        KMessageWidget * m_topMessage;
        KMessageWidget * m_formsMessage;
270
        KMessageWidget * m_infoMessage;
271 272 273
        QPointer<ThumbnailList> m_thumbnailList;
        QPointer<PageView> m_pageView;
        QPointer<TOC> m_toc;
Albert Astals Cid's avatar
Albert Astals Cid committed
274
        QPointer<MiniBarLogic> m_miniBarLogic;
275
        QPointer<MiniBar> m_miniBar;
276
        QPointer<MiniBar> m_pageNumberTool;
277
        QPointer<QWidget> m_bottomBar;
278 279 280
        QPointer<PresentationWidget> m_presentationWidget;
        QPointer<ProgressWidget> m_progressWidget;
        QPointer<PageSizeLabel> m_pageSizeLabel;
281 282
        QPointer<Reviews> m_reviewsWidget;
        QPointer<BookmarkList> m_bookmarkList;
283
        QPointer<Layers> m_layers;
284 285 286 287

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
288
        KUrl m_oldUrl;
289 290
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
291
        int m_dirtyToolboxIndex;
292
        bool m_wasSidebarVisible;
293
        bool m_wasSidebarCollapsed;
294
        bool m_fileWasRemoved;
295
        Rotation m_dirtyPageRotation;
296 297 298 299 300

        // Remember the search history
        QStringList m_searchHistory;

        // actions
301 302 303
        KAction *m_gotoPage;
        KAction *m_prevPage;
        KAction *m_nextPage;
304 305
        KAction *m_beginningOfDocument;
        KAction *m_endOfDocument;
306 307 308
        KAction *m_historyBack;
        KAction *m_historyNext;
        KAction *m_addBookmark;
309
        KAction *m_renameBookmark;
310 311 312 313 314 315
        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
316
        KAction *m_findPrev;
317 318 319 320 321 322
        KAction *m_saveAs;
        KAction *m_saveCopyAs;
        KAction *m_printPreview;
        KAction *m_showProperties;
        KAction *m_showEmbeddedFiles;
        KAction *m_exportAs;
323
        QAction *m_exportAsText;
324
        QAction *m_exportAsDocArchive;
325
        KAction *m_showPresentation;
326 327
        KToggleAction* m_showMenuBarAction;
        KToggleAction* m_showLeftPanel;
328
        KToggleAction* m_showBottomBar;
329
        KToggleFullScreenAction* m_showFullScreenAction;
330 331
        KAction *m_aboutBackend;
        KAction *m_reload;
332
        QMenu *m_exportAsMenu;
Jiri Baum's avatar
Jiri Baum committed
333
        KAction *m_closeFindBar;
334 335 336 337 338

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
339
        QList<QAction*> m_bookmarkActions;
340
        bool m_cliPresentation;
341
        bool m_cliPrint;
342
        QString m_addBookmarkText;
343
        QIcon m_addBookmarkIcon;
344

345
        EmbedMode m_embedMode;
346

347 348
        KUrl m_realUrl;

349
        KXMLGUIClient *m_generatorGuiClient;
350
        FileKeeper *m_keeper;
351

352 353 354
        // Timer for m_infoMessage
        QTimer *m_infoTimer;

355
    private slots:
356
        void slotAnnotationPreferences();
Michel Ludwig's avatar
Michel Ludwig committed
357
        void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
358
};
Wilco Greven's avatar
Wilco Greven committed
359

360 361 362 363 364 365 366 367 368 369 370 371
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);
};

372 373
}

374 375
#endif

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