00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __ko_document_h__
00023 #define __ko_document_h__
00024
00025 namespace std { }
00026 using namespace std;
00027 #include <qwmatrix.h>
00028
00029 #include <kparts/part.h>
00030 #include <kurl.h>
00031 #include <kservice.h>
00032 #include <koGlobal.h>
00033 #include <koPageLayout.h>
00034 #include <koffice_export.h>
00035
00036 class QDomElement;
00037 class QDomDocument;
00038 class QXmlSimpleReader;
00039
00040 class KoStore;
00041 class KoMainWindow;
00042
00043 class KoChild;
00044 class KoDocumentChild;
00045 class KoView;
00046 class KoDocumentInfo;
00047 class DCOPObject;
00048 class KoOasisStyles;
00049 class KoXmlWriter;
00050
00058 class KOFFICECORE_EXPORT KoDocument : public KParts::ReadWritePart
00059 {
00060 Q_OBJECT
00061 Q_PROPERTY( QCString dcopObjectId READ dcopObjectId)
00062 Q_PROPERTY( bool backupFile READ backupFile WRITE setBackupFile )
00063
00064 public:
00065
00082 KoDocument( QWidget* parentWidget,
00083 const char* widgetName,
00084 QObject* parent,
00085 const char* name,
00086 bool singleViewMode = false );
00087
00094 virtual ~KoDocument();
00095
00100 bool isSingleViewMode() const;
00101
00105 bool isEmbedded() const;
00106
00122 virtual KAction *action( const QDomElement &element ) const;
00123
00128 virtual QDomDocument domDocument() const;
00129
00133 virtual void setManager( KParts::PartManager *manager );
00134
00139 virtual bool openURL( const KURL & url );
00140
00151 bool import( const KURL &url );
00152
00163 bool exp0rt( const KURL &url );
00164
00172 virtual void setReadWrite( bool readwrite = true );
00173
00184 static QCString readNativeFormatMimeType( KInstance *instance = 0 );
00185
00196 static QStringList readExtraNativeMimeTypes( KInstance *instance = 0 );
00197
00201 static void setupXmlReader( QXmlSimpleReader& reader, bool namespaceProcessing = false );
00202
00210 virtual QCString nativeFormatMimeType() const;
00211
00216 QCString nativeOasisMimeType() const;
00217
00219 bool isNativeFormat( const QCString& mimetype ) const;
00220
00223 virtual QStringList extraNativeMimeTypes() const;
00224
00226 enum { SaveAsKOffice1dot1 = 1,
00227 SaveAsDirectoryStore = 2
00228
00229 };
00230
00235 virtual int supportedSpecialFormats() const;
00236
00240 QCString mimeType() const;
00241
00248 void setMimeType( const QCString & mimeType );
00249
00257 void setOutputMimeType( const QCString & mimeType, int specialOutputFlag = 0 );
00258 QCString outputMimeType() const;
00259 int specialOutputFlag() const;
00260
00274 bool confirmNonNativeSave( const bool exporting ) const;
00275 void setConfirmNonNativeSave( const bool exporting, const bool on );
00276
00283 void setErrorMessage( const QString& errMsg );
00284
00290 QString errorMessage() const;
00291
00298 void showSavingErrorDialog();
00299
00307 void showLoadingErrorDialog();
00308
00312 KoView *createView( QWidget *parent = 0, const char *name = 0 );
00313
00320 virtual void addView( KoView *view );
00321
00325 virtual void removeView( KoView *view );
00326
00330 const QPtrList<KoView> & views() const;
00331
00335 int viewCount() const;
00336
00340 virtual KParts::Part *hitTest( QWidget *widget, const QPoint &globalPos );
00341
00358 virtual KoDocument *hitTest( const QPoint &pos, const QWMatrix &matrix = QWMatrix() );
00359
00370 virtual void paintEverything( QPainter &painter, const QRect &rect, bool transparent = false,
00371 KoView *view = 0L, double zoomX = 1.0, double zoomY = 1.0 );
00372
00377 virtual QPixmap generatePreview( const QSize& size );
00378
00390 virtual void paintChildren( QPainter &painter, const QRect &rect, KoView *view, double zoomX = 1.0, double zoomY = 1.0 );
00391
00403 virtual void paintChild( KoDocumentChild *child, QPainter &painter, KoView *view,
00404 double zoomX = 1.0, double zoomY = 1.0 );
00405
00419 virtual void paintContent( QPainter &painter, const QRect &rect, bool transparent = false,
00420 double zoomX = 1.0, double zoomY = 1.0 ) = 0;
00421
00425 bool checkAutoSaveFile();
00426
00434 enum InitDocFlags { InitDocAppStarting, InitDocFileNew, InitDocFileClose, InitDocEmbedded, InitDocEmpty };
00435
00441 virtual bool initDoc(InitDocFlags flags, QWidget* parentWidget=0) = 0;
00442
00447 virtual void setModified( bool _mod );
00448
00454 virtual void setTitleModified();
00455
00459 virtual bool isEmpty() const { return m_bEmpty; }
00460
00469 virtual void setEmpty() { m_bEmpty = true; }
00470
00477 virtual bool loadFromStore( KoStore* store, const QString& url );
00478
00483 virtual bool loadOasisFromStore( KoStore* store );
00484
00490 virtual bool saveToStore( KoStore* store, const QString& path );
00491
00500 virtual bool loadXML( QIODevice *, const QDomDocument & doc ) = 0;
00501
00508 virtual bool loadOasis( const QDomDocument & doc, KoOasisStyles& oasisStyles,
00509 const QDomDocument & settings, KoStore* store ) = 0;
00510
00515 virtual bool saveOasis( KoStore* store, KoXmlWriter* manifestWriter ) = 0;
00516
00521 virtual QDomDocument saveXML();
00522
00530 QDomDocument createDomDocument( const QString& tagName, const QString& version ) const;
00531
00549 static KoXmlWriter* createOasisXmlWriter( QIODevice* dev, const char* rootElementName );
00550
00559 static QDomDocument createDomDocument( const QString& appName, const QString& tagName, const QString& version );
00560
00566 virtual bool saveToStream( QIODevice * dev );
00567
00574 virtual bool loadNativeFormat( const QString & file );
00575
00581 virtual bool saveNativeFormat( const QString & file );
00582
00587 void setAutoSave( int delay );
00588
00592 bool isAutosaving() const;
00593
00599 void setCheckAutoSaveFile( bool b );
00600
00606 void setAutoErrorHandlingEnabled( bool b );
00607
00612 bool isAutoErrorHandlingEnabled() const;
00613
00618 static int defaultAutoSave() { return s_defaultAutoSave; }
00619
00624 const QPtrList<KoDocumentChild>& children() const;
00625
00633 KoDocumentChild *child( KoDocument *doc );
00634
00639 KoDocumentInfo *documentInfo() const;
00640
00641 void setViewBuildDocument( KoView *view, const QDomDocument &doc );
00642 QDomDocument viewBuildDocument( KoView *view );
00643
00651 virtual void addShell( KoMainWindow *shell );
00652
00657 virtual void removeShell( KoMainWindow *shell );
00658
00662 const QPtrList<KoMainWindow>& shells() const;
00663
00667 int shellCount() const;
00668
00672 static QPtrList<KoDocument> *documentList() { return s_documentList; }
00673
00680 virtual DCOPObject * dcopObject();
00681
00685 QCString dcopObjectId() const;
00686
00690 void emitProgress( int value ) { emit sigProgress( value ); }
00691
00692 bool isInOperation() const;
00693 virtual void emitBeginOperation();
00694 virtual void emitEndOperation();
00695
00700 virtual bool isStoredExtern() const;
00701
00707 KoPageLayout pageLayout() const { return m_pageLayout; }
00708
00712 void removeAutoSaveFiles();
00713
00714 void setBackupFile( bool _b );
00715
00716 bool backupFile()const;
00717
00721 bool isModified() const;
00722
00726 bool isLoading() const;
00727
00728 int queryCloseExternalChildren();
00729 int queryCloseDia();
00730
00744 void setDoNotSaveExtDoc( bool on = true );
00745
00749 void setBackupPath( const QString & _path );
00750
00754 QString backupPath()const;
00755
00761 void setCurrent( bool on = true );
00762
00766 void forceCurrent( bool on );
00767 bool isCurrent() const;
00768
00769 void setTitleModified( const QString caption, bool mod );
00770
00777 void resetURL() { m_url = KURL(); m_file = QString::null; }
00778
00782 void setStoreInternal( bool i );
00783
00787 bool storeInternal() const;
00788
00789 bool hasExternURL() const;
00790
00795 void setURL( const KURL& url ) { m_url = url; }
00796
00805 QString &file() { return m_file; }
00806
00815 void setFile( const QString &file ) { m_file = file; }
00816
00820 void setMimeTypeAfterLoading( const QString& mimeType );
00821
00822 signals:
00831 void childChanged( KoDocumentChild *child );
00832
00838 void sigProgress( int value );
00839
00844 void sigStatusBarMessage( const QString& text );
00845
00850 void sigClearStatusBarMessage();
00851
00852 void sigBeginOperation();
00853 void sigEndOperation();
00854
00855 protected:
00856
00857 QString autoSaveFile( const QString & path ) const;
00858
00859 virtual KoView *createViewInstance( QWidget *parent, const char *name ) = 0;
00860
00869 virtual bool openFile();
00870
00877 virtual bool saveFile();
00878
00884 bool isImporting() const;
00885
00893 bool isExporting() const;
00894
00915 virtual bool loadChildren( KoStore* );
00916
00922 virtual bool saveChildren( KoStore* store );
00923
00930 virtual bool saveChildrenOasis( KoStore* store, KoXmlWriter* manifestWriter );
00931
00937 virtual bool completeLoading( KoStore* store );
00938
00949 virtual bool completeSaving( KoStore* store );
00950
00962 virtual void insertChild( KoDocumentChild *child );
00963
00965 virtual void setModified() { KParts::ReadWritePart::setModified(); }
00966
00968 virtual void insertChild(QObject *o) { QObject::insertChild(o); }
00969
00970 KoPageLayout m_pageLayout;
00971
00977 virtual bool saveExternalChildren();
00978
00979 private slots:
00980 void slotChildChanged( KoChild *c );
00981 void slotChildDestroyed();
00982 void slotAutoSave();
00983 void slotStarted( KIO::Job* );
00984
00985 private:
00986 static KService::Ptr readNativeService( KInstance *instance );
00987 KService::Ptr nativeService();
00988
00989 bool oldLoadAndParse( KoStore* store, const QString& filename, QDomDocument& doc );
00990 bool loadNativeFormatFromStore( const QString& file );
00991 bool savePreview( KoStore* store );
00992 bool saveOasisPreview( KoStore* store, KoXmlWriter* manifestWriter );
00993
00994 class Private;
00995 Private *d;
00996 KService::Ptr m_nativeService;
00997 bool m_bEmpty;
00998 static QPtrList<KoDocument> *s_documentList;
00999 static const int s_defaultAutoSave;
01000 };
01001
01002 #endif