本文整理汇总了C++中BMimeType::GetIconForType方法的典型用法代码示例。如果您正苦于以下问题:C++ BMimeType::GetIconForType方法的具体用法?C++ BMimeType::GetIconForType怎么用?C++ BMimeType::GetIconForType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BMimeType
的用法示例。
在下文中一共展示了BMimeType::GetIconForType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: type
static status_t
GetTrackerIcon(BMimeType &type, BBitmap *icon, icon_size iconSize)
{
// set some icon size related variables
status_t error = B_OK;
BRect bounds;
switch (iconSize) {
case B_MINI_ICON:
bounds.Set(0, 0, 15, 15);
break;
case B_LARGE_ICON:
bounds.Set(0, 0, 31, 31);
break;
default:
error = B_BAD_VALUE;
break;
}
// check parameters and initialization
if (error == B_OK
&& (!icon || icon->InitCheck() != B_OK || icon->Bounds() != bounds))
return B_BAD_VALUE;
bool success = false;
// Ask the MIME database for the preferred application for the file type
// and whether this application has a special icon for the type.
char signature[B_MIME_TYPE_LENGTH];
if (type.GetPreferredApp(signature) == B_OK) {
BMimeType type(signature);
success = (type.GetIconForType(type.Type(), icon, iconSize) == B_OK);
}
// Ask the MIME database whether there is an icon for the node's file type.
if (error == B_OK && !success)
success = (type.GetIcon(icon, iconSize) == B_OK);
// Ask the MIME database for the super type and start all over
if (error == B_OK && !success) {
BMimeType super;
if (type.GetSupertype(&super) == B_OK)
return GetTrackerIcon(super, icon, iconSize);
}
// Return the icon for "application/octet-stream" from the MIME database.
if (error == B_OK && !success) {
// get the "application/octet-stream" icon
BMimeType type("application/octet-stream");
error = type.GetIcon(icon, iconSize);
}
return error;
}
示例2: mime
/***********************************************************
* Constructor
***********************************************************/
HAttachmentItem::HAttachmentItem(const char* name,
off_t file_offset,
int32 data_len,
const char *content_type,
const char *encoding,
const char *charset)
:CLVEasyItem(0,false,false,20.0)
,fFileOffset(file_offset)
,fDataLen(data_len)
,fExtracted(false)
,fContentType(NULL)
,fEncoding(NULL)
,fCharset(NULL)
,fName(NULL)
{
fName = (name)?name:_("Unknown");
Encoding().Mime2UTF8(fName);
SetColumnContent(1,fName.String());
SetColumnContent(2,(content_type)?content_type:_("(Unknown)"));
char *size = new char[15];
float d = 0;
char *unit = new char[6];
if(data_len < 1024)
{
d = data_len;
::strcpy(unit,_("bytes"));
}else if(data_len >= 1024 && data_len < 1024*1024){
d = data_len/1024.0;
::strcpy(unit,_("KB"));
}else{
d = data_len/(1024.0*1024.0);
::strcpy(unit,_("MB"));
}
::sprintf(size,"%6.2f %s",d,unit);
SetColumnContent(3,size);
delete[] size;
delete[] unit;
BBitmap *bitmap = new BBitmap(BRect(0,0,15,15),B_CMAP8);
BMimeType preferredApp;
if(content_type)
{
BMimeType mime(content_type);
char prefApp[B_MIME_TYPE_LENGTH];
mime.GetPreferredApp(prefApp);
preferredApp.SetTo(prefApp);
fContentType = ::strdup(content_type);
if(preferredApp.GetIconForType(content_type,bitmap,B_MINI_ICON) != B_OK)
{
mime.GetIcon(bitmap,B_MINI_ICON);
}
SetColumnContent(0,bitmap);
}
delete bitmap;
if(encoding)
fEncoding = ::strdup(encoding);
if(charset)
fCharset = ::strdup(charset);
}