6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
35 // Dedicated to BModel
40 #include <AppFileInfo.h>
43 #include <StorageDefs.h>
46 #include "IconCache.h"
47 #include "ObjectList.h"
56 #if __GNUC__ && __GNUC__ < 3
57 // using std::stat instead of just stat here because of what
58 // seems to be a gcc bug involving namespace and struct stat interaction
59 typedef struct std::stat StatStruct
;
61 // on mwcc std isn't turned on but there is no bug either.
62 // Also seems to be fixed in gcc 3.
63 typedef struct stat StatStruct
;
72 kModelSupportsSupertype
,
81 Model(const Model
& other
);
82 Model(const BEntry
* entry
, bool open
= false, bool writable
= false);
83 Model(const entry_ref
*, bool traverse
= false, bool open
= false,
84 bool writable
= false);
85 Model(const node_ref
* dirNode
, const node_ref
* node
, const char* name
,
86 bool open
= false, bool writable
= false);
89 Model
& operator=(const Model
&);
91 status_t
InitCheck() const;
93 status_t
SetTo(const BEntry
*, bool open
= false,
94 bool writable
= false);
95 status_t
SetTo(const entry_ref
*, bool traverse
= false,
96 bool open
= false, bool writable
= false);
97 status_t
SetTo(const node_ref
* dirNode
, const node_ref
* node
,
98 const char* name
, bool open
= false, bool writable
= false);
100 int CompareFolderNamesFirst(const Model
* compareModel
) const;
103 status_t
OpenNode(bool writable
= false);
104 // also used to switch from read-only to writable
106 bool IsNodeOpen() const;
107 bool IsNodeOpenForWriting() const;
109 status_t
UpdateStatAndOpenNode(bool writable
= false);
110 // like OpenNode, called on zombie poses to check if they turned
111 // real, starts by rereading the stat structure
114 const char* Name() const;
115 const entry_ref
* EntryRef() const;
116 const node_ref
* NodeRef() const;
117 const StatStruct
* StatBuf() const;
120 // returns NULL if not open
121 void GetPath(BPath
*) const;
122 void GetEntry(BEntry
*) const;
124 const char* MimeType() const;
125 const char* PreferredAppSignature() const;
126 // only not-null if not default for type and not self for app
127 void SetPreferredAppSignature(const char*);
129 void GetPreferredAppForBrokenSymLink(BString
&result
);
130 // special purpose call - if a symlink is unresolvable, it makes
131 // sense to be able to get at it's preferred handler which may be
132 // different from the Tracker. Used by the network neighborhood.
136 bool IsDirectory() const;
137 bool IsQuery() const;
138 bool IsQueryTemplate() const;
139 bool IsContainer() const;
140 bool IsExecutable() const;
141 bool IsSymLink() const;
143 bool IsTrash() const;
144 bool IsDesktop() const;
145 bool IsVolume() const;
146 bool IsVirtualDirectory() const;
148 IconSource
IconFrom() const;
149 void SetIconFrom(IconSource
);
150 // where is this model getting it's icon from
152 void ResetIconFrom();
153 // called from the attribute changed calls to force a lookup of
156 // symlink handling calls, mainly used by the IconCache
157 const Model
* ResolveIfLink() const;
158 Model
* ResolveIfLink();
160 Model
* LinkTo() const;
161 // fast, works only on symlinks
162 void SetLinkTo(Model
*);
164 status_t
GetLongVersionString(BString
&, version_kind
);
165 status_t
GetVersionString(BString
&, version_kind
);
166 status_t
AttrAsString(BString
&, int64
* value
,
167 const char* attributeName
, uint32 attributeType
);
169 // Node monitor update call
170 void UpdateEntryRef(const node_ref
* dirRef
, const char* name
);
171 bool AttrChanged(const char* attrName
);
172 // returns true if pose needs to update it's icon, etc.
173 // pass null to force full update
175 // returns true if pose needs to update it's icon
177 status_t
WatchVolumeAndMountPoint(uint32
, BHandler
*);
178 // correctly handles boot volume name watching
180 bool IsDropTarget(const Model
* forDocument
= 0,
181 bool traverse
= false) const;
182 // if nonzero <forDocument> passed, mime info is used to
183 // resolve if document can be opened
184 // if zero, all executables, directories and volumes pass
185 // if traverse, dereference symlinks
186 bool IsDropTargetForList(const BObjectList
<BString
>* list
) const;
187 // <list> contains mime types of all documents about to be handled
191 void PrintToStream(int32 level
= 1, bool deep
= false);
192 void TrackIconSource(icon_size
);
195 bool IsSuperHandler() const;
196 int32
SupportsMimeType(const char* type
,
197 const BObjectList
<BString
>* list
, bool exactReason
= false) const;
198 // pass in one string in <type> or a bunch in <list>
199 // if <exactReason> false, returns as soon as it figures out that
200 // app supports a given type, if true, returns an exact reason
203 ssize_t
WriteAttr(const char* attr
, type_code type
, off_t
,
204 const void* buffer
, size_t );
205 // cover call, creates a writable node and writes out attributes
206 // into it; work around for file nodes not being writeable
207 ssize_t
WriteAttrKillForeign(const char* attr
,
208 const char* foreignAttr
, type_code type
, off_t
,
209 const void* buffer
, size_t);
211 bool Mimeset(bool force
);
212 // returns true if mime type changed
214 bool HasLocalizedName() const;
217 status_t
OpenNodeCommon(bool writable
);
218 void SetupBaseType();
219 void FinishSettingUpType();
220 void DeletePreferredAppVolumeNameLinkTo();
221 void CacheLocalizedName();
223 status_t
FetchOneQuery(const BQuery
*, BHandler
* target
,
224 BObjectList
<BQuery
>*, BVolume
*);
226 enum CanHandleResult
{
232 CanHandleResult
CanHandleDrops() const;
245 kVirtualDirectoryNode
,
252 // should use string that may be shared for common types
254 // bit of overloading hackery here to save on footprint
256 char* fPreferredAppName
; // used if we are neither a volume
258 char* fVolumeName
; // used if we are a volume
259 Model
* fLinkTo
; // used if we are a symlink
267 BString fLocalizedName
;
268 bool fHasLocalizedName
;
269 bool fLocalizedNameIsCached
;
273 class ModelNodeLazyOpener
{
274 // a utility open state manager, usefull to allocate on stack
275 // and have close up model when done, etc.
277 // consider failing when open does not succeed
279 ModelNodeLazyOpener(Model
* model
, bool writable
= false,
280 bool openLater
= true);
281 ~ModelNodeLazyOpener();
284 bool IsOpenForWriting() const;
285 bool IsOpen(bool forWriting
) const;
286 Model
* TargetModel() const;
287 status_t
OpenNode(bool writable
= false);
292 bool fWasOpenForWriting
;
295 // handy flavors of openers
296 class BModelOpener
: public ModelNodeLazyOpener
{
298 BModelOpener(Model
* model
)
299 : ModelNodeLazyOpener(model
, false, false)
304 class BModelWriteOpener
: public ModelNodeLazyOpener
{
306 BModelWriteOpener(Model
* model
)
307 : ModelNodeLazyOpener(model
, true, false)
314 // #define CHECK_OPEN_MODEL_LEAKS
317 #ifdef CHECK_OPEN_MODEL_LEAKS
318 void DumpOpenModels(bool extensive
);
319 void InitOpenModelDumping();
322 // inlines follow -----------------------------------
325 Model::MimeType() const
327 return fMimeType
.String();
331 inline const entry_ref
*
332 Model::EntryRef() const
338 inline const node_ref
*
339 Model::NodeRef() const
341 // the stat structure begins with a node_ref
342 return (node_ref
*)&fStatBuf
;
353 inline const StatStruct
*
354 Model::StatBuf() const
361 Model::IconFrom() const
363 return (IconSource
)fIconFrom
;
368 Model::SetIconFrom(IconSource from
)
375 Model::LinkTo() const
383 Model::IsFile() const
385 return fBaseType
== kPlainNode
386 || fBaseType
== kQueryNode
387 || fBaseType
== kQueryTemplateNode
388 || fBaseType
== kExecutableNode
389 || fBaseType
== kVirtualDirectoryNode
;
394 Model::IsVolume() const
396 return fBaseType
== kVolumeNode
;
401 Model::IsDirectory() const
403 return fBaseType
== kDirectoryNode
404 || fBaseType
== kVolumeNode
405 || fBaseType
== kRootNode
406 || fBaseType
== kTrashNode
407 || fBaseType
== kDesktopNode
;
412 Model::IsQuery() const
414 return fBaseType
== kQueryNode
;
419 Model::IsQueryTemplate() const
421 return fBaseType
== kQueryTemplateNode
;
426 Model::IsContainer() const
428 // I guess as in should show container window -
429 // volumes show the volume window
430 return IsQuery() || IsDirectory() || IsVirtualDirectory();
435 Model::IsRoot() const
437 return fBaseType
== kRootNode
;
442 Model::IsTrash() const
444 return fBaseType
== kTrashNode
;
449 Model::IsDesktop() const
451 return fBaseType
== kDesktopNode
;
456 Model::IsExecutable() const
458 return fBaseType
== kExecutableNode
;
463 Model::IsSymLink() const
465 return fBaseType
== kLinkNode
;
470 Model::IsVirtualDirectory() const
472 return fBaseType
== kVirtualDirectoryNode
;
477 Model::HasLocalizedName() const
479 return fHasLocalizedName
;
484 ModelNodeLazyOpener::ModelNodeLazyOpener(Model
* model
, bool writable
,
488 fWasOpen(model
->IsNodeOpen()),
489 fWasOpenForWriting(model
->IsNodeOpenForWriting())
497 ModelNodeLazyOpener::~ModelNodeLazyOpener()
499 if (!fModel
->IsNodeOpen())
503 else if (!fWasOpenForWriting
)
509 ModelNodeLazyOpener::IsOpen() const
511 return fModel
->IsNodeOpen();
516 ModelNodeLazyOpener::IsOpenForWriting() const
518 return fModel
->IsNodeOpenForWriting();
523 ModelNodeLazyOpener::IsOpen(bool forWriting
) const
525 return forWriting
? fModel
->IsNodeOpenForWriting() : fModel
->IsNodeOpen();
530 ModelNodeLazyOpener::TargetModel() const
537 ModelNodeLazyOpener::OpenNode(bool writable
)
540 if (!fModel
->IsNodeOpenForWriting())
541 return fModel
->OpenNode(true);
542 } else if (!fModel
->IsNodeOpen())
543 return fModel
->OpenNode();
548 } // namespace BPrivate
551 #endif // _NU_MODEL_H