part.h 6.38 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;
43

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

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

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

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

80 81
	// Destructor
	~Part();
82

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

87
	static KAboutData* createAboutData();
88

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

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

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

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

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

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

154 155
private:
	void doPrint( KPrinter& printer );
156
    void fillGenerators();
157 158
        bool handleCompressed(KUrl & url, const QString &path, const KMimeType::Ptr mimetype);
	
159
	// the document
160
	Okular::Document * m_document;
161
	QString m_temporaryLocalFile;
162 163

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

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

183 184 185
	// Remember the search history
	QStringList m_searchHistory;

186
	// actions
Laurent Montel's avatar
Laurent Montel committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
	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;
204
	QAction *m_exportAsText;
Laurent Montel's avatar
Laurent Montel committed
205
	QAction *m_showPresentation;
206
	KToggleAction* m_showMenuBarAction;
207
	KToggleAction* m_showLeftPanel;
208
	KToggleFullScreenAction* m_showFullScreenAction;	
209

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

214 215 216 217 218 219
  // 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
220
	QList<Okular::ExportFormat> m_exportFormats;
221
	bool m_cliPresentation;
222

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

227

228 229 230 231 232
class BrowserExtension : public KParts::BrowserExtension
{
Q_OBJECT

public:
233
	BrowserExtension(Part*);
Wilco Greven's avatar
Wilco Greven committed
234

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

240 241 242
#endif

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