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; }
void DockItem::GetGenericIcon( void ) { if ( IsFolder() ) { BMimeType type; type.SetType( "application/x-vnd.Be-directory" ); type.GetIcon( mLargeIcon, B_LARGE_ICON ); type.GetIcon( mSmallIcon, B_MINI_ICON ); } else { app_info appInfo; BFile appFile; BAppFileInfo appFileInfo; be_app->GetAppInfo( &appInfo ); appFile.SetTo( &appInfo.ref, B_READ_WRITE ); appFileInfo.SetTo( &appFile ); appFileInfo.GetIconForType( "application/x-be-executable", mLargeIcon, B_LARGE_ICON ); appFileInfo.GetIconForType( "application/x-be-executable", mSmallIcon, B_MINI_ICON ); /* BMimeType appType; appType.SetType( "application/x-vnd.HK-LaunchPad" ); appType.GetIcon( mLargeIcon, B_LARGE_ICON ); appType.GetIcon( mSmallIcon, B_MINI_ICON ); */ } }
/*! Determines if the data in \a inSource is of the UTF8 plain \param data buffer containing data already read (must be at least DATA_BUFFER_SIZE bytes large) \param nread number of bytes that have already been read from the stream \param header the STXT stream header read in by Identify() or Translate() \param inSource the stream with the STXT data \param outInfo information about the type of data from inSource is stored here \param outType the desired output type for the data in inSource */ status_t identify_text(uint8* data, int32 bytesRead, BPositionIO* source, translator_info* outInfo, uint32 outType, const char*& encoding) { ssize_t readLater = source->Read(data + bytesRead, DATA_BUFFER_SIZE - bytesRead); if (readLater < B_OK) return B_NO_TRANSLATOR; bytesRead += readLater; // TODO: identify encoding as possible! BMimeType type; if (!file_ascmagic((const unsigned char*)data, bytesRead, &type, encoding)) return B_NO_TRANSLATOR; float capability = TEXT_IN_CAPABILITY; if (bytesRead < 20) capability = .1f; // return information about the data in the stream outInfo->type = B_TRANSLATOR_TEXT; outInfo->group = B_TRANSLATOR_TEXT; outInfo->quality = TEXT_IN_QUALITY; outInfo->capability = capability; char description[B_MIME_TYPE_LENGTH]; if (type.GetLongDescription(description) == B_OK) strlcpy(outInfo->name, description, sizeof(outInfo->name)); else strlcpy(outInfo->name, "Plain text file", sizeof(outInfo->name)); //strlcpy(outInfo->MIME, type.Type(), sizeof(outInfo->MIME)); strcpy(outInfo->MIME, "text/plain"); return B_OK; }
IconMenuItem::IconMenuItem(BMenu* submenu, BMessage* message, const char* iconType, icon_size which) : PositionPassingMenuItem(submenu, message), fDeviceIcon(NULL), fHeightDelta(0), fWhich(which) { BMimeType mime(iconType); fDeviceIcon = new BBitmap(BRect(0, 0, which - 1, which - 1), kDefaultIconDepth); if (mime.GetIcon(fDeviceIcon, which) != B_OK) { BMimeType super; mime.GetSupertype(&super); if (super.GetIcon(fDeviceIcon, which) != B_OK) { delete fDeviceIcon; fDeviceIcon = NULL; } } // IconMenuItem is used in synchronously invoked menus, make sure // we invoke with a timeout SetTimeout(kSynchMenuInvokeTimeout); }
/*! \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; }
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; }
/*! \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; }
void ExtensionListView::SetType(BMimeType* type) { if (type != NULL) fType.SetTo(type->Type()); else fType.Unset(); }
MimeTypeItem::MimeTypeItem(BMimeType& type, bool showIcon, bool flat) : BStringItem(type.Type(), !flat && !type.IsSupertypeOnly() ? 1 : 0, false), fType(type.Type()), fFlat(flat), fShowIcon(showIcon) { _SetTo(type); }
// Returns whether this and the supplied MIME type are equal bool BMimeType::operator==(const char* type) const { BMimeType mime; if (type) mime.SetTo(type); return (*this) == mime; }
// 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; }
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; }
// Returns whether this and the supplied MIME type are equal bool BMimeType::operator==(const BMimeType &type) const { if (InitCheck() == B_NO_INIT && type.InitCheck() == B_NO_INIT) return true; else if (InitCheck() == B_OK && type.InitCheck() == B_OK) return strcasecmp(Type(), type.Type()) == 0; return false; }
/*! \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) { // 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) { // check param -- supported types must be valid const char *type; for (int32 i = 0; error == B_OK && types->FindString("types", i, &type) == B_OK; i++) { if (!BMimeType::IsValid(type)) error = B_BAD_VALUE; } // get flattened size ssize_t size = 0; if (error == B_OK) { size = types->FlattenedSize(); if (size < 0) error = size; } // allocate a buffer for the flattened data char *buffer = NULL; if (error == B_OK) { buffer = new(nothrow) char[size]; 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()) error = mimeType.SetSupportedTypes(types, syncAll); } return error; }
bool mimetype_is_application_signature(BMimeType& type) { char preferredApp[B_MIME_TYPE_LENGTH]; // The preferred application of an application is the same // as its signature. return type.GetPreferredApp(preferredApp) == B_OK && !strcasecmp(type.Type(), preferredApp); }
status_t Icon::CopyTo(BMimeType& type, bool force) const { status_t status = B_OK; if (fLarge != NULL || force) status = type.SetIcon(fLarge, B_LARGE_ICON); if (fMini != NULL || force) status = type.SetIcon(fMini, B_MINI_ICON); if (fData != NULL || force) status = type.SetIcon(fData, fSize); return status; }
void IconView::SetTo(const BMimeType& type) { Unset(); if (type.Type() == NULL) return; fHasType = true; fType.SetTo(type.Type()); _StartWatching(); Update(); }
void TorrentObject::MimeType(BMimeType& mime) { mime.SetTo(B_DIRECTORY_MIME_TYPE); if( !IsFolder() && !IsMagnet() ) BMimeType::GuessMimeType(Info()->files[0].name, &mime); }
void PieView::_Launch(FileInfo* info, const entry_ref* appRef) { BMessage msg(B_REFS_RECEIVED); msg.AddRef("refs", &info->ref); if (appRef == NULL) { // Let the registrar pick an app based on the file's MIME type. BMimeType* type = info->Type(); be_roster->Launch(type->Type(), &msg); delete type; } else { // Launch a designated app to handle this file. be_roster->Launch(appRef, &msg); } }
/*static*/ BString Playlist::_MIMEString(const entry_ref* ref) { BFile file(ref, B_READ_ONLY); BNodeInfo nodeInfo(&file); char mimeString[B_MIME_TYPE_LENGTH]; if (nodeInfo.GetType(mimeString) != B_OK) { BMimeType type; if (BMimeType::GuessMimeType(ref, &type) != B_OK) return BString(); strlcpy(mimeString, type.Type(), B_MIME_TYPE_LENGTH); nodeInfo.SetType(type.Type()); } return BString(mimeString); }
void CMimeItem::DrawItem(BView *owner, BRect bounds, bool) { BBitmap bm(BRect(0, 0, 15, 15), B_COLOR_8_BIT); if (IsSelected()) { bm.SetBits(fIconSelected, 256, 0, B_COLOR_8_BIT); owner->SetLowColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); } else { bm.SetBits(fIcon, 256, 0, B_COLOR_8_BIT); owner->SetLowColor(kWhite); } BRect r(bounds); owner->FillRect(r, B_SOLID_LOW); r.InsetBy(1, 1); font_height fh; be_plain_font->GetHeight(&fh); owner->SetDrawingMode(B_OP_OVER); owner->DrawBitmap(&bm, BPoint(r.left + 2, r.top)); owner->SetDrawingMode(B_OP_COPY); owner->DrawString(fMime.Type(), BPoint(r.left + 22, r.bottom - fh.descent)); owner->SetLowColor(kWhite); } /* CMimeItem::DrawItem */
void KindAttributeText::ReadValue(BString *result) { BMimeType mime; char desc[B_MIME_TYPE_LENGTH]; // get the mime type if (mime.SetType(fModel->MimeType()) != B_OK) *result = "Unknown"; // get the short mime type description else if (mime.GetShortDescription(desc) == B_OK) *result = desc; else *result = fModel->MimeType(); fValueDirty = false; }
//! newExtensionsList contains all the entries (char*) which are to be added. status_t merge_extensions(BMimeType& type, const BList& newExtensionsList, const char* removeExtension) { BMessage extensions; status_t status = type.GetFileExtensions(&extensions); if (status < B_OK) return status; // replace the entry, and remove any equivalent entries BList mergedList; mergedList.AddList(&newExtensionsList); int32 originalCount = mergedList.CountItems(); const char* extension; for (int32 i = 0; extensions.FindString("extensions", i, &extension) == B_OK; i++) { for (int32 j = originalCount; j-- > 0;) { if (!strcmp((const char*)mergedList.ItemAt(j), extension)) { // Do not add this old item again, since it's already // there. mergedList.RemoveItem(j); originalCount--; } } // The item will be added behind "originalCount", so we cannot // remove it accidentally in the next iterations, it's is added // for good. if (removeExtension == NULL || strcmp(removeExtension, extension)) mergedList.AddItem((void *)extension); } mergedList.SortItems(compare_extensions); // Copy them to a new message (their memory is still part of the // original BMessage) BMessage newExtensions; for (int32 i = 0; i < mergedList.CountItems(); i++) { newExtensions.AddString("extensions", (const char*)mergedList.ItemAt(i)); } return type.SetFileExtensions(&newExtensions); }
status_t icon_for_type(const BMimeType& type, uint8** _data, size_t* _size, icon_source* _source) { if (_data == NULL || _size == NULL) return B_BAD_VALUE; icon_source source = kNoIcon; uint8* data; size_t size; if (type.GetIcon(&data, &size) == B_OK) source = kOwnIcon; if (source == kNoIcon) { // check for icon from preferred app char preferred[B_MIME_TYPE_LENGTH]; if (type.GetPreferredApp(preferred) == B_OK) { BMimeType preferredApp(preferred); if (preferredApp.GetIconForType(type.Type(), &data, &size) == B_OK) source = kApplicationIcon; } } if (source == kNoIcon) { // check super type for an icon BMimeType superType; if (type.GetSupertype(&superType) == B_OK) { if (superType.GetIcon(&data, &size) == B_OK) source = kSupertypeIcon; else { // check the super type's preferred app char preferred[B_MIME_TYPE_LENGTH]; if (superType.GetPreferredApp(preferred) == B_OK) { BMimeType preferredApp(preferred); if (preferredApp.GetIconForType(superType.Type(), &data, &size) == B_OK) source = kSupertypeIcon; } } } } if (source != kNoIcon) { *_data = data; *_size = size; } // NOTE: else there is no data, so nothing is leaked. if (_source) *_source = source; return source != kNoIcon ? B_OK : B_ERROR; }
void KindAttributeText::ReadValue(BString* outString) { BMimeType mime; char desc[B_MIME_TYPE_LENGTH]; // get the mime type if (mime.SetType(fModel->MimeType()) != B_OK) *outString = B_TRANSLATE("Unknown"); else if (mime.GetShortDescription(desc) == B_OK) { // get the short mime type description *outString = desc; } else *outString = fModel->MimeType(); fValueDirty = false; }
void MimeTypeListView::_AddNewType(const char* type) { MimeTypeItem* item = FindItem(type); BMimeType mimeType(type); bool isApp = mimetype_is_application_signature(mimeType); if (fApplicationMode ^ isApp || !mimeType.IsInstalled()) { if (item != NULL) { // type doesn't belong here RemoveItem(item); delete item; } return; } if (item != NULL) { // for some reason, the type already exists return; } BMimeType superType; MimeTypeItem* superItem = NULL; if (mimeType.GetSupertype(&superType) == B_OK) superItem = FindItem(superType.Type()); item = new MimeTypeItem(mimeType, fShowIcons, fSupertype.Type() != NULL); if (item->IsSupertypeOnly()) item->ShowIcon(false); item->SetApplicationMode(isApp); if (superItem != NULL) { AddUnder(item, superItem); InvalidateItem(IndexOf(superItem)); // the super item is not picked up from the class (ie. bug) } else AddItem(item); UpdateItem(item); if (!fSelectNewType.ICompare(mimeType.Type())) { SelectItem(item); fSelectNewType = ""; } }
status_t IconView::GetMimeType(BMimeType& type) const { if (!fHasType) return B_BAD_TYPE; type.SetTo(fType.Type()); return B_OK; }
status_t IconView::SetIcon(const char* mimeTypeString) { if (!mimeTypeString) return B_BAD_VALUE; // get type icon BMimeType mimeType(mimeTypeString); status_t status = mimeType.GetIcon(fIconBitmap, B_LARGE_ICON); // get supertype icon if (status != B_OK) { BMimeType superType; status = mimeType.GetSupertype(&superType); if (status == B_OK) status = superType.GetIcon(fIconBitmap, B_LARGE_ICON); } return status; }
ShortMimeInfo::ShortMimeInfo(const BMimeType& mimeType) : fCommonMimeType(true) { fPrivateName = mimeType.Type(); char buffer[B_MIME_TYPE_LENGTH]; // weed out apps - their preferred handler is themselves if (mimeType.GetPreferredApp(buffer) == B_OK && fPrivateName.ICompare(buffer) == 0) { fCommonMimeType = false; } // weed out metamimes without a short description if (mimeType.GetShortDescription(buffer) != B_OK || buffer[0] == 0) fCommonMimeType = false; else fShortDescription = buffer; }
void buildMimeDB() { BMimeType mime; BMessage msg; char *data; ssize_t bytes; FILE *fp = fopen("/boot/home/mime.txt", "w"); mime.GetInstalledTypes(&msg); for (int i = 0; msg.FindString("types", i, (const char **) &data) == B_OK; i++) { BMimeType t(data); BMessage m; char *ext; if (t.GetFileExtensions(&m) == B_OK) { for (int j = 0; m.FindString("extensions", j, (const char **) &ext) == B_OK; j++) fprintf(fp, "%-6s%s\n", ext, data); } } fclose(fp); }