part.h 6.43 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
#ifndef _PART_H_
#define _PART_H_
18

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

Pino Toscano's avatar
Pino Toscano committed
27
#include <QtDBus/QtDBus>
28

29
class QAction;
30
class QWidget;
31
class QSplitter;
32
class QToolBox;
33

Pino Toscano's avatar
porting  
Pino Toscano committed
34
class KUrl;
35
class KAction;
36
class KConfig;
Albert Astals Cid's avatar
Albert Astals Cid committed
37
class KDirWatch;
38
class KToggleAction;
39
class KToggleFullScreenAction;
40
class KSelectAction;
41 42
class KAboutData;
class KPrinter;
Leandro Emanuel López's avatar
Leandro Emanuel López committed
43
class KTemporaryFile;
44

Albert Astals Cid's avatar
Albert Astals Cid committed
45
class ThumbnailList;
46
class ThumbnailController;
Albert Astals Cid's avatar
Albert Astals Cid committed
47
class PageSizeLabel;
48
class PageView;
49
class PageViewTopMessage;
50
class PresentationWidget;
51
class ProgressWidget;
52
class SearchWidget;
Albert Astals Cid's avatar
Albert Astals Cid committed
53 54
class TOC;
class MiniBar;
55

56 57
namespace Okular {
class Document;
Tobias Koenig's avatar
Tobias Koenig committed
58
class ExportFormat;
59
}
60 61 62 63 64 65 66 67 68 69 70

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
 */
71
class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, public KDocumentViewer
72
{
73
Q_OBJECT
Albert Astals Cid's avatar
Albert Astals Cid committed
74
Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
75
Q_INTERFACES(KDocumentViewer)
76 77 78

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

81 82
	// Destructor
	~Part();
83

84
    // inherited from DocumentObserver
85
    uint observerId() const { return PART_ID; }
Enrico Ros's avatar
Enrico Ros committed
86
    void notifyViewportChanged( bool smoothMove );
87

88
	static KAboutData* createAboutData();
89

90 91 92
	bool openDocument(const KUrl& url, uint page);
	void startPresentation();

93
public slots: // dbus
Pino Toscano's avatar
Pino Toscano committed
94 95
	Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page);
	Q_SCRIPTABLE Q_NOREPLY void openDocument(KUrl doc);
96 97 98 99 100 101 102 103 104 105
	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();
106

Piotr Szymanski's avatar
Piotr Szymanski committed
107 108 109
signals:
	void enablePrintAction(bool enable);

110
protected:
111
	// reimplemented from KParts::ReadOnlyPart
112
	bool openFile();
113 114
	bool openUrl(const KUrl &url);
	bool closeUrl();
115
	void supportedMimetypes();
Laurent Montel's avatar
Laurent Montel committed
116

117
protected slots:
118
	// connected to actions
119
	void openUrlFromDocument(const KUrl &url);
120
	void slotGoToPage();
121 122
	void slotHistoryBack();
	void slotHistoryNext();
123 124
	void slotPreviousBookmark();
	void slotNextBookmark();
125
	void slotFindNext();
126
	void slotSaveFileAs();
Enrico Ros's avatar
Enrico Ros committed
127
	void slotGetNewStuff();
128
	void slotNewConfig();
129
	void slotShowMenu(const Okular::Page *page, const QPoint &point);
Albert Astals Cid's avatar
Albert Astals Cid committed
130
	void slotShowProperties();
131
	void slotShowEmbeddedFiles();
132
	void slotShowLeftPanel();
133
	void slotShowPresentation();
134
	void slotHidePresentation();
135
	void slotExportAs(QAction *);
136
	bool slotImportPSFile();
Piotr Szymanski's avatar
Piotr Szymanski committed
137 138
	void close();
	void cannotQuit();
139
	void splitterMoved( int pos, int index );
Piotr Szymanski's avatar
Piotr Szymanski committed
140
	void setMimeTypes(KIO::Job *job);
141
	void saveSplitterSize();
142
	// can be connected to widget elements
143
	void updateViewActions();
144
	void enableTOC(bool enable);
145

