本文整理汇总了C++中BMimeType::SetTo方法的典型用法代码示例。如果您正苦于以下问题:C++ BMimeType::SetTo方法的具体用法?C++ BMimeType::SetTo怎么用?C++ BMimeType::SetTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BMimeType
的用法示例。
在下文中一共展示了BMimeType::SetTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExternalProtocolHandlerExists
NS_IMETHODIMP nsOSHelperAppService::ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists)
{
LOG(("-- nsOSHelperAppService::ExternalProtocolHandlerExists for '%s'\n",
aProtocolScheme));
// look up the protocol scheme in the MIME database
*aHandlerExists = PR_FALSE;
if (aProtocolScheme && *aProtocolScheme)
{
BString protoStr(aProtocolScheme);
protoStr.Prepend("application/x-vnd.Be.URL.");
BMimeType protocol;
if (protocol.SetTo(protoStr.String()) == B_OK)
{
if (protocol.IsInstalled())
*aHandlerExists = PR_TRUE;
}
if ((!*aHandlerExists) && (!strcmp("mailto", aProtocolScheme)))
{
// mailto link, no x-vnd.Be.URL.mailto entry
if (protocol.SetTo("text/x-email") == B_OK)
{
if (protocol.IsInstalled())
*aHandlerExists = PR_TRUE;
}
}
}
return NS_OK;
}
示例2: GetSupportedTypes
/*! \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);
// get the supported types
BMessage types;
if (error == B_OK)
error = GetSupportedTypes(&types);
// turn type into a BMimeType
BMimeType mimeType;
if (error == B_OK)
error = mimeType.SetTo(type);
// iterate through the supported types
bool found = false;
if (error == B_OK) {
const char *supportedType;
for (int32 i = 0;
!found && types.FindString("types", i, &supportedType) == B_OK;
i++) {
found = !strcmp(supportedType, "application/octet-stream")
|| BMimeType(supportedType).Contains(&mimeType);
}
}
return found;
}
示例3:
/*! \brief Returns a list of all currently installed types of the given
supertype in the pre-allocated \c BMessage pointed to by \c types.
See \c BMimeType::GetInstalledTypes(const char*, BMessage*) for more
information.
*/
status_t
InstalledTypes::GetInstalledTypes(const char *supertype, BMessage *types)
{
if (supertype == NULL || types == NULL)
return B_BAD_VALUE;
// Verify the supertype is valid *and* is a supertype
BMimeType mime;
BMimeType super;
// Make sure the supertype is valid
status_t err = mime.SetTo(supertype);
// Make sure it's really a supertype
if (!err && !mime.IsSupertypeOnly())
err = B_BAD_VALUE;
// See if we need to do our initial build still
if (!err && !fHaveDoneFullBuild)
err = _BuildInstalledTypesList();
// Ask the appropriate supertype for its list
if (!err) {
std::map<std::string, Supertype>::iterator i = fSupertypes.find(supertype);
if (i != fSupertypes.end())
err = i->second.GetInstalledSubtypes(types);
else
err = B_NAME_NOT_FOUND;
}
return err;
}
示例4: LoadUriInternal
nsresult nsOSHelperAppService::LoadUriInternal(nsIURI * aURL)
{
LOG(("-- nsOSHelperAppService::LoadUrl\n"));
nsresult rv = NS_OK;
if (aURL) {
// Get the Protocol
nsCAutoString scheme;
aURL->GetScheme(scheme);
BString protoStr(scheme.get());
protoStr.Prepend("application/x-vnd.Be.URL.");
// Get the Spec
nsCAutoString spec;
aURL->GetSpec(spec);
const char* args[] = { spec.get() };
//Launch the app
BMimeType protocol;
bool isInstalled = false;
if (protocol.SetTo(protoStr.String()) == B_OK)
{
if(protocol.IsInstalled())
{
isInstalled = true;
be_roster->Launch(protoStr.String(), NS_ARRAY_LENGTH(args), (char **)args);
}
}
if ((!isInstalled) && (!strcmp("mailto", scheme.get())))
be_roster->Launch("text/x-email", NS_ARRAY_LENGTH(args), (char **)args);
}
return rv;
}
示例5: MimeType
void TorrentObject::MimeType(BMimeType& mime)
{
mime.SetTo(B_DIRECTORY_MIME_TYPE);
if( !IsFolder() && !IsMagnet() )
BMimeType::GuessMimeType(Info()->files[0].name, &mime);
}
示例6:
void
ExtensionListView::SetType(BMimeType* type)
{
if (type != NULL)
fType.SetTo(type->Type());
else
fType.Unset();
}
示例7:
// Fetches a \c BMessage containing a list of MIME signatures of
// applications that are able to handle files of any type.
status_t
BMimeType::GetWildcardApps(BMessage* wild_ones)
{
BMimeType mime;
status_t err = mime.SetTo("application/octet-stream");
if (err == B_OK)
err = mime.GetSupportingApps(wild_ones);
return err;
}
示例8:
status_t
IconView::GetMimeType(BMimeType& type) const
{
if (!fHasType)
return B_BAD_TYPE;
type.SetTo(fType.Type());
return B_OK;
}
示例9: file
void
TBarApp::FetchAppIcon(BarTeamInfo* barInfo)
{
int32 width = IconSize();
int32 index = (width - kMinimumIconSize) / kIconSizeInterval;
// first look in the icon cache
barInfo->icon = barInfo->iconCache[index];
if (barInfo->icon != NULL)
return;
// icon wasn't in cache, get it from be_roster and cache it
app_info appInfo;
icon_size size = width >= 31 ? B_LARGE_ICON : B_MINI_ICON;
BBitmap* icon = new BBitmap(IconRect(), kIconColorSpace);
if (be_roster->GetAppInfo(barInfo->sig, &appInfo) == B_OK) {
// fetch the app icon
BFile file(&appInfo.ref, B_READ_ONLY);
BAppFileInfo appMime(&file);
if (appMime.GetIcon(icon, size) == B_OK) {
delete barInfo->iconCache[index];
barInfo->iconCache[index] = barInfo->icon = icon;
return;
}
}
// couldn't find the app icon
// fetch the generic 3 boxes icon and cache it
BMimeType defaultAppMime;
defaultAppMime.SetTo(B_APP_MIME_TYPE);
if (defaultAppMime.GetIcon(icon, size) == B_OK) {
delete barInfo->iconCache[index];
barInfo->iconCache[index] = barInfo->icon = icon;
return;
}
// couldn't find generic 3 boxes icon
// fill with transparent
uint8* iconBits = (uint8*)icon->Bits();
if (icon->ColorSpace() == B_RGBA32) {
int32 i = 0;
while (i < icon->BitsLength()) {
iconBits[i++] = B_TRANSPARENT_32_BIT.red;
iconBits[i++] = B_TRANSPARENT_32_BIT.green;
iconBits[i++] = B_TRANSPARENT_32_BIT.blue;
iconBits[i++] = B_TRANSPARENT_32_BIT.alpha;
}
} else {
// Assume B_CMAP8
for (int32 i = 0; i < icon->BitsLength(); i++)
iconBits[i] = B_TRANSPARENT_MAGIC_CMAP8;
}
delete barInfo->iconCache[index];
barInfo->iconCache[index] = barInfo->icon = icon;
}
示例10: checkMimeTypes
void checkMimeTypes()
{
BMimeType mime;
mime.SetTo("application/x-vnd.BeServed-fileserver");
mime.Delete();
if (!mime.IsInstalled())
{
mime.Install();
mime.SetShortDescription("Network File Server");
mime.SetLongDescription("A network server running BeServed");
setMimeIcon(&mime, MYNET_ICON_HOST_LARGE, B_LARGE_ICON);
setMimeIcon(&mime, MYNET_ICON_HOST_SMALL, B_MINI_ICON);
}
mime.SetTo("application/x-vnd.BeServed-inetserver");
mime.Delete();
if (!mime.IsInstalled())
{
mime.Install();
mime.SetShortDescription("Public File Server");
mime.SetLongDescription("A remote network server running BeServed");
setMimeIcon(&mime, MYNET_ICON_INETHOST_LARGE, B_LARGE_ICON);
setMimeIcon(&mime, MYNET_ICON_INETHOST_SMALL, B_MINI_ICON);
}
mime.SetTo("application/x-vnd.BeServed-fileshare");
mime.Delete();
if (!mime.IsInstalled())
{
mime.Install();
mime.SetShortDescription("Shared Volume");
mime.SetLongDescription("A BeServed network shared volume");
setMimeIcon(&mime, MYNET_ICON_SHARE_LARGE, B_LARGE_ICON);
setMimeIcon(&mime, MYNET_ICON_SHARE_SMALL, B_MINI_ICON);
}
}
示例11: file
void
TBarApp::FetchAppIcon(const char* signature, BBitmap* icon)
{
app_info appInfo;
icon_size size = icon->Bounds().IntegerHeight() >= 32
? B_LARGE_ICON : B_MINI_ICON;
if (be_roster->GetAppInfo(signature, &appInfo) == B_OK) {
// fetch the app icon
BFile file(&appInfo.ref, B_READ_ONLY);
BAppFileInfo appMime(&file);
if (appMime.GetIcon(icon, size) == B_OK)
return;
}
// couldn't find the app icon
// fetch the generic 3 boxes icon
BMimeType defaultAppMime;
defaultAppMime.SetTo(B_APP_MIME_TYPE);
if (defaultAppMime.GetIcon(icon, size) == B_OK)
return;
// couldn't find generic 3 boxes icon
// fill with transparent
uint8* iconBits = (uint8*)icon->Bits();
if (icon->ColorSpace() == B_RGBA32) {
int32 i = 0;
while (i < icon->BitsLength()) {
iconBits[i++] = B_TRANSPARENT_32_BIT.red;
iconBits[i++] = B_TRANSPARENT_32_BIT.green;
iconBits[i++] = B_TRANSPARENT_32_BIT.blue;
iconBits[i++] = B_TRANSPARENT_32_BIT.alpha;
}
} else {
// Assume B_CMAP8
for (int32 i = 0; i < icon->BitsLength(); i++)
iconBits[i] = B_TRANSPARENT_MAGIC_CMAP8;
}
}
示例12: node
bool
FileIterator::_ExamineFile(BEntry& entry, char* buffer, bool textFilesOnly)
{
BPath path;
if (entry.GetPath(&path) != B_OK)
return false;
strcpy(buffer, path.Path());
if (!textFilesOnly)
return true;
BMimeType mimeType;
BNode node(&entry);
BNodeInfo nodeInfo(&node);
char mimeTypeString[B_MIME_TYPE_LENGTH];
if (nodeInfo.GetType(mimeTypeString) != B_OK) {
// try to get a MIME type before failing
if (BMimeType::GuessMimeType(path.Path(), &mimeType) != B_OK)
return false;
nodeInfo.SetType(mimeType.Type());
} else
mimeType.SetTo(mimeTypeString);
BMimeType superType;
if (mimeType.GetSupertype(&superType) == B_OK) {
if (strcmp("text", superType.Type()) == 0
|| strcmp("message", superType.Type()) == 0) {
return true;
}
}
return false;
}
示例13: extStr
CFtpDialog::CFtpDialog(BRect frame, const char *name, window_type type, int flags,
BWindow *owner)
: HDialog(frame, name, type, flags, owner, NULL)
{
fReply = new char[1024];
fPath = new char[PATH_MAX];
fSave = false;
fSocket = -1;
Create();
Layout();
#if 0
// Build Extension->Mimetype list // Takes looong
typedef pair<string,string> entry;
BMessage mimDat;
BMessage extDat;
BMimeType mimTyp;
int32 mimIdx = -1;
int32 extIdx = 0;
const char* mimCStr;
const char* extCStr;
if (BMimeType::GetInstalledTypes(&mimDat) == B_OK) {
while (mimDat.FindString("types", ++mimIdx, &mimCStr) == B_OK) {
if ((mimTyp.SetTo(mimCStr) == B_OK) && (mimTyp.GetFileExtensions(&extDat) == B_OK)) {
extIdx = -1;
while (extDat.FindString("extensions", ++extIdx, &extCStr) == B_OK) {
BString extStr(extCStr);
extStr.ToLower();
if (extStr.ByteAt(0) == '.') extStr.Remove(0, 1);
fExtMime[extCStr] = mimCStr;
}
}
}
}
#else
// perhaps it's better to go with some predefiend types:
fExtMime["aiff"] = "audio/x-aiff";
fExtMime["bz2"] = "application/x-bzip2";
fExtMime["cc"] = "text/x-source-code";
fExtMime["cpp"] = "text/x-source-code";
fExtMime["css"] = "text/css";
fExtMime["gif"] = "image/gif";
fExtMime["gz"] = "application/x-gzip";
fExtMime["h"] = "text/x-source-code";
fExtMime["htm"] = "text/html";
fExtMime["html"] = "text/html";
fExtMime["jpeg"] = "image/jpeg";
fExtMime["jpg"] = "image/jpeg";
fExtMime["mod"] = "audio/x-mod";
fExtMime["mov"] = "video/quicktime";
fExtMime["mp3"] = "audio/x-mpeg";
fExtMime["ogg"] = "audio/ogg.vorbis";
fExtMime["pdf"] = "application/pdf";
fExtMime["php"] = "text/x-php";
fExtMime["pl"] = "text/x-perl";
fExtMime["pkg"] = "application/x-scode-UPkg";
fExtMime["png"] = "image/png";
fExtMime["py"] = "text/x-source-code";
fExtMime["rar"] = "application/x-rar";
fExtMime["swf"] = "application/x-shockwave-flash";
fExtMime["tar"] = "application/x-tar";
fExtMime["tga"] = "image/x-targa";
fExtMime["tgz"] = "application/x-gzip";
fExtMime["txt"] = "text/plain";
fExtMime["xml"] = "text/xml";
fExtMime["zip"] = "application/zip";
#endif
} // CFtpDialog::CFtpDialog
示例14: BPopUpMenu
void
TestView::SetupTestMenu(void)
{
// These ones will always exist. Type is the default because it's probably
// going to be the one most used
BMessage *msg;
BPopUpMenu *menu = new BPopUpMenu("Test");
// Read in the types in the MIME database which have extra attributes
// associated with them
BMimeType mime;
BMessage types, info, attr;
BString string;
BMimeType::GetInstalledTypes(&types);
int32 index = 0;
while (types.FindString("types",index,&string) == B_OK)
{
index++;
mime.SetTo(string.String());
if (mime.GetAttrInfo(&info) != B_OK)
continue;
int32 infoindex = 0;
BString attrName;
BString attrPublicName;
int32 attrType;
char attrTypeName[B_MIME_TYPE_LENGTH];
mime.GetShortDescription(attrTypeName);
while (info.FindString("attr:name",infoindex,&attrName) == B_OK)
{
// This is where we create tests based on a particular type's "special" attributes
// Just string attributes are supported for now
if (info.FindInt32("attr:type",infoindex,&attrType) != B_OK ||
attrType != B_STRING_TYPE ||
info.FindString("attr:public_name",infoindex,&attrPublicName) != B_OK)
{
infoindex++;
continue;
}
BMenu *submenu = GetMenu(menu,attrTypeName);
if (!submenu)
submenu = AddMenuSorted(menu,attrTypeName);
msg = new BMessage(M_TEST_CHOSEN);
msg->AddString("name","Attribute");
msg->AddString("attrtype",attrName);
msg->AddString("attrname",attrPublicName);
msg->AddString("mimetype",string);
msg->AddString("typename",attrTypeName);
submenu->AddItem(new BMenuItem(attrPublicName.String(),msg));
infoindex++;
}
}
menu->AddItem(new BSeparatorItem(),0);
// All this weirdness is to have the "standard" tests at the top and
// the attribute tests at the bottom with a separator in between
BString testtype;
int32 i = 0;
while (fTestTypes.FindString("tests",i,&testtype) == B_OK)
i++;
i--;
while (i >= 0)
{
fTestTypes.FindString("tests",i,&testtype);
msg = new BMessage(M_TEST_CHOSEN);
msg->AddString("name",testtype);
menu->AddItem(new BMenuItem(testtype.String(),msg),0);
i--;
}
menu->Archive(&fArchivedTestMenu);
delete menu;
}
示例15: 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);
}