part.h 5.7 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-2006 by Albert Astals Cid <tsdgeos@terra.es>       *
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 18
#ifndef _KPDF_PART_H_
#define _KPDF_PART_H_

Wilco Greven's avatar
Wilco Greven committed
19
#include <kparts/browserextension.h>
20
#include <kparts/part.h>
21
#include <qpointer.h>
22
#include "core/observer.h"
23
#include "core/document.h"
24 25

#include <dbus/qdbus.h>
26

27
class QWidget;
28
class QSplitter;
29
class QToolBox;
30

Pino Toscano's avatar
porting  
Pino Toscano committed
31
class KUrl;
32
class KAction;
33
class KConfig;
Albert Astals Cid's avatar
Albert Astals Cid committed
34
class KDirWatch;
35
class KToggleAction;
36
class KToggleFullScreenAction;
37
class KSelectAction;
38 39
class KAboutData;
class KPrinter;
40

41
class KPDFDocument;
Albert Astals Cid's avatar
Albert Astals Cid committed
42
class ThumbnailList;
43
class ThumbnailController;
44
class PageView;
45
class PresentationWidget;
46
class SearchWidget;
Albert Astals Cid's avatar
Albert Astals Cid committed
47 48
class TOC;
class MiniBar;
49

Albert Astals Cid's avatar
Albert Astals Cid committed
50
namespace okular {
51 52 53 54 55 56 57 58 59 60 61

class BrowserExtension;

/**
 * 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
 */
62
class Part : public KParts::ReadOnlyPart, public DocumentObserver
63
{
64
Q_OBJECT
Albert Astals Cid's avatar
Albert Astals Cid committed
65
Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
66 67 68

public:
	// Default constructor
Albert Astals Cid's avatar
compile  
Albert Astals Cid committed
69
	Part(QWidget* parentWidget, QObject* parent, const QStringList& args);
70

71 72
	// Destructor
	~Part();
73

74
    // inherited from DocumentObserver
75
    uint observerId() const { return PART_ID; }
Enrico Ros's avatar
Enrico Ros committed
76
    void notifyViewportChanged( bool smoothMove );
77

78
	static KAboutData* createAboutData();
79

80 81 82 83 84 85 86 87 88 89 90 91 92
public slots: // dbus
	Q_SCRIPTABLE Q_ASYNC void goToPage(uint page);
	Q_SCRIPTABLE Q_ASYNC void openDocument(KUrl doc);
	Q_SCRIPTABLE uint pages();
	Q_SCRIPTABLE uint currentPage();
	Q_SCRIPTABLE KUrl currentDocument();
	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();
93

Piotr Szymanski's avatar
Piotr Szymanski committed
94 95 96
signals:
	void enablePrintAction(bool enable);

97
protected:
98
	// reimplemented from KParts::ReadOnlyPart
99
	bool openFile();
Pino Toscano's avatar
porting  
Pino Toscano committed
100
	bool openURL(const KUrl &url);
101
	bool closeURL();
102 103
	// filter that watches for splitter size changes
	bool eventFilter( QObject * watched, QEvent * e );
104
	void supportedMimetypes();
Laurent Montel's avatar
Laurent Montel committed
105

106
protected slots:
107
	// connected to actions
Pino Toscano's avatar
porting  
Pino Toscano committed
108
	void openURLFromDocument(const KUrl &url);
109
	void slotGoToPage();
110 111
	void slotHistoryBack();
	void slotHistoryNext();
112 113
	void slotPreviousBookmark();
	void slotNextBookmark();
114
	void slotFindNext();
115
	void slotSaveFileAs();
Enrico Ros's avatar
Enrico Ros committed
116
	void slotGetNewStuff();
117
	void slotNewConfig();
118
	void slotShowMenu(const KPDFPage *page, const QPoint &point);
Albert Astals Cid's avatar
Albert Astals Cid committed
119
	void slotShowProperties();
120
	void slotShowEmbeddedFiles();
121
	void slotShowLeftPanel();
122
	void slotShowPresentation();
123
	void slotHidePresentation();
124
	bool slotImportPSFile();
Piotr Szymanski's avatar
Piotr Szymanski committed
125 126 127
	void close();
	void cannotQuit();
	void setMimeTypes(KIO::Job *job);
128
	void saveSplitterSize();
129
	// can be connected to widget elements
130
	void updateViewActions();
131
	void enableTOC(bool enable);
132

133
public slots:
134
	// connected to Shell action (and browserExtension), not local one
135
	void slotPrint();
Pino Toscano's avatar
porting  
Pino Toscano committed
136
	void restoreDocument(const KUrl &url, int page);
Albert Astals Cid's avatar
Albert Astals Cid committed
137 138 139
	void saveDocumentRestoreInfo(KConfig* config);
	void slotFileDirty( const QString& );
	void slotDoFileDirty();
140
	void psTransformEnded();
141

142 143
private:
	void doPrint( KPrinter& printer );
144
    void fillGenerators();
145

146
	// the document
147
	KPDFDocument * m_document;
148
	QString m_temporaryLocalFile;
149 150

	// main widgets
151
	QSplitter *m_splitter;
152
	QWidget *m_leftPanel;
153
	QToolBox *m_toolBox;
154
	SearchWidget *m_searchWidget;
155 156 157 158 159
	QPointer<ThumbnailList> m_thumbnailList;
	QPointer<PageView> m_pageView;
	QPointer<TOC> m_toc;
	QPointer<MiniBar> m_miniBar;
	QPointer<PresentationWidget> m_presentationWidget;
160

161
	// document watcher (and reloader) variables
Albert Astals Cid's avatar
Albert Astals Cid committed
162 163
	KDirWatch *m_watcher;
	QTimer *m_dirtyHandler;
164
	DocumentViewport m_viewportDirty;
165 166 167 168 169 170 171

	// actions
	KAction *m_gotoPage;
	KAction *m_prevPage;
	KAction *m_nextPage;
	KAction *m_firstPage;
	KAction *m_lastPage;
172 173
	KAction *m_historyBack;
	KAction *m_historyNext;
174 175
	KAction *m_prevBookmark;
	KAction *m_nextBookmark;
176 177
	KAction *m_find;
	KAction *m_findNext;
178 179
	KAction *m_saveAs;
	KAction *m_printPreview;
Albert Astals Cid's avatar
Albert Astals Cid committed
180
	KAction *m_showProperties;
181
	KAction *m_showEmbeddedFiles;
182
	KAction *m_showPresentation;
183
	KToggleAction* m_showMenuBarAction;
184
	KToggleAction* m_showLeftPanel;
185
	KToggleFullScreenAction* m_showFullScreenAction;
186

Albert Astals Cid's avatar
Albert Astals Cid committed
187
	bool m_actionsSearched;
188
	bool m_searchStarted;
189
	BrowserExtension *m_bExtension;
190

191 192
    // QHash: key is the name of the generator
   QHash<QString, Generator*> m_loadedGenerators;
193 194
    // list of names of the generators that have settings
    QStringList m_generatorsWithSettings;
Piotr Szymanski's avatar
Piotr Szymanski committed
195
    QStringList m_supportedMimeTypes;
196 197 198 199
    KSelectAction * m_confGens;

    private slots:
    void slotGeneratorPreferences();
200
};
Wilco Greven's avatar
Wilco Greven committed
201

202

203 204 205 206 207
class BrowserExtension : public KParts::BrowserExtension
{
Q_OBJECT

public:
208
	BrowserExtension(Part*);
Wilco Greven's avatar
Wilco Greven committed
209

210
public slots:
211 212
	// Automatically detected by the host.
	void print();
213
};
214

215 216 217 218 219
}

#endif

// vim:ts=2:sw=2:tw=78:et