예제 #1
0
void
InitFileTypes(void)
{
	BMimeType mime;
	BString string;
	BMessage msg,ext;
	
	BBitmap	large_icon(BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1), B_COLOR_8_BIT);
	memcpy(large_icon.Bits(),kProjectLargeIconBits,1024);
	BBitmap	mini_icon(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_COLOR_8_BIT);
	memcpy(mini_icon.Bits(),kProjectSmallIconBits,256);
	
	mime.SetType(PROJECT_MIME_TYPE);
	mime.SetShortDescription(TR("Paladin Project"));
	mime.SetLongDescription(TR("File to build a program with Paladin"));
	mime.SetIcon(&large_icon, B_LARGE_ICON);
	mime.SetIcon(&mini_icon, B_MINI_ICON);
	
	#ifdef __HAIKU__
	mime.SetIcon(kProjectVectorIconBits, sizeof(kProjectVectorIconBits));
	#endif
	
	mime.SetSnifferRule("0.50  [0:32]( -i \"NAME=\" | \"TARGETNAME=\" | "
						"\"PLATFORM=\" | \"GROUP=\" | \"SOURCEFILE=\")");
	mime.SetPreferredApp(APP_SIGNATURE);
	mime.Install();
	
	ext.AddString("extensions","pld");
	mime.SetFileExtensions(&ext);
}
예제 #2
0
//! 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);
}