コード例 #1
0
void
MimeTypeListView::_CollectSubtypes(const char* supertype,
	MimeTypeItem* supertypeItem)
{
	BMessage types;
	if (BMimeType::GetInstalledTypes(supertype, &types) != B_OK)
		return;

	const char* type;
	int32 index = 0;
	while (types.FindString("types", index++, &type) == B_OK) {
		BMimeType mimeType(type);

		bool isApp = mimetype_is_application_signature(mimeType);
		if (fApplicationMode ^ isApp)
			continue;

		MimeTypeItem* typeItem = new MimeTypeItem(mimeType, fShowIcons,
			supertypeItem == NULL);
		typeItem->SetApplicationMode(isApp);

		if (supertypeItem != NULL)
			AddUnder(typeItem, supertypeItem);
		else
			AddItem(typeItem);
	}
}
コード例 #2
0
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 = "";
	}
}