2 * Copyright 2004-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
12 #include <ObjectList.h>
23 class DataEditor
: public BLocker
{
26 DataEditor(entry_ref
&ref
, const char *attribute
= NULL
);
27 DataEditor(BEntry
&entry
, const char *attribute
= NULL
);
28 DataEditor(const DataEditor
&editor
);
31 status_t
SetTo(const char *path
, const char *attribute
= NULL
);
32 status_t
SetTo(entry_ref
&ref
, const char *attribute
= NULL
);
33 status_t
SetTo(BEntry
&entry
, const char *attribute
= NULL
);
37 bool IsReadOnly() const { return fIsReadOnly
; }
38 bool IsDevice() const { return fIsDevice
; }
39 bool IsAttribute() const { return fAttribute
!= NULL
; }
40 bool IsModified() const { return fLastChange
!= fFirstChange
; }
42 const char *Attribute() const { return fAttribute
; }
43 type_code
Type() const { return fType
; }
47 status_t
Replace(off_t offset
, const uint8
*data
, size_t length
);
48 status_t
Remove(off_t offset
, off_t length
);
49 status_t
Insert(off_t offset
, const uint8
*data
, size_t length
);
51 status_t
MoveBy(int32 bytes
);
52 status_t
MoveTo(off_t offset
);
60 status_t
SetFileSize(off_t size
);
61 off_t
FileSize() const { return fSize
; }
63 status_t
SetViewOffset(off_t offset
);
64 off_t
ViewOffset() const { return fViewOffset
; }
66 status_t
SetViewSize(size_t size
);
67 size_t ViewSize() const { return fViewSize
; }
69 status_t
SetBlockSize(size_t size
);
70 size_t BlockSize() const { return fBlockSize
; }
72 status_t
UpdateIfNeeded(bool *_updated
= NULL
);
73 status_t
ForceUpdate();
74 status_t
GetViewBuffer(const uint8
**_buffer
);
76 status_t
StartWatching(BMessenger target
);
77 status_t
StartWatching(BHandler
*handler
, BLooper
*looper
= NULL
);
78 void StopWatching(BMessenger target
);
79 void StopWatching(BHandler
*handler
, BLooper
*looper
= NULL
);
81 off_t
Find(off_t startPosition
, const uint8
*data
, size_t dataSize
,
82 bool caseInsensitive
, bool cyclic
,
83 BMessenger progressMessenger
, volatile bool *stop
= NULL
);
85 BFile
&File() { return fFile
; }
86 const entry_ref
&AttributeRef() const { return fAttributeRef
; }
87 const entry_ref
&Ref() const { return fRef
; }
90 friend class StateWatcher
;
92 status_t
SetViewOffset(off_t offset
, bool sendNotices
);
93 status_t
SetViewSize(size_t size
, bool sendNotices
);
94 void SendNotices(uint32 what
, BMessage
*message
= NULL
);
95 void SendNotices(DataChange
*change
);
97 void AddChange(DataChange
*change
);
101 BObjectList
<BMessenger
> fObservers
;
103 entry_ref fRef
, fAttributeRef
;
105 const char *fAttribute
;
107 bool fIsDevice
, fIsReadOnly
;
108 off_t fRealSize
, fSize
;
110 BObjectList
<DataChange
> fChanges
;
111 DataChange
*fFirstChange
;
112 DataChange
*fLastChange
;
113 int32 fChangesFromSaved
;
116 off_t fRealViewOffset
, fViewOffset
;
117 size_t fRealViewSize
, fViewSize
;
123 static const uint32 kMsgDataEditorStateChange
= 'deSC';
124 static const uint32 kMsgDataEditorUpdate
= 'deUp';
125 static const uint32 kMsgDataEditorParameterChange
= 'dePC';
127 static const uint32 kMsgDataEditorFindProgress
= 'deFP';
129 #endif /* DATA_EDITOR_H */