• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

xad_Document.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
00002 
00003 /* AbiSource Application Framework
00004  * Copyright (C) 1998,1999 AbiSource, Inc.
00005  * Copyright (C) 2004 Tomas Frydrych <tomasfrydrych@yahoo.co.uk>
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00020  * 02110-1301 USA.
00021  */
00022 
00023 
00024 #ifndef AD_DOCUMENT_H
00025 #define AD_DOCUMENT_H
00026 
00027 #include <memory>
00028 #include <string>
00029 
00030 #ifndef UT_TYPES_H
00031 #include "ut_types.h"
00032 #endif
00033 #include "ut_bytebuf.h"
00034 #include "ut_string_class.h"
00035 #include "ut_vector.h"
00036 #include "ut_uuid.h"
00037 #include "time.h"
00038 
00039 // fwd. decl.
00040 class XAP_ResourceManager;
00041 class XAP_Frame;
00042 class AV_View;
00043 
00044 // a helper class for history tracking
00045 class ABI_EXPORT AD_VersionData
00046 {
00047   public:
00048 
00049     // constructor for importers
00050     AD_VersionData(UT_uint32 v, const std::string &uuid, time_t start, bool autorev, UT_uint32 xid);
00051     AD_VersionData(UT_uint32 v, const char * uuid, time_t start, bool autorev, UT_uint32 xid);
00052 
00053     // constructor for new entries
00054     AD_VersionData(UT_uint32 v, time_t start, bool autorev, UT_uint32 xid);
00055 
00056     // copy constructor
00057     AD_VersionData(const AD_VersionData & v);
00058 
00059     virtual ~AD_VersionData();
00060 
00061     AD_VersionData & operator = (const AD_VersionData &v);
00062 
00063     bool operator == (const AD_VersionData &v);
00064 
00065     UT_uint32      getId()const{return m_iId;}
00066     time_t         getTime()const;
00067     time_t         getStartTime()const {return m_tStart;}
00068     const UT_UUID& getUID()const {return (const UT_UUID&)*m_pUUID;}
00069     bool           newUID(); // true on success
00070 
00071     void           setId(UT_uint32 iid) {m_iId = iid;}
00072 
00073     bool           isAutoRevisioned()const {return m_bAutoRevision;}
00074     void           setAutoRevisioned(bool autorev);
00075 
00076     UT_uint32      getTopXID() const {return m_iTopXID;}
00077 
00078   private:
00079     UT_uint32   m_iId;
00080     UT_UUID *   m_pUUID;
00081     time_t      m_tStart;
00082     bool        m_bAutoRevision;
00083     UT_uint32   m_iTopXID;
00084 };
00085 
00086 enum AD_HISTORY_STATE
00087 {
00088     ADHIST_FULL_RESTORE,
00089     ADHIST_PARTIAL_RESTORE,
00090     ADHIST_NO_RESTORE
00091 };
00092 
00093 
00094 // a helper class for keeping track of revisions in the document
00095 class ABI_EXPORT AD_Revision
00096 {
00097   public:
00098     AD_Revision(UT_uint32 iId, UT_UCS4Char * pDesc, time_t start, UT_uint32 iVer = 0)
00099         :m_iId(iId),m_pDescription(pDesc), m_tStart(start), m_iVersion(iVer){};
00100 
00101     ~AD_Revision(){delete [] m_pDescription;}
00102 
00103     UT_uint32         getId()const{return m_iId;}
00104     UT_UCS4Char *     getDescription() const {return m_pDescription;}
00105 
00106     // NB: getStartTime() == 0 should be interpreted as 'unknown'
00107     time_t            getStartTime() const {return m_tStart;}
00108     void              setStartTime(time_t t) {m_tStart = t;}
00109 
00110     UT_uint32         getVersion()const {return m_iVersion;}
00111     void              setVersion(UT_uint32 iVer) {m_iVersion = iVer;}
00112 
00113   private:
00114     UT_uint32     m_iId;
00115     UT_UCS4Char * m_pDescription;
00116     time_t        m_tStart;
00117     UT_uint32     m_iVersion;
00118 };
00119 
00120 enum AD_DOCUMENT_TYPE
00121 {
00122     ADDOCUMENT_ABIWORD
00123 };
00124 
00125 struct _dataItemPair;
00126 typedef _dataItemPair* PD_DataItemHandle;
00127 
00128 class ABI_EXPORT AD_Document
00129 {
00130 public:
00131     AD_Document();
00132     void                ref(void);
00133     void                unref(void);
00134 
00135     virtual AD_DOCUMENT_TYPE getType() const = 0;
00136 
00137     XAP_ResourceManager &   resourceManager () const { return *m_pResourceManager; }
00138 
00139     const std::string     & getFilename(void) const;
00140     const std::string     & getPrintFilename(void) const;
00141     void                    setPrintFilename(const std::string & sFile);
00142     void                    clearFilename(void) {_setFilename(""); forceDirty();}
00143     // TODO - this should be returning IEFileType,
00144     // but that's AP stuff, so it's not here
00145 
00146     virtual UT_Error        readFromFile(const char * szFilename, int ieft, const char * props = NULL) = 0;
00147     virtual UT_Error        importFile(const char * szFilename, int ieft, bool markClean = false, bool bImportStylesFirst = true, const char * props = NULL) = 0;
00148     virtual UT_Error        newDocument() = 0;
00149     virtual bool            isDirty(void) const = 0;
00150     virtual void            forceDirty() {m_bForcedDirty = true;};
00151     bool                    isForcedDirty() const {return m_bForcedDirty;}
00152 
00153     virtual bool            canDo(bool bUndo) const = 0;
00154     virtual bool            undoCmd(UT_uint32 repeatCount) = 0;
00155     virtual bool            redoCmd(UT_uint32 repeatCount) = 0;
00156 
00157     UT_Error                saveAs(const char * szFilename, int ieft, const char * props = NULL);
00158     UT_Error                saveAs(const char * szFilename, int ieft, bool cpy, const char * props = NULL);
00159     UT_Error                save(void);
00160     virtual bool            createDataItem(const char * szName,
00161                                            bool bBase64,
00162                                            const UT_ConstByteBufPtr & pByteBuf,
00163                                            const std::string & mime_type,
00164                                            PD_DataItemHandle* ppHandle) = 0;
00165     virtual bool            replaceDataItem(const char * szName,
00166                                             const UT_ConstByteBufPtr & pByteBuf) = 0;
00167     virtual bool            getDataItemDataByName(const char * szName,
00168                                                   UT_ConstByteBufPtr& pByteBuf,
00169                                                   std::string * mime_type,
00170                                                   PD_DataItemHandle* ppHandle) const = 0;
00171 public:
00172 
00176     time_t          getTimeSinceSave () const { return (time(NULL) - m_lastSavedTime); }
00177     time_t          getLastSavedTime() const {return m_lastSavedTime;}
00178     void            setLastSavedTime(time_t t) {m_lastSavedTime = t;}
00179     virtual UT_uint32 getLastSavedAsType() const = 0;
00180 
00181     time_t          getTimeSinceOpen () const { return (time(NULL) - m_lastOpenedTime); }
00182     time_t          getLastOpenedTime() const {return m_lastOpenedTime;}
00183     void            setLastOpenedTime(time_t t) {m_lastOpenedTime = t;}
00184 
00185     time_t          getEditTime()const {return (m_iEditTime + (time(NULL) - m_lastOpenedTime));}
00186     void            setEditTime(UT_uint32 t) {m_iEditTime = t;}
00187 
00188     void            setDocVersion(UT_uint32 i){m_iVersion = i;}
00189     UT_uint32       getDocVersion() const {return m_iVersion;}
00190 
00191     void            setEncodingName(const char * szEncodingName);
00192     const char *    getEncodingName() const;
00193 
00194     bool            isPieceTableChanging(void) const;
00195 
00196     virtual void setMetaDataProp (const std::string & key, const std::string & value) = 0;
00197     virtual bool getMetaDataProp (const std::string & key, std::string & outProp) const = 0;
00198 
00199     // RIVERA TODO not working and may not be needed
00200     virtual void setAnnotationProp (const std::string & key, const std::string & value) = 0;
00201     virtual bool getAnnotationProp (const std::string & key, std::string & outProp) const = 0;
00202 
00203     // history tracking
00204     void            addRecordToHistory(const AD_VersionData & v);
00205     void            purgeHistory();
00206     UT_sint32       getHistoryCount()const {return m_vHistory.getItemCount();}
00207     UT_uint32       getHistoryNthId(UT_sint32 i)const;
00208     time_t          getHistoryNthTime(UT_sint32 i)const;
00209     time_t          getHistoryNthTimeStarted(UT_sint32 i)const;
00210     time_t          getHistoryNthEditTime(UT_sint32 i)const;
00211     const UT_UUID&  getHistoryNthUID(UT_sint32 i)const;
00212     bool            getHistoryNthAutoRevisioned(UT_sint32 i)const;
00213     UT_uint32       getHistoryNthTopXID(UT_sint32 i)const;
00214 
00215     AD_HISTORY_STATE       verifyHistoryState(UT_uint32 &iVersion) const;
00216     const AD_VersionData * findHistoryRecord(UT_uint32 iVersion) const;
00217     bool                   showHistory(AV_View * pView);
00218 
00219     bool            areDocumentsRelated (const AD_Document &d) const;
00220     bool            areDocumentHistoriesEqual(const AD_Document &d, UT_uint32 &iVer) const;
00221 
00222     virtual bool    areDocumentContentsEqual(const AD_Document &d, UT_uint32 &pos) const = 0;
00223     virtual bool    areDocumentFormatsEqual(const AD_Document &d, UT_uint32 &pos) const = 0;
00224     virtual bool    areDocumentStylesheetsEqual(const AD_Document &d) const = 0;
00225 
00226     void            setDocUUID(const char * u);
00227     const char *    getDocUUIDString()const;
00228     const UT_UUID * getDocUUID()const {return m_pUUID;};
00229     void            setOrigUUID(const char * u);
00230     const char *    getOrigDocUUIDString()const;
00231     const UT_UUID * getOrigDocUUID()const {return m_pOrigUUID;};
00232     void            setMyUUID(const char * u);
00233     std::string     getMyUUIDString()const;
00234     const UT_UUID * getMyUUID()const {return m_pMyUUID;};
00235 
00236     UT_UUIDPtr      getNewUUID()   const;
00237     UT_uint32       getNewUUID32() const;
00238     UT_uint64       getNewUUID64() const;
00239 
00240     bool            addRevision(UT_uint32 iId, UT_UCS4Char * pDesc,
00241                                 time_t tStart, UT_uint32 iVersion, bool bGenCR=true);
00242 
00243     bool            addRevision(UT_uint32 iId, const UT_UCS4Char * pDesc, UT_uint32 iLen,
00244                                 time_t tStart, UT_uint32 iVersion, bool bGenCR=true);
00245     bool            addRevision(AD_Revision * pRev, bool bGenCR=true);
00246     virtual bool    createAndSendDocPropCR( const gchar ** pAtts, const gchar ** pProps) = 0;
00247 
00248     const UT_GenericVector<AD_Revision*> &         getRevisions() {return m_vRevisions;}
00249     UT_uint32           getHighestRevisionId() const;
00250     const AD_Revision*  getHighestRevision() const;
00251     UT_sint32           getRevisionIndxFromId(UT_uint32 iId) const;
00252     bool                usingChangeTracking() const;
00253 
00254     bool                isMarkRevisions() const{ return m_bMarkRevisions;}
00255     bool                isShowRevisions() const{ return m_bShowRevisions;}
00256 
00257     UT_uint32           getShowRevisionId() const {return m_iShowRevisionID;}
00258     UT_uint32           getRevisionId() const{ return m_iRevisionID;}
00259 
00260     UT_uint32           findAutoRevisionId(UT_uint32 iVersion) const;
00261     UT_uint32           findNearestAutoRevisionId(UT_uint32 iVersion, bool bLesser = true) const;
00262 
00263     void                toggleMarkRevisions();
00264     void                toggleShowRevisions();
00265 
00266     virtual void        setMarkRevisions(bool bMark);
00267     void                setShowRevisions(bool bShow);
00268     void                setShowRevisionId(UT_uint32 iId);
00269     void                setRevisionId(UT_uint32 iId);
00270 
00271     bool                isAutoRevisioning()const {return m_bAutoRevisioning;}
00272     virtual void        setAutoRevisioning(bool autorev);
00273 
00274     virtual void        purgeRevisionTable(bool bUnconditional = false) = 0;
00275 
00276     virtual bool        acceptRejectRevision(bool bReject,
00277                                              UT_uint32 iStart,
00278                                              UT_uint32 iEnd,
00279                                              UT_uint32 iLevel) = 0;
00280 
00281     virtual bool        rejectAllHigherRevisions(UT_uint32 iLevel) = 0;
00282 
00283     virtual bool        acceptAllRevisions() = 0;
00284 
00285     bool                purgeAllRevisions(AV_View * pView);
00286     bool                isOrigUUID(void) const;
00287     void                setFilename(const char * name)
00288     { _setFilename(name); }
00289     virtual UT_uint32   getXID() const = 0;
00290     virtual UT_uint32   getTopXID() const = 0;
00291 
00292  protected:
00293     virtual UT_Error    _saveAs(const char * szFilename, int ieft, const char * props = NULL) = 0;
00294     virtual UT_Error    _saveAs(const char * szFilename, int ieft, bool cpy, const char * props = NULL) = 0;
00295     virtual UT_Error    _save(void) = 0;
00296 
00297     void            _purgeRevisionTable();
00298     void            _adjustHistoryOnSave();
00299     void            _setFilename(const char * name)
00300         { if (name) m_szFilename = name; else m_szFilename.clear(); }
00301     void            _setForceDirty(bool b) {m_bForcedDirty = b;}
00302     void            _setPieceTableChanging(bool b) {m_bPieceTableChanging = b;}
00303     void            _setMarkRevisions(bool bMark) {m_bMarkRevisions = bMark;}
00304 
00305     bool            _restoreVersion(XAP_Frame * pFrame, UT_uint32 iVersion);
00306 
00307     virtual void    _clearUndo() = 0;
00308 
00309 
00310     virtual ~AD_Document();     //  Use unref() instead.
00311 
00312 private:
00313     XAP_ResourceManager *   m_pResourceManager;
00314 
00315     int             m_iRefCount;
00316     std::string     m_szFilename;
00317     UT_String       m_szEncodingName;
00318 
00319     bool            m_bPieceTableChanging;
00320     time_t          m_lastSavedTime;
00321     time_t          m_lastOpenedTime;
00322     time_t          m_iEditTime;     // previous edit time (up till open)
00323     UT_uint32       m_iVersion;
00324 
00325     // these are for tracking versioning
00326     bool            m_bHistoryWasSaved;
00327     UT_Vector       m_vHistory;
00328     UT_GenericVector<AD_Revision*> m_vRevisions;
00329 
00330     bool            m_bMarkRevisions;
00331     bool            m_bShowRevisions;
00332     UT_uint32       m_iRevisionID;
00333     UT_uint32       m_iShowRevisionID;
00334     bool            m_bAutoRevisioning;
00335 
00336     bool            m_bForcedDirty;
00337 
00338     UT_UUID *       m_pUUID;
00339     UT_UUID *       m_pOrigUUID;
00340     UT_UUID *       m_pMyUUID;
00341     bool            m_bDoNotAdjustHistory;
00342     bool            m_bAfterFirstSave;
00343     std::string     m_sMyUUIDString;
00344     std::string     m_sOrigUUIDString;
00345     std::string     m_sPrintFilename;
00346 };
00347 
00348 
00349 #endif /* AD_DOCUMENT_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1