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

Generated on Mon May 28 2012 for AbiWord by  doxygen 1.7.1