Example #1
0
void
CookieTest::MaxNumberTest()
{
	BNetworkCookieJar jar;
	status_t result;

	BUrl url("http://testsuites.opera.com/cookies/007.php");
	BString cookieString;

	for (int i = 1; i <= 20; i++)
	{
		cookieString.SetToFormat("007-%d=1", i);
		result = jar.AddCookie(cookieString, url);
		CPPUNIT_ASSERT(result == B_OK);
	}

	url.SetUrlString("http://testsuites.opera.com/cookies/007-1.php");
	for (int i = 1; i <= 20; i++)
	{
		cookieString.SetToFormat("007-%d", i);
		const BNetworkCookie* cookie = _GetCookie(jar, url, cookieString.String());
		CPPUNIT_ASSERT(cookie != NULL);
		CPPUNIT_ASSERT(cookie->Value() == "1");
	}
}
status_t
DebugReportGenerator::_DumpSemaphores(BFile& _output)
{
	BObjectList<SemaphoreInfo> semaphores(20, true);
	status_t error = fDebuggerInterface->GetSemaphoreInfos(semaphores);
	if (error != B_OK)
		return error;

	semaphores.SortItems(&_CompareSemaphores);

	BString data = "\nSemaphores:\n";
	WRITE_AND_CHECK(_output, data);
	data.SetToFormat("\tID\t\tCount\tLast Holder\tName\n\t");
	WRITE_AND_CHECK(_output, data);
	data.Truncate(0L);
	data.Append('-', 60);
	data.Append("\n");
	WRITE_AND_CHECK(_output, data);
	SemaphoreInfo* info;
	for (int32 i = 0; (info = semaphores.ItemAt(i)) != NULL; i++) {
		try {
			data.SetToFormat("\t%" B_PRId32 "\t%5" B_PRId32 "\t%11" B_PRId32
				"\t%s\n", info->SemID(), info->Count(),
				info->LatestHolder(), info->Name().String());

			WRITE_AND_CHECK(_output, data);
		} catch (...) {
			return B_NO_MEMORY;
		}
	}

	return B_OK;
}
Example #3
0
bool
ResultWindow::_AddPackages(BGroupLayout* packagesGroup,
	const PackageList& packages, const PackageSet& ignorePackages, bool install)
{
	bool packagesAdded = false;

	for (int32 i = 0; BSolverPackage* package = packages.ItemAt(i);
		i++) {
		if (ignorePackages.find(package) != ignorePackages.end())
			continue;

		BString text;
		if (install) {
			text.SetToFormat("install package %s from repository %s\n",
				package->Info().FileName().String(),
				package->Repository()->Name().String());
		} else {
			text.SetToFormat("uninstall package %s\n",
				package->VersionedName().String());
		}

		BStringView* packageView = new BStringView(NULL, text);
		packagesGroup->AddView(packageView);
		packageView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

		packagesAdded = true;
	}

	return packagesAdded;
}
Example #4
0
	bool _GetBreakpointValueAt(UserBreakpoint* breakpoint, int32 rowIndex,
		int32 columnIndex, BVariant &value)
	{
		const UserBreakpointLocation& location = breakpoint->Location();

		switch (columnIndex) {
			case 0:
				value.SetTo((int32)breakpoint->IsEnabled());
				return true;
			case 1:
				value.SetTo(location.GetFunctionID()->FunctionName(),
					B_VARIANT_DONT_COPY_DATA);
				return true;
			case 2:
			{
				LocatableFile* sourceFile = location.SourceFile();
				BString data;
				if (sourceFile != NULL) {
					data.SetToFormat("%s:%" B_PRId32, sourceFile->Name(),
						location.GetSourceLocation().Line() + 1);
				} else {
					AutoLocker<Team> teamLocker(fTeam);
					if (UserBreakpointInstance* instance
							= breakpoint->InstanceAt(0)) {
						data.SetToFormat("%#" B_PRIx64, instance->Address());
					}
				}
				value.SetTo(data);
				return true;
			}
			default:
				return false;
		}
	}
