| 1 |
/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ |
| 2 |
|
| 3 |
/* AbiSource Application Framework |
| 4 |
* Copyright (C) 1998,1999 AbiSource, Inc. |
| 5 |
* Copyright (C) 2004 Tomas Frydrych <[email protected]> |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU General Public License |
| 9 |
* as published by the Free Software Foundation; either version 2 |
| 10 |
* of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 20 |
* 02110-1301 USA. |
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
#ifndef AD_DOCUMENT_H |
| 25 |
#define AD_DOCUMENT_H |
| 26 |
|
| 27 |
#include <string> |
| 28 |
|
| 29 |
#ifndef UT_TYPES_H |
| 30 |
#include "ut_types.h" |
| 31 |
#endif |
| 32 |
#include "ut_string_class.h" |
| 33 |
#include "ut_vector.h" |
| 34 |
#include "time.h" |
| 35 |
|
| 36 |
// fwd. decl. |
| 37 |
class XAP_ResourceManager; |
| 38 |
class UT_UUID; |
| 39 |
class XAP_Frame; |
| 40 |
class AV_View; |
| 41 |
|
| 42 |
// a helper class for history tracking |
| 43 |
class ABI_EXPORT AD_VersionData |
| 44 |
{ |
| 45 |
public: |
| 46 |
|
| 47 |
// constructor for importers |
| 48 |
AD_VersionData(UT_uint32 v, UT_UTF8String &uuid, time_t start, bool autorev, UT_uint32 xid); |
| 49 |
AD_VersionData(UT_uint32 v, const char * uuid, time_t start, bool autorev, UT_uint32 xid); |
| 50 |
|
| 51 |
// constructor for new entries |
| 52 |
AD_VersionData(UT_uint32 v, time_t start, bool autorev, UT_uint32 xid); |
| 53 |
|
| 54 |
// copy constructor |
| 55 |
AD_VersionData(const AD_VersionData & v); |
| 56 |
|
| 57 |
virtual ~AD_VersionData(); |
| 58 |
|
| 59 |
AD_VersionData & operator = (const AD_VersionData &v); |
| 60 |
|
| 61 |
bool operator == (const AD_VersionData &v); |
| 62 |
|
| 63 |
UT_uint32 getId()const{return m_iId;} |
| 64 |
time_t getTime()const; |
| 65 |
time_t getStartTime()const {return m_tStart;} |
| 66 |
const UT_UUID& getUID()const {return (const UT_UUID&)*m_pUUID;} |
| 67 |
bool newUID(); // true on success |
| 68 |
|
| 69 |
void setId(UT_uint32 iid) {m_iId = iid;} |
| 70 |
|
| 71 |
bool isAutoRevisioned()const {return m_bAutoRevision;} |
| 72 |
void setAutoRevisioned(bool autorev); |
| 73 |
|
| 74 |
UT_uint32 getTopXID() const {return m_iTopXID;} |
| 75 |
|
| 76 |
private: |
| 77 |
UT_uint32 m_iId; |
| 78 |
UT_UUID * m_pUUID; |
| 79 |
time_t m_tStart; |
| 80 |
bool m_bAutoRevision; |
| 81 |
UT_uint32 m_iTopXID; |
| 82 |
}; |
| 83 |
|
| 84 |
enum AD_HISTORY_STATE |
| 85 |
{ |
| 86 |
ADHIST_FULL_RESTORE, |
| 87 |
ADHIST_PARTIAL_RESTORE, |
| 88 |
ADHIST_NO_RESTORE |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
// a helper class for keeping track of revisions in the document |
| 93 |
class ABI_EXPORT AD_Revision |
| 94 |
{ |
| 95 |
public: |
| 96 |
AD_Revision(UT_uint32 iId, UT_UCS4Char * pDesc, time_t start, UT_uint32 iVer = 0) |
| 97 |
:m_iId(iId),m_pDescription(pDesc), m_tStart(start), m_iVersion(iVer){}; |
| 98 |
|
| 99 |
~AD_Revision(){delete [] m_pDescription;} |
| 100 |
|
| 101 |
UT_uint32 getId()const{return m_iId;} |
| 102 |
UT_UCS4Char * getDescription() const {return m_pDescription;} |
| 103 |
|
| 104 |
// NB: getStartTime() == 0 should be interpreted as 'unknown' |
| 105 |
time_t getStartTime() const {return m_tStart;} |
| 106 |
void setStartTime(time_t t) {m_tStart = t;} |
| 107 |
|
| 108 |
UT_uint32 getVersion()const {return m_iVersion;} |
| 109 |
void setVersion(UT_uint32 iVer) {m_iVersion = iVer;} |
| 110 |
|
| 111 |
private: |
| 112 |
UT_uint32 m_iId; |
| 113 |
UT_UCS4Char * m_pDescription; |
| 114 |
time_t m_tStart; |
| 115 |
UT_uint32 m_iVersion; |
| 116 |
}; |
| 117 |
|
| 118 |
enum AD_DOCUMENT_TYPE |
| 119 |
{ |
| 120 |
ADDOCUMENT_ABIWORD |
| 121 |
}; |
| 122 |
|
| 123 |
struct _dataItemPair; |
| 124 |
typedef _dataItemPair* PD_DataItemHandle; |
| 125 |
|
| 126 |
class ABI_EXPORT AD_Document |
| 127 |
{ |
| 128 |
public: |
| 129 |
AD_Document(); |
| 130 |
void ref(void); |
| 131 |
void unref(void); |
| 132 |
|
| 133 |
virtual AD_DOCUMENT_TYPE getType() const = 0; |
| 134 |
|
| 135 |
XAP_ResourceManager & resourceManager () const { return *m_pResourceManager; } |
| 136 |
|
| 137 |
const char * getFilename(void) const; |
| 138 |
const std::string & getPrintFilename(void) const; |
| 139 |
void setPrintFilename(const std::string & sFile); |
| 140 |
void clearFilename(void) {_setFilename(NULL); forceDirty();} |
| 141 |
// TODO - this should be returning IEFileType, |
| 142 |
// but that's AP stuff, so it's not here |
| 143 |
|
| 144 |
virtual UT_Error readFromFile(const char * szFilename, int ieft, const char * props = NULL) = 0; |
| 145 |
virtual UT_Error importFile(const char * szFilename, int ieft, bool markClean = false, bool bImportStylesFirst = true, const char * props = NULL) = 0; |
| 146 |
virtual UT_Error newDocument() = 0; |
| 147 |
virtual bool isDirty(void) const = 0; |
| 148 |
virtual void forceDirty() {m_bForcedDirty = true;}; |
| 149 |
bool isForcedDirty() const {return m_bForcedDirty;} |
| 150 |
|
| 151 |
virtual bool canDo(bool bUndo) const = 0; |
| 152 |
virtual bool undoCmd(UT_uint32 repeatCount) = 0; |
| 153 |
virtual bool redoCmd(UT_uint32 repeatCount) = 0; |
| 154 |
|
| 155 |
UT_Error saveAs(const char * szFilename, int ieft, const char * props = NULL); |
| 156 |
UT_Error saveAs(const char * szFilename, int ieft, bool cpy, const char * props = NULL); |
| 157 |
UT_Error save(void); |
| 158 |
virtual bool createDataItem(const char * szName, |
| 159 |
bool bBase64, |
| 160 |
const UT_ByteBuf * pByteBuf, |
| 161 |
const std::string & mime_type, |
| 162 |
PD_DataItemHandle* ppHandle) = 0; |
| 163 |
virtual bool replaceDataItem(const char * szName, |
| 164 |
const UT_ByteBuf * pByteBuf) = 0; |
| 165 |
virtual bool getDataItemDataByName(const char * szName, |
| 166 |
const UT_ByteBuf ** ppByteBuf, |
| 167 |
std::string * mime_type, |
| 168 |
PD_DataItemHandle* ppHandle) const = 0; |
| 169 |
public: |
| 170 |
|
| 171 |
/** |
| 172 |
* Returns the # of seconds since the last save of this file |
| 173 |
*/ |
| 174 |
time_t getTimeSinceSave () const { return (time(NULL) - m_lastSavedTime); } |
| 175 |
time_t getLastSavedTime() const {return m_lastSavedTime;} |
| 176 |
void setLastSavedTime(time_t t) {m_lastSavedTime = t;} |
| 177 |
virtual UT_uint32 getLastSavedAsType() const = 0; |
| 178 |
|
| 179 |
time_t getTimeSinceOpen () const { return (time(NULL) - m_lastOpenedTime); } |
| 180 |
time_t getLastOpenedTime() const {return m_lastOpenedTime;} |
| 181 |
void setLastOpenedTime(time_t t) {m_lastOpenedTime = t;} |
| 182 |
|
| 183 |
time_t getEditTime()const {return (m_iEditTime + (time(NULL) - m_lastOpenedTime));} |
| 184 |
void setEditTime(UT_uint32 t) {m_iEditTime = t;} |
| 185 |
|
| 186 |
void setDocVersion(UT_uint32 i){m_iVersion = i;} |
| 187 |
UT_uint32 getDocVersion() const {return m_iVersion;} |
| 188 |
|
| 189 |
void setEncodingName(const char * szEncodingName); |
| 190 |
const char * getEncodingName() const; |
| 191 |
|
| 192 |
bool isPieceTableChanging(void) const; |
| 193 |
|
| 194 |
virtual void setMetaDataProp (const std::string & key, const std::string & value) = 0; |
| 195 |
virtual bool getMetaDataProp (const std::string & key, std::string & outProp) const = 0; |
| 196 |
|
| 197 |
// RIVERA TODO not working and may not be needed |
| 198 |
virtual void setAnnotationProp (const std::string & key, const std::string & value) = 0; |
| 199 |
virtual bool getAnnotationProp (const std::string & key, std::string & outProp) const = 0; |
| 200 |
|
| 201 |
// history tracking |
| 202 |
void addRecordToHistory(const AD_VersionData & v); |
| 203 |
void purgeHistory(); |
| 204 |
UT_sint32 getHistoryCount()const {return m_vHistory.getItemCount();} |
| 205 |
UT_uint32 getHistoryNthId(UT_sint32 i)const; |
| 206 |
time_t getHistoryNthTime(UT_sint32 i)const; |
| 207 |
time_t getHistoryNthTimeStarted(UT_sint32 i)const; |
| 208 |
time_t getHistoryNthEditTime(UT_sint32 i)const; |
| 209 |
const UT_UUID& getHistoryNthUID(UT_sint32 i)const; |
| 210 |
bool getHistoryNthAutoRevisioned(UT_sint32 i)const; |
| 211 |
UT_uint32 getHistoryNthTopXID(UT_sint32 i)const; |
| 212 |
|
| 213 |
AD_HISTORY_STATE verifyHistoryState(UT_uint32 &iVersion) const; |
| 214 |
const AD_VersionData * findHistoryRecord(UT_uint32 iVersion) const; |
| 215 |
bool showHistory(AV_View * pView); |
| 216 |
|
| 217 |
bool areDocumentsRelated (const AD_Document &d) const; |
| 218 |
bool areDocumentHistoriesEqual(const AD_Document &d, UT_uint32 &iVer) const; |
| 219 |
|
| 220 |
virtual bool areDocumentContentsEqual(const AD_Document &d, UT_uint32 &pos) const = 0; |
| 221 |
virtual bool areDocumentFormatsEqual(const AD_Document &d, UT_uint32 &pos) const = 0; |
| 222 |
virtual bool areDocumentStylesheetsEqual(const AD_Document &d) const = 0; |
| 223 |
|
| 224 |
void setDocUUID(const char * u); |
| 225 |
const char * getDocUUIDString()const; |
| 226 |
const UT_UUID * getDocUUID()const {return m_pUUID;}; |
| 227 |
void setOrigUUID(const char * u); |
| 228 |
const char * getOrigDocUUIDString()const; |
| 229 |
const UT_UUID * getOrigDocUUID()const {return m_pOrigUUID;}; |
| 230 |
void setMyUUID(const char * u); |
| 231 |
UT_UTF8String getMyUUIDString()const; |
| 232 |
const UT_UUID * getMyUUID()const {return m_pMyUUID;}; |
| 233 |
|
| 234 |
UT_UUID * getNewUUID() const; |
| 235 |
UT_uint32 getNewUUID32() const; |
| 236 |
UT_uint64 getNewUUID64() const; |
| 237 |
|
| 238 |
bool addRevision(UT_uint32 iId, const UT_UCS4Char * pDesc, UT_uint32 iLen, |
| 239 |
time_t tStart, UT_uint32 iVersion, bool bGenCR=true); |
| 240 |
bool addRevision(AD_Revision * pRev, bool bGenCR=true); |
| 241 |
virtual bool createAndSendDocPropCR( const gchar ** pAtts, const gchar ** pProps) = 0; |
| 242 |
|
| 243 |
const UT_GenericVector<AD_Revision*> & getRevisions() {return m_vRevisions;} |
| 244 |
UT_uint32 getHighestRevisionId() const; |
| 245 |
const AD_Revision* getHighestRevision() const; |
| 246 |
UT_sint32 getRevisionIndxFromId(UT_uint32 iId) const; |
| 247 |
bool usingChangeTracking() const; |
| 248 |
|
| 249 |
bool isMarkRevisions() const{ return m_bMarkRevisions;} |
| 250 |
bool isShowRevisions() const{ return m_bShowRevisions;} |
| 251 |
|
| 252 |
UT_uint32 getShowRevisionId() const {return m_iShowRevisionID;} |
| 253 |
UT_uint32 getRevisionId() const{ return m_iRevisionID;} |
| 254 |
|
| 255 |
UT_uint32 findAutoRevisionId(UT_uint32 iVersion) const; |
| 256 |
UT_uint32 findNearestAutoRevisionId(UT_uint32 iVersion, bool bLesser = true) const; |
| 257 |
|
| 258 |
void toggleMarkRevisions(); |
| 259 |
void toggleShowRevisions(); |
| 260 |
|
| 261 |
virtual void setMarkRevisions(bool bMark); |
| 262 |
void setShowRevisions(bool bShow); |
| 263 |
void setShowRevisionId(UT_uint32 iId); |
| 264 |
void setRevisionId(UT_uint32 iId); |
| 265 |
|
| 266 |
bool isAutoRevisioning()const {return m_bAutoRevisioning;} |
| 267 |
virtual void setAutoRevisioning(bool autorev); |
| 268 |
|
| 269 |
virtual void purgeRevisionTable(bool bUnconditional = false) = 0; |
| 270 |
|
| 271 |
virtual bool acceptRejectRevision(bool bReject, |
| 272 |
UT_uint32 iStart, |
| 273 |
UT_uint32 iEnd, |
| 274 |
UT_uint32 iLevel) = 0; |
| 275 |
|
| 276 |
virtual bool rejectAllHigherRevisions(UT_uint32 iLevel) = 0; |
| 277 |
|
| 278 |
virtual bool acceptAllRevisions() = 0; |
| 279 |
|
| 280 |
bool purgeAllRevisions(AV_View * pView); |
| 281 |
bool isOrigUUID(void) const; |
| 282 |
void setFilename(char * name) |
| 283 |
{_setFilename(name);} |
| 284 |
virtual UT_uint32 getXID() const = 0; |
| 285 |
virtual UT_uint32 getTopXID() const = 0; |
| 286 |
|
| 287 |
protected: |
| 288 |
virtual UT_Error _saveAs(const char * szFilename, int ieft, const char * props = NULL) = 0; |
| 289 |
virtual UT_Error _saveAs(const char * szFilename, int ieft, bool cpy, const char * props = NULL) = 0; |
| 290 |
virtual UT_Error _save(void) = 0; |
| 291 |
|
| 292 |
void _purgeRevisionTable(); |
| 293 |
void _adjustHistoryOnSave(); |
| 294 |
void _setFilename(char * name) {FREEP(m_szFilename); m_szFilename = name;} |
| 295 |
void _setForceDirty(bool b) {m_bForcedDirty = b;} |
| 296 |
void _setPieceTableChanging(bool b) {m_bPieceTableChanging = b;} |
| 297 |
void _setMarkRevisions(bool bMark) {m_bMarkRevisions = bMark;} |
| 298 |
|
| 299 |
bool _restoreVersion(XAP_Frame * pFrame, UT_uint32 iVersion); |
| 300 |
|
| 301 |
virtual void _clearUndo() = 0; |
| 302 |
|
| 303 |
|
| 304 |
virtual ~AD_Document(); // Use unref() instead. |
| 305 |
|
| 306 |
private: |
| 307 |
XAP_ResourceManager * m_pResourceManager; |
| 308 |
|
| 309 |
int m_iRefCount; |
| 310 |
const char * m_szFilename; |
| 311 |
UT_String m_szEncodingName; |
| 312 |
|
| 313 |
bool m_bPieceTableChanging; |
| 314 |
time_t m_lastSavedTime; |
| 315 |
time_t m_lastOpenedTime; |
| 316 |
time_t m_iEditTime; // previous edit time (up till open) |
| 317 |
UT_uint32 m_iVersion; |
| 318 |
|
| 319 |
// these are for tracking versioning |
| 320 |
bool m_bHistoryWasSaved; |
| 321 |
UT_Vector m_vHistory; |
| 322 |
UT_GenericVector<AD_Revision*> m_vRevisions; |
| 323 |
|
| 324 |
bool m_bMarkRevisions; |
| 325 |
bool m_bShowRevisions; |
| 326 |
UT_uint32 m_iRevisionID; |
| 327 |
UT_uint32 m_iShowRevisionID; |
| 328 |
bool m_bAutoRevisioning; |
| 329 |
|
| 330 |
bool m_bForcedDirty; |
| 331 |
|
| 332 |
UT_UUID * m_pUUID; |
| 333 |
UT_UUID * m_pOrigUUID; |
| 334 |
UT_UUID * m_pMyUUID; |
| 335 |
bool m_bDoNotAdjustHistory; |
| 336 |
bool m_bAfterFirstSave; |
| 337 |
UT_UTF8String m_sMyUUIDString; |
| 338 |
UT_UTF8String m_sOrigUUIDString; |
| 339 |
std::string m_sPrintFilename; |
| 340 |
}; |
| 341 |
|
| 342 |
|
| 343 |
#endif /* AD_DOCUMENT_H */ |