part.h 7.66 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 58 59
namespace Okular
{
    class Document;
    class ExportFormat;
60
}
61

62

63 64 65 66 67 68 69 70 71 72
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
 */
73
class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, public KDocumentViewer
74
{
75 76 77 78 79 80 81 82 83 84 85 86 87
    Q_OBJECT
        Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
        Q_INTERFACES(KDocumentViewer)

        public:
        // Default constructor
        Part(QWidget* parentWidget, QObject* parent, const QStringList& args);

        // Destructor
        ~Part();

        // inherited from DocumentObserver
        uint observerId() const { return PART_ID; }
88
        void notifySetup( const QVector< Okular::Page * > &pages, bool documentChanged );
89
        void notifyViewportChanged( bool smoothMove );
90
        void notifyPageChanged( int page, int flags );
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

        static KAboutData* createAboutData();

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

    public slots:                // dbus
        Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page);
        Q_SCRIPTABLE Q_NOREPLY 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();

        signals:
        void enablePrintAction(bool enable);

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

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

    public slots:
        // connected to Shell action (and browserExtension), not local one
        void slotPrint();
        void restoreDocument(KConfig* config);
        void saveDocumentRestoreInfo(KConfig* config);
        void slotFileDirty( const QString& );
        void slotDoFileDirty();
        void psTransformEnded();

    private:
        void doPrint( KPrinter& printer );
        void fillGenerators();
163
        bool handleCompressed(KUrl & url, const QString &path, const KMimeType::Ptr mimetype);
164
        void rebuildBookmarkMenu( bool unplugActions = true );
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
        KTemporaryFile *m_tempfile;

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

        // main widgets
        QSplitter *m_splitter;
        QWidget *m_leftPanel;
        QToolBox *m_toolBox;
        SearchWidget *m_searchWidget;
        PageViewTopMessage * m_topMessage;
        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;

        // 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;
        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;
        QAction *m_exportAsText;
        QAction *m_showPresentation;
        KToggleAction* m_showMenuBarAction;
        KToggleAction* m_showLeftPanel;
        KToggleFullScreenAction* m_showFullScreenAction;

        bool m_actionsSearched;
        bool m_searchStarted;
        BrowserExtension *m_bExtension;

        // 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;
        QList<Okular::ExportFormat> m_exportFormats;
229
        QList<QAction*> m_bookmarkActions;
230 231 232 233
        bool m_cliPresentation;

    private slots:
        void slotGeneratorPreferences();
234
};
Wilco Greven's avatar
Wilco Greven committed
235

236 237
class BrowserExtension : public KParts::BrowserExtension
{
238
    Q_OBJECT
239

240 241
        public:
        BrowserExtension(Part*);
Wilco Greven's avatar
Wilco Greven committed
242

243 244 245
    public slots:
        // Automatically detected by the host.
        void print();
246
};
247 248 249
#endif

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