Example #1
0
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;
}
Example #2
0
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;
}
Example #3
0
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;
}
Example #4
0
void
SearchForSignatureEntryList::RelationDescription(const BMessage* entriesToOpen,
	const Model* applicationModel, BString* description,
	const entry_ref* preferredApp, const entry_ref* preferredAppForFile)
{
	for (int32 index = 0; ;index++) {
		entry_ref ref;
		if (entriesToOpen->FindRef("refs", index, &ref) != B_OK)
			break;

		if (preferredAppForFile && ref == *preferredAppForFile) {
			description->SetTo(B_TRANSLATE("Preferred for file"));
			return;
		}

		Model model(&ref, true, true);
		if (model.InitCheck())
			continue;

		BMimeType mimeType;
		int32 result = Relation(&model, applicationModel);
		switch (result) {
			case kDoesNotSupportType:
				continue;

			case kSuperhandler:
				description->SetTo(B_TRANSLATE("Handles any file"));
				return;

			case kSupportsSupertype:
			{
				mimeType.SetTo(model.MimeType());
				// status_t result = mimeType.GetSupertype(&mimeType);

				char* type = (char*)mimeType.Type();
				char* tmp = strchr(type, '/');
				if (tmp != NULL)
					*tmp = '\0';

				//PRINT(("getting supertype for %s, result %s, got %s\n",
				//	model.MimeType(), strerror(result), mimeType.Type()));
				description->SetTo(B_TRANSLATE("Handles any %type"));
				//*description += mimeType.Type();
				description->ReplaceFirst("%type", type);
				return;
			}

			case kSupportsType:
			{
				mimeType.SetTo(model.MimeType());

				if (preferredApp != NULL
					&& *applicationModel->EntryRef() == *preferredApp) {
					// application matches cached preferred app, we are done
					description->SetTo(B_TRANSLATE("Preferred for %type"));
				} else
					description->SetTo(B_TRANSLATE("Handles %type"));

				char shortDescription[256];
				if (mimeType.GetShortDescription(shortDescription) == B_OK)
					description->ReplaceFirst("%type", shortDescription);
				else
					description->ReplaceFirst("%type", mimeType.Type());

				return;
			}
		}
	}

	description->SetTo(B_TRANSLATE("Does not handle file"));
}
Example #5
0
void
ImageFilePanel::SelectionChanged()
{
	entry_ref ref;
	Rewind();

	if (GetNextSelectedRef(&ref) == B_OK) {
		BEntry entry(&ref);
		BNode node(&ref);
		fImageView->ClearViewBitmap();

		if (node.IsFile()) {
			BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref);

			if (bitmap != NULL) {
				BRect dest(fImageView->Bounds());
				if (bitmap->Bounds().Width() > bitmap->Bounds().Height()) {
					dest.InsetBy(0, (dest.Height() + 1
						- ((bitmap->Bounds().Height() + 1)
						/ (bitmap->Bounds().Width() + 1)
						* (dest.Width() + 1))) / 2);
				} else {
					dest.InsetBy((dest.Width() + 1
						- ((bitmap->Bounds().Width() + 1)
						/ (bitmap->Bounds().Height() + 1)
						* (dest.Height() + 1))) / 2, 0);
				}
				fImageView->SetViewBitmap(bitmap, bitmap->Bounds(), dest,
					B_FOLLOW_LEFT | B_FOLLOW_TOP, 0);

				BString resolution;
				resolution << B_TRANSLATE("Resolution: ")
					<< (int)(bitmap->Bounds().Width() + 1)
					<< "x" << (int)(bitmap->Bounds().Height() + 1);
				fResolutionView->SetText(resolution.String());
				delete bitmap;

				BNodeInfo nodeInfo(&node);
				char type[B_MIME_TYPE_LENGTH];
				if (nodeInfo.GetType(type) == B_OK) {
					BMimeType mimeType(type);
					mimeType.GetShortDescription(type);
					// if this fails, the MIME type will be displayed
					fImageTypeView->SetText(type);
				} else {
					BMimeType refType;
					if (BMimeType::GuessMimeType(&ref, &refType) == B_OK) {
						refType.GetShortDescription(type);
						// if this fails, the MIME type will be displayed
						fImageTypeView->SetText(type);
					} else
						fImageTypeView->SetText("");
				}
			}
		} else {
			fResolutionView->SetText("");
			fImageTypeView->SetText("");
		}
		fImageView->Invalidate();
		fResolutionView->Invalidate();
	}

	BFilePanel::SelectionChanged();
}
Example #6
0
InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent)
	: BWindow(BRect(p, p), kEmptyStr, B_FLOATING_WINDOW_LOOK,
		B_FLOATING_SUBSET_WINDOW_FEEL,
		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE)
{
	AddToSubset(parent);

	typedef pair<string, string> Item;
	typedef vector<Item> InfoList;

	char name[B_PATH_NAME_LENGTH];
	strcpy(name, f->ref.name);
	strcat(name, " info");
	SetTitle(name);

	InfoList info;
	Item item;

	// Size
	size_to_string(f->size, name);
	if (f->count > 0) {
		// This is a directory.
		char str[64];
		sprintf(str, kInfoInFiles, f->count);
		strcat(name, str);
	}
	info.push_back(Item(kInfoSize, name));

	// Created & modified dates
	BEntry entry(&f->ref);
	time_t t;
	entry.GetCreationTime(&t);
	strftime(name, 64, kInfoTimeFmt, localtime(&t));
	info.push_back(Item(kInfoCreated, name));
	entry.GetModificationTime(&t);
	strftime(name, 64, kInfoTimeFmt, localtime(&t));
	info.push_back(Item(kInfoModified, name));

	// Kind
	BMimeType* type = f->Type();
	type->GetShortDescription(name);
	info.push_back(Item(kInfoKind, name));
	delete type;

	// Path
	string path;
	f->GetPath(path);
	info.push_back(Item(kInfoPath, path));

	// Icon
	BBitmap *icon = new BBitmap(BRect(0.0, 0.0, 31.0, 31.0), B_RGBA32);
	entry_ref ref;
	entry.GetRef(&ref);
	BNodeInfo::GetTrackerIcon(&ref, icon, B_LARGE_ICON);

	// Compute the window size and add the views.
	BFont smallFont(be_plain_font);
	smallFont.SetSize(floorf(smallFont.Size() * 0.95));

	struct font_height fh;
	smallFont.GetHeight(&fh);
	float fontHeight = fh.ascent + fh.descent + fh.leading;

	float leftWidth = 32.0;
	float rightWidth = 0.0;
	InfoList::iterator i = info.begin();
	while (i != info.end()) {
		float w = smallFont.StringWidth((*i).first.c_str()) + 2.0 * kSmallHMargin;
		leftWidth = max_c(leftWidth, w);
		w = smallFont.StringWidth((*i).second.c_str()) + 2.0 * kSmallHMargin;
		rightWidth = max_c(rightWidth, w);
		i++;
	}

	float winHeight = 32.0 + 4.0 * kSmallVMargin + 5.0 * (fontHeight + kSmallVMargin);
	float winWidth = leftWidth + rightWidth;
	ResizeTo(winWidth, winHeight);

	LeftView *leftView = new LeftView(BRect(0.0, 0.0, leftWidth, winHeight), icon);
	BView *rightView = new BView(
		BRect(leftWidth + 1.0, 0.0, winWidth, winHeight), NULL,
		B_FOLLOW_NONE, B_WILL_DRAW);

	AddChild(leftView);
	AddChild(rightView);

	BStringView *sv = new BStringView(
		BRect(kSmallHMargin, kSmallVMargin, rightView->Bounds().Width(), kSmallVMargin + 30.0),
		NULL, f->ref.name, B_FOLLOW_ALL);

	BFont largeFont(be_plain_font);
	largeFont.SetSize(ceilf(largeFont.Size() * 1.1));
	sv->SetFont(&largeFont);
	rightView->AddChild(sv);

	float y = 32.0 + 4.0 * kSmallVMargin;
	i = info.begin();
	while (i != info.end()) {
		sv = new BStringView(
			BRect(kSmallHMargin, y, leftView->Bounds().Width(), y + fontHeight),
			NULL, (*i).first.c_str());
		sv->SetFont(&smallFont);
		sv->SetAlignment(B_ALIGN_RIGHT);
		sv->SetHighColor(kBasePieColor[1]); // arbitrary
		leftView->AddChild(sv);

		sv = new BStringView(
			BRect(kSmallHMargin, y, rightView->Bounds().Width(), y + fontHeight),
			NULL, (*i).second.c_str());
		sv->SetFont(&smallFont);
		rightView->AddChild(sv);

		y += fontHeight + kSmallVMargin;
		i++;
	}

	Show();
}
Example #7
0
void
TestView::SetupTestMenu(void)
{
	// These ones will always exist. Type is the default because it's probably
	// going to be the one most used
	BMessage *msg;
	BPopUpMenu *menu = new BPopUpMenu("Test");
	
	
	// Read in the types in the MIME database which have extra attributes
	// associated with them
	
	BMimeType mime;
	BMessage types, info, attr;
	BString string;
	
	BMimeType::GetInstalledTypes(&types);
	
	int32 index = 0;
	while (types.FindString("types",index,&string) == B_OK)
	{
		index++;
		mime.SetTo(string.String());
		if (mime.GetAttrInfo(&info) != B_OK)
			continue;
		
		int32 infoindex = 0;
		BString attrName;
		BString attrPublicName;
		int32 attrType;
		
		char attrTypeName[B_MIME_TYPE_LENGTH];
		mime.GetShortDescription(attrTypeName);
		
		while (info.FindString("attr:name",infoindex,&attrName) == B_OK)
		{
			// This is where we create tests based on a particular type's "special" attributes
			
			// Just string attributes are supported for now
			if (info.FindInt32("attr:type",infoindex,&attrType) != B_OK ||
				attrType != B_STRING_TYPE ||
				info.FindString("attr:public_name",infoindex,&attrPublicName) != B_OK)
			{
				infoindex++;
				continue;
			}
			
			BMenu *submenu = GetMenu(menu,attrTypeName);
			if (!submenu)
				submenu = AddMenuSorted(menu,attrTypeName);
			
			msg = new BMessage(M_TEST_CHOSEN);
			msg->AddString("name","Attribute");
			msg->AddString("attrtype",attrName);
			msg->AddString("attrname",attrPublicName);
			msg->AddString("mimetype",string);
			msg->AddString("typename",attrTypeName);
			submenu->AddItem(new BMenuItem(attrPublicName.String(),msg));
			
			infoindex++;
		}
	}
	
	menu->AddItem(new BSeparatorItem(),0);
	
	
	// All this weirdness is to have the "standard"	tests at the top and
	// the attribute tests at the bottom with a separator in between
	BString testtype;
	int32 i = 0;
	while (fTestTypes.FindString("tests",i,&testtype) == B_OK)
		i++;
	
	i--;
	
	while (i >= 0)
	{
		fTestTypes.FindString("tests",i,&testtype);
		msg = new BMessage(M_TEST_CHOSEN);
		msg->AddString("name",testtype);
		menu->AddItem(new BMenuItem(testtype.String(),msg),0);
		i--;
	}
	
	
	menu->Archive(&fArchivedTestMenu);
	delete menu;
}
Example #8
0
InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent)
	: BWindow(BRect(p, p), kEmptyStr, B_FLOATING_WINDOW_LOOK,
		B_FLOATING_SUBSET_WINDOW_FEEL,
		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE)
{
	AddToSubset(parent);

	typedef pair<string, string> Item;
	typedef vector<Item> InfoList;

	BString stringTitle("%refName% info");
	stringTitle.ReplaceFirst("%refName%", f->ref.name);
	SetTitle(stringTitle.String());

	InfoList info;
	Item item;

	// Size
	BString name;
	if (f->count > 0) {
		// This is a directory, include file count information
		static BMessageFormat format(B_TRANSLATE(
		"%size% in {0, plural, one{# file} other{# files}}"));

		format.Format(name, f->count);
	} else
		name = "%size%";

	char tmp[B_PATH_NAME_LENGTH] = { 0 };
	string_for_size(f->size, tmp, sizeof(tmp));
	name.ReplaceFirst("%size%", tmp);

	info.push_back(Item(B_TRANSLATE_MARK("Size"), name.String()));

	// Created & modified dates
	BEntry entry(&f->ref);
	time_t t;
	entry.GetCreationTime(&t);
	strftime(tmp, 64, B_TRANSLATE("%a, %d %b %Y, %r"), localtime(&t));
	info.push_back(Item(B_TRANSLATE("Created"), tmp));
	entry.GetModificationTime(&t);
	strftime(tmp, 64, B_TRANSLATE("%a, %d %b %Y, %r"), localtime(&t));
	info.push_back(Item(B_TRANSLATE("Modified"), tmp));

	// Kind
	BMimeType* type = f->Type();
	type->GetShortDescription(tmp);
	info.push_back(Item(B_TRANSLATE("Kind"), tmp));
	delete type;

	// Path
	string path;
	f->GetPath(path);
	info.push_back(Item(B_TRANSLATE("Path"), path));

	// Icon
	BBitmap *icon = new BBitmap(BRect(0.0, 0.0, 31.0, 31.0), B_RGBA32);
	entry_ref ref;
	entry.GetRef(&ref);
	BNodeInfo::GetTrackerIcon(&ref, icon, B_LARGE_ICON);

	// Compute the window size and add the views.
	BFont smallFont(be_plain_font);
	smallFont.SetSize(floorf(smallFont.Size() * 0.95));

	struct font_height fh;
	smallFont.GetHeight(&fh);
	float fontHeight = fh.ascent + fh.descent + fh.leading;

	float leftWidth = 32.0;
	float rightWidth = 0.0;
	InfoList::iterator i = info.begin();
	while (i != info.end()) {
		float w = smallFont.StringWidth((*i).first.c_str())
			+ 2.0 * kSmallHMargin;
		leftWidth = max_c(leftWidth, w);
		w = smallFont.StringWidth((*i).second.c_str()) + 2.0 * kSmallHMargin;
		rightWidth = max_c(rightWidth, w);
		i++;
	}

	float winHeight = 32.0 + 4.0 * kSmallVMargin + 5.0 * (fontHeight
		+ kSmallVMargin);
	float winWidth = leftWidth + rightWidth;
	ResizeTo(winWidth, winHeight);

	LeftView *leftView = new LeftView(BRect(0.0, 0.0, leftWidth, winHeight),
		icon);
	BView *rightView = new BView(
		BRect(leftWidth + 1.0, 0.0, winWidth, winHeight), NULL,
		B_FOLLOW_NONE, B_WILL_DRAW);

	AddChild(leftView);
	AddChild(rightView);

	BStringView *sv = new BStringView(
		BRect(kSmallHMargin, kSmallVMargin, rightView->Bounds().Width(),
		kSmallVMargin + 30.0), NULL, f->ref.name, B_FOLLOW_ALL);

	BFont largeFont(be_plain_font);
	largeFont.SetSize(ceilf(largeFont.Size() * 1.1));
	sv->SetFont(&largeFont);
	rightView->AddChild(sv);

	float y = 32.0 + 4.0 * kSmallVMargin;
	i = info.begin();
	while (i != info.end()) {
		sv = new BStringView(
			BRect(kSmallHMargin, y, leftView->Bounds().Width(),
			y + fontHeight), NULL, (*i).first.c_str());
		sv->SetFont(&smallFont);
		sv->SetAlignment(B_ALIGN_RIGHT);
		sv->SetHighColor(kBasePieColor[1]); // arbitrary
		leftView->AddChild(sv);

		sv = new BStringView(
			BRect(kSmallHMargin, y, rightView->Bounds().Width(),
			y + fontHeight), NULL, (*i).second.c_str());
		sv->SetFont(&smallFont);
		rightView->AddChild(sv);

		y += fontHeight + kSmallVMargin;
		i++;
	}

	Show();
}