KParts
part.h
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 1999 Simon Hausmann <hausmann@kde.org> 00003 (C) 1999 David Faure <faure@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 #ifndef _KPART_H 00021 #define _KPART_H 00022 00023 #include <QtCore/QPointer> 00024 #include <QtCore/QEvent> 00025 #include <QtCore/QSharedDataPointer> 00026 #include <QtXml/QDomElement> // KDE5: remove 00027 00028 #include <kurl.h> 00029 #include <kxmlguiclient.h> 00030 00031 #include <kparts/kparts_export.h> 00032 00033 #define KPARTS_DECLARE_PRIVATE(Class) \ 00034 inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(PartBase::d_ptr); } \ 00035 inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(PartBase::d_ptr); } \ 00036 friend class Class##Private; 00037 00038 class KIconLoader; 00039 class KComponentData; 00040 class QWidget; 00041 class QEvent; 00042 class QPoint; 00043 struct QUnknownInterface; 00044 00045 class KJob; 00046 namespace KIO { 00047 class Job; 00048 } 00049 00050 namespace KParts 00051 { 00052 00053 class PartManager; 00054 class Plugin; 00055 class PartPrivate; 00056 class PartActivateEvent; 00057 class PartSelectEvent; 00058 class GUIActivateEvent; 00059 class PartBasePrivate; 00060 00064 class KPARTS_EXPORT PartBase : virtual public KXMLGUIClient 00065 { 00066 KPARTS_DECLARE_PRIVATE(PartBase) 00067 00068 public: 00069 00073 PartBase(); 00074 00078 virtual ~PartBase(); 00079 00085 void setPartObject( QObject *object ); 00086 QObject *partObject() const; 00087 00088 protected: 00095 virtual void setComponentData(const KComponentData &componentData); 00096 00108 virtual void setComponentData(const KComponentData &componentData, bool loadPlugins); 00109 // TODO KDE5: merge the above two methods, using loadPlugins=true. Or better, remove loadPlugins 00110 // altogether and change plugins to call loadPlugins() manually at the end of their ctor. 00111 // In the case of KParts MainWindows, plugins are automatically loaded in createGUI anyway, 00112 // so setComponentData() should really not load the plugins. 00113 00119 enum PluginLoadingMode { 00123 DoNotLoadPlugins = 0, 00130 LoadPlugins = 1, 00137 LoadPluginsIfEnabled = 2 00138 }; 00139 00156 void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const KComponentData &componentData); 00157 00165 void setPluginLoadingMode( PluginLoadingMode loadingMode ); 00166 00179 void setPluginInterfaceVersion( int version ); 00180 00181 protected: 00182 PartBase(PartBasePrivate &dd); 00183 00184 PartBasePrivate *d_ptr; 00185 00186 private: 00187 Q_DISABLE_COPY(PartBase) 00188 }; 00189 00215 class KPARTS_EXPORT Part : public QObject, public PartBase 00216 { 00217 Q_OBJECT 00218 00219 KPARTS_DECLARE_PRIVATE(Part) 00220 00221 public: 00222 00228 explicit Part( QObject *parent = 0 ); 00229 00233 virtual ~Part(); 00234 00246 virtual void embed( QWidget * parentWidget ); 00247 00251 virtual QWidget *widget(); 00252 00257 virtual void setManager( PartManager * manager ); 00258 00262 PartManager * manager() const; 00263 00272 void setAutoDeleteWidget(bool autoDeleteWidget); 00273 00282 void setAutoDeletePart(bool autoDeletePart); 00283 00292 virtual Part *hitTest( QWidget *widget, const QPoint &globalPos ); 00293 00297 virtual void setSelectable( bool selectable ); 00298 00302 bool isSelectable() const; 00303 00311 KIconLoader* iconLoader(); 00312 00313 Q_SIGNALS: 00318 void setWindowCaption( const QString & caption ); 00323 void setStatusBarText( const QString & text ); 00324 00325 protected: 00331 virtual void setWidget( QWidget * widget ); 00332 00336 virtual void customEvent( QEvent *event ); 00337 00343 virtual void partActivateEvent( PartActivateEvent *event ); 00344 00351 virtual void partSelectEvent( PartSelectEvent *event ); 00352 00359 virtual void guiActivateEvent( GUIActivateEvent *event ); 00360 00365 QWidget *hostContainer( const QString &containerName ); 00366 00373 void loadPlugins(); 00374 using PartBase::loadPlugins; 00375 00376 protected Q_SLOTS: 00380 void slotWidgetDestroyed(); 00381 00382 protected: 00383 Part(PartPrivate &dd, QObject *parent); 00384 00385 private: 00386 Q_DISABLE_COPY(Part) 00387 }; 00388 00389 class ReadWritePart; 00390 class ReadOnlyPartPrivate; 00391 class BrowserExtension; 00392 class OpenUrlArgumentsPrivate; 00393 00404 class KPARTS_EXPORT OpenUrlArguments 00405 { 00406 public: 00407 OpenUrlArguments(); 00408 OpenUrlArguments(const OpenUrlArguments &other); 00409 OpenUrlArguments &operator=( const OpenUrlArguments &other); 00410 ~OpenUrlArguments(); 00411 00416 bool reload() const; 00421 void setReload(bool b); 00422 00428 int xOffset() const; 00429 void setXOffset(int x); 00430 00436 int yOffset() const; 00437 void setYOffset(int y); 00438 00442 QString mimeType() const; 00443 void setMimeType(const QString& mime); 00444 00452 bool actionRequestedByUser() const; 00453 void setActionRequestedByUser(bool userRequested); 00454 00460 QMap<QString, QString> &metaData(); 00461 const QMap<QString, QString> &metaData() const; 00462 00463 private: 00464 QSharedDataPointer<OpenUrlArgumentsPrivate> d; 00465 }; 00466 00467 00488 class KPARTS_EXPORT ReadOnlyPart : public Part 00489 { 00490 Q_OBJECT 00491 00492 Q_PROPERTY( KUrl url READ url ) 00493 00494 KPARTS_DECLARE_PRIVATE(ReadOnlyPart) 00495 00496 public: 00501 explicit ReadOnlyPart( QObject *parent = 0 ); 00502 00506 virtual ~ReadOnlyPart(); 00507 00515 void setProgressInfoEnabled( bool show ); 00516 00521 bool isProgressInfoEnabled() const; 00522 00523 #ifndef KDE_NO_COMPAT 00524 void showProgressInfo( bool show ); 00525 #endif 00526 00527 public Q_SLOTS: 00536 virtual bool openUrl( const KUrl &url ); 00537 00538 public: 00544 KUrl url() const; 00545 00554 virtual bool closeUrl(); 00555 00560 BrowserExtension* browserExtension() const; 00561 00565 void setArguments(const OpenUrlArguments& arguments); 00566 // TODO to avoid problems with the case where the loading fails, this could also be a openUrl() argument (heavy porting!). 00567 // However we need to have setArguments in any case for updated made by the part, see e.g. KHTMLPart::openUrl. 00568 // Well, maybe we should have setArguments (affects next openurl call) and updateArguments? 00569 00570 00574 OpenUrlArguments arguments() const; 00575 00576 public: 00587 bool openStream( const QString& mimeType, const KUrl& url ); 00588 00595 bool writeStream( const QByteArray& data ); 00596 00602 bool closeStream(); 00603 00604 private: // Makes no sense for inherited classes to call those. But make it protected there. 00605 00611 virtual bool doOpenStream( const QString& /*mimeType*/ ) { return false; } 00618 virtual bool doWriteStream( const QByteArray& /*data*/ ) { return false; } 00624 virtual bool doCloseStream() { return false; } 00625 00626 Q_SIGNALS: 00632 void started( KIO::Job * ); 00633 00639 void completed(); 00640 00650 void completed( bool pendingAction ); 00651 00656 void canceled( const QString &errMsg ); 00657 00658 protected: 00664 virtual bool openFile(); 00665 00669 void abortLoad(); 00670 00681 virtual void guiActivateEvent( GUIActivateEvent *event ); 00682 00686 #ifndef KDE_NO_DEPRECATED 00687 KDE_DEPRECATED bool isLocalFileTemporary() const; 00688 #endif 00689 00693 #ifndef KDE_NO_DEPRECATED 00694 KDE_DEPRECATED void setLocalFileTemporary( bool temp ); 00695 #endif 00696 00700 void setUrl(const KUrl &url); 00701 00705 QString localFilePath() const; 00706 00710 void setLocalFilePath( const QString &localFilePath ); 00711 00712 protected: 00713 ReadOnlyPart(ReadOnlyPartPrivate &dd, QObject *parent); 00714 00715 private: 00716 Q_PRIVATE_SLOT(d_func(), void _k_slotJobFinished( KJob * job )) 00717 Q_PRIVATE_SLOT(d_func(), void _k_slotStatJobFinished(KJob*)) 00718 Q_PRIVATE_SLOT(d_func(), void _k_slotGotMimeType(KIO::Job *job, const QString &mime)) 00719 00720 Q_DISABLE_COPY(ReadOnlyPart) 00721 }; 00722 class ReadWritePartPrivate; 00723 00739 class KPARTS_EXPORT ReadWritePart : public ReadOnlyPart 00740 { 00741 Q_OBJECT 00742 00743 KPARTS_DECLARE_PRIVATE(ReadWritePart) 00744 00745 public: 00750 explicit ReadWritePart( QObject *parent = 0 ); 00759 virtual ~ReadWritePart(); 00760 00764 bool isReadWrite() const; 00765 00770 virtual void setReadWrite ( bool readwrite = true ); 00771 00775 bool isModified() const; 00776 00785 virtual bool queryClose(); 00786 00798 virtual bool closeUrl(); 00799 00808 virtual bool closeUrl( bool promptToSave ); 00809 00815 virtual bool saveAs( const KUrl &url ); 00816 00820 virtual void setModified( bool modified ); 00821 00822 Q_SIGNALS: 00828 void sigQueryClose(bool *handled, bool* abortClosing); 00829 00830 public Q_SLOTS: 00836 void setModified(); 00837 00843 virtual bool save(); 00844 00849 bool waitSaveComplete(); 00850 00851 protected: 00863 virtual bool saveFile() = 0; 00864 00873 virtual bool saveToUrl(); 00874 00875 private: 00876 Q_PRIVATE_SLOT(d_func(), void _k_slotUploadFinished( KJob * job )) 00877 00878 Q_DISABLE_COPY(ReadWritePart) 00879 }; 00880 00881 } // namespace 00882 00883 00884 #undef KPARTS_DECLARE_PRIVATE 00885 00886 #endif
KDE 4.6 API Reference