void
DataTranslationsWindow::_ShowInfoAlert(int32 id)
{
	const char* name = NULL;
	const char* info = NULL;
	BPath path;
	int32 version = 0;
	_GetTranslatorInfo(id, name, info, version, path);

	const char* labels[] = { B_TRANSLATE("Name:"), B_TRANSLATE("Version:"),
		B_TRANSLATE("Info:"), B_TRANSLATE("Path:"), NULL };
	int offsets[4];

	BString message;
	BString temp;

	offsets[0] = 0;
	temp.SetToFormat("%s %s\n", labels[0], name);

	message.Append(temp);

	offsets[1] = message.Length();
	// Convert the version number into a readable format
	temp.SetToFormat("%s %" B_PRId32 ".%" B_PRId32 ".%" B_PRId32 "\n\n", labels[1],
		B_TRANSLATION_MAJOR_VERSION(version),
		B_TRANSLATION_MINOR_VERSION(version),
		B_TRANSLATION_REVISION_VERSION(version));

	message.Append(temp);

	offsets[2] = message.Length();
	temp.SetToFormat("%s\n%s\n\n", labels[2], info);

	message.Append(temp);

	offsets[3] = message.Length();
	temp.SetToFormat("%s %s\n", labels[3], path.Path());

	message.Append(temp);

	BAlert* alert = new BAlert(B_TRANSLATE("Info"), message.String(),
		B_TRANSLATE("OK"));
	BTextView* view = alert->TextView();
	BFont font;

	view->SetStylable(true);

	view->GetFont(&font);
	font.SetFace(B_BOLD_FACE);

	for (int32 i = 0; labels[i]; i++) {
		view->SetFontAndColor(offsets[i], offsets[i] + strlen(labels[i]), &font);
	}

	alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
	alert->Go();
}
Example #6
0
status_t
DebugReportGenerator::_DumpDebuggedThreadInfo(BString& _output,
	::Thread* thread)
{
	AutoLocker< ::Team> locker;
	if (thread->State() != THREAD_STATE_STOPPED)
		return B_OK;

	StackTrace* trace = NULL;
	for (;;) {
		trace = thread->GetStackTrace();
		if (trace != NULL)
			break;

		locker.Unlock();
		status_t result = acquire_sem(fTeamDataSem);
		if (result != B_OK)
			return result;

		locker.Lock();
	}

	_output << "\t\tFrame\t\tIP\t\t\tFunction Name\n";
	_output << "\t\t-----------------------------------------------\n";
	BString data;
	for (int32 i = 0; StackFrame* frame = trace->FrameAt(i); i++) {
		char functionName[512];
		data.SetToFormat("\t\t%#08" B_PRIx64 "\t%#08" B_PRIx64 "\t%s\n",
			frame->FrameAddress(), frame->InstructionPointer(),
			UiUtils::FunctionNameForFrame(frame, functionName,
				sizeof(functionName)));

		_output << data;
	}

	_output << "\n\t\tRegisters:\n";

	CpuState* state = thread->GetCpuState();
	BVariant value;
	const Register* reg = NULL;
	for (int32 i = 0; i < fArchitecture->CountRegisters(); i++) {
		reg = fArchitecture->Registers() + i;
		state->GetRegisterValue(reg, value);

		char buffer[64];
		data.SetToFormat("\t\t\t%5s:\t%s\n", reg->Name(),
			UiUtils::VariantToString(value, buffer, sizeof(buffer)));
		_output << data;
	}

	return B_OK;
}
BObjectList<PootleProject>
PootleProjectsEndpoint::Get(int limit, int offset)
{
	BObjectList<PootleProject> objectlist(20, true);
	BString url;
	int32 count = -1;
	if (limit == -1)
		limit = 100;

	url.SetToFormat("?limit=%d&offset=%d", limit, offset);
	BMessage data = _GetAll(url, limit < 0 ? 0 : limit);
	data.GetInfo("data", NULL, &count);

	if (count < 0)
		return objectlist;

	for (int32 i = 0; i < count; i++) {
		BMessage msg;
		data.FindMessage("data", i, &msg);
		PootleProject *lang = new PootleProject(this, msg);
		objectlist.AddItem(lang);
	}
	
	return objectlist;
}
Example #8
0
void
MainWin::SetupChannelMenu()
{
	fChannelMenu->RemoveItems(0, fChannelMenu->CountItems(), true);

	int interface = fController->CurrentInterface();
	printf("MainWin::SetupChannelMenu: interface %d\n", interface);

	int channels = fController->ChannelCount();

	if (channels == 0) {
		fChannelMenu->AddItem(new BMenuItem(B_TRANSLATE("None"),
			new BMessage(M_DUMMY)));
	} else {
		fChannelMenu->AddItem(new BMenuItem(B_TRANSLATE("Next channel"),
			new BMessage(M_CHANNEL_NEXT), '+', B_COMMAND_KEY));
		fChannelMenu->AddItem(new BMenuItem(B_TRANSLATE("Previous channel"),
			new BMessage(M_CHANNEL_PREV), '-', B_COMMAND_KEY));
		fChannelMenu->AddSeparatorItem();
	}

	for (int i = 0; i < channels; i++) {
		BString string;
		string.SetToFormat("%s%d %s", (i < 9) ? "  " : "", i + 1,
			fController->ChannelName(i));
		fChannelMenu->AddItem(new BMenuItem(string,
			new BMessage(M_SELECT_CHANNEL + i)));
	}
}
Example #9
0
status_t
ConfigWindow::_SetToGeneralSettings(BMailSettings* settings)
{
	if (settings == NULL)
		return B_BAD_VALUE;

	status_t status = settings->InitCheck();
	if (status != B_OK)
		return status;

	// retrieval frequency
	uint32 interval = uint32(settings->AutoCheckInterval() / 60000000L);
	fCheckMailCheckBox->SetValue(interval != 0 ? B_CONTROL_ON : B_CONTROL_OFF);

	if (interval == 0)
		interval = 5;

	BString intervalText;
	intervalText.SetToFormat("%" B_PRIu32, interval);
	fIntervalControl->SetText(intervalText.String());

	int32 showStatusIndex = settings->ShowStatusWindow();
	BMenuItem* item = fStatusModeField->Menu()->ItemAt(showStatusIndex);
	if (item != NULL) {
		item->SetMarked(true);
		// send live update to the server by simulating a menu click
		BMessage msg(kMsgShowStatusWindowChanged);
		msg.AddInt32("ShowStatusWindow", showStatusIndex);
		PostMessage(&msg);
	}

	return B_OK;
}
Example #10
0
void
CookieWindow::_ShowCookiesForDomain(BString domain)
{
	BString label;
	label.SetToFormat(B_TRANSLATE("Cookies for %s"), domain.String());
	fHeaderView->SetText(label);

	// Empty the cookie list
	fCookies->Clear();

	// Populate the domain list
	BNetworkCookieJar::Iterator it = fCookieJar.GetIterator();

	const BNetworkCookie* cookie;
	/* FIXME A direct access to a domain would be needed in BNetworkCookieJar. */
	while ((cookie = it.Next()) != NULL) {
		if (cookie->Domain() == domain)
			break;
	}

	if (cookie == NULL)
		return;

	do {
		new CookieRow(fCookies, *cookie); // Attaches itself to the list
		cookie = it.Next();
	} while (cookie != NULL && cookie->Domain() == domain);
}
Example #11
0
status_t
DebugReportGenerator::_DumpLoadedImages(BString& _output)
{
	AutoLocker< ::Team> locker(fTeam);

	_output << "\nLoaded Images:\n";
	BString data;
	for (ImageList::ConstIterator it = fTeam->Images().GetIterator();
		 Image* image = it.Next();) {
		const ImageInfo& info = image->Info();
		char buffer[32];
		try {
			target_addr_t textBase = info.TextBase();
			target_addr_t dataBase = info.DataBase();

			data.SetToFormat("\t%s (%" B_PRId32 ", %s) "
				"Text: %#08" B_PRIx64 " - %#08" B_PRIx64 ", Data: %#08"
				B_PRIx64 " - %#08" B_PRIx64 "\n", info.Name().String(),
				info.ImageID(), UiUtils::ImageTypeToString(info.Type(),
					buffer, sizeof(buffer)), textBase,
				textBase + info.TextSize(), dataBase,
				dataBase + info.DataSize());

			_output << data;
		} catch (...) {
			return B_NO_MEMORY;
		}
	}

	return B_OK;
}
Example #12
0
void
VariableEditWindow::_Init()
{
    BString label;
    BString initialValue;
    fInitialValue->ToString(initialValue);
    label.SetToFormat("Initial value for '%s': %s\n",
                      fNode->Name().String(), initialValue.String());

    BLayoutBuilder::Group<>(this, B_VERTICAL)
    .SetInsets(B_USE_DEFAULT_SPACING)
    .AddGroup(B_HORIZONTAL, 4.0f)
    .Add(new BStringView("initialLabel", label))
    .End()
    .AddGroup(B_HORIZONTAL, 4.0f)
    .Add(new BStringView("newLabel", "New value:"))
    .Add(fEditor->GetView())
    .End()
    .AddGroup(B_HORIZONTAL, 4.0f)
    .AddGlue()
    .Add((fCancelButton = new BButton("Cancel",
                                      new BMessage(B_QUIT_REQUESTED))))
    .Add((fSaveButton = new BButton("Save",
                                    new BMessage(MSG_WRITE_VARIABLE_VALUE))))
    .End();

    fCancelButton->SetTarget(this);
    fSaveButton->SetTarget(this);
    fSaveButton->MakeDefault(true);
    fEditor->GetView()->MakeFocus(true);
}
Example #13
0
status_t
CLanguageFamily::EvaluateExpression(const BString& expression,
	ValueNodeManager* manager, TeamTypeInformation* info,
	ExpressionResult*& _output, ValueNode*& _neededNode)
{
	_output = NULL;
	_neededNode = NULL;
	CLanguageExpressionEvaluator evaluator;
	try {
		_output = evaluator.Evaluate(expression, manager, info);
		return B_OK;
	} catch (ParseException ex) {
		BString error;
		error.SetToFormat("Parse error at position %" B_PRId32 ": %s",
			ex.position, ex.message.String());
		StringValue* value = new(std::nothrow) StringValue(error.String());
		if (value == NULL)
			return B_NO_MEMORY;
		BReference<Value> valueReference(value, true);
		_output = new(std::nothrow) ExpressionResult();
		if (_output == NULL)
			return B_NO_MEMORY;
		_output->SetToPrimitive(value);
		return B_BAD_DATA;
	} catch (ValueNeededException ex) {
		_neededNode = ex.value;
	}

	return B_OK;
}
Example #14
0
status_t
BProxySecureSocket::Connect(const BNetworkAddress& peer, bigtime_t timeout)
{
	status_t status = InitCheck();
	if (status != B_OK)
		return status;

	BSocket::Connect(fProxyAddress, timeout);
	if (status != B_OK)
		return status;

	BString connectRequest;
	connectRequest.SetToFormat("CONNECT %s:%d HTTP/1.0\r\n\r\n",
		peer.HostName().String(), peer.Port());
	BSocket::Write(connectRequest.String(), connectRequest.Length());

	char buffer[256];
	ssize_t length = BSocket::Read(buffer, sizeof(buffer) - 1);
	if (length <= 0)
		return length;

	buffer[length] = '\0';
	int httpStatus = 0;
	int matches = scanf(buffer, "HTTP/1.0 %d %*[^\r\n]\r\n\r\n", httpStatus);
	if (matches != 2)
		return B_BAD_DATA;

	if (httpStatus < 200 || httpStatus > 299)
		return B_BAD_VALUE;

	return _Setup();
}
Example #15
0
void
PackageManager::_PrintResult(InstalledRepository& installationRepository)
{
	if (!installationRepository.HasChanges())
		return;

	printf("  in %s:\n", installationRepository.Name().String());

	PackageList& packagesToActivate
		= installationRepository.PackagesToActivate();
	PackageList& packagesToDeactivate
		= installationRepository.PackagesToDeactivate();

	BStringList upgradedPackages;
	for (int32 i = 0;
		BSolverPackage* installPackage = packagesToActivate.ItemAt(i);
		i++) {
		for (int32 j = 0;
			BSolverPackage* uninstallPackage = packagesToDeactivate.ItemAt(j);
			j++) {
			if (installPackage->Info().Name() == uninstallPackage->Info().Name()) {
				upgradedPackages.Add(installPackage->Info().Name());
				break;
			}
		}
	}

	for (int32 i = 0; BSolverPackage* package = packagesToActivate.ItemAt(i);
		i++) {
		BString repository;
		if (dynamic_cast<MiscLocalRepository*>(package->Repository()) != NULL)
			repository = "local file";
		else
			repository.SetToFormat("repository %s", package->Repository()->Name().String());

		if (upgradedPackages.HasString(package->Info().Name())) {
			printf("    upgrade package %s to %s from %s\n",
				package->Info().Name().String(),
				package->Info().Version().ToString().String(),
				repository.String());
		} else {
			printf("    install package %s-%s from %s\n",
				package->Info().Name().String(),
				package->Info().Version().ToString().String(),
				repository.String());
		}
	}

	for (int32 i = 0; BSolverPackage* package = packagesToDeactivate.ItemAt(i);
		i++) {
		if (upgradedPackages.HasString(package->Info().Name()))
			continue;
		printf("    uninstall package %s\n", package->VersionedName().String());
	}
// TODO: Print file/download sizes. Unfortunately our package infos don't
// contain the file size. Which is probably correct. The file size (and possibly
// other information) should, however, be provided by the repository cache in
// some way. Extend BPackageInfo? Create a BPackageFileInfo?
}
Example #16
0
 BString _GetLabel() const
 {
     BString label;
     if (fItemCount == 1)
         label = B_TRANSLATE("1 item");
     else
         label.SetToFormat(B_TRANSLATE("%ld items"), fItemCount);
     return label;
 }
