void UAE::RegisterMimeTypes() { /*** register the configuration MimeType ***/ BMimeType mimeType(kConfigurationMIMEType); if (mimeType.InitCheck() != B_OK) return; if (mimeType.IsInstalled()) // work has already been done { mimeType.SetPreferredApp(kApplicationSignature,B_OPEN); mimeType.SetShortDescription("UAE configuration"); } BBitmap largeIcon(BRect(0, 0, 31, 31), B_COLOR_8_BIT); BBitmap miniIcon(BRect(0, 0, 15, 15), B_COLOR_8_BIT); if (mimeType.GetIcon(&largeIcon,B_LARGE_ICON) != B_OK) // no large icon { if (GetIconResource("uae:ConfigIcon",B_LARGE_ICON,&largeIcon) == B_OK) mimeType.SetIcon(&largeIcon, B_LARGE_ICON); } if (mimeType.GetIcon(&miniIcon,B_MINI_ICON) != B_OK) // no mini icon { if (GetIconResource("uae:ConfigIcon",B_MINI_ICON,&miniIcon) == B_OK) mimeType.SetIcon(&miniIcon, B_MINI_ICON); } }
bool TTracker::InstallMimeIfNeeded(const char *type, int32 bitsID, const char *shortDescription, const char *longDescription, const char *preferredAppSignature, uint32 forceMask) { // used by InitMimeTypes - checks if a metamime of a given <type> is // installed and if it has all the specified attributes; if not, the // whole mime type is installed and all attributes are set; nulls can // be passed for attributes that don't matter; returns true if anything // had to be changed BBitmap largeIcon(BRect(0, 0, 31, 31), B_CMAP8); BBitmap miniIcon(BRect(0, 0, 15, 15), B_CMAP8); char tmp[B_MIME_TYPE_LENGTH]; BMimeType mime(type); bool installed = mime.IsInstalled(); if (!installed || (bitsID >= 0 && ((forceMask & kForceLargeIcon) || mime.GetIcon(&largeIcon, B_LARGE_ICON) != B_OK)) || (bitsID >= 0 && ((forceMask & kForceMiniIcon) || mime.GetIcon(&miniIcon, B_MINI_ICON) != B_OK)) || (shortDescription && ((forceMask & kForceShortDescription) || mime.GetShortDescription(tmp) != B_OK)) || (longDescription && ((forceMask & kForceLongDescription) || mime.GetLongDescription(tmp) != B_OK)) || (preferredAppSignature && ((forceMask & kForcePreferredApp) || mime.GetPreferredApp(tmp) != B_OK))) { if (!installed) mime.Install(); if (bitsID >= 0) { if (GetTrackerResources()-> GetIconResource(bitsID, B_LARGE_ICON, &largeIcon) == B_OK) mime.SetIcon(&largeIcon, B_LARGE_ICON); if (GetTrackerResources()-> GetIconResource(bitsID, B_MINI_ICON, &miniIcon) == B_OK) mime.SetIcon(&miniIcon, B_MINI_ICON); } if (shortDescription) mime.SetShortDescription(shortDescription); if (longDescription) mime.SetLongDescription(longDescription); if (preferredAppSignature) mime.SetPreferredApp(preferredAppSignature); return true; } return false; }
status_t CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref* ref, bool* _entryIsDir) { if (ref == NULL) return B_BAD_VALUE; BNode typeNode; BFile file; status_t status = file.SetTo(ref, B_READ_ONLY); if (status < B_OK) return status; bool isDir = file.IsDirectory(); if (_entryIsDir != NULL) *_entryIsDir = isDir; if (isDir) return B_OK; BAppFileInfo appInfo(&file); status = appInfo.InitCheck(); if (status < B_OK) return status; // Read the app sig (which consequently keeps us from updating // non-applications, since we get an error if the file has no // app sig) BString signature; status = file.ReadAttrString("BEOS:APP_SIG", &signature); if (status < B_OK) return B_BAD_TYPE; // Init our various objects BMimeType mime; status = mime.SetTo(signature.String()); if (status < B_OK) return status; InstallNotificationDeferrer _(fDatabase, signature.String()); if (!mime.IsInstalled()) mime.Install(); BString path = "/"; path.Append(signature); path.ToLower(); // Signatures and MIME types are case insensitive, but we want to // preserve the case wherever possible path.Prepend(get_database_directory().c_str()); status = typeNode.SetTo(path.String()); if (status < B_OK) return status; // Preferred App attr_info info; if (status == B_OK && (fForce || typeNode.GetAttrInfo(kPreferredAppAttr, &info) != B_OK)) status = mime.SetPreferredApp(signature.String()); // Short Description (name of the application) if (status == B_OK && (fForce || typeNode.GetAttrInfo(kShortDescriptionAttr, &info) != B_OK)) status = mime.SetShortDescription(ref->name); // App Hint if (status == B_OK && (fForce || typeNode.GetAttrInfo(kAppHintAttr, &info) != B_OK)) status = mime.SetAppHint(ref); // Vector Icon if (status == B_OK && (fForce || typeNode.GetAttrInfo(kIconAttr, &info) != B_OK)) { uint8* data = NULL; size_t size = 0; if (appInfo.GetIcon(&data, &size) == B_OK) { status = mime.SetIcon(data, size); free(data); } } // Mini Icon BBitmap miniIcon(BRect(0, 0, 15, 15), B_BITMAP_NO_SERVER_LINK, B_CMAP8); if (status == B_OK && (fForce || typeNode.GetAttrInfo(kMiniIconAttr, &info) != B_OK)) { if (appInfo.GetIcon(&miniIcon, B_MINI_ICON) == B_OK) status = mime.SetIcon(&miniIcon, B_MINI_ICON); } // Large Icon BBitmap largeIcon(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK, B_CMAP8); if (status == B_OK && (fForce || typeNode.GetAttrInfo(kLargeIconAttr, &info) != B_OK)) { if (appInfo.GetIcon(&largeIcon, B_LARGE_ICON) == B_OK) status = mime.SetIcon(&largeIcon, B_LARGE_ICON); } // Supported Types bool setSupportedTypes = false; BMessage supportedTypes; if (status == B_OK && (fForce || typeNode.GetAttrInfo(kSupportedTypesAttr, &info) != B_OK)) { if (appInfo.GetSupportedTypes(&supportedTypes) == B_OK) setSupportedTypes = true; } // defer notifications for supported types const char* type; for (int32 i = 0; supportedTypes.FindString("types", i, &type) == B_OK; i++) fDatabase->DeferInstallNotification(type); // set supported types if (setSupportedTypes) status = mime.SetSupportedTypes(&supportedTypes); // Icons for supported types for (int32 i = 0; supportedTypes.FindString("types", i, &type) == B_OK; i++) { // vector icon uint8* data = NULL; size_t size = 0; if (status == B_OK && appInfo.GetIconForType(type, &data, &size) == B_OK) { status = mime.SetIconForType(type, data, size); free(data); } // mini icon if (status == B_OK && appInfo.GetIconForType(type, &miniIcon, B_MINI_ICON) == B_OK) status = mime.SetIconForType(type, &miniIcon, B_MINI_ICON); // large icon if (status == B_OK && appInfo.GetIconForType(type, &largeIcon, B_LARGE_ICON) == B_OK) status = mime.SetIconForType(type, &largeIcon, B_LARGE_ICON); } // undefer notifications for supported types for (int32 i = 0; supportedTypes.FindString("types", i, &type) == B_OK; i++) fDatabase->UndeferInstallNotification(type); return status; }