Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

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

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

Pino Toscano's avatar
Pino Toscano committed
29
#include <QtDBus/QtDBus>
30

31
class QAction;
32
class QWidget;
33
class QPrinter;
34

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

44
class FindBar;
Albert Astals Cid's avatar
Albert Astals Cid committed
45
class ThumbnailList;
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;
Pino Toscano's avatar
Pino Toscano committed
52
class Sidebar;
Albert Astals Cid's avatar
Albert Astals Cid committed
53 54
class TOC;
class MiniBar;
55

56 57
namespace Okular
{
Pino Toscano's avatar
Pino Toscano 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
Pino Toscano's avatar
Pino Toscano committed
74 75
    Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
    Q_INTERFACES(KDocumentViewer)
76

Pino Toscano's avatar
Pino Toscano committed
77
    public:
78
        // Default constructor
79
        Part(QWidget* parentWidget, QObject* parent, const QVariantList& args);
80 81 82 83 84 85

        // Destructor
        ~Part();

        // inherited from DocumentObserver
        uint observerId() const { return PART_ID; }
86
        void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags );
87
        void notifyViewportChanged( bool smoothMove );
88
        void notifyPageChanged( int page, int flags );
89 90 91

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

94 95
        KUrl realUrl() const;

96 97
    public slots:                // dbus
        Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page);
98
        Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc );
99 100
        Q_SCRIPTABLE uint pages();
        Q_SCRIPTABLE uint currentPage();
101
        Q_SCRIPTABLE QString currentDocument();
102 103 104 105 106 107 108
        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();
109
        Q_SCRIPTABLE void slotTogglePresentation();
110

Pino Toscano's avatar
Pino Toscano committed
111
    signals:
112 113 114 115 116 117 118 119 120 121 122
        void enablePrintAction(bool enable);

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

    protected slots:
        // connected to actions
        void openUrlFromDocument(const KUrl &url);
123
        void openUrlFromBookmarks(const KUrl &url);
124 125 126
        void slotGoToPage();
        void slotHistoryBack();
        void slotHistoryNext();
127
        void slotAddBookmark();
128 129 130 131 132 133
        void slotPreviousBookmark();
        void slotNextBookmark();
        void slotFindNext();
        void slotSaveFileAs();
        void slotGetNewStuff();
        void slotNewConfig();
134
        void slotNewGeneratorConfig();
135 136 137 138 139 140 141 142
        void slotShowMenu(const Okular::Page *page, const QPoint &point);
        void slotShowProperties();
        void slotShowEmbeddedFiles();
        void slotShowLeftPanel();
        void slotShowPresentation();
        void slotHidePresentation();
        void slotExportAs(QAction *);
        bool slotImportPSFile();
143
        void slotAboutBackend();
144
        void slotReload();
145 146
        void close();
        void cannotQuit();
147 148
        void slotShowFindBar();
        void slotHideFindBar();
149
        void setMimeTypes(KIO::Job *job);
150 151
        void loadCancelled(const QString &reason);
        void setWindowTitleFromDocument();
152 153
        // can be connected to widget elements
        void updateViewActions();
154
        void updateBookmarksActions();
155 156 157 158 159
        void enableTOC(bool enable);

    public slots:
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
Pino Toscano's avatar
Pino Toscano committed
160
        void restoreDocument(const KConfigGroup &group);
Tobias Koenig's avatar
Tobias Koenig committed
161
        void saveDocumentRestoreInfo(KConfigGroup &group);
162 163
        void slotFileDirty( const QString& );
        void slotDoFileDirty();
164
        void psTransformEnded(int, QProcess::ExitStatus);
165 166

    private:
167
        void doPrint( QPrinter& printer );
168
        bool handleCompressed( QString &destpath, const QString &path, const QString &compressedMimetype );
169
        void rebuildBookmarkMenu( bool unplugActions = true );
170
        void updateAboutBackendAction();
Albert Astals Cid's avatar
Albert Astals Cid committed
171 172
        void unsetDummyMode();

173 174 175 176 177 178 179
        KTemporaryFile *m_tempfile;

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

        // main widgets
Pino Toscano's avatar
Pino Toscano committed
180
        Sidebar *m_sidebar;
181
        SearchWidget *m_searchWidget;
182
        FindBar * m_findBar;
183
        PageViewTopMessage * m_topMessage;
184
        PageViewTopMessage * m_formsMessage;
185 186 187 188 189 190 191 192 193 194 195 196 197
        QPointer<ThumbnailList> m_thumbnailList;
        QPointer<PageView> m_pageView;
        QPointer<TOC> m_toc;
        QPointer<MiniBar> m_miniBar;
        QPointer<PresentationWidget> m_presentationWidget;
        QPointer<ProgressWidget> m_progressWidget;
        QPointer<PageSizeLabel> m_pageSizeLabel;

        // document watcher (and reloader) variables
        KDirWatch *m_watcher;
        QTimer *m_dirtyHandler;
        Okular::DocumentViewport m_viewportDirty;
        bool m_wasPresentationOpen;
198
        int m_dirtyToolboxIndex;
199 200 201 202 203 204 205 206 207 208 209 210

        // Remember the search history
        QStringList m_searchHistory;

        // actions
        QAction *m_gotoPage;
        QAction *m_prevPage;
        QAction *m_nextPage;
        QAction *m_firstPage;
        QAction *m_lastPage;
        QAction *m_historyBack;
        QAction *m_historyNext;
211
        QAction *m_addBookmark;
212 213 214
        QAction *m_prevBookmark;
        QAction *m_nextBookmark;
        QAction *m_copy;
215
        QAction *m_selectAll;
216 217 218 219 220 221 222 223 224 225 226 227
        QAction *m_find;
        QAction *m_findNext;
        QAction *m_saveAs;
        QAction *m_printPreview;
        QAction *m_showProperties;
        QAction *m_showEmbeddedFiles;
        QAction *m_exportAs;
        QAction *m_exportAsText;
        QAction *m_showPresentation;
        KToggleAction* m_showMenuBarAction;
        KToggleAction* m_showLeftPanel;
        KToggleFullScreenAction* m_showFullScreenAction;
228
        QAction *m_aboutBackend;
229
        QAction *m_reload;
230 231 232 233 234

        bool m_actionsSearched;
        BrowserExtension *m_bExtension;

        QList<Okular::ExportFormat> m_exportFormats;
235
        QList<QAction*> m_bookmarkActions;
236
        bool m_cliPresentation;
237
        QString m_addBookmarkText;
238
        QIcon m_addBookmarkIcon;
239

240 241
        bool m_dummyMode;

242 243
        KUrl m_realUrl;

244 245
        KXMLGUIClient *m_generatorGuiClient;

246 247
    private slots:
        void slotGeneratorPreferences();
248
};
Wilco Greven's avatar
Wilco Greven committed
249

250 251
class BrowserExtension : public KParts::BrowserExtension
{
252
    Q_OBJECT
253

Pino Toscano's avatar
Pino Toscano committed
254
    public:
255
        BrowserExtension(Part*);
Wilco Greven's avatar
Wilco Greven committed
256

257 258 259
    public slots:
        // Automatically detected by the host.
        void print();
260 261 262

    private:
        Part *m_part;
263
};
264 265 266
#endif

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