Example #17
0
void
TeamDescriptionView::SetItem(TeamListItem* item)
{
	fItem = item;

	if (item == NULL) {
		int32 styleStart = 0;
		int32 styleEnd = 0;
		BString text;

		text.SetToFormat(fInfoString, fSeconds);
		fInfoTextView->SetText(text);
		if (fRebootRunner != NULL && fSeconds < 4) {
			styleStart = text.FindLast('\n');
			styleEnd = text.Length();
		}

		if (styleStart != styleEnd && fInfoTextView != NULL) {
			BFont font;
			fInfoTextView->GetFont(&font);
			font.SetFace(B_BOLD_FACE);
			fInfoTextView->SetStylable(true);
			fInfoTextView->SetFontAndColor(styleStart, styleEnd, &font);
		}
	} else {
		fTeamName->SetText(item->Path()->Path());

		if (item->IsSystemServer()) {
			if (fSysComponent->IsHidden(fSysComponent))
				fSysComponent->Show();
		} else {
			if (!fSysComponent->IsHidden(fSysComponent))
				fSysComponent->Hide();
		}

		if (item->IsRefusingToQuit()) {
			if (fQuitOverdue->IsHidden(fQuitOverdue))
				fQuitOverdue->Show();
		} else {
			if (!fQuitOverdue->IsHidden(fQuitOverdue))
				fQuitOverdue->Hide();
		}

		fIconView->SetIcon(item->Path()->Path());
	}

	if (fLayout == NULL)
		return;

	if (item == NULL)
		fLayout->SetVisibleItem((int32)0);
	else
		fLayout->SetVisibleItem((int32)1);

	Invalidate();
}
Example #18
0
void
MainWin::UpdateWindowTitle()
{
	BString title;
	title.SetToFormat("%s - %d x %d, %.3f:%.3f => %.0f x %.0f",
		B_TRANSLATE_SYSTEM_NAME(NAME),
		fSourceWidth, fSourceHeight, fWidthScale, fHeightScale,
		fVideoView->Bounds().Width() + 1, fVideoView->Bounds().Height() + 1);
	SetTitle(title);
}
Example #19
0
	virtual status_t Perform()
	{
		fPackageManager->Init(BPackageManager::B_ADD_INSTALLED_REPOSITORIES
			| BPackageManager::B_ADD_REMOTE_REPOSITORIES
			| BPackageManager::B_REFRESH_REPOSITORIES);
		PackageInfoRef ref(Package());
		ref->SetState(PENDING);

		fPackageManager->SetCurrentActionPackage(ref, true);
		fPackageManager->AddProgressListener(this);

		BString packageName;
		if (ref->IsLocalFile())
			packageName = ref->LocalFilePath();
		else
			packageName = ref->Title();

		const char* packageNameString = packageName.String();
		try {
			fPackageManager->Install(&packageNameString, 1);
		} catch (BFatalErrorException ex) {
			_SetDownloadedPackagesState(NONE);
			BString errorString;
			errorString.SetToFormat(
				"Fatal error occurred while installing package %s: "
				"%s (%s)\n", packageNameString, ex.Message().String(),
				ex.Details().String());
			BAlert* alert(new(std::nothrow) BAlert(B_TRANSLATE("Fatal error"),
				errorString, B_TRANSLATE("Close")));
			if (alert != NULL)
				alert->Go(NULL);
			return ex.Error();
		} catch (BAbortedByUserException ex) {
			fprintf(stderr, "Installation of package "
				"%s aborted by user: %s\n", packageNameString,
				ex.Message().String());
			_SetDownloadedPackagesState(NONE);
			return B_OK;
		} catch (BNothingToDoException ex) {
			fprintf(stderr, "Nothing to do while installing package "
				"%s: %s\n", packageNameString, ex.Message().String());
			return B_OK;
		} catch (BException ex) {
			fprintf(stderr, "Exception occurred while installing package "
				"%s: %s\n", packageNameString, ex.Message().String());
			_SetDownloadedPackagesState(NONE);
			return B_ERROR;;
		}

		fPackageManager->RemoveProgressListener(this);

		_SetDownloadedPackagesState(ACTIVATED);

		return B_OK;
	}
