Esempio n. 1
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();
}
Esempio n. 2
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();
}