146
public slots:
147
	// connected to Shell action (and browserExtension), not local one
148
	void slotPrint();
149
	void restoreDocument(KConfig* config);
Albert Astals Cid's avatar
Albert Astals Cid committed
150 151 152
	void saveDocumentRestoreInfo(KConfig* config);
	void slotFileDirty( const QString& );
	void slotDoFileDirty();
153
	void psTransformEnded();
154

155 156
private:
	void doPrint( KPrinter& printer );
157
    void fillGenerators();
158
        bool handleCompressed(KUrl & url, const QString &path, const KMimeType::Ptr mimetype);
Leandro Emanuel López's avatar
Leandro Emanuel López committed
159
 	KTemporaryFile *m_tempfile;
160
	
161
	// the document
162
	Okular::Document * m_document;
163
	QString m_temporaryLocalFile;
164 165

	// main widgets
166
	QSplitter *m_splitter;
167
	QWidget *m_leftPanel;
168
	QToolBox *m_toolBox;
169
	SearchWidget *m_searchWidget;
170
	PageViewTopMessage * m_topMessage;
171 172 173 174 175
	QPointer<ThumbnailList> m_thumbnailList;
	QPointer<PageView> m_pageView;
	QPointer<TOC> m_toc;
	QPointer<MiniBar> m_miniBar;
	QPointer<PresentationWidget> m_presentationWidget;
176
	QPointer<ProgressWidget> m_progressWidget;
Albert Astals Cid's avatar
Albert Astals Cid committed
177
	QPointer<PageSizeLabel> m_pageSizeLabel;
178

179
	// document watcher (and reloader) variables
Albert Astals Cid's avatar
Albert Astals Cid committed
180 181
	KDirWatch *m_watcher;
	QTimer *m_dirtyHandler;
182
	Okular::DocumentViewport m_viewportDirty;
Albert Astals Cid's avatar
Albert Astals Cid committed
183
	bool m_wasPresentationOpen;
184

185 186 187
	// Remember the search history
	QStringList m_searchHistory;

188
	// actions
Laurent Montel's avatar
Laurent Montel committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
	QAction *m_gotoPage;
	QAction *m_prevPage;
	QAction *m_nextPage;
	QAction *m_firstPage;
	QAction *m_lastPage;
	QAction *m_historyBack;
	QAction *m_historyNext;
	QAction *m_prevBookmark;
	QAction *m_nextBookmark;
	QAction *m_copy;
	QAction *m_find;
	QAction *m_findNext;
	QAction *m_saveAs;
	QAction *m_printPreview;
	QAction *m_showProperties;
	QAction *m_showEmbeddedFiles;
	QAction *m_exportAs;
206
	QAction *m_exportAsText;
Laurent Montel's avatar
Laurent Montel committed
207
	QAction *m_showPresentation;
208
	KToggleAction* m_showMenuBarAction;
209
	KToggleAction* m_showLeftPanel;
210
	KToggleFullScreenAction* m_showFullScreenAction;	
211

Albert Astals Cid's avatar
Albert Astals Cid committed
212
	bool m_actionsSearched;
213
	bool m_searchStarted;
214
	BrowserExtension *m_bExtension;
215

216 217 218 219 220 221
  // QHash: key is the name of the generator
  QHash<QString, Okular::Generator*> m_loadedGenerators;
  // list of names of the generators that have settings
  QStringList m_generatorsWithSettings;
  QStringList m_supportedMimeTypes;
  KSelectAction * m_confGens;
Tobias Koenig's avatar
Tobias Koenig committed
222
	QList<Okular::ExportFormat> m_exportFormats;
223
	bool m_cliPresentation;
224

225
private slots:
226
    void slotGeneratorPreferences();
227
};
Wilco Greven's avatar
Wilco Greven committed
228

229

230 231 232 233 234
class BrowserExtension : public KParts::BrowserExtension
{
Q_OBJECT

public:
235
	BrowserExtension(Part*);
Wilco Greven's avatar
Wilco Greven committed
236

237
public slots:
238 239
	// Automatically detected by the host.
	void print();
240
};
241

242 243 244
#endif

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