Example #20
0
void
InfoWin::_UpdateVideo()
{
	bool visible = fController->VideoTrackCount() > 0;
	if (visible) {
		BString info;
		media_format format;
		media_raw_video_format videoFormat = {};
		status_t status = fController->GetEncodedVideoFormat(&format);
		if (status != B_OK) {
			info << "(" << strerror(status) << ")\n";
		} else if (format.type == B_MEDIA_ENCODED_VIDEO) {
			videoFormat = format.u.encoded_video.output;
			media_codec_info mci;
			status = fController->GetVideoCodecInfo(&mci);
			if (status != B_OK) {
				if (format.user_data_type == B_CODEC_TYPE_INFO) {
					info << (char *)format.user_data << " "
						<< B_TRANSLATE("(not supported)");
				} else
					info = strerror(status);
			} else
				info << mci.pretty_name; //<< "(" << mci.short_name << ")";
		} else if (format.type == B_MEDIA_RAW_VIDEO) {
			videoFormat = format.u.raw_video;
			info << B_TRANSLATE("raw video");
		} else
			info << B_TRANSLATE("unknown format");

		fVideoFormatInfo->SetText(info.String());

		info.SetToFormat("%" B_PRIu32 " x %" B_PRIu32, format.Width(),
			format.Height());

		// encoded has output as 1st field...
		char fpsString[20];
		snprintf(fpsString, sizeof(fpsString), B_TRANSLATE("%.3f fps"),
			videoFormat.field_rate);
		info << ", " << fpsString;

		fVideoConfigInfo->SetText(info.String());

		if (fController->IsOverlayActive())
			fDisplayModeInfo->SetText(B_TRANSLATE("Overlay"));
		else
			fDisplayModeInfo->SetText(B_TRANSLATE("DrawBitmap"));
	}

	fVideoSeparator->SetVisible(visible);
	_SetVisible(fVideoLabel, visible);
	_SetVisible(fVideoFormatInfo, visible);
	_SetVisible(fVideoConfigInfo, visible);
	_SetVisible(fDisplayModeLabel, visible);
	_SetVisible(fDisplayModeInfo, visible);
}
Example #21
0
void
InspectorWindow::TargetAddressChanged(target_addr_t address)
{
	AutoLocker<BLooper> lock(this);
	if (lock.IsLocked()) {
		fCurrentAddress = address;
		BString computedAddress;
		computedAddress.SetToFormat("0x%" B_PRIx64, address);
		fAddressInput->SetText(computedAddress.String());
	}
}
Example #22
0
	virtual void Pulse()
	{
		if (fToolTip != NULL)
			fToolTip->ReleaseReference();

		BString text;
		text.SetToFormat("New tool tip every second! (%d)", fCounter++);

		fToolTip = new CustomToolTip(text.String());
		SetToolTip(fToolTip);
	}
