int FilePropertiesDialog::find(QString s, InfoList &list) {
	qDebug("FilePropertiesDialog::find");

	int n=0;
	InfoList::iterator it;

	for ( it = list.begin(); it != list.end(); ++it ) {
		//qDebug(" * item: '%s', s: '%s'", (*it).name().toUtf8().data(), s.toUtf8().data());
		if ((*it).name() == s) return n;
		n++;
	}
	return -1;
}
Пример #2
0
/** Lists the bus configuration.
 */
void CommandConfig::listConfigs(
        MasterDevice &m,
        const ConfigList &configList,
        bool doIndent
        )
{
    ConfigList::const_iterator configIter;
    stringstream str;
    Info info;
    typedef list<Info> InfoList;
    InfoList list;
    InfoList::const_iterator iter;
    unsigned int maxAliasWidth = 0, maxPosWidth = 0,
                 maxSlavePosWidth = 0, maxStateWidth = 0;
    ec_ioctl_slave_t slave;
    string indent(doIndent ? "  " : "");

    for (configIter = configList.begin();
            configIter != configList.end();
            configIter++) {

        str << dec << configIter->alias;
        info.alias = str.str();
        str.clear();
        str.str("");

        str << configIter->position;
        info.pos = str.str();
        str.clear();
        str.str("");

        str << hex << setfill('0')
            << "0x" << setw(8) << configIter->vendor_id
            << "/0x" << setw(8) << configIter->product_code;
        info.ident = str.str();
        str.clear();
        str.str("");

        if (configIter->slave_position != -1) {
            m.getSlave(&slave, configIter->slave_position);

            str << dec << configIter->slave_position;
            info.slavePos = str.str();
            str.clear();
            str.str("");

            info.state = alStateString(slave.al_state);
        } else {
            str << "-";
            info.slavePos = str.str();
            str.clear();
            str.str("");

            str << "-";
            info.state = str.str();
            str.clear();
            str.str("");
        }

        list.push_back(info);

        if (info.alias.length() > maxAliasWidth)
            maxAliasWidth = info.alias.length();
        if (info.pos.length() > maxPosWidth)
            maxPosWidth = info.pos.length();
        if (info.slavePos.length() > maxSlavePosWidth)
            maxSlavePosWidth = info.slavePos.length();
        if (info.state.length() > maxStateWidth)
            maxStateWidth = info.state.length();
    }

    for (iter = list.begin(); iter != list.end(); iter++) {
        cout << indent << setfill(' ') << right
            << setw(maxAliasWidth) << iter->alias
            << ":" << left
            << setw(maxPosWidth) << iter->pos
            << "  "
            << iter->ident
            << "  "
            << setw(maxSlavePosWidth) << iter->slavePos << "  "
            << setw(maxStateWidth) << iter->state << "  "
            << endl;
    }
}
Пример #3
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();
}
Пример #4
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();
}