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; }
status_t icon_for_type(const BMimeType& type, BBitmap& bitmap, icon_size size, icon_source* _source) { icon_source source = kNoIcon; if (type.GetIcon(&bitmap, 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(), &bitmap, 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(&bitmap, 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(), &bitmap, size) == B_OK) source = kSupertypeIcon; } } } } if (_source) *_source = source; return source != kNoIcon ? B_OK : B_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); }
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; }
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; }
BMenu* PieView::_BuildOpenWithMenu(FileInfo* info) { vector<AppMenuItem*> appList; // Get preferred app. BMimeType* type = info->Type(); char appSignature[B_MIME_TYPE_LENGTH]; if (type->GetPreferredApp(appSignature) == B_OK) _AddAppToList(appList, appSignature, 1); // Get apps that handle this subtype and supertype. BMessage msg; if (type->GetSupportingApps(&msg) == B_OK) { int32 subs, supers, i; msg.FindInt32("be:sub", &subs); msg.FindInt32("be:super", &supers); const char* appSig; for (i = 0; i < subs; i++) { msg.FindString("applications", i, &appSig); _AddAppToList(appList, appSig, 2); } int hold = i; for (i = 0; i < supers; i++) { msg.FindString("applications", i + hold, &appSig); _AddAppToList(appList, appSig, 3); } } // Get apps that handle any type. if (BMimeType::GetWildcardApps(&msg) == B_OK) { const char* appSig; for (int32 i = 0; true; i++) { if (msg.FindString("applications", i, &appSig) == B_OK) _AddAppToList(appList, appSig, 4); else break; } } delete type; BMenu* openWith = new BMenu(B_TRANSLATE("Open With")); if (appList.size() == 0) { BMenuItem* item = new BMenuItem(B_TRANSLATE("no supporting apps"), NULL); item->SetEnabled(false); openWith->AddItem(item); } else { vector<AppMenuItem*>::iterator i = appList.begin(); int category = (*i)->Category(); while (i != appList.end()) { if (category != (*i)->Category()) { openWith->AddSeparatorItem(); category = (*i)->Category(); } openWith->AddItem(*i); i++; } } return openWith; }