part.h
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 #ifndef _KPART_H
00021 #define _KPART_H
00022 
00023 #include <qstring.h>
00024 #include <qdom.h>
00025 #include <qguardedptr.h>
00026 #include <kurl.h>
00027 
00028 #include <kxmlguiclient.h>
00029 
00030 class KInstance;
00031 class QWidget;
00032 class KAction;
00033 class KActionCollection;
00034 class QEvent;
00035 struct QUnknownInterface;
00036 
00037 namespace KIO {
00038   class Job;
00039 }
00040 
00041 namespace KParts
00042 {
00043 
00044 class PartManager;
00045 class Plugin;
00046 class PartPrivate;
00047 class PartActivateEvent;
00048 class PartSelectEvent;
00049 class GUIActivateEvent;
00050 class PartBasePrivate;
00051 
00057 class PartBase : virtual public KXMLGUIClient
00058 {
00059     friend class PartBasePrivate;
00060 public:
00061 
00065   PartBase();
00066 
00070   virtual ~PartBase();
00071 
00077   void setPartObject( QObject *object );
00078   QObject *partObject() const;
00079 
00080 protected:
00087   virtual void setInstance( KInstance *instance );
00088 
00095   virtual void setInstance( KInstance *instance, bool loadPlugins );
00096 
00102   enum PluginLoadingMode {
00106     DoNotLoadPlugins = 0,
00113     LoadPlugins = 1,
00120     LoadPluginsIfEnabled = 2
00121   };
00122 
00143   void loadPlugins( QObject *parent, KXMLGUIClient *parentGUIClient, KInstance *instance );
00144 
00149   void setPluginLoadingMode( PluginLoadingMode loadingMode );
00150 
00151 private:
00152     PartBasePrivate *d;
00153     QObject *m_obj;
00154 };
00155 
00181 class Part : public QObject, public PartBase
00182 {
00183     Q_OBJECT
00184 
00185 public:
00186 
00193     Part( QObject *parent = 0, const char* name = 0 );
00194 
00198     virtual ~Part();
00199 
00211     virtual void embed( QWidget * parentWidget );
00212 
00216     virtual QWidget *widget();
00217 
00222     virtual void setManager( PartManager * manager );
00223 
00227     PartManager * manager() const;
00228 
00232     virtual Part *hitTest( QWidget *widget, const QPoint &globalPos );
00233 
00237     virtual void setSelectable( bool selectable );
00238 
00242     bool isSelectable() const;
00243 
00244 signals:
00249     void setWindowCaption( const QString & caption );
00254     void setStatusBarText( const QString & text );
00255 
00256 protected:
00257 
00263     virtual void setWidget( QWidget * widget );
00264 
00268     virtual void customEvent( QCustomEvent *event );
00269 
00275     virtual void partActivateEvent( PartActivateEvent *event );
00276 
00283     virtual void partSelectEvent( PartSelectEvent *event );
00284 
00291     virtual void guiActivateEvent( GUIActivateEvent *event );
00292 
00297     QWidget *hostContainer( const QString &containerName );
00298 
00299 private slots:
00300     void slotWidgetDestroyed();
00301 
00302 private:
00303     QGuardedPtr<QWidget> m_widget;
00304 
00305     PartManager * m_manager;
00306 
00307     PartPrivate *d;
00308 };
00309 
00310 class ReadWritePart;
00311 class ReadOnlyPartPrivate;
00312 
00330 class ReadOnlyPart : public Part
00331 {
00332   Q_OBJECT
00333   friend class ReadWritePart;
00334 public:
00339   ReadOnlyPart( QObject *parent = 0, const char *name = 0 );
00340 
00344   virtual ~ReadOnlyPart();
00345 
00353   void setProgressInfoEnabled( bool show );
00354 
00359   bool isProgressInfoEnabled() const;
00360 
00361 #ifndef KDE_NO_COMPAT
00362   void showProgressInfo( bool show );
00363 #endif
00364 
00365 public slots:
00373   virtual bool openURL( const KURL &url );
00374 
00375 public:
00381   KURL url() const { return m_url; }
00382 
00391   virtual bool closeURL();
00392 
00393 public:
00404   bool openStream( const QString& mimeType, const KURL& url );
00405 
00412   bool writeStream( const QByteArray& data );
00413 
00419   bool closeStream();
00420 
00421 private: 
00422 
00428   virtual bool doOpenStream( const QString&  ) { return false; }
00435   virtual bool doWriteStream( const QByteArray&  ) { return false; }
00441   virtual bool doCloseStream() { return false; }
00442 
00443 signals:
00449   void started( KIO::Job * );
00450 
00456   void completed();
00457 
00467   void completed( bool pendingAction );
00468 
00473   void canceled( const QString &errMsg );
00474 
00475 protected slots:
00476   void slotJobFinished( KIO::Job * job );
00477 
00478 protected:
00484   virtual bool openFile() = 0;
00485 
00489   void abortLoad();
00490 
00501   virtual void guiActivateEvent( GUIActivateEvent *event );
00502 
00506   KURL m_url;
00510   QString m_file;
00514   bool m_bTemp;
00515 
00516 private:
00517   ReadOnlyPartPrivate *d;
00518 };
00519 
00535 class ReadWritePart : public ReadOnlyPart
00536 {
00537   Q_OBJECT
00538 public:
00543   ReadWritePart( QObject *parent = 0, const char *name = 0 );
00552   virtual ~ReadWritePart();
00553 
00557   bool isReadWrite() const { return m_bReadWrite; }
00558 
00563   virtual void setReadWrite ( bool readwrite = true );
00564 
00568   bool isModified() const { return m_bModified; }
00569 
00580   
00581   bool queryClose();
00582 
00594   virtual bool closeURL();
00595 
00606   
00607   bool closeURL( bool promptToSave );
00608 
00614   virtual bool saveAs( const KURL &url );
00615 
00619   virtual void setModified( bool modified );
00620 
00621 signals:
00629    void sigQueryClose(bool *handled, bool* abortClosing);
00630 
00631 public slots:
00637   virtual void setModified();
00638 
00644   virtual bool save();
00645 
00650   bool waitSaveComplete();
00651 
00652 protected:
00664   virtual bool saveFile() = 0;
00665 
00674   virtual bool saveToURL();
00675 
00676 protected slots:
00680   void slotUploadFinished( KIO::Job * job );
00681 
00682 private:
00683   bool m_bModified;
00684   bool m_bReadWrite;
00685   bool m_bClosing;
00686 };
00687 
00688 } 
00689 
00690 #endif
 
This file is part of the documentation for kparts Library Version 3.2.0.