Example #23
0
status_t
BDaemonClient::CreateTransaction(BPackageInstallationLocation location,
	BActivationTransaction& _transaction, BDirectory& _transactionDirectory)
{
	// get an info for the location
	BInstallationLocationInfo info;
	status_t error = GetInstallationLocationInfo(location, info);
	if (error != B_OK)
		return error;

	// open admin directory
	entry_ref entryRef;
	entryRef.device = info.PackagesDirectoryRef().device;
	entryRef.directory = info.PackagesDirectoryRef().node;
	error = entryRef.set_name(PACKAGES_DIRECTORY_ADMIN_DIRECTORY);
	if (error != B_OK)
		return error;
	
	BDirectory adminDirectory;
	error = adminDirectory.SetTo(&entryRef);
	if (error != B_OK)
		return error;

	// create a transaction directory
	int uniqueId = 1;
	BString directoryName;
	for (;; uniqueId++) {
		directoryName.SetToFormat("transaction-%d", uniqueId);
		if (directoryName.IsEmpty())
			return B_NO_MEMORY;

		error = adminDirectory.CreateDirectory(directoryName,
			&_transactionDirectory);
		if (error == B_OK)
			break;
		if (error != B_FILE_EXISTS)
			return error;
	}

	// init the transaction
	error = _transaction.SetTo(location, info.ChangeCount(), directoryName);
	if (error != B_OK) {
		BEntry entry;
		_transactionDirectory.GetEntry(&entry);
		_transactionDirectory.Unset();
		if (entry.InitCheck() == B_OK)
			entry.Remove();
		return error;
	}

	return B_OK;
}
		status_t ConvertToDriverSettings(const BMessage& source,
			const char* name, int32 index, uint32 type, BString& value)
		{
			int32 intValue;
			if (index == 0 && source.FindInt32(name, 0, &intValue) == B_OK) {
				BString string;
				string.SetToFormat("0x%" B_PRIu32, intValue);
				value << string;

				return B_OK;
			}
			return B_NOT_SUPPORTED;
		}
Example #25
0
status_t
InspectorWindow::_SaveMenuFieldMode(BMenuField* field, const char* name,
	BMessage& settings)
{
	BMenuItem* item = field->Menu()->FindMarked();
	if (item && item->Message()) {
		int32 mode = item->Message()->FindInt32("mode");
		BString fieldName;
		fieldName.SetToFormat("%sMode", name);
		return settings.AddInt32(fieldName.String(), mode);
	}

	return B_OK;
}
	void Update()
	{
		if (!Lock())
			return;

		MixerControl control;
		control.Connect(fWhich);

		BString text;
		text.SetToFormat(B_TRANSLATE("%g dB"), control.Volume());
		fView->SetText(text.String());

		Unlock();
	}
void
TeamDescriptionView::SetItem(TeamListItem* item)
{
	fItem = item;
	int32 styleStart = 0;
	int32 styleEnd = 0;
	BTextView* view = NULL;

	if (item == NULL) {
		BString text;
		text.SetToFormat(fInfoString, fSeconds);
		fInfoTextView->SetText(text);
		if (fRebootRunner != NULL && fSeconds < 4) {
			styleStart = text.FindLast('\n');
			styleEnd = text.Length();
		}
		view = fInfoTextView;
	} else {
		BString text = item->Path()->Path();
		if (item->IsSystemServer())
			text << "\n" << fSysComponentString;
		if (item->IsRefusingToQuit()) {
			text << "\n\n" << fQuitOverdueString;
			styleStart = text.FindLast('\n');
			styleEnd = text.Length();
		}
		view = fIconTextView;
		fIconTextView->SetText(text);
		fIconView->SetIcon(item->Path()->Path());
	}

	if (styleStart != styleEnd && view != NULL) {
		BFont font;
		view->GetFont(&font);
		font.SetFace(B_BOLD_FACE);
		view->SetStylable(true);
		view->SetFontAndColor(styleStart, styleEnd, &font);
	}

	if (fLayout == NULL)
		return;

	if (item == NULL)
		fLayout->SetVisibleItem((int32)0);
	else
		fLayout->SetVisibleItem((int32)1);

	Invalidate();
}
Example #28
0
status_t
DebugReportGenerator::_GenerateReportHeader(BString& _output)
{
	AutoLocker< ::Team> locker(fTeam);

	BString data;
	data.SetToFormat("Debug information for team %s (%" B_PRId32 "):\n",
		fTeam->Name(), fTeam->ID());
	_output << data;

	// TODO: this information should probably be requested via the debugger
	// interface, since e.g. in the case of a remote team, the report should
	// include data about the target, not the debugging host
	system_info info;
	if (get_system_info(&info) == B_OK) {
		data.SetToFormat("CPU(s): %" B_PRId32 "x %s %s\n",
			info.cpu_count, get_cpu_vendor_string(info.cpu_type),
			get_cpu_model_string(&info));
		_output << data;
		char maxSize[32];
		char usedSize[32];

		data.SetToFormat("Memory: %s total, %s used\n",
			BPrivate::string_for_size((int64)info.max_pages * B_PAGE_SIZE,
				maxSize, sizeof(maxSize)),
			BPrivate::string_for_size((int64)info.used_pages * B_PAGE_SIZE,
				usedSize, sizeof(usedSize)));
		_output << data;
	}
	utsname name;
	uname(&name);
	data.SetToFormat("Haiku revision: %s (%s)\n", name.version, name.machine);
	_output << data;

	return B_OK;
}
Example #29
0
int32
add_query_menu_items(BMenu* menu, const char* attribute, uint32 what,
	const char* format, bool popup)
{
	BVolume	volume;
	BVolumeRoster().GetBootVolume(&volume);

	BQuery query;
	query.SetVolume(&volume);
	query.PushAttr(attribute);
	query.PushString("*");
	query.PushOp(B_EQ);
	query.Fetch();

	int32 index = 0;
	BEntry entry;
	while (query.GetNextEntry(&entry) == B_OK) {
		BFile file(&entry, B_READ_ONLY);
		if (file.InitCheck() == B_OK) {
			BMessage* message = new BMessage(what);

			entry_ref ref;
			entry.GetRef(&ref);
			message->AddRef("ref", &ref);

			BString value;
			if (file.ReadAttrString(attribute, &value) < B_OK)
				continue;

			message->AddString("attribute", value.String());

			BString name;
			if (format != NULL)
				name.SetToFormat(format, value.String());
			else
				name = value;

			if (index < 9 && !popup)
				menu->AddItem(new BMenuItem(name, message, '1' + index));
			else
				menu->AddItem(new BMenuItem(name, message));
			index++;
		}
	}

	return index;
}
Example #30
0
void
InspectorWindow::_LoadMenuFieldMode(BMenuField* field, const char* name,
	const BMessage& settings)
{
	BString fieldName;
	int32 mode;
	fieldName.SetToFormat("%sMode", name);
	if (settings.FindInt32(fieldName.String(), &mode) == B_OK) {
		BMenu* menu = field->Menu();
		for (int32 i = 0; i < menu->CountItems(); i++) {
			BInvoker* item = menu->ItemAt(i);
			if (item->Message()->FindInt32("mode") == mode) {
				item->Invoke();
				break;
			}
		}
	}
}