part.h 9.62 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

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

61 62
namespace Okular
{
63 64

class BrowserExtension;
65
class ExportFormat;
66 67 68 69 70 71 72 73 74

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

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

        // Destructor
        ~Part();

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

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

105 106
        KUrl realUrl() const;

107 108
        void showSourceLocation(const QString& fileName, int line, int column);
        void setWatchFileModeEnabled(bool b);
109
        void setShowSourceLocationsGraphically(bool b);
110

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

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

    protected:
        // reimplemented from KParts::ReadOnlyPart
        bool openFile();
        bool openUrl(const KUrl &url);
        bool closeUrl();

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

    public slots:
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
Pino Toscano's avatar
Pino Toscano committed
184
        void restoreDocument(const KConfigGroup &group);
Tobias Koenig's avatar
Tobias Koenig committed
185
        void saveDocumentRestoreInfo(KConfigGroup &group);
186 187
        void slotFileDirty( const QString& );
        void slotDoFileDirty();
188
        void psTransformEnded(int, QProcess::ExitStatus);
189 190

    private:
191 192 193
        void setupViewerActions();
        void setupActions();

John Layt's avatar
John Layt committed
194 195
        void setupPrint( QPrinter &printer );
        void doPrint( QPrinter &printer );
196
        bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype );
197
        void rebuildBookmarkMenu( bool unplugActions = true );
198
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
199 200
        void unsetDummyMode();

201 202 203 204 205 206 207
        KTemporaryFile *m_tempfile;

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

        // main widgets
Pino Toscano's avatar
Pino Toscano committed
208
        Sidebar *m_sidebar;
209
        SearchWidget *m_searchWidget;
210
        FindBar * m_findBar;
211
        PageViewTopMessage * m_topMessage;
212
        PageViewTopMessage * m_formsMessage;
213 214 215 216
        QPointer<ThumbnailList> m_thumbnailList;
        QPointer<PageView> m_pageView;
        QPointer<TOC> m_toc;
        QPointer<MiniBar> m_miniBar;
217
        QPointer<QWidget> m_bottomBar;
218 219 220
        QPointer<PresentationWidget> m_presentationWidget;
        QPointer<ProgressWidget> m_progressWidget;
        QPointer<PageSizeLabel> m_pageSizeLabel;
221 222
        QPointer<Reviews> m_reviewsWidget;
        QPointer<BookmarkList> m_bookmarkList;
223 224 225 226 227 228

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
229
        int m_dirtyToolboxIndex;
230
        bool m_wasSidebarVisible;
231
        bool m_fileWasRemoved;
232
        Rotation m_dirtyPageRotation;
233 234 235 236 237

        // Remember the search history
        QStringList m_searchHistory;

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

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
275
        QList<QAction*> m_bookmarkActions;
276
        bool m_cliPresentation;
277
        QString m_addBookmarkText;
278
        QIcon m_addBookmarkIcon;
279

280
        EmbedMode m_embedMode;
281

282 283
        KUrl m_realUrl;

284
        KXMLGUIClient *m_generatorGuiClient;
285
        FileKeeper *m_keeper;
286

287 288
    private slots:
        void slotGeneratorPreferences();
289
        void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool &handled);
290
};
Wilco Greven's avatar
Wilco Greven committed
291

292 293
}

294 295
#endif

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