示例#1
0
void
dump_partition_info(const BPartition* partition)
{
	char size[1024];
	printf("\tOffset(): %Ld\n", partition->Offset());
	printf("\tSize(): %s\n", string_for_size(partition->Size(),size));
	printf("\tContentSize(): %s\n", string_for_size(partition->ContentSize(),
		size));
	printf("\tBlockSize(): %ld\n", partition->BlockSize());
	printf("\tIndex(): %ld\n", partition->Index());
	printf("\tStatus(): %ld\n\n", partition->Status());
	printf("\tContainsFileSystem(): %s\n",
		partition->ContainsFileSystem() ? "true" : "false");
	printf("\tContainsPartitioningSystem(): %s\n\n",
		partition->ContainsPartitioningSystem() ? "true" : "false");
	printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false");
	printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false");
	printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false");
	printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false");
	printf("\tFlags(): %lx\n\n", partition->Flags());
	printf("\tName(): %s\n", partition->Name());
	printf("\tContentName(): %s\n", partition->ContentName());
	printf("\tType(): %s\n", partition->Type());
	printf("\tContentType(): %s\n", partition->ContentType());
	printf("\tID(): %lx\n\n", partition->ID());
}
void
FolderConfigWindow::_LoadFolders()
{
	StatusWindow* status = new StatusWindow(
		B_TRANSLATE("Fetching IMAP folders, have patience..."));
	status->Show();

	BString server;
	fSettings.FindString("server", &server);
	int32 ssl;
	fSettings.FindInt32("flavor", &ssl);
	bool useSSL = false;
	if (ssl == 1)
		useSSL = true;

	BString username;
	fSettings.FindString("username", &username);

	BString password;
	char* passwd = get_passwd(&fSettings, "cpasswd");
	if (passwd != NULL) {
		password = passwd;
		delete[] passwd;
	}

	fIMAPFolders.Connect(server, username, password, useSSL);
	fFolderList.clear();
	fIMAPFolders.GetFolders(fFolderList);
	for (unsigned int i = 0; i < fFolderList.size(); i++) {
		FolderInfo& info = fFolderList[i];
		CheckBoxItem* item = new CheckBoxItem(info.folder, info.subscribed);
		fFolderListView->AddItem(item);
		item->SetListView(fFolderListView);
	}

	uint64 used, total;
	if (fIMAPFolders.GetQuota(used, total) == B_OK) {
		char buffer[256];
		BString quotaString = "Server storage: ";
		quotaString += string_for_size(used, buffer, 256);
		quotaString += " / ";
		quotaString += string_for_size(total, buffer, 256);
		quotaString += " used.";
		fQuotaView->SetText(quotaString);
	}

	status->PostMessage(B_QUIT_REQUESTED);
}
示例#3
0
MemoryBarMenu::MemoryBarMenu(const char* name, info_pack* infos, system_info& systemInfo)
	: BMenu(name),
	fFirstShow(true)
{
	fTeamCount = systemInfo.used_teams + EXTRA;
	SetFlags(Flags() | B_PULSE_NEEDED);

	fTeamList = (team_id*)malloc(sizeof (team_id) * fTeamCount);

	unsigned int k;
	for (k = 0; k < systemInfo.used_teams; k++) {
		fTeamList[k] = infos[k].team_info.team;
	}

	while (k < fTeamCount) {
		fTeamList[k++] = -1;
	}

	char buffer[64];
	string_for_size(99999999.9, buffer, sizeof(buffer));
	gMemoryTextWidth = 2 * StringWidth(buffer) + 32;

	fRecycleCount = EXTRA;
	fRecycleList = (MRecycleItem*)malloc(sizeof(MRecycleItem) * fRecycleCount);
	SetFont(be_plain_font);
	AddItem(new KernelMemoryBarMenuItem(systemInfo));
}
示例#4
0
DriveItem::DriveItem(const BDiskDevice& device, const BootMenuList& menus)
	:
	fBaselineOffset(0),
	fSizeWidth(0)
{
	device.GetPath(&fPath);
	if (device.Name() != NULL && device.Name()[0])
		fName = device.Name();
	else if (strstr(fPath.Path(), "usb") != NULL)
		fName = B_TRANSLATE_COMMENT("USB Drive", "Default disk name");
	else
		fName = B_TRANSLATE_COMMENT("Hard Drive", "Default disk name");

	fIcon = new BBitmap(BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1),
		B_RGBA32);
	if (device.GetIcon(fIcon, B_LARGE_ICON) != B_OK)
		memset(fIcon->Bits(), 0, fIcon->BitsLength());

	fDrive = new BootDrive(fPath.Path());

	fIsInstalled = fDrive->InstalledMenu(menus) != NULL;
	fCanBeInstalled = fDrive->CanMenuBeInstalled(menus);

	char buffer[256];
	fSize = string_for_size(device.Size(), buffer, sizeof(buffer));
}
BString
BStatusView::_FullSpeedString()
{
	BString buffer;
	if (fBytesPerSecond != 0.0) {
		char sizeBuffer[128];
		buffer.SetTo(B_TRANSLATE(
			"%SizeProcessed of %TotalSize, %BytesPerSecond/s"));
		buffer.ReplaceFirst("%SizeProcessed",
			string_for_size((double)fSizeProcessed, sizeBuffer,
			sizeof(sizeBuffer)));
		buffer.ReplaceFirst("%TotalSize",
			string_for_size((double)fTotalSize, sizeBuffer,
			sizeof(sizeBuffer)));
		buffer.ReplaceFirst("%BytesPerSecond",
			string_for_size(fBytesPerSecond, sizeBuffer, sizeof(sizeBuffer)));
	}
	return buffer;
}
BString
BStatusView::_ShortSpeedString()
{
	BString buffer;
	if (fBytesPerSecond != 0.0) {
		char sizeBuffer[128];
		buffer << B_TRANSLATE("%BytesPerSecond/s");
		buffer.ReplaceFirst("%BytesPerSecond",
			string_for_size(fBytesPerSecond, sizeBuffer, sizeof(sizeBuffer)));
	}
	return buffer;
}
示例#7
0
void
PackagesView::GetTotalSizeAsString(char* string, size_t stringSize)
{
    int32 count = CountChildren();
    int32 size = 0;
    for (int32 i = 0; i < count; i++) {
        PackageCheckBox* cb = dynamic_cast<PackageCheckBox*>(ChildAt(i));
        if (cb && cb->Value())
            size += cb->GetPackage()->Size();
    }
    string_for_size(size, string, stringSize);
}
示例#8
0
BString
PackageView::_NamePlusSizeString(BString baseName, size_t size,
	const char* format) const
{
	char sizeString[48];
	string_for_size(size, sizeString, sizeof(sizeString));

	BString name(format);
	name.ReplaceAll("%name%", baseName);
	name.ReplaceAll("%size%", sizeString);

	return name;
}
示例#9
0
void
StatusView::ShowInfo(const FileInfo* info)
{
	if (info == fCurrentFileInfo)
		return;

	fCurrentFileInfo = info;

	if (info == NULL) {
		fPathView->SetText(kEmptyStr);
		fSizeView->SetText(kEmptyStr);
		fCountView->SetText(kEmptyStr);
		return;
	}

	if (!info->pseudo) {
		BNode node(&info->ref);
		if (node.InitCheck() != B_OK) {
			fPathView->SetText(B_TRANSLATE("file unavailable"));
			fSizeView->SetText(kEmptyStr);
			fCountView->SetText(kEmptyStr);
			return;
		}
	}

	float viewWidth = fPathView->Bounds().Width();
	string path;
	info->GetPath(path);
	BString pathLabel = path.c_str();
	be_plain_font->TruncateString(&pathLabel, B_TRUNCATE_BEGINNING, viewWidth);
	fPathView->SetText(pathLabel.String());

	char label[B_PATH_NAME_LENGTH];
	string_for_size(info->size, label, sizeof(label));
	fSizeView->SetText(label);

	if (info->count > 0) {
		static BMessageFormat format(B_TRANSLATE("{0, plural, "
			"one{# file} other{# files}}"));
		BString label;
		format.Format(label, info->count);
		fCountView->SetText(label);
	} else {
		fCountView->SetText(kEmptyStr);
	}
}
示例#10
0
PartitionListRow::PartitionListRow(BPartition* partition)
	:
	Inherited(),
	fPartitionID(partition->ID()),
	fParentID(partition->Parent() ? partition->Parent()->ID() : -1),
	fOffset(partition->Offset()),
	fSize(partition->Size())
{
	BPath path;
	partition->GetPath(&path);

	BBitmap* icon = NULL;
	if (partition->IsDevice()) {
		icon_size size = B_MINI_ICON;
		icon = new BBitmap(BRect(0, 0, size - 1, size - 1), B_RGBA32);
		if (partition->GetIcon(icon, size) != B_OK) {
			delete icon;
			icon = NULL;
		}
	}

	SetField(new BBitmapStringField(icon, path.Path()), kDeviceColumn);

	if (partition->ContainsFileSystem()) {
		SetField(new BStringField(partition->ContentType()), kFilesystemColumn);
		SetField(new BStringField(partition->ContentName()), kVolumeNameColumn);
	} else if (partition->CountChildren() > 0) {
		SetField(new BStringField(kUnavailableString), kFilesystemColumn);
		SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
	} else {
		SetField(new BStringField(partition->Type()), kFilesystemColumn);
		SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
	}

	if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK) {
		SetField(new BStringField(path.Path()),  kMountedAtColumn);
	} else {
		SetField(new BStringField(kUnavailableString), kMountedAtColumn);
	}

	char size[1024];
	SetField(new BStringField(string_for_size(partition->Size(), size,
		sizeof(size))), kSizeColumn);
}
示例#11
0
void
SizeField::SetSize(double size)
{
	if (size < 0.0)
		size = 0.0;

	if (size == fSize)
		return;

	BString sizeString;
	if (size == 0) {
		sizeString = B_TRANSLATE_CONTEXT("-", "no package size");
	} else {
		char buffer[256];
		sizeString = string_for_size(size, buffer, sizeof(buffer));
	}

	fSize = size;
	SetString(sizeString.String());
}
PartitionListRow::PartitionListRow(partition_id parentID, partition_id id,
		off_t offset, off_t size)
	:
	Inherited(),
	fPartitionID(id),
	fParentID(parentID),
	fOffset(offset),
	fSize(size)
{
	// TODO: design icon for spaces on partitions
	SetField(new BBitmapStringField(NULL, "-"), kDeviceColumn);

	SetField(new BStringField(B_TRANSLATE("<empty>")), kFilesystemColumn);
	SetField(new BStringField(kUnavailableString), kVolumeNameColumn);

	SetField(new BStringField(kUnavailableString), kMountedAtColumn);

	char sizeString[1024];
	SetField(new BStringField(string_for_size(size, sizeString,
		sizeof(sizeString))), kSizeColumn);
}
示例#13
0
static void
make_partition_label(BPartition* partition, char* label, char* menuLabel,
	bool showContentType)
{
	char size[20];
	string_for_size(partition->Size(), size, sizeof(size));

	BPath path;
	partition->GetPath(&path);

	if (showContentType) {
		const char* type = partition->ContentType();
		if (type == NULL)
			type = B_TRANSLATE_COMMENT("Unknown Type", "Partition content type");

		sprintf(label, "%s - %s [%s] (%s)", partition->ContentName(), size,
			path.Path(), type);
	} else {
		sprintf(label, "%s - %s [%s]", partition->ContentName(), size,
			path.Path());
	}

	sprintf(menuLabel, "%s - %s", partition->ContentName(), size);
}
void
PartitionsPage::_CreateSizeText(int64 size, BString* text)
{
	char buffer[256];
	*text = string_for_size(size, buffer, sizeof(buffer));
}
PartitionListRow::PartitionListRow(BPartition* partition)
	:
	Inherited(),
	fPartitionID(partition->ID()),
	fParentID(partition->Parent() ? partition->Parent()->ID() : -1),
	fOffset(partition->Offset()),
	fSize(partition->Size())
{
	BPath path;
	partition->GetPath(&path);

	// Device icon

	BBitmap* icon = NULL;
	if (partition->IsDevice()) {
		icon_size size = B_MINI_ICON;
		icon = new BBitmap(BRect(0, 0, size - 1, size - 1), B_RGBA32);
		if (partition->GetIcon(icon, size) != B_OK) {
			delete icon;
			icon = NULL;
		}
	}

	SetField(new BBitmapStringField(icon, path.Path()), kDeviceColumn);

	// File system & volume name

	BString partitionType(partition->Type());

	if (partition->ContainsFileSystem()) {
		SetField(new BStringField(partition->ContentType()), kFilesystemColumn);
		SetField(new BStringField(partition->ContentName()), kVolumeNameColumn);
	} else if (partition->IsDevice()) {
		SetField(new BStringField(kUnavailableString), kFilesystemColumn);
		if (partition->Name() != NULL && partition->Name()[0])
			SetField(new BStringField(partition->Name()), kVolumeNameColumn);
		else
			SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
	} else if (partition->CountChildren() > 0) {
		SetField(new BStringField(kUnavailableString), kFilesystemColumn);
		SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
	} else {
		if (!partitionType.IsEmpty()) {
			partitionType.Prepend("(");
			partitionType.Append(")");
			SetField(new BStringField(partitionType), kFilesystemColumn);
		} else
			SetField(new BStringField(kUnavailableString), kFilesystemColumn);

		SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
	}

	// Mounted at

	if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK)
		SetField(new BStringField(path.Path()), kMountedAtColumn);
	else
		SetField(new BStringField(kUnavailableString), kMountedAtColumn);

	// Size

	if (fSize > 0) {
		char size[1024];
		SetField(new BStringField(string_for_size(partition->Size(), size,
			sizeof(size))), kSizeColumn);
	} else {
		SetField(new BStringField(kUnavailableString), kSizeColumn);
	}

	// Additional parameters

	if (partition->Parameters() != NULL) {
		BString parameters;

		// check parameters
		void* handle = parse_driver_settings_string(partition->Parameters());
		if (handle != NULL) {
			bool active = get_driver_boolean_parameter(handle, "active", false, true);
			if (active)
				parameters += B_TRANSLATE("Active");

			delete_driver_settings(handle);
		}

		SetField(new BStringField(parameters), kParametersColumn);
	} else {
		SetField(new BStringField(kUnavailableString), kParametersColumn);
	}

	// Partition type

	if (partitionType.IsEmpty())
		partitionType = partition->ContentType();
	SetField(new BStringField(partitionType), kPartitionTypeColumn);
}
示例#16
0
void
DownloadProgressView::_UpdateStatusText()
{
	fInfoView->SetText("");
	BString buffer;
	if (sShowSpeed && fBytesPerSecond != 0.0) {
		// Draw speed info
		char sizeBuffer[128];
		buffer = "(";
		// Get strings for current and expected size and remove the unit
		// from the current size string if it's the same as the expected
		// size unit.
		BString currentSize = string_for_size((double)fCurrentSize, sizeBuffer,
			sizeof(sizeBuffer));
		BString expectedSize = string_for_size((double)fExpectedSize, sizeBuffer,
			sizeof(sizeBuffer));
		int currentSizeUnitPos = currentSize.FindLast(' ');
		int expectedSizeUnitPos = expectedSize.FindLast(' ');
		if (currentSizeUnitPos >= 0 && expectedSizeUnitPos >= 0
			&& strcmp(currentSize.String() + currentSizeUnitPos,
				expectedSize.String() + expectedSizeUnitPos) == 0) {
			currentSize.Truncate(currentSizeUnitPos);
		}
		buffer << currentSize;
		buffer << " of ";
		buffer << expectedSize;
		buffer << ", ";
		buffer << string_for_size(fBytesPerSecond, sizeBuffer,
			sizeof(sizeBuffer));
		buffer << "/s)";
		float stringWidth = fInfoView->StringWidth(buffer.String());
		if (stringWidth < fInfoView->Bounds().Width())
			fInfoView->SetText(buffer.String());
		else {
			// complete string too wide, try with shorter version
			buffer << string_for_size(fBytesPerSecond, sizeBuffer,
				sizeof(sizeBuffer));
			buffer << "/s";
			stringWidth = fInfoView->StringWidth(buffer.String());
			if (stringWidth < fInfoView->Bounds().Width())
				fInfoView->SetText(buffer.String());
		}
	} else if (!sShowSpeed && fCurrentSize < fExpectedSize) {
		double totalBytesPerSecond = (double)(fCurrentSize
				- fEstimatedFinishReferenceSize)
			* 1000000LL / (system_time() - fEstimatedFinishReferenceTime);
		double secondsRemaining = (fExpectedSize - fCurrentSize)
			/ totalBytesPerSecond;
		time_t now = (time_t)real_time_clock();
		time_t finishTime = (time_t)(now + secondsRemaining);

		tm _time;
		tm* time = localtime_r(&finishTime, &_time);
		int32 year = time->tm_year + 1900;

		char timeText[32];
		time_t secondsPerDay = 24 * 60 * 60;
		// TODO: Localization of time string...
		if (now < finishTime - secondsPerDay) {
			// process is going to take more than a day!
			sprintf(timeText, "%0*d:%0*d %0*d/%0*d/%ld",
				2, time->tm_hour, 2, time->tm_min,
				2, time->tm_mon + 1, 2, time->tm_mday, year);
		} else {
			sprintf(timeText, "%0*d:%0*d",
				2, time->tm_hour, 2, time->tm_min);
		}

		BString buffer1("Finish: ");
		buffer1 << timeText;
		finishTime -= now;
		time = gmtime(&finishTime);

		BString buffer2;
		if (finishTime > secondsPerDay) {
			int64 days = finishTime / secondsPerDay;
			if (days == 1)
				buffer2 << "Over 1 day";
			else
				buffer2 << "Over " << days << " days";
		} else if (finishTime > 60 * 60) {
			int64 hours = finishTime / (60 * 60);
			if (hours == 1)
				buffer2 << "Over 1 hour";
			else
				buffer2 << "Over " << hours << " hours";
		} else if (finishTime > 60) {
			int64 minutes = finishTime / 60;
			if (minutes == 1)
				buffer2 << "Over 1 minute";
			else
				buffer2 << minutes << " minutes";
		} else {
			if (finishTime == 1)
				buffer2 << "1 second";
			else
				buffer2 << finishTime << " seconds";
		}

		buffer2 << " left";

		buffer = "(";
		buffer << buffer1 << " - " << buffer2 << ")";

		float stringWidth = fInfoView->StringWidth(buffer.String());
		if (stringWidth < fInfoView->Bounds().Width())
			fInfoView->SetText(buffer.String());
		else {
			// complete string too wide, try with shorter version
			buffer = "(";
			buffer << buffer1 << ")";
			stringWidth = fInfoView->StringWidth(buffer.String());
			if (stringWidth < fInfoView->Bounds().Width())
				fInfoView->SetText(buffer.String());
		}
	}
}
示例#17
0
void
MemoryBarMenuItem::DrawBar(bool force)
{
	// only draw anything if something has changed
	if (!force && fWriteMemory == fLastWrite && fAllMemory == fLastAll
		&& fCommittedMemory == fLastCommitted)
		return;

	bool selected = IsSelected();
	BRect frame = Frame();
	BMenu* menu = Menu();

	// draw the bar itself

	BRect rect(frame.right - kMargin - kBarWidth, frame.top + 5,
		frame.right - kMargin, frame.top + 13);
	if (fWriteMemory < 0)
		return;

	if (fGrenze1 < 0)
		force = true;

	if (force) {
		if (selected)
			menu->SetHighColor(gFrameColorSelected);
		else
			menu->SetHighColor(gFrameColor);
		menu->StrokeRect(rect);
	}

	rect.InsetBy(1, 1);
	BRect r = rect;
	double grenze1 = rect.left + (rect.right - rect.left) * float(fWriteMemory)
		/ fCommittedMemory;
	double grenze2 = rect.left + (rect.right - rect.left) * float(fAllMemory)
		/ fCommittedMemory;
	if (grenze1 > rect.right)
		grenze1 = rect.right;
	if (grenze2 > rect.right)
		grenze2 = rect.right;
	r.right = grenze1;
	if (!force)
		r.left = fGrenze1;
	if (r.left < r.right) {
		if (selected)
			menu->SetHighColor(gKernelColorSelected);
		else
			menu->SetHighColor(gKernelColor);
		menu->FillRect(r);
	}

	r.left = grenze1;
	r.right = grenze2;

	if (!force) {
		if (fGrenze2 > r.left && r.left >= fGrenze1)
			r.left = fGrenze2;
		if (fGrenze1 < r.right && r.right  <= fGrenze2)
			r.right = fGrenze1;
	}

	if (r.left < r.right) {
		if (selected)
			menu->SetHighColor(gUserColorSelected);
		else
			menu->SetHighColor(gUserColor);
		menu->FillRect(r);
	}

	r.left = grenze2;
	r.right = rect.right;

	if (!force)
		r.right = fGrenze2;

	if (r.left < r.right) {
		if (selected)
			menu->SetHighColor(gWhiteSelected);
		else
			menu->SetHighColor(kWhite);
		menu->FillRect(r);
	}

	menu->SetHighColor(kBlack);
	fGrenze1 = grenze1;
	fGrenze2 = grenze2;

	fLastCommitted = fCommittedMemory;

	// Draw the values if necessary; if only fCommitedMemory changes, only
	// the bar might have to be updated

	if (!force && fWriteMemory == fLastWrite && fAllMemory == fLastAll)
		return;

	if (selected)
		menu->SetLowColor(gMenuBackColorSelected);
	else
		menu->SetLowColor(gMenuBackColor);

	BRect textRect(rect.left - kMargin - gMemoryTextWidth, frame.top,
		rect.left - kMargin, frame.bottom);
	menu->FillRect(textRect, B_SOLID_LOW);

	fLastWrite = fWriteMemory;
	fLastAll = fAllMemory;

	menu->SetHighColor(kBlack);

	char infos[128];
	string_for_size(fWriteMemory * 1024.0, infos, sizeof(infos));

	BPoint loc(rect.left - kMargin - gMemoryTextWidth / 2 - menu->StringWidth(infos),
		rect.bottom + 1);
	menu->DrawString(infos, loc);

	string_for_size(fAllMemory * 1024.0, infos, sizeof(infos));
	loc.x = rect.left - kMargin - menu->StringWidth(infos);
	menu->DrawString(infos, loc);
}
示例#18
0
status_t
InterfaceHardwareView::Update()
{
	// Populate fields with current settings
	if (fSettings->HasLink()) {
		if (fSettings->IsWireless()) {
			BString network = fSettings->WirelessNetwork();
			network.Prepend(" (");
			network.Prepend(B_TRANSLATE("connected"));
			network.Append(")");
			fStatusField->SetText(network.String());
		} else {
			fStatusField->SetText(B_TRANSLATE("connected"));
		}
	} else
		fStatusField->SetText(B_TRANSLATE("disconnected"));

	fMacAddressField->SetText(fSettings->HardwareAddress());

	// TODO : Find how to get link speed
	fLinkSpeedField->SetText("100 Mb/s");

	// Update Link stats
	ifreq_stats stats;
	char buffer[100];
	fSettings->Stats(&stats);

	string_for_size(stats.send.bytes, buffer, sizeof(buffer));
	fLinkTxField->SetText(buffer);

	string_for_size(stats.receive.bytes, buffer, sizeof(buffer));
	fLinkRxField->SetText(buffer);

	// TODO move the wireless info to a separate tab. We should have a
	// BListView of available networks, rather than a menu, to make them more
	// readable and easier to browse and select.
	if (fNetworkMenuField->IsHidden(fNetworkMenuField)
		&& fSettings->IsWireless()) {
		fNetworkMenuField->Show();
	} else if (!fNetworkMenuField->IsHidden(fNetworkMenuField)
		&& !fSettings->IsWireless()) {
		fNetworkMenuField->Hide();
	}

	if (fSettings->IsWireless()) {
		// Rebuild network menu
		BMenu* menu = fNetworkMenuField->Menu();
		menu->RemoveItems(0, menu->CountItems(), true);

		std::set<BNetworkAddress> associated;
		BNetworkAddress address;
		uint32 cookie = 0;
		while (fSettings->GetNextAssociatedNetwork(cookie, address) == B_OK)
			associated.insert(address);

		wireless_network network;
		int32 count = 0;
		cookie = 0;
		while (fSettings->GetNextNetwork(cookie, network) == B_OK) {
			BMessage* message = new BMessage(kMsgNetwork);

			message->AddString("device", fSettings->Name());
			message->AddString("name", network.name);

			BMenuItem* item = new WirelessNetworkMenuItem(network.name,
				network.signal_strength,
				network.authentication_mode, message);
			if (associated.find(network.address) != associated.end())
				item->SetMarked(true);
			menu->AddItem(item);

			count++;
		}
		if (count == 0) {
			BMenuItem* item = new BMenuItem(
				B_TRANSLATE("<no wireless networks found>"), NULL);
			item->SetEnabled(false);
			menu->AddItem(item);
		} else {
			BMenuItem* item = new BMenuItem(
				B_TRANSLATE("Choose automatically"), NULL);
			if (menu->FindMarked() == NULL)
				item->SetMarked(true);
			menu->AddItem(item, 0);
			menu->AddItem(new BSeparatorItem(), 1);
		}
		menu->SetTargetForItems(this);
	}

	fRenegotiate->SetEnabled(!fSettings->IsDisabled());
	fOnOff->SetLabel(fSettings->IsDisabled() ? "Enable" : "Disable");

	return B_OK;
}
示例#19
0
void
Package::GetSizeAsString(char* string, size_t stringSize)
{
    string_for_size(fSize, string, stringSize);
}
void
KernelMemoryBarMenuItem::DrawBar(bool force)
{
	bool selected = IsSelected();
	BRect frame = Frame();
	BMenu* menu = Menu();

	// draw the bar itself
	BRect cadre (frame.right - kMargin - kBarWidth, frame.top + 5,
		frame.right - kMargin, frame.top + 13);

	if (fLastSum < 0)
		force = true;
	if (force) {
		if (selected)
			menu->SetHighColor(gFrameColorSelected);
		else
			menu->SetHighColor(gFrameColor);
		menu->StrokeRect (cadre);
	}
	cadre.InsetBy(1, 1);
	BRect r = cadre;

	float grenze1 = cadre.left + (cadre.right - cadre.left)
						* fCachedMemory / fPhysicalMemory;
	float grenze2 = cadre.left + (cadre.right - cadre.left)
						* fCommittedMemory / fPhysicalMemory;
	if (grenze1 > cadre.right)
		grenze1 = cadre.right;
	if (grenze2 > cadre.right)
		grenze2 = cadre.right;
	r.right = grenze1;
	if (!force)
		r.left = fGrenze1;
	if (r.left < r.right) {
		if (selected)
			menu->SetHighColor(gKernelColorSelected);
		else
			menu->SetHighColor(gKernelColor);
//		menu->SetHighColor(gKernelColor);
		menu->FillRect (r);
	}
	r.left = grenze1;
	r.right = grenze2;
	if (!force) {
		if (fGrenze2 > r.left && r.left >= fGrenze1)
			r.left = fGrenze2;
		if (fGrenze1 < r.right && r.right <= fGrenze2)
			r.right = fGrenze1;
	}
	if (r.left < r.right) {
		if (selected)
			menu->SetHighColor(tint_color (kLavender, B_HIGHLIGHT_BACKGROUND_TINT));
		else
			menu->SetHighColor(kLavender);
//		menu->SetHighColor(gUserColor);
		menu->FillRect (r);
	}
	r.left = grenze2;
	r.right = cadre.right;
	if (!force)
		r.right = fGrenze2;
	if (r.left < r.right) {
		if (selected)
			menu->SetHighColor(gWhiteSelected);
		else
			menu->SetHighColor(kWhite);
		menu->FillRect(r);
	}
	menu->SetHighColor(kBlack);
	fGrenze1 = grenze1;
	fGrenze2 = grenze2;

	// draw the value
	double sum = fCachedMemory * FLT_MAX + fCommittedMemory;
	if (force || sum != fLastSum) {
		if (selected) {
			menu->SetLowColor(gMenuBackColorSelected);
			menu->SetHighColor(gMenuBackColorSelected);
		} else {
			menu->SetLowColor(gMenuBackColor);
			menu->SetHighColor(gMenuBackColor);
		}
		BRect trect(cadre.left - kMargin - gMemoryTextWidth, frame.top,
			cadre.left - kMargin, frame.bottom);
		menu->FillRect(trect);
		menu->SetHighColor(kBlack);

		char infos[128];
		string_for_size(fCachedMemory * 1024.0, infos, sizeof(infos));
		BPoint loc(cadre.left, cadre.bottom + 1);
		loc.x -= kMargin + gMemoryTextWidth / 2 + menu->StringWidth(infos);
		menu->DrawString(infos, loc);
		string_for_size(fCommittedMemory * 1024.0, infos, sizeof(infos));
		loc.x = cadre.left - kMargin - menu->StringWidth(infos);
		menu->DrawString(infos, loc);
		fLastSum = sum;
	}
}