BAppFileInfo: Add method versions that don't touch the MIME DB
Add SetSupportedTypes() and SetIcon[ForType]() versions with an additional bool updateMimeDB parameter. If false, the method doesn't update the MIME DB entries for the type.
This commit is contained in:
parent
3b07762c54
commit
c41356fab5
@ -315,6 +315,41 @@
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn status_t BAppFileInfo::SetSupportedTypes(const BMessage* types,
|
||||
bool updateMimeDB, bool syncAll)
|
||||
\brief Sets the MIME types that are supported by the application and allows
|
||||
you to specify whether or not the supported types in the MIME DB shall
|
||||
be updated as well.
|
||||
|
||||
If \a types is \c NULL then 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.
|
||||
|
||||
If \a updateMimeDB is \c true, the method will inform the registrar about
|
||||
this news. In this case for each supported type the result of
|
||||
BMimeType::GetSupportingApps() will afterward include the signature of this
|
||||
application. That is, the application file needs to have a signature set.
|
||||
|
||||
\a syncAll specifies whether the no longer supported types shall be
|
||||
updated as well, i.e. whether or not this application shall be removed
|
||||
from the list of supporting applications. Only relevant when \a updateMimeDB
|
||||
is \c true.
|
||||
|
||||
\param types The supported types to be assigned to the file.
|
||||
May be \c NULL.
|
||||
\param updateMimeDB \c true to update the supported types in the MIME DB,
|
||||
\c false otherwise.
|
||||
\param syncAll \c true to also synchronize the no-longer supported
|
||||
types, \c false otherwise.
|
||||
|
||||
\returns A status code.
|
||||
\retval B_OK Everything went fine.
|
||||
\retval B_NO_INIT The object is not properly initialized.
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn status_t BAppFileInfo::SetSupportedTypes(const BMessage* types,
|
||||
bool syncAll)
|
||||
@ -438,12 +473,37 @@
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn status_t BAppFileInfo::SetIcon(const BBitmap* icon, icon_size which,
|
||||
bool updateMimeDB)
|
||||
\brief Sets the icon of the associated file from a BBitmap.
|
||||
|
||||
If \a icon is \c NULL then the icon of the file is unset.
|
||||
|
||||
\param icon A pointer to the BBitmap containing the icon to be set.
|
||||
May be \c NULL to specify no icon.
|
||||
\param which Specifies the size of the icon to be set: \c B_MINI_ICON for
|
||||
16x16 mini icon and \c B_LARGE_ICON for the 32x32 large icon.
|
||||
For HVIF icons this parameter has no effect.
|
||||
\param updateMimeDB \c true to also set the icon for the application in the
|
||||
MIME DB. \c false otherwise.
|
||||
|
||||
\returns A status code.
|
||||
\retval B_OK Everything went fine.
|
||||
\retval B_NO_INIT The object is not properly initialized.
|
||||
\retval B_BAD_VALUE Unknown icon size \a which or bitmap dimensions
|
||||
(\a icon) and icon size (\a which) do not match.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn status_t BAppFileInfo::SetIcon(const BBitmap* icon, icon_size which)
|
||||
\brief Sets the icon of the associated file from a BBitmap.
|
||||
|
||||
If \a icon is \c NULL then the icon of the file is unset.
|
||||
|
||||
Also sets the application's icon in the MIME DB, if the file has a valid
|
||||
application signature.
|
||||
|
||||
\param icon A pointer to the BBitmap containing the icon to be set.
|
||||
May be \c NULL to specify no icon.
|
||||
\param which Specifies the size of the icon to be set: \c B_MINI_ICON for
|
||||
@ -458,12 +518,35 @@
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn status_t BAppFileInfo::SetIcon(const uint8* data, size_t size,
|
||||
bool updateMimeDB)
|
||||
\brief Sets the icon of the associated file from a buffer.
|
||||
|
||||
If \a data is \c NULL then the icon of the file 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.
|
||||
\param updateMimeDB \c true to also set the icon for the application in the
|
||||
MIME DB. \c false otherwise.
|
||||
|
||||
\returns A status code.
|
||||
\retval B_OK Everything went fine.
|
||||
\retval B_NO_INIT The object is not properly initialized.
|
||||
\retval B_BAD_VALUE \c NULL data.
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn status_t BAppFileInfo::SetIcon(const uint8* data, size_t size)
|
||||
\brief Sets the icon of the associated file from a buffer.
|
||||
|
||||
If \a data is \c NULL then the icon of the file is unset.
|
||||
|
||||
Also sets the application's icon in the MIME DB, if the file has a valid
|
||||
application signature.
|
||||
|
||||
\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.
|
||||
@ -520,6 +603,36 @@
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn status_t BAppFileInfo::SetIconForType(const char* type,
|
||||
const BBitmap* icon, icon_size which, bool updateMimeDB)
|
||||
\brief Sets the icon the application provides for a given MIME type from a
|
||||
BBitmap.
|
||||
|
||||
\note If \a type is \c NULL then the icon is set.
|
||||
\note If \a icon is \c NULL then the icon is unset.
|
||||
|
||||
If \a updateMimeDB is \c true and 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.
|
||||
\param updateMimeDB \c true to also set the icon for the type in the MIME
|
||||
DB. \c false otherwise.
|
||||
|
||||
\returns A status code.
|
||||
\retval B_OK Everything went fine.
|
||||
\retval B_NO_INIT The object is not properly initialized.
|
||||
\retval B_BAD_VALUE Either the icon size \a which is unknown,
|
||||
the bitmap dimensions (\a icon) and icon size (\a which) do not
|
||||
match, or the provided \a type is not a valid MIME type.
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn status_t BAppFileInfo::SetIconForType(const char* type,
|
||||
const BBitmap* icon, icon_size which)
|
||||
@ -544,7 +657,34 @@
|
||||
\retval B_NO_INIT The object is not properly initialized.
|
||||
\retval B_BAD_VALUE Either the icon size \a which is unknown,
|
||||
the bitmap dimensions (\a icon) and icon size (\a which) do not
|
||||
match, or the provided \a type is not a valid MIME type.
|
||||
match, or the provided \a type is not a valid MIME type.
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn status_t BAppFileInfo::SetIconForType(const char* type,
|
||||
const uint8* data, size_t size, bool updateMimeDB)
|
||||
\brief Sets the icon the application provides for a given MIME type from a
|
||||
buffer.
|
||||
|
||||
\note If \a type is \c NULL then the icon is set.
|
||||
\note If \a data is \c NULL then the icon is unset.
|
||||
|
||||
If \a updateMimeDB is \c true and 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.
|
||||
\param updateMimeDB \c true to also set the icon for the type in the MIME
|
||||
DB. \c false otherwise.
|
||||
|
||||
\returns A status code.
|
||||
\retval B_OK Everything went fine.
|
||||
\retval B_NO_INIT The object is not properly initialized.
|
||||
\retval B_BAD_VALUE The provided \a type is not a valid MIME type.
|
||||
*/
|
||||
|
||||
|
||||
|
@ -68,6 +68,8 @@ public:
|
||||
status_t RemoveAppFlags();
|
||||
|
||||
status_t GetSupportedTypes(BMessage* types) const;
|
||||
status_t SetSupportedTypes(const BMessage* types,
|
||||
bool updateMimeDB, bool syncAll);
|
||||
status_t SetSupportedTypes(const BMessage* types,
|
||||
bool syncAll);
|
||||
status_t SetSupportedTypes(const BMessage* types);
|
||||
@ -75,9 +77,13 @@ public:
|
||||
bool Supports(BMimeType* type) const;
|
||||
|
||||
virtual status_t GetIcon(BBitmap* icon, icon_size which) const;
|
||||
status_t SetIcon(const BBitmap* icon, icon_size which,
|
||||
bool updateMimeDB);
|
||||
virtual status_t SetIcon(const BBitmap* icon, icon_size which);
|
||||
|
||||
status_t GetIcon(uint8** data, size_t* size) const;
|
||||
status_t SetIcon(const uint8* data, size_t size,
|
||||
bool updateMimeDB);
|
||||
status_t SetIcon(const uint8* data, size_t size);
|
||||
|
||||
status_t GetVersionInfo(version_info* info,
|
||||
@ -89,8 +95,14 @@ public:
|
||||
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,
|
||||
bool updateMimeDB);
|
||||
status_t SetIconForType(const char* type,
|
||||
const BBitmap* icon, icon_size which);
|
||||
status_t SetIconForType(const char* type,
|
||||
const uint8* data, size_t size,
|
||||
bool updateMimeDB);
|
||||
status_t SetIconForType(const char* type,
|
||||
const uint8* data, size_t size);
|
||||
|
||||
|
@ -368,15 +368,18 @@ BAppFileInfo::GetSupportedTypes(BMessage* types) const
|
||||
|
||||
|
||||
status_t
|
||||
BAppFileInfo::SetSupportedTypes(const BMessage* types, bool syncAll)
|
||||
BAppFileInfo::SetSupportedTypes(const BMessage* types, bool updateMimeDB,
|
||||
bool syncAll)
|
||||
{
|
||||
// check initialization
|
||||
status_t error = B_OK;
|
||||
if (error == B_OK && InitCheck() != B_OK)
|
||||
error = B_NO_INIT;
|
||||
|
||||
BMimeType mimeType;
|
||||
if (error == B_OK)
|
||||
error = GetMetaMime(&mimeType);
|
||||
|
||||
if (error == B_OK || error == B_ENTRY_NOT_FOUND) {
|
||||
error = B_OK;
|
||||
if (types) {
|
||||
@ -388,6 +391,7 @@ BAppFileInfo::SetSupportedTypes(const BMessage* types, bool syncAll)
|
||||
if (!BMimeType::IsValid(type))
|
||||
error = B_BAD_VALUE;
|
||||
}
|
||||
|
||||
// get flattened size
|
||||
ssize_t size = 0;
|
||||
if (error == B_OK) {
|
||||
@ -395,6 +399,7 @@ BAppFileInfo::SetSupportedTypes(const BMessage* types, bool syncAll)
|
||||
if (size < 0)
|
||||
error = size;
|
||||
}
|
||||
|
||||
// allocate a buffer for the flattened data
|
||||
char* buffer = NULL;
|
||||
if (error == B_OK) {
|
||||
@ -402,30 +407,40 @@ BAppFileInfo::SetSupportedTypes(const BMessage* types, bool syncAll)
|
||||
if (!buffer)
|
||||
error = B_NO_MEMORY;
|
||||
}
|
||||
|
||||
// flatten the message
|
||||
if (error == B_OK)
|
||||
error = types->Flatten(buffer, size);
|
||||
|
||||
// write the data
|
||||
if (error == B_OK) {
|
||||
error = _WriteData(kSupportedTypesAttribute,
|
||||
kSupportedTypesResourceID, B_MESSAGE_TYPE, buffer, size);
|
||||
}
|
||||
// clean up
|
||||
|
||||
delete[] buffer;
|
||||
} else
|
||||
error = _RemoveData(kSupportedTypesAttribute, B_MESSAGE_TYPE);
|
||||
|
||||
// update the MIME database, if the app signature is installed
|
||||
if (error == B_OK && mimeType.IsInstalled())
|
||||
if (updateMimeDB && error == B_OK && mimeType.IsInstalled())
|
||||
error = mimeType.SetSupportedTypes(types, syncAll);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BAppFileInfo::SetSupportedTypes(const BMessage* types, bool syncAll)
|
||||
{
|
||||
return SetSupportedTypes(types, true, syncAll);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BAppFileInfo::SetSupportedTypes(const BMessage* types)
|
||||
{
|
||||
return SetSupportedTypes(types, false);
|
||||
return SetSupportedTypes(types, true, false);
|
||||
}
|
||||
|
||||
|
||||
@ -493,17 +508,31 @@ BAppFileInfo::GetIcon(uint8** data, size_t* size) const
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BAppFileInfo::SetIcon(const BBitmap* icon, icon_size which, bool updateMimeDB)
|
||||
{
|
||||
return SetIconForType(NULL, icon, which, updateMimeDB);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BAppFileInfo::SetIcon(const BBitmap* icon, icon_size which)
|
||||
{
|
||||
return SetIconForType(NULL, icon, which);
|
||||
return SetIconForType(NULL, icon, which, true);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BAppFileInfo::SetIcon(const uint8* data, size_t size, bool updateMimeDB)
|
||||
{
|
||||
return SetIconForType(NULL, data, size, updateMimeDB);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BAppFileInfo::SetIcon(const uint8* data, size_t size)
|
||||
{
|
||||
return SetIconForType(NULL, data, size);
|
||||
return SetIconForType(NULL, data, size, true);
|
||||
}
|
||||
|
||||
|
||||
@ -678,15 +707,9 @@ BAppFileInfo::GetIconForType(const char* type, BBitmap* icon, icon_size size)
|
||||
default:
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
// check type param
|
||||
if (type) {
|
||||
if (BMimeType::IsValid(type))
|
||||
attributeString += type;
|
||||
else
|
||||
return B_BAD_VALUE;
|
||||
} else
|
||||
attributeString += kStandardIconType;
|
||||
|
||||
// compose attribute name
|
||||
attributeString += type != NULL ? type : kStandardIconType;
|
||||
attribute = attributeString.String();
|
||||
|
||||
// check parameters
|
||||
@ -763,9 +786,10 @@ BAppFileInfo::GetIconForType(const char* type, uint8** data, size_t* size) const
|
||||
|
||||
status_t
|
||||
BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon,
|
||||
icon_size which)
|
||||
icon_size which, bool updateMimeDB)
|
||||
{
|
||||
status_t error = B_OK;
|
||||
|
||||
// set some icon size related variables
|
||||
BString attributeString;
|
||||
BRect bounds;
|
||||
@ -793,6 +817,7 @@ BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon,
|
||||
error = B_BAD_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
// check type param
|
||||
if (error == B_OK) {
|
||||
if (type != NULL) {
|
||||
@ -804,6 +829,7 @@ BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon,
|
||||
attributeString += kStandardIconType;
|
||||
}
|
||||
const char* attribute = attributeString.String();
|
||||
|
||||
// check parameter and initialization
|
||||
if (error == B_OK && icon != NULL
|
||||
&& (icon->InitCheck() != B_OK || icon->Bounds() != bounds)) {
|
||||
@ -811,6 +837,7 @@ BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon,
|
||||
}
|
||||
if (error == B_OK && InitCheck() != B_OK)
|
||||
error = B_NO_INIT;
|
||||
|
||||
// write/remove the attribute
|
||||
if (error == B_OK) {
|
||||
if (icon != NULL) {
|
||||
@ -831,9 +858,10 @@ BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon,
|
||||
} else // no icon given => remove
|
||||
error = _RemoveData(attribute, attrType);
|
||||
}
|
||||
|
||||
// set the attribute on the MIME type, if the file has a signature
|
||||
BMimeType mimeType;
|
||||
if (error == B_OK && GetMetaMime(&mimeType) == B_OK) {
|
||||
if (updateMimeDB && error == B_OK && GetMetaMime(&mimeType) == B_OK) {
|
||||
if (!mimeType.IsInstalled())
|
||||
error = mimeType.Install();
|
||||
if (error == B_OK)
|
||||
@ -844,7 +872,16 @@ BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon,
|
||||
|
||||
|
||||
status_t
|
||||
BAppFileInfo::SetIconForType(const char* type, const uint8* data, size_t size)
|
||||
BAppFileInfo::SetIconForType(const char* type, const BBitmap* icon,
|
||||
icon_size which)
|
||||
{
|
||||
return SetIconForType(type, icon, which, true);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BAppFileInfo::SetIconForType(const char* type, const uint8* data, size_t size,
|
||||
bool updateMimeDB)
|
||||
{
|
||||
if (InitCheck() != B_OK)
|
||||
return B_NO_INIT;
|
||||
@ -874,7 +911,7 @@ BAppFileInfo::SetIconForType(const char* type, const uint8* data, size_t size)
|
||||
|
||||
// set the attribute on the MIME type, if the file has a signature
|
||||
BMimeType mimeType;
|
||||
if (error == B_OK && GetMetaMime(&mimeType) == B_OK) {
|
||||
if (updateMimeDB && error == B_OK && GetMetaMime(&mimeType) == B_OK) {
|
||||
if (!mimeType.IsInstalled())
|
||||
error = mimeType.Install();
|
||||
if (error == B_OK)
|
||||
@ -884,6 +921,13 @@ BAppFileInfo::SetIconForType(const char* type, const uint8* data, size_t size)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BAppFileInfo::SetIconForType(const char* type, const uint8* data, size_t size)
|
||||
{
|
||||
return SetIconForType(type, data, size, true);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BAppFileInfo::SetInfoLocation(info_location location)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user