2 * Copyright 2013-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
7 * John Scipione, jscipione@gmail.com
8 * Ingo Weinhold, bonefish@users.sf.net
11 * headers/os/storage/NodeInfo.h hrev47402
12 * src/kits/storage/NodeInfo.cpp hrev47402
20 \brief Provides the BNodeInfo class.
28 \brief Provides access to file type meta data on a node.
30 BNodeInfo provides a nice wrapper to all sorts of useful meta data such as
31 the MIME-type, the file's icon and the application that will open
39 \fn BNodeInfo::BNodeInfo()
40 \brief Creates an uninitialized BNodeInfo object.
42 After created a BNodeInfo with this, you should call SetTo().
44 \see SetTo(BNode* node)
51 \fn BNodeInfo::BNodeInfo(BNode* node)
52 \brief Creates a BNodeInfo object and initializes it to the supplied
55 \param node The \a node to initialize to and gather information.
62 \fn BNodeInfo::~BNodeInfo()
63 \brief Frees the object and associated resources.
65 The internal BNode object is not deleted.
72 \name Constructor helper methods
80 \fn status_t BNodeInfo::SetTo(BNode* node)
81 \brief Initializes the BNodeInfo to the supplied \a node.
83 The BNodeInfo object does not copy the supplied \a node object, it uses it
84 directly instead. You must not delete the supply \a node while the
85 BNodeInfo object exists. The BNodeInfo does not take over ownership of the
86 \a node and it doesn't delete it on destruction either.
88 \param node The \a node to gather information on.
90 \returns A status code.
91 \retval B_OK Everything went fine.
92 \retval B_BAD_VALUE The node was not properly initialized.
99 \fn status_t BNodeInfo::InitCheck() const
100 \brief Checks whether or not the object has been properly initialized.
102 \returns A status code.
103 \retval B_OK The object was properly initialized.
104 \retval B_BAD_VALUE The object was \b not properly initialized.
114 \name MIME-type methods
122 \fn status_t BNodeInfo::GetType(char* type) const
123 \brief Writes the MIME-type of the node into \a type.
125 The source of the type information is the \c BEOS:TYPE attribute of the
126 node. The \a type buffer should be pre-allocated before it is passed into
127 GetType(), it should be at least \c B_MIME_TYPE_LENGTH in length.
129 \param type A pointer to a pre-allocated char buffer of at least
130 \c B_MIME_TYPE_LENGTH length into which the MIME-type of the
133 \returns A status code.
134 \retval B_OK Everything went fine.
135 \retval B_NO_INIT The object is not properly initialized.
136 \retval B_BAD_VALUE \c NULL \a type or the type string stored in the
137 attribute is longer than \c B_MIME_TYPE_LENGTH.
138 \retval B_BAD_TYPE The stored type string attribute has the wrong type.
139 \retval B_ENTRY_NOT_FOUND No type is set on the node.
146 \fn status_t BNodeInfo::SetType(const char* type)
147 \brief Sets the MIME-type of the node. If \a type is \c NULL the
148 \c BEOS:TYPE attribute is removed instead.
150 The \a type string is written into the \c BEOS:TYPE attribute of the node.
151 If \a type is \c NULL, the \c BEOS:TYPE attribute is removed instead. The
152 \a type parameter may not by longer than \c B_MIME_TYPE_LENGTH in length
153 including the terminating \0 character.
155 \param type The MIME-type to be assigned to the \a node. Must not be
156 longer than \c B_MIME_TYPE_LENGTH (including the terminating
157 \c NUL). May be \c NULL to remove the attribute.
159 \returns A status code.
160 \retval B_OK Everything went fine.
161 \retval B_NO_INIT The object was not properly initialized.
162 \retval B_BAD_VALUE \a type is longer than \c B_MIME_TYPE_LENGTH.
180 \fn status_t BNodeInfo::GetIcon(BBitmap* icon, icon_size which) const
181 \brief Gets the icon of the node.
183 The icon stored in the \c BEOS:L:STD_ICON attribute (large) or
184 \c BEOS:M:STD_ICON attribute (mini) is retrieved.
186 \param icon A pointer to a pre-allocated BBitmap object of the correct
187 dimension to store the requested icon: 16x16 for the mini or
188 32x32 for the large icon.
189 \param which The size of the icon to be retrieved: \c B_MINI_ICON for a 16x16
190 icon and \c B_LARGE_ICON for a 32x32 icon.
192 \returns A status code.
193 \retval B_OK Everything went fine.
194 \retval B_NO_INIT The object was not properly initialized.
195 \retval B_BAD_VALUE \c NULL \a icon, unsupported icon size \a k or bitmap
196 dimensions (\a icon) and icon size (\a k) do not match.
203 \fn status_t BNodeInfo::SetIcon(const BBitmap* icon, icon_size which)
204 \brief Sets the icon of the node. If \a icon is \c NULL, the attribute is
207 The icon is stored in the \c BEOS:L:STD_ICON attribute (large) or
208 \c BEOS:M:STD_ICON attribute (mini). If \a icon is \c NULL the respective
209 attribute is removed instead.
211 \param icon A pointer to a BBitmap object containing the icon to be set.
213 \param which The size of the icon to be set: \c B_MINI_ICON for the mini or
214 \c B_LARGE_ICON for the large icon.
216 \returns A status code.
217 \retval B_OK Everything went fine.
218 \retval B_NO_INIT The object is not properly initialized.
219 \retval B_BAD_VALUE Unknown icon size \a k or bitmap dimensions (\a icon)
220 and icon size (\a k) do not match.
227 \fn status_t BNodeInfo::GetIcon(uint8** data, size_t* size,
228 type_code* type) const
229 \brief Gets the icon of the node.
231 The icon stored in the \c BEOS:ICON attribute of the node is retrieved.
232 The caller is responsible to <tt>delete[]</tt> the data if the icon was
235 \param data A pointer in which a pointer to the icon data
237 \param size A pointer in which the size of the found icon data
239 \param type A pointer in which the type of the found icon data
242 \returns A status code.
243 \retval B_OK Everything went fine.
244 \retval B_NO_INIT The object was not properly initialized.
245 \retval B_BAD_VALUE \c NULL \a data, \c NULL \a size or \c NULL \a type.
246 \retval B_NO_MEMORY No memory to allocate the \a data buffer.
253 \fn status_t BNodeInfo::SetIcon(const uint8* data, size_t size)
254 \brief Sets the node icon of the node. If \a data is \c NULL or \a size
255 is 0, the \c BEOS:ICON attribute is removed instead.
257 The icon is stored in the \c BEOS:ICON attribute of the node.
259 \param data A pointer to valid icon data. May be \c NULL.
260 \param size The size of the provided data buffer. May be 0.
262 \returns A status code.
263 \retval B_OK Everything went fine.
264 \retval B_NO_INIT The object was not properly initialized.
271 \fn status_t BNodeInfo::GetTrackerIcon(BBitmap* icon,
272 icon_size which) const
273 \brief Gets the icon displayed by Tracker for the icon.
275 This method tries really hard to find an icon for the node:
276 - If the node has no type this method returns the icon for
277 \c B_FILE_MIME_TYPE if it's a regular file or
278 \c B_DIRECTORY_MIME_TYPE if it's a directory, even if the node has its
280 - Next it will ask GetIcon() for an icon.
281 - If this fails it will get the preferred application and ask the MIME
282 database if the application has an icon for the file type of the
284 - Next it will ask the MIME database whether there is an icon for the file
286 - Then it will ask the MIME database for the preferred application for
287 the file type of the node and whether this application has a special
289 - Finally it will return a generic icon for whatever type of file type
290 (file/dir/etc.) the node is from the MIME database.
292 The first action that provides an icon is used. In the case that none of
293 them yield an icon this method fails, this is very unlikely though.
295 \remarks You can set \a which to get a scaled icon instead of using
296 a predefined icon_size constant, pass in an integer casted
297 to icon_size. For example to get a 64x64 icon pass in:
302 \param icon A pointer to a pre-allocated BBitmap of the correct dimension
303 to store the requested icon (16x16 for the mini and 32x32 for the
305 \param which The size of the icon to be retrieved: \c B_MINI_ICON
306 for a 16x16 icon or \c B_LARGE_ICON for a 32x32 icon.
308 \returns A status code.
309 \retval B_OK Everything went fine.
310 \retval B_NO_INIT The object was not properly initialized.
311 \retval B_BAD_VALUE \c NULL \a icon, unsupported icon size \a which
312 or bitmap dimensions (\a icon) and icon size (\a which) do
320 \fn status_t BNodeInfo::GetTrackerIcon(const entry_ref* ref,
321 BBitmap* icon, icon_size which)
322 \brief Gets the icon displayed by Tracker for the node referred to by
325 This methods works similarly to the non-static version but \a ref
326 identifies the node. \a icon must be pre-allocated to the size requested
327 using \a which before being passed to this method.
329 \param ref An entry_ref referring to the node for which the icon is
331 \param icon A pointer to a pre-allocated BBitmap object of the correct
332 dimension to store the requested icon (16x16 for the mini and 32x32
334 \param which The size of the icon to be retrieved: \c B_MINI_ICON
335 for a 16x16 icon or \c B_LARGE_ICON for a 32x32 icon.
337 \returns A status code.
338 \retval B_OK: Everything went fine.
339 \retval B_NO_INIT: The object is not properly initialized.
340 \retval B_BAD_VALUE: \c NULL ref or \a icon, unsupported icon size
341 \a which or bitmap dimensions (\a icon) and icon size
342 (\a which) do not match.
352 \name Preferred Application
360 \fn status_t BNodeInfo::GetPreferredApp(char* signature,
362 \brief Gets the preferred application of the node.
364 Writes the contents of the \c BEOS:PREF_APP attribute into the
365 \a signature buffer. The preferred application can be identified by its
366 signature. \a signature should be at least \c B_MIME_TYPE_LENGTH or
367 longer and pre-allocated before it is passed into this method.
369 \param signature A pointer to a pre-allocated character buffer of size
370 \c B_MIME_TYPE_LENGTH or larger into which the MIME-type of the
371 preferred application is written.
372 \param verb The type of access the preferred application is requested.
373 Currently \c B_OPEN is the only meaningful option.
375 \returns A status code.
376 \retval B_OK Everything went fine.
377 \retval B_NO_INIT The object was not properly initialized.
378 \retval B_BAD_VALUE \c NULL \a signature or bad app_verb.
383 \fn status_t BNodeInfo::SetPreferredApp(const char* signature,
385 \brief Sets the preferred application of the node. If \a signature is
386 \c NULL, the \c BEOS:PREF_APP attribute is removed instead.
388 The supplied string is written into the \c BEOS:PREF_APP attribute of the
389 node. If \a signature is \c NULL, the respective attribute is removed
390 instead. \a signature must not be longer than \c B_MIME_TYPE_LENGTH
391 (including the terminating \c NUL).
393 \param signature The signature of the preferred application to be set.
395 \param verb The type of access set to the preferred application.
396 Currently only \c B_OPEN is meaningful.
398 \returns A status code.
399 \retval B_OK Everything went fine.
400 \retval B_NO_INIT The object is not properly initialized.
401 \retval B_BAD_VALUE \c NULL \a signature, \a signature is longer than
402 \c B_MIME_TYPE_LENGTH or bad app_verb.
410 \name Application Hint
418 \fn status_t BNodeInfo::GetAppHint(entry_ref* ref) const
419 \brief Fills out \a ref with a pointer to a hint about the application
420 that will open this node.
422 The path contained in the \c BEOS:PPATH attribute of the node is converted
423 into an entry_ref and returned. \a ref should be pre-allocated before being
424 passed into this method.
426 \param ref A pointer to a pre-allocated entry_ref into which the app hint
429 \returns A status code.
430 \retval B_OK Everything went fine.
431 \retval B_BAD_DATA Attribute size greater than \c B_PATH_NAME_LENGTH.
432 \retval B_BAD_TYPE The stored type string attribute has the wrong type.
433 \retval B_BAD_VALUE The \a ref object passed in was \c NULL.
434 \retval B_ERROR Unable to read \c BEOS:PPATH attribute.
435 \retval B_NO_INIT The object was not properly initialized.
440 \fn status_t BNodeInfo::SetAppHint(const entry_ref* ref)
441 \brief Sets the application that will open the file type of the node. If
442 \a ref is \c NULL, the \c BEOS:PPATH attribute is removed instead.
444 \a ref is converted into a path and stored in the \c BEOS:PPATH attribute
445 of the node. If \a ref is NULL \c BEOS:PPATH is removed instead.
447 \param ref A pointer to an entry_ref referring to the application.
450 \returns A status code.
451 \retval B_OK Everything went fine.
452 \retval B_BAD_VALUE The \a ref object passed in was \c NULL.
453 \retval B_ENTRY_NOT_FOUND \c BEOS:PPATH attribute not found.
454 \retval B_ERROR Unable to write \c BEOS:PPATH attribute.
455 \retval B_NO_INIT The object was not properly initialized.