From 3b07762c548ec4016dea480d1061577cd15ec614 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 26 Jan 2014 11:56:27 +0100 Subject: [PATCH] BAppFileInfo: Coding style update Also remove doxygen comments. --- headers/os/storage/AppFileInfo.h | 123 +++--- src/kits/storage/AppFileInfo.cpp | 671 ++++--------------------------- 2 files changed, 150 insertions(+), 644 deletions(-) diff --git a/headers/os/storage/AppFileInfo.h b/headers/os/storage/AppFileInfo.h index 146db54b4f..b00609377b 100644 --- a/headers/os/storage/AppFileInfo.h +++ b/headers/os/storage/AppFileInfo.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2014, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _APP_FILE_INFO_H @@ -8,6 +8,7 @@ #include + class BBitmap; class BFile; class BMessage; @@ -44,83 +45,83 @@ enum version_kind { B_SYSTEM_VERSION_KIND }; -/*! \brief Executable meta information handling. - The BAppFileInfo class provides access to meta data that can be associated - with executables, libraries and add-ons. - \author Ingo Weinhold - \version 0.0.0 -*/ class BAppFileInfo: public BNodeInfo { - public: - BAppFileInfo(); - BAppFileInfo(BFile *file); - virtual ~BAppFileInfo(); +public: + BAppFileInfo(); + BAppFileInfo(BFile* file); + virtual ~BAppFileInfo(); - status_t SetTo(BFile *file); + status_t SetTo(BFile* file); - virtual status_t GetType(char *type) const; - virtual status_t SetType(const char *type); + virtual status_t GetType(char* type) const; + virtual status_t SetType(const char* type); - status_t GetSignature(char *signature) const; - status_t SetSignature(const char *signature); - - status_t GetCatalogEntry(char *catalogEntry) const; - status_t SetCatalogEntry(const char *catalogEntry); + status_t GetSignature(char* signature) const; + status_t SetSignature(const char* signature); - status_t GetAppFlags(uint32 *flags) const; - status_t SetAppFlags(uint32 flags); - status_t RemoveAppFlags(); + status_t GetCatalogEntry(char* catalogEntry) const; + status_t SetCatalogEntry(const char* catalogEntry); - status_t GetSupportedTypes(BMessage *types) const; - status_t SetSupportedTypes(const BMessage *types, bool syncAll); - status_t SetSupportedTypes(const BMessage *types); - bool IsSupportedType(const char *type) const; - bool Supports(BMimeType *type) const; + status_t GetAppFlags(uint32* flags) const; + status_t SetAppFlags(uint32 flags); + status_t RemoveAppFlags(); - virtual status_t GetIcon(BBitmap *icon, icon_size which) const; - virtual status_t SetIcon(const BBitmap *icon, icon_size which); + status_t GetSupportedTypes(BMessage* types) const; + status_t SetSupportedTypes(const BMessage* types, + bool syncAll); + status_t SetSupportedTypes(const BMessage* types); + bool IsSupportedType(const char* type) const; + bool Supports(BMimeType* type) const; - status_t GetIcon(uint8** data, size_t* size) const; - status_t SetIcon(const uint8* data, size_t size); + virtual status_t GetIcon(BBitmap* icon, icon_size which) const; + virtual status_t SetIcon(const BBitmap* icon, icon_size which); - status_t GetVersionInfo(version_info *info, version_kind kind) const; - status_t SetVersionInfo(const version_info *info, version_kind kind); + status_t GetIcon(uint8** data, size_t* size) const; + status_t SetIcon(const uint8* data, size_t size); - status_t GetIconForType(const char *type, BBitmap *icon, - icon_size which) const; - status_t GetIconForType(const char *type, uint8** data, - size_t* size) const; - status_t SetIconForType(const char *type, const BBitmap *icon, - icon_size which); - status_t SetIconForType(const char *type, const uint8* data, - size_t size); + status_t GetVersionInfo(version_info* info, + version_kind kind) const; + status_t SetVersionInfo(const version_info* info, + version_kind kind); - void SetInfoLocation(info_location location); - bool IsUsingAttributes() const; - bool IsUsingResources() const; + status_t GetIconForType(const char* type, BBitmap* icon, + icon_size which) const; + status_t GetIconForType(const char* type, uint8** data, + size_t* size) const; + status_t SetIconForType(const char* type, + const BBitmap* icon, icon_size which); + status_t SetIconForType(const char* type, + const uint8* data, size_t size); - private: - virtual void _ReservedAppFileInfo1(); - virtual void _ReservedAppFileInfo2(); - virtual void _ReservedAppFileInfo3(); + void SetInfoLocation(info_location location); + bool IsUsingAttributes() const; + bool IsUsingResources() const; - BAppFileInfo &operator=(const BAppFileInfo &); - BAppFileInfo(const BAppFileInfo &); +private: + virtual void _ReservedAppFileInfo1(); + virtual void _ReservedAppFileInfo2(); + virtual void _ReservedAppFileInfo3(); - status_t GetMetaMime(BMimeType *meta) const; + BAppFileInfo& operator=(const BAppFileInfo&); + BAppFileInfo(const BAppFileInfo&); - status_t _ReadData(const char *name, int32 id, type_code type, - void *buffer, size_t bufferSize, - size_t &bytesRead, void **allocatedBuffer = NULL) const; - status_t _WriteData(const char *name, int32 id, type_code type, - const void *buffer, size_t bufferSize, - bool findID = false); - status_t _RemoveData(const char *name, type_code type); + status_t GetMetaMime(BMimeType* meta) const; - BResources *fResources; - info_location fWhere; - uint32 _reserved[2]; + status_t _ReadData(const char* name, int32 id, + type_code type, void* buffer, + size_t bufferSize, size_t& bytesRead, + void** allocatedBuffer = NULL) const; + status_t _WriteData(const char* name, int32 id, + type_code type, const void* buffer, + size_t bufferSize, bool findID = false); + status_t _RemoveData(const char* name, type_code type); + +private: + BResources* fResources; + info_location fWhere; + uint32 _reserved[2]; }; + #endif // _APP_FILE_INFO_H diff --git a/src/kits/storage/AppFileInfo.cpp b/src/kits/storage/AppFileInfo.cpp index ad81175416..c681310012 100644 --- a/src/kits/storage/AppFileInfo.cpp +++ b/src/kits/storage/AppFileInfo.cpp @@ -1,9 +1,9 @@ /* - * Copyright 2002-2007, Haiku Inc. + * Copyright 2002-2014, Haiku, Inc. * Distributed under the terms of the MIT License. * * Authors: - * Ingo Weinhold, bonefish@users.sf.net + * Ingo Weinhold, ingo_weinhold@gmx.de */ @@ -23,7 +23,19 @@ #include #include -using namespace std; + +// debugging +//#define DBG(x) x +#define DBG(x) +#define OUT printf + + +// type codes +enum { + B_APP_FLAGS_TYPE = 'APPF', + B_VERSION_INFO_TYPE = 'APPV', +}; + // attributes static const char* kTypeAttribute = "BEOS:TYPE"; @@ -52,12 +64,6 @@ static const int32 kLargeIconForTypeResourceID = 0; static const int32 kIconForTypeResourceID = 0; static const int32 kCatalogEntryResourceID = 1; -// type codes -enum { - B_APP_FLAGS_TYPE = 'APPF', - B_VERSION_INFO_TYPE = 'APPV', -}; - // R5 also exports these (Tracker is using them): // (maybe we better want to drop them silently and declare // the above in a public Haiku header - and use that one in @@ -66,14 +72,7 @@ extern const uint32 MINI_ICON_TYPE, LARGE_ICON_TYPE; const uint32 MINI_ICON_TYPE = 'MICN'; const uint32 LARGE_ICON_TYPE = 'ICON'; -// debugging -//#define DBG(x) x -#define DBG(x) -#define OUT printf -// constructor -/*! \brief Creates an uninitialized BAppFileInfo object. -*/ BAppFileInfo::BAppFileInfo() : fResources(NULL), @@ -82,16 +81,6 @@ BAppFileInfo::BAppFileInfo() } -// constructor -/*! \brief Creates an BAppFileInfo object and initializes it to the supplied - file. - - The caller retains ownership of the supplied BFile object. It must not - be deleted during the life time of the BAppFileInfo. It is not deleted - when the BAppFileInfo is destroyed. - - \param file The file the object shall be initialized to. -*/ BAppFileInfo::BAppFileInfo(BFile* file) : fResources(NULL), @@ -101,32 +90,14 @@ BAppFileInfo::BAppFileInfo(BFile* file) } -// destructor -/*! \brief Frees all resources associated with this object. - - The BFile the object is set to is not deleted. -*/ BAppFileInfo::~BAppFileInfo() { delete fResources; } -// SetTo -/*! \brief Initializes the BAppFileInfo to the supplied file. - - The caller retains ownership of the supplied BFile object. It must not - be deleted during the life time of the BAppFileInfo. It is not deleted - when the BAppFileInfo is destroyed. - - \param file The file the object shall be initialized to. - - \return - - \c B_OK: Everything went fine. - - \c B_BAD_VALUE: \c NULL \a file or \a file is not properly initialized. -*/ status_t -BAppFileInfo::SetTo(BFile *file) +BAppFileInfo::SetTo(BFile* file) { // unset the old file BNodeInfo::SetTo(NULL); @@ -136,13 +107,14 @@ BAppFileInfo::SetTo(BFile *file) } // check param - status_t error = (file && file->InitCheck() == B_OK ? B_OK : B_BAD_VALUE); + status_t error + = file != NULL && file->InitCheck() == B_OK ? B_OK : B_BAD_VALUE; info_location where = B_USE_BOTH_LOCATIONS; // create resources if (error == B_OK) { - fResources = new(nothrow) BResources(); + fResources = new(std::nothrow) BResources(); if (fResources) { error = fResources->SetTo(file); if (error != B_OK) { @@ -180,34 +152,18 @@ BAppFileInfo::SetTo(BFile *file) } -// GetType -/*! \brief Gets the file's MIME type. - - \param type A pointer to a pre-allocated character buffer of size - \c B_MIME_TYPE_LENGTH or larger into which the MIME type of the - file shall be written. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \c NULL \a type or the type string stored in the - attribute/resources is longer than \c B_MIME_TYPE_LENGTH. - - \c B_BAD_TYPE: The attribute/resources the type string is stored in have - the wrong type. - - \c B_ENTRY_NOT_FOUND: No type is set on the file. - - other error codes -*/ status_t -BAppFileInfo::GetType(char *type) const +BAppFileInfo::GetType(char* type) const { // check param and initialization - status_t error = (type ? B_OK : B_BAD_VALUE); + status_t error = type != NULL ? B_OK : B_BAD_VALUE; if (error == B_OK && InitCheck() != B_OK) error = B_NO_INIT; // read the data size_t read = 0; if (error == B_OK) { error = _ReadData(kTypeAttribute, kTypeResourceID, B_MIME_STRING_TYPE, - type, B_MIME_TYPE_LENGTH, read); + type, B_MIME_TYPE_LENGTH, read); } // check the read data -- null terminate the string if (error == B_OK && type[read - 1] != '\0') { @@ -220,20 +176,6 @@ BAppFileInfo::GetType(char *type) const } -// SetType -/*! \brief Sets the file's MIME type. - - If \a type is \c NULL the file's MIME type is unset. - - \param type The MIME type to be assigned to the file. Must not be longer - than \c B_MIME_TYPE_LENGTH (including the terminating null). - May be \c NULL. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \a type is longer than \c B_MIME_TYPE_LENGTH. - - other error codes -*/ status_t BAppFileInfo::SetType(const char* type) { @@ -242,7 +184,7 @@ BAppFileInfo::SetType(const char* type) if (error == B_OK && InitCheck() != B_OK) error = B_NO_INIT; if (error == B_OK) { - if (type) { + if (type != NULL) { // check param size_t typeLen = strlen(type); if (error == B_OK && typeLen >= B_MIME_TYPE_LENGTH) @@ -250,7 +192,7 @@ BAppFileInfo::SetType(const char* type) // write the data if (error == B_OK) { error = _WriteData(kTypeAttribute, kTypeResourceID, - B_MIME_STRING_TYPE, type, typeLen + 1); + B_MIME_STRING_TYPE, type, typeLen + 1); } } else error = _RemoveData(kTypeAttribute, B_MIME_STRING_TYPE); @@ -259,22 +201,6 @@ BAppFileInfo::SetType(const char* type) } -// GetSignature -/*! \brief Gets the file's application signature. - - \param signature A pointer to a pre-allocated character buffer of size - \c B_MIME_TYPE_LENGTH or larger into which the application - signature of the file shall be written. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \c NULL \a signature or the signature stored in the - attribute/resources is longer than \c B_MIME_TYPE_LENGTH. - - \c B_BAD_TYPE: The attribute/resources the signature is stored in have - the wrong type. - - \c B_ENTRY_NOT_FOUND: No signature is set on the file. - - other error codes -*/ status_t BAppFileInfo::GetSignature(char* signature) const { @@ -286,8 +212,7 @@ BAppFileInfo::GetSignature(char* signature) const size_t read = 0; if (error == B_OK) { error = _ReadData(kSignatureAttribute, kSignatureResourceID, - B_MIME_STRING_TYPE, signature, - B_MIME_TYPE_LENGTH, read); + B_MIME_STRING_TYPE, signature, B_MIME_TYPE_LENGTH, read); } // check the read data -- null terminate the string if (error == B_OK && signature[read - 1] != '\0') { @@ -300,20 +225,6 @@ BAppFileInfo::GetSignature(char* signature) const } -// SetSignature -/*! \brief Sets the file's application signature. - - If \a signature is \c NULL the file's application signature is unset. - - \param signature The application signature to be assigned to the file. - Must not be longer than \c B_MIME_TYPE_LENGTH (including the - terminating null). May be \c NULL. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \a signature is longer than \c B_MIME_TYPE_LENGTH. - - other error codes -*/ status_t BAppFileInfo::SetSignature(const char* signature) { @@ -330,8 +241,7 @@ BAppFileInfo::SetSignature(const char* signature) // write the data if (error == B_OK) { error = _WriteData(kSignatureAttribute, kSignatureResourceID, - B_MIME_STRING_TYPE, signature, - signatureLen + 1); + B_MIME_STRING_TYPE, signature, signatureLen + 1); } } else error = _RemoveData(kSignatureAttribute, B_MIME_STRING_TYPE); @@ -340,24 +250,8 @@ BAppFileInfo::SetSignature(const char* signature) } -// GetCatalogEntry -/*! \brief Gets the file's catalog entry. (localization) - - \param catalogEntry A pointer to a pre-allocated character buffer of size - \c B_MIME_TYPE_LENGTH * 3 or larger into which the catalog entry - of the file shall be written. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \c NULL \a catalogEntry or the entry stored in the - attribute/resources is longer than \c B_MIME_TYPE_LENGTH * 3. - - \c B_BAD_TYPE: The attribute/resources the entry is stored in have - the wrong type. - - \c B_ENTRY_NOT_FOUND: No catalog entry is set on the file. - - other error codes -*/ status_t -BAppFileInfo::GetCatalogEntry(char *catalogEntry) const +BAppFileInfo::GetCatalogEntry(char* catalogEntry) const { if (catalogEntry == NULL) return B_BAD_VALUE; @@ -381,21 +275,6 @@ BAppFileInfo::GetCatalogEntry(char *catalogEntry) const } -// SetCatalogEntry -/*! \brief Sets the file's catalog entry. (localization) - - If \a catalogEntry is \c NULL the file's catalog entry is unset. - - \param catalogEntry The catalog entry to be assigned to the file. - Of the form "x-vnd.Haiku-app:context:name". - Must not be longer than \c B_MIME_TYPE_LENGTH * 3 - (including the terminating null). May be \c NULL. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \a catalogEntry is longer than \c B_MIME_TYPE_LENGTH * 3. - - other error codes -*/ status_t BAppFileInfo::SetCatalogEntry(const char* catalogEntry) { @@ -414,33 +293,18 @@ BAppFileInfo::SetCatalogEntry(const char* catalogEntry) } -// GetAppFlags -/*! \brief Gets the file's application flags. - - \param flags A pointer to a pre-allocated uint32 into which the application - flags of the file shall be written. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \c NULL \a flags. - - \c B_BAD_TYPE: The attribute/resources the flags are stored in have - the wrong type. - - \c B_ENTRY_NOT_FOUND: No application flags are set on the file. - - other error codes -*/ status_t BAppFileInfo::GetAppFlags(uint32* flags) const { // check param and initialization - status_t error = (flags ? B_OK : B_BAD_VALUE); + status_t error = flags != NULL ? B_OK : B_BAD_VALUE; if (error == B_OK && InitCheck() != B_OK) error = B_NO_INIT; // read the data size_t read = 0; if (error == B_OK) { error = _ReadData(kAppFlagsAttribute, kAppFlagsResourceID, - B_APP_FLAGS_TYPE, flags, sizeof(uint32), - read); + B_APP_FLAGS_TYPE, flags, sizeof(uint32), read); } // check the read data if (error == B_OK && read != sizeof(uint32)) @@ -449,14 +313,6 @@ BAppFileInfo::GetAppFlags(uint32* flags) const } -// SetAppFlags -/*! \brief Sets the file's application flags. - \param flags The application flags to be assigned to the file. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - other error codes -*/ status_t BAppFileInfo::SetAppFlags(uint32 flags) { @@ -467,19 +323,12 @@ BAppFileInfo::SetAppFlags(uint32 flags) if (error == B_OK) { // write the data error = _WriteData(kAppFlagsAttribute, kAppFlagsResourceID, - B_APP_FLAGS_TYPE, &flags, sizeof(uint32)); + B_APP_FLAGS_TYPE, &flags, sizeof(uint32)); } return error; } -// RemoveAppFlags -/*! \brief Removes the file's application flags. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - other error codes -*/ status_t BAppFileInfo::RemoveAppFlags() { @@ -495,36 +344,19 @@ BAppFileInfo::RemoveAppFlags() } -// GetSupportedTypes -/*! \brief Gets the MIME types supported by the application. - - The supported MIME types are added to a field "types" of type - \c B_STRING_TYPE in \a types. - - \param types A pointer to a pre-allocated BMessage into which the - MIME types supported by the appplication shall be written. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \c NULL \a types. - - \c B_BAD_TYPE: The attribute/resources the supported types are stored in - have the wrong type. - - \c B_ENTRY_NOT_FOUND: No supported types are set on the file. - - other error codes -*/ status_t BAppFileInfo::GetSupportedTypes(BMessage* types) const { // check param and initialization - status_t error = (types ? B_OK : B_BAD_VALUE); + status_t error = types != NULL ? B_OK : B_BAD_VALUE; if (error == B_OK && InitCheck() != B_OK) error = B_NO_INIT; // read the data size_t read = 0; - void *buffer = NULL; + void* buffer = NULL; if (error == B_OK) { error = _ReadData(kSupportedTypesAttribute, kSupportedTypesResourceID, - B_MESSAGE_TYPE, NULL, 0, read, &buffer); + B_MESSAGE_TYPE, NULL, 0, read, &buffer); } // unflatten the buffer if (error == B_OK) @@ -535,32 +367,6 @@ BAppFileInfo::GetSupportedTypes(BMessage* types) const } -// SetSupportedTypes -/*! \brief Sets the MIME types supported by the application. - - If \a types is \c NULL the application's supported types are unset. - - The supported MIME types must be stored in a field "types" of type - \c B_STRING_TYPE in \a types. - - The method informs the registrar about this news. - For each supported type the result of BMimeType::GetSupportingApps() will - afterwards include the signature of this application. That is, the - application file needs to have a signature set. - - \a syncAll specifies whether the not longer supported types shall be - updated as well, i.e. whether this application shall be remove from the - lists of supporting applications. - - \param types The supported types to be assigned to the file. - May be \c NULL. - \param syncAll \c true to also synchronize the not longer supported - types, \c false otherwise. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - other error codes -*/ status_t BAppFileInfo::SetSupportedTypes(const BMessage* types, bool syncAll) { @@ -592,7 +398,7 @@ BAppFileInfo::SetSupportedTypes(const BMessage* types, bool syncAll) // allocate a buffer for the flattened data char* buffer = NULL; if (error == B_OK) { - buffer = new(nothrow) char[size]; + buffer = new(std::nothrow) char[size]; if (!buffer) error = B_NO_MEMORY; } @@ -602,8 +408,7 @@ BAppFileInfo::SetSupportedTypes(const BMessage* types, bool syncAll) // write the data if (error == B_OK) { error = _WriteData(kSupportedTypesAttribute, - kSupportedTypesResourceID, B_MESSAGE_TYPE, - buffer, size); + kSupportedTypesResourceID, B_MESSAGE_TYPE, buffer, size); } // clean up delete[] buffer; @@ -617,19 +422,6 @@ BAppFileInfo::SetSupportedTypes(const BMessage* types, bool syncAll) } -// SetSupportedTypes -/*! \brief Sets the MIME types supported by the application. - - This method is a short-hand for SetSupportedTypes(types, false). - \see SetSupportedType(const BMessage*, bool) for detailed information. - - \param types The supported types to be assigned to the file. - May be \c NULL. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - other error codes -*/ status_t BAppFileInfo::SetSupportedTypes(const BMessage* types) { @@ -637,20 +429,10 @@ BAppFileInfo::SetSupportedTypes(const BMessage* types) } -// IsSupportedType -/*! \brief Returns whether the application supports the supplied MIME type. - - If the application supports the wildcard type "application/octet-stream" - any this method returns \c true for any MIME type. - - \param type The MIME type in question. - \return \c true, if \a type is a valid MIME type and it is supported by - the application, \c false otherwise. -*/ bool BAppFileInfo::IsSupportedType(const char* type) const { - status_t error = (type ? B_OK : B_BAD_VALUE); + status_t error = type != NULL ? B_OK : B_BAD_VALUE; // get the supported types BMessage types; if (error == B_OK) @@ -666,30 +448,19 @@ BAppFileInfo::IsSupportedType(const char* type) const for (int32 i = 0; !found && types.FindString("types", i, &supportedType) == B_OK; i++) { - found = !strcmp(supportedType, "application/octet-stream") - || BMimeType(supportedType).Contains(&mimeType); + found = strcmp(supportedType, "application/octet-stream") == 0 + || BMimeType(supportedType).Contains(&mimeType); } } return found; } -// Supports -/*! \brief Returns whether the application supports the supplied MIME type - explicitly. - - Unlike IsSupportedType(), this method returns \c true, only if the type - is explicitly supported, regardless of whether it supports - "application/octet-stream". - - \param type The MIME type in question. - \return \c true, if \a type is a valid MIME type and it is explicitly - supported by the application, \c false otherwise. -*/ bool BAppFileInfo::Supports(BMimeType* type) const { - status_t error = (type && type->InitCheck() == B_OK ? B_OK : B_BAD_VALUE); + status_t error + = type != NULL && type->InitCheck() == B_OK ? B_OK : B_BAD_VALUE; // get the supported types BMessage types; if (error == B_OK) @@ -708,20 +479,6 @@ BAppFileInfo::Supports(BMimeType* type) const } -// GetIcon -/*! \brief Gets the file's icon. - \param icon A pointer to a pre-allocated BBitmap of the correct dimension - to store the requested icon (16x16 for the mini and 32x32 for the - large icon). - \param which Specifies the size of the icon to be retrieved: - \c B_MINI_ICON for the mini and \c B_LARGE_ICON for the large icon. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \c NULL \a icon, unsupported icon size \a which or bitmap - dimensions (\a icon) and icon size (\a which) do not match. - - other error codes -*/ status_t BAppFileInfo::GetIcon(BBitmap* icon, icon_size which) const { @@ -729,16 +486,6 @@ BAppFileInfo::GetIcon(BBitmap* icon, icon_size which) const } -// GetIcon -/*! \brief Gets the file's icon. - \param data The pointer in which the flat icon data will be returned. - \param size The pointer in which the size of the data found will be returned. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \c NULL \a data or \c NULL size. - - other error codes -*/ status_t BAppFileInfo::GetIcon(uint8** data, size_t* size) const { @@ -746,22 +493,6 @@ BAppFileInfo::GetIcon(uint8** data, size_t* size) const } -// SetIcon -/*! \brief Sets the file's icon. - - If \a icon is \c NULL the file's icon is unset. - - \param icon A pointer to the BBitmap containing the icon to be set. - May be \c NULL. - \param which Specifies the size of the icon to be set: \c B_MINI_ICON - for the mini and \c B_LARGE_ICON for the large icon. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: Unknown icon size \a which or bitmap dimensions (\a icon) - and icon size (\a which) do not match. - - other error codes -*/ status_t BAppFileInfo::SetIcon(const BBitmap* icon, icon_size which) { @@ -769,20 +500,6 @@ BAppFileInfo::SetIcon(const BBitmap* icon, icon_size which) } -// SetIcon -/*! \brief Sets the file's icon. - - If \a icon is \c NULL the file's icon is unset. - - \param data A pointer to the data buffer containing the vector icon - to be set. May be \c NULL. - \param size Specifies the size of buffer pointed to by \a data. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \c NULL data. - - other error codes -*/ status_t BAppFileInfo::SetIcon(const uint8* data, size_t size) { @@ -790,25 +507,11 @@ BAppFileInfo::SetIcon(const uint8* data, size_t size) } -// GetVersionInfo -/*! \brief Gets the file's version info. - \param info A pointer to a pre-allocated version_info structure into which - the version info should be written. - \param kind Specifies the kind of the version info to be retrieved: - \c B_APP_VERSION_KIND for the application's version info and - \c B_SYSTEM_VERSION_KIND for the suite's info the application - belongs to. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \c NULL \a info. - - other error codes -*/ status_t BAppFileInfo::GetVersionInfo(version_info* info, version_kind kind) const { // check params and initialization - if (!info) + if (info == NULL) return B_BAD_VALUE; int32 index = 0; @@ -851,21 +554,6 @@ BAppFileInfo::GetVersionInfo(version_info* info, version_kind kind) const } -// SetVersionInfo -/*! \brief Sets the file's version info. - - If \a info is \c NULL the file's version info is unset. - - \param info The version info to be set. May be \c NULL. - \param kind Specifies kind of version info to be set: - \c B_APP_VERSION_KIND for the application's version info and - \c B_SYSTEM_VERSION_KIND for the suite's info the application - belongs to. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - other error codes -*/ status_t BAppFileInfo::SetVersionInfo(const version_info* info, version_kind kind) { @@ -874,7 +562,7 @@ BAppFileInfo::SetVersionInfo(const version_info* info, version_kind kind) if (error == B_OK && InitCheck() != B_OK) error = B_NO_INIT; if (error == B_OK) { - if (info) { + if (info != NULL) { // check param int32 index = 0; if (error == B_OK) { @@ -909,9 +597,8 @@ BAppFileInfo::SetVersionInfo(const version_info* info, version_kind kind) // write the data if (error == B_OK) { error = _WriteData(kVersionInfoAttribute, - kVersionInfoResourceID, - B_VERSION_INFO_TYPE, infos, - 2 * sizeof(version_info)); + kVersionInfoResourceID, B_VERSION_INFO_TYPE, infos, + 2 * sizeof(version_info)); } } else error = _RemoveData(kVersionInfoAttribute, B_VERSION_INFO_TYPE); @@ -920,33 +607,14 @@ BAppFileInfo::SetVersionInfo(const version_info* info, version_kind kind) } -// GetIconForType -/*! \brief Gets the icon the application provides for a given MIME type. - - If \a type is \c NULL, the application's icon is retrieved. - - \param type The MIME type in question. May be \c NULL. - \param icon A pointer to a pre-allocated BBitmap of the correct dimension - to store the requested icon (16x16 for the mini and 32x32 for the - large icon). - \param which Specifies the size of the icon to be retrieved: - \c B_MINI_ICON for the mini and \c B_LARGE_ICON for the large icon. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \c NULL \a icon, unsupported icon size - \a which or bitmap dimensions (\a icon) and icon size (\a which) do - not match. - - other error codes -*/ status_t -BAppFileInfo::GetIconForType(const char* type, BBitmap* icon, - icon_size size) const +BAppFileInfo::GetIconForType(const char* type, BBitmap* icon, icon_size size) + const { if (InitCheck() != B_OK) return B_NO_INIT; - if (!icon || icon->InitCheck() != B_OK) + if (icon == NULL || icon->InitCheck() != B_OK) return B_BAD_VALUE; // TODO: for consistency with attribute based icon reading, we @@ -960,7 +628,7 @@ BAppFileInfo::GetIconForType(const char* type, BBitmap* icon, BString vectorAttributeName(kIconAttribute); // check type param - if (type) { + if (type != NULL) { if (BMimeType::IsValid(type)) vectorAttributeName += type; else @@ -973,7 +641,7 @@ BAppFileInfo::GetIconForType(const char* type, BBitmap* icon, size_t bytesRead; void* allocatedBuffer; status_t error = _ReadData(attribute, -1, B_VECTOR_ICON_TYPE, NULL, 0, - bytesRead, &allocatedBuffer); + bytesRead, &allocatedBuffer); if (error == B_OK) { error = BIconUtils::GetVectorIcon((uint8*)allocatedBuffer, bytesRead, icon); @@ -1028,33 +696,30 @@ BAppFileInfo::GetIconForType(const char* type, BBitmap* icon, // read the data if (error == B_OK) { - bool tempBuffer = (icon->ColorSpace() != B_CMAP8 - || icon->Bounds() != bounds); + bool tempBuffer + = icon->ColorSpace() != B_CMAP8 || icon->Bounds() != bounds; uint8* buffer = NULL; size_t read; if (tempBuffer) { // other color space or bitmap size than stored in attribute - buffer = new(nothrow) uint8[attrSize]; + buffer = new(std::nothrow) uint8[attrSize]; if (!buffer) { error = B_NO_MEMORY; } else { error = _ReadData(attribute, -1, attrType, buffer, attrSize, - read); + read); } } else { error = _ReadData(attribute, -1, attrType, icon->Bits(), attrSize, - read); + read); } if (error == B_OK && read != attrSize) error = B_ERROR; if (tempBuffer) { // other color space than stored in attribute if (error == B_OK) { - error = BIconUtils::ConvertFromCMAP8(buffer, - (uint32)size, - (uint32)size, - (uint32)size, - icon); + error = BIconUtils::ConvertFromCMAP8(buffer, (uint32)size, + (uint32)size, (uint32)size, icon); } delete[] buffer; } @@ -1063,48 +728,30 @@ BAppFileInfo::GetIconForType(const char* type, BBitmap* icon, } -// GetIconForType -/*! \brief Gets the icon the application provides for a given MIME type. - - If \a type is \c NULL, the application's icon is retrieved. - - \param type The MIME type in question. May be \c NULL. - \param data A pointer in which the icon data will be returned. When you - are done with the data, you should use free() to deallocate it. - \param size A pointer in which the size of the retrieved data is returned. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: \c NULL \a data and/or \a size. Or the supplied - \a type is not a valid MIME type. - - other error codes -*/ status_t -BAppFileInfo::GetIconForType(const char* type, uint8** data, - size_t* size) const +BAppFileInfo::GetIconForType(const char* type, uint8** data, size_t* size) const { if (InitCheck() != B_OK) return B_NO_INIT; - if (!data || !size) + if (data == NULL || size == NULL) return B_BAD_VALUE; // get vector icon BString attributeName(kIconAttribute); // check type param - if (type) { + if (type != NULL) { if (BMimeType::IsValid(type)) attributeName += type; else return B_BAD_VALUE; - } else { + } else attributeName += kIconType; - } void* allocatedBuffer = NULL; - status_t ret = _ReadData(attributeName.String(), -1, - B_VECTOR_ICON_TYPE, NULL, 0, *size, &allocatedBuffer); + status_t ret = _ReadData(attributeName.String(), -1, B_VECTOR_ICON_TYPE, + NULL, 0, *size, &allocatedBuffer); if (ret < B_OK) return ret; @@ -1114,32 +761,9 @@ BAppFileInfo::GetIconForType(const char* type, uint8** data, } -// SetIconForType -/*! \brief Sets the icon the application provides for a given MIME type. - - If \a type is \c NULL, the application's icon is set. - If \a icon is \c NULL the icon is unset. - - If the file has a signature, then the icon is also set on the MIME type. - If the type for the signature has not been installed yet, it is installed - before. - - \param type The MIME type in question. May be \c NULL. - \param icon A pointer to the BBitmap containing the icon to be set. - May be \c NULL. - \param which Specifies the size of the icon to be set: \c B_MINI_ICON - for the mini and \c B_LARGE_ICON for the large icon. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: Either the icon size \a which is unkown, bitmap dimensions (\a icon) - and icon size (\a which) do not match, or the provided \a type is - not a valid MIME type. - - other error codes -*/ status_t BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon, - icon_size which) + icon_size which) { status_t error = B_OK; // set some icon size related variables @@ -1154,16 +778,16 @@ BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon, bounds.Set(0, 0, 15, 15); attrType = B_MINI_ICON_TYPE; attrSize = 16 * 16; - resourceID = (type ? kMiniIconForTypeResourceID - : kMiniIconResourceID); + resourceID = type != NULL + ? kMiniIconForTypeResourceID : kMiniIconResourceID; break; case B_LARGE_ICON: attributeString = kLargeIconAttribute; bounds.Set(0, 0, 31, 31); attrType = B_LARGE_ICON_TYPE; attrSize = 32 * 32; - resourceID = (type ? kLargeIconForTypeResourceID - : kLargeIconResourceID); + resourceID = type != NULL + ? kLargeIconForTypeResourceID : kLargeIconResourceID; break; default: error = B_BAD_VALUE; @@ -1171,7 +795,7 @@ BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon, } // check type param if (error == B_OK) { - if (type) { + if (type != NULL) { if (BMimeType::IsValid(type)) attributeString += type; else @@ -1181,7 +805,7 @@ BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon, } const char* attribute = attributeString.String(); // check parameter and initialization - if (error == B_OK && icon + if (error == B_OK && icon != NULL && (icon->InitCheck() != B_OK || icon->Bounds() != bounds)) { error = B_BAD_VALUE; } @@ -1189,7 +813,7 @@ BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon, error = B_NO_INIT; // write/remove the attribute if (error == B_OK) { - if (icon) { + if (icon != NULL) { bool otherColorSpace = (icon->ColorSpace() != B_CMAP8); if (otherColorSpace) { BBitmap bitmap(bounds, B_BITMAP_NO_SERVER_LINK, B_CMAP8); @@ -1198,11 +822,11 @@ BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon, error = bitmap.ImportBits(icon); if (error == B_OK) { error = _WriteData(attribute, resourceID, attrType, - bitmap.Bits(), attrSize, true); + bitmap.Bits(), attrSize, true); } } else { error = _WriteData(attribute, resourceID, attrType, - icon->Bits(), attrSize, true); + icon->Bits(), attrSize, true); } } else // no icon given => remove error = _RemoveData(attribute, attrType); @@ -1219,29 +843,8 @@ BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon, } -// SetIconForType -/*! \brief Sets the icon the application provides for a given MIME type. - - If \a type is \c NULL, the application's icon is set. - If \a data is \c NULL the icon is unset. - - If the file has a signature, then the icon is also set on the MIME type. - If the type for the signature has not been installed yet, it is installed - before. - - \param type The MIME type in question. May be \c NULL. - \param data A pointer to the data containing the icon to be set. - May be \c NULL. - \param size Specifies the size of buffer provided in \a data. - \return - - \c B_OK: Everything went fine. - - \c B_NO_INIT: The object is not properly initialized. - - \c B_BAD_VALUE: The provided \a type is not a valid MIME type. - - other error codes -*/ status_t -BAppFileInfo::SetIconForType(const char* type, const uint8* data, - size_t size) +BAppFileInfo::SetIconForType(const char* type, const uint8* data, size_t size) { if (InitCheck() != B_OK) return B_NO_INIT; @@ -1252,7 +855,7 @@ BAppFileInfo::SetIconForType(const char* type, const uint8* data, uint32 attrType = B_VECTOR_ICON_TYPE; // check type param - if (type) { + if (type != NULL) { if (BMimeType::IsValid(type)) attributeString += type; else @@ -1264,7 +867,7 @@ BAppFileInfo::SetIconForType(const char* type, const uint8* data, status_t error; // write/remove the attribute - if (data) + if (data != NULL) error = _WriteData(attribute, resourceID, attrType, data, size, true); else // no icon given => remove error = _RemoveData(attribute, attrType); @@ -1281,16 +884,6 @@ BAppFileInfo::SetIconForType(const char* type, const uint8* data, } -// SetInfoLocation -/*! \brief Specifies the location where the meta data shall be stored. - - The options for \a location are: - - \c B_USE_ATTRIBUTES: Store the data in the attributes. - - \c B_USE_RESOURCES: Store the data in the resources. - - \c B_USE_BOTH_LOCATIONS: Store the data in attributes and resources. - - \param location The location where the meta data shall be stored. -*/ void BAppFileInfo::SetInfoLocation(info_location location) { @@ -1301,12 +894,6 @@ BAppFileInfo::SetInfoLocation(info_location location) fWhere = location; } -// IsUsingAttributes -/*! \brief Returns whether the object stores the meta data (also) in the - file's attributes. - \return \c true, if the meta data are (also) stored in the file's - attributes, \c false otherwise. -*/ bool BAppFileInfo::IsUsingAttributes() const { @@ -1314,12 +901,6 @@ BAppFileInfo::IsUsingAttributes() const } -// IsUsingResources -/*! \brief Returns whether the object stores the meta data (also) in the - file's resources. - \return \c true, if the meta data are (also) stored in the file's - resources, \c false otherwise. -*/ bool BAppFileInfo::IsUsingResources() const { @@ -1333,39 +914,18 @@ void BAppFileInfo::_ReservedAppFileInfo2() {} void BAppFileInfo::_ReservedAppFileInfo3() {} -// = -/*! \brief Privatized assignment operator to prevent usage. -*/ -BAppFileInfo & -BAppFileInfo::operator=(const BAppFileInfo &) +BAppFileInfo& +BAppFileInfo::operator=(const BAppFileInfo&) { return *this; } -// copy constructor -/*! \brief Privatized copy constructor to prevent usage. -*/ -BAppFileInfo::BAppFileInfo(const BAppFileInfo &) +BAppFileInfo::BAppFileInfo(const BAppFileInfo&) { } -// GetMetaMime -/*! \brief Initializes a BMimeType to the file's signature. - - The parameter \a meta is not checked. - - \param meta A pointer to a pre-allocated BMimeType that shall be - initialized to the file's signature. - \return - - \c B_OK: Everything went fine. - - \c B_BAD_VALUE: \c NULL \a meta - - \c B_ENTRY_NOT_FOUND: The file has not signature or the signature is -( not installed in the MIME database.) - no valid MIME string. - - other error codes -*/ status_t BAppFileInfo::GetMetaMime(BMimeType* meta) const { @@ -1381,35 +941,13 @@ BAppFileInfo::GetMetaMime(BMimeType* meta) const } -// _ReadData -/*! \brief Reads data from an attribute or resource. - - The data are read from the location specified by \a fWhere. - - The object must be properly initialized. The parameters are NOT checked. - - \param name The name of the attribute/resource to be read. - \param id The resource ID of the resource to be read. Is ignored, when - < 0. - \param type The type of the attribute/resource to be read. - \param buffer A pre-allocated buffer for the data to be read. - \param bufferSize The size of the supplied buffer. - \param bytesRead A reference parameter, set to the number of bytes - actually read. - \param allocatedBuffer If not \c NULL, the method allocates a buffer - large enough too store the whole data and writes a pointer to it - into this variable. If \c NULL, the supplied buffer is used. - \return - - \c B_OK: Everything went fine. - - error code -*/ status_t BAppFileInfo::_ReadData(const char* name, int32 id, type_code type, - void* buffer, size_t bufferSize, - size_t &bytesRead, void** allocatedBuffer) const + void* buffer, size_t bufferSize, size_t& bytesRead, void** allocatedBuffer) + const { status_t error = B_OK; - + if (allocatedBuffer) buffer = NULL; @@ -1424,9 +962,9 @@ BAppFileInfo::_ReadData(const char* name, int32 id, type_code type, // check type and size, allocate a buffer, if required if (error == B_OK && info.type != type) error = B_BAD_VALUE; - if (error == B_OK && allocatedBuffer) { + if (error == B_OK && allocatedBuffer != NULL) { buffer = malloc(info.size); - if (!buffer) + if (buffer == NULL) error = B_NO_MEMORY; bufferSize = info.size; } @@ -1444,10 +982,10 @@ BAppFileInfo::_ReadData(const char* name, int32 id, type_code type, bytesRead = read; } - foundData = (error == B_OK); + foundData = error == B_OK; // free the allocated buffer on error - if (!foundData && allocatedBuffer && buffer) { + if (!foundData && allocatedBuffer != NULL && buffer != NULL) { free(buffer); buffer = NULL; } @@ -1479,7 +1017,7 @@ BAppFileInfo::_ReadData(const char* name, int32 id, type_code type, const void* resourceData = NULL; if (error == B_OK) { resourceData = fResources->LoadResource(type, name, &bytesRead); - if (resourceData && sizeFound == bytesRead) + if (resourceData != NULL && sizeFound == bytesRead) memcpy(buffer, resourceData, bytesRead); else error = B_ERROR; @@ -1488,7 +1026,7 @@ BAppFileInfo::_ReadData(const char* name, int32 id, type_code type, error = B_BAD_VALUE; // return the allocated buffer, or free it on error - if (allocatedBuffer) { + if (allocatedBuffer != NULL) { if (error == B_OK) *allocatedBuffer = buffer; else @@ -1499,29 +1037,9 @@ BAppFileInfo::_ReadData(const char* name, int32 id, type_code type, } -// _WriteData -/*! \brief Writes data to an attribute or resource. - - The data are written to the location(s) specified by \a fWhere. - - The object must be properly initialized. The parameters are NOT checked. - - \param name The name of the attribute/resource to be written. - \param id The resource ID of the resource to be written. - \param type The type of the attribute/resource to be written. - \param buffer A buffer containing the data to be written. - \param bufferSize The size of the supplied buffer. - \param findID If set to \c true use the ID that is already assigned to the - \a name / \a type pair or take the first unused ID >= \a id. - If \c false, \a id is used. - If \a id is already in use and . - \return - - \c B_OK: Everything went fine. - - error code -*/ status_t BAppFileInfo::_WriteData(const char* name, int32 id, type_code type, - const void* buffer, size_t bufferSize, bool findID) + const void* buffer, size_t bufferSize, bool findID) { if (!IsUsingAttributes() && !IsUsingResources()) return B_NO_INIT; @@ -1555,19 +1073,7 @@ BAppFileInfo::_WriteData(const char* name, int32 id, type_code type, return error; } -// _RemoveData -/*! \brief Removes an attribute or resource. - The removal location is specified by \a fWhere. - - The object must be properly initialized. The parameters are NOT checked. - - \param name The name of the attribute/resource to be remove. - \param type The type of the attribute/resource to be removed. - \return - - \c B_OK: Everything went fine. - - error code -*/ status_t BAppFileInfo::_RemoveData(const char* name, type_code type) { @@ -1593,4 +1099,3 @@ BAppFileInfo::_RemoveData(const char* name, type_code type) } return error; } -