Example #1
0
void StatusView::setMessage(
	BString &title,
	BString &details,
	status_t error) {
	D_OPERATION(("StatusView::setMessage(%s)\n", title.String()));

	// get the tip manager instance and reset
	TipManager *manager = TipManager::Instance();
	manager->removeAll(this);

	// append error string
	if (error) {
		title << " (" << strerror(error) << ")";
	}

	// truncate if necessary
	bool truncated = false;
	m_fullText = title;
	if (be_plain_font->StringWidth(title.String()) > Bounds().Width() - 25.0) {
		be_plain_font->TruncateString(&title, B_TRUNCATE_END,
									  Bounds().Width() - 25.0);
		truncated = true;
	}
	BStringView::SetText(title.String());

	if (truncated || details.CountChars() > 0) {
		BString tip = m_fullText;
		if (details.CountChars() > 0) {
			tip << "\n" << details;
		}
		manager->setTip(tip.String(), this);
	}

	if (error) {
		beep();
		// set icon
		if (m_icon) {
			delete m_icon;
			m_icon = 0;
		}
		BRect iconRect(0.0, 0.0, 7.0, 11.0);
		m_icon = new BBitmap(iconRect, B_CMAP8);
		m_icon->SetBits(ERROR_ICON_BITS, 96, 0, B_CMAP8);
	}
	else {
		// set icon
		if (m_icon) {
			delete m_icon;
			m_icon = 0;
		}
		BRect iconRect(0.0, 0.0, 7.0, 11.0);
		m_icon = new BBitmap(iconRect, B_CMAP8);
		m_icon->SetBits(INFO_ICON_BITS, 96, 0, B_CMAP8);
	}
	m_dirty = true;
	startFade();
	Invalidate();
}
Example #2
0
int32_t
PRosterGetAppInfo(void *pobject, void *in, void *out, void *ptr)
{
	if (!pobject || !in || !out)
		return B_ERROR;
	
	PRoster *roster = static_cast<PRoster*>(pobject);
	if (!roster)
		return B_BAD_TYPE;
	
	PArgs *args = static_cast<PArgs*>(in);
	
	BString path;
	if (args->FindString("path", &path) != B_OK)
		path = "";
	
	BString signature;
	if (args->FindString("signature", &signature) != B_OK)
		signature = "";
	
	app_info info;
	status_t status;
	if (path.CountChars() > 1)
	{
		entry_ref pathRef;
		BEntry entry(path.String());
		entry.GetRef(&pathRef);
		
		status = be_roster->GetAppInfo(&pathRef, &info);
	}
	else if(signature.CountChars() < 1)
	{
		status = be_roster->GetAppInfo(signature.String(), &info);
	}
	else
		return B_ERROR;
	
	PArgs infoList;
	infoList.AddInt32("thread", info.thread);
	infoList.AddInt32("team", info.team);
	infoList.AddInt32("port", info.port);
	infoList.AddInt32("flags", info.flags);
	infoList.AddRef("entry_ref", info.ref);
	infoList.AddString("signature", info.signature);
	
	PArgs *outArgs = static_cast<PArgs*>(out);
	outArgs->MakeEmpty();
	outArgs->AddPArg("app_info", infoList);
	outArgs->AddInt32("status", status);
	
	return B_OK;
}
Example #3
0
int32_t
PRosterFindApp(void *pobject, void *in, void *out, void *ptr)
{
	if (!pobject || !in || !out)
		return B_ERROR;
	
	PRoster *roster = static_cast<PRoster*>(pobject);
	if (!roster)
		return B_BAD_TYPE;
	
	PArgs *args = static_cast<PArgs*>(in);
	
	BString path;
	if (args->FindString("path", &path) != B_OK)
		path = "";
	
	BString signature;
	if (args->FindString("signature", &signature) != B_OK)
		signature = "";
	
	entry_ref ref;
	status_t status;
	if (path.CountChars() > 1)
	{
		entry_ref pathRef;
		BEntry entry(path.String());
		entry.GetRef(&pathRef);
		
		status = be_roster->FindApp(&pathRef, &ref);
	}
	else if(signature.CountChars() < 1)
	{
		status = be_roster->FindApp(signature.String(), &ref);
	}
	else
		return B_ERROR;
	
	PArgs refList;
	refList.AddInt32("device", ref.device);
	refList.AddInt64("directory", ref.directory);
	refList.AddString("name", ref.name);
	
	PArgs *outArgs = static_cast<PArgs*>(out);
	outArgs->MakeEmpty();
	outArgs->AddPArg("entry_ref", refList);
	outArgs->AddInt32("status", status);
	
	return B_OK;
}
Example #4
0
bool
StringCompare(const BString &from, const BString &to, const char *mode,
			const bool &match_case)
{
	if (!mode)
	{
		debugger("NULL mode in StringCompare");
		return false;
	}
	
	if (strcmp(mode,"is") == 0)
		if (match_case)
			return from.Compare(to) == 0;
		else
			return from.ICompare(to) == 0;
	else if (strcmp(mode,"is not") == 0)
		if (match_case)
			return from.Compare(to) != 0;
		else
			return from.ICompare(to) != 0;
	else if (strcmp(mode,"contains") == 0)
		if (match_case)
			return to.FindFirst(from) >= 0;
		else
			return to.IFindFirst(from) >= 0;
	else if (strcmp(mode,"does not contain") == 0)
		if (match_case)
			return to.FindFirst(from) < 0;
		else
			return to.IFindFirst(from) < 0;
	else if (strcmp(mode,"starts with") == 0)
		if (match_case)
			return to.FindFirst(from) == 0;
		else
			return to.IFindFirst(from) == 0;
	else if (strcmp(mode,"ends with") == 0)
	{
		int32 pos;
		if (match_case)
			pos = to.FindLast(from);
		else
			pos = to.IFindLast(from);
		
		return (to.CountChars() - from.CountChars() == pos);
	}	
	
	return false;
}
status_t
BLocale::FormatTime(BString* string, time_t time, BString format,
	const BTimeZone* timeZone) const
{
	BAutolock lock(fLock);
	if (!lock.IsLocked())
		return B_ERROR;

	if (format == NULL || format.CountChars() <= 0)
		return B_BAD_VALUE;

	ObjectDeleter<DateFormat> timeFormatter(_CreateTimeFormatter(format));
	if (timeFormatter.Get() == NULL)
		return B_NO_MEMORY;

	if (timeZone != NULL) {
		ObjectDeleter<TimeZone> icuTimeZone(
			TimeZone::createTimeZone(timeZone->ID().String()));
		if (icuTimeZone.Get() == NULL)
			return B_NO_MEMORY;
		timeFormatter->setTimeZone(*icuTimeZone.Get());
	}

	UnicodeString icuString;
	timeFormatter->format((UDate)time * 1000, icuString);

	string->Truncate(0);
	BStringByteSink stringConverter(string);
	icuString.toUTF8(stringConverter);

	return B_OK;
}
Example #6
0
BString
DNSTools::ConvertToDNSName(const BString& string)
{
	BString outString = string;
	int32 dot, lastDot, diff;

	dot = string.FindFirst(".");
	if (dot != B_ERROR) {
		outString.Prepend((char*)&dot, 1);
		// because we prepend a char add 1 more
		lastDot = dot + 1;

		while (true) {
			dot = outString.FindFirst(".", lastDot + 1);
			if (dot == B_ERROR)
				break;

			// set a counts to the dot
			diff =  dot - 1 - lastDot;
			outString[lastDot] = (char)diff;
			lastDot = dot;
		}
	} else
		lastDot = 0;

	diff = outString.CountChars() - 1 - lastDot;
	outString[lastDot] = (char)diff;

	return outString;
}
Example #7
0
int32_t
PTextViewDisallowChars(void *pobject, void *in, void *out, void *extraData)
{
	if (!pobject || !in || !out)
		return B_ERROR;
	
	PView *parent = static_cast<PView*>(pobject);
	if (!parent)
		return B_BAD_TYPE;
	
	BTextView *backend = (BTextView*)parent->GetView();
	
	PArgs *inArgs = static_cast<PArgs*>(in);
	BString string;
	if (inArgs->FindString("chars", &string) != B_OK)
		return B_ERROR;
	
	if (backend->Window())
		backend->Window()->Lock();
	
	for (int32 i = 0; i < string.CountChars(); i++)
	{
		char c = string.ByteAt(i);
		if (c)
			backend->DisallowChar(c);
	}
	
	if (backend->Window())
		backend->Window()->Unlock();
	
	return B_OK;
}
Example #8
0
void
BHttpRequest::_ParseStatus()
{
	// Status line should be formatted like: HTTP/M.m SSS ...
	// With:   M = Major version of the protocol
	//         m = Minor version of the protocol
	//       SSS = three-digit status code of the response
	//       ... = additional text info
	BString statusLine;
	if (_GetLine(statusLine) == B_ERROR)
		return;

	if (statusLine.CountChars() < 12)
		return;

	fRequestStatus = kRequestStatusReceived;

	BString statusCodeStr;
	BString statusText;
	statusLine.CopyInto(statusCodeStr, 9, 3);
	_SetResultStatusCode(atoi(statusCodeStr.String()));

	statusLine.CopyInto(_ResultStatusText(), 13, statusLine.Length() - 13);

	_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Status line received: Code %d (%s)",
		atoi(statusCodeStr.String()), _ResultStatusText().String());
}
Example #9
0
void AddTorrentWindow::UpdateFileList()
{	
	//
	//
	int 	 fileCount = fTorrent->Info()->fileCount;
	tr_file* fileList  = fTorrent->Info()->files;
	
	for( int i = 0; i < fileCount; i++ )
	{
		char FormatBuffer[128] = { 0 };
		BRow* row = new BRow(FILE_COLUMN_HEIGHT);
		
		const char* name = fTorrent->IsFolder() ? (strchr(fileList[i].name, '/') + 1) : fileList[i].name;
		
		//
		//
		//
		BString FileExtension = B_EMPTY_STRING;
		BString FilePath = fileList[i].name;
		FilePath.CopyInto(FileExtension, FilePath.FindLast('.') + 1, FilePath.CountChars());
		
		
		const char* info = tr_formatter_mem_B(FormatBuffer, fileList[i].length, sizeof(FormatBuffer));;
		const BBitmap* icon = GetIconFromExtension(FileExtension);
		
		row->SetField(new FileField(icon, name, info), COLUMN_FILE_NAME);
		row->SetField(new CheckBoxField(true), COLUMN_FILE_DOWNLOAD);
		////row->SetField(new BIntegerField(PeerStatus[i].progress * 100.0), COLUMN_PEER_PROGRESS);
		
		fFileList->AddRow(row, i);

	} 	
}
Example #10
0
TextSpan::TextSpan(const BString& text, const TextStyle& style)
	:
	fText(text),
	fCharCount(text.CountChars()),
	fStyle(style)
{
}
ssize_t
BLocale::FormatTime(char* string, size_t maxSize, time_t time,
	BString format) const
{
	BAutolock lock(fLock);
	if (!lock.IsLocked())
		return B_ERROR;

	if (format == NULL || format.CountChars() <= 0)
		return B_BAD_VALUE;

	ObjectDeleter<DateFormat> timeFormatter(_CreateTimeFormatter(format));
	if (timeFormatter.Get() == NULL)
		return B_NO_MEMORY;

	UnicodeString icuString;
	timeFormatter->format((UDate)time * 1000, icuString);

	CheckedArrayByteSink stringConverter(string, maxSize);
	icuString.toUTF8(stringConverter);

	if (stringConverter.Overflowed())
		return B_BAD_VALUE;

	return stringConverter.NumberOfBytesWritten();
}
Example #12
0
FindOpenFileWindow::FindOpenFileWindow(const char* panelText)
	:
	DWindow(BRect(0, 0, 0, 0), TR("Find and open file"), B_TITLED_WINDOW,
		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
{
	AddCommonFilter(new EscapeCancelFilter());

	BView* top = GetBackgroundView();

	fNameTextControl = new AutoTextControl("nameText", TR("Open: "), "",
		new BMessage);
	fNameTextControl->SetExplicitMinSize(
		BSize(fNameTextControl->StringWidth("M") * 20, B_SIZE_UNSET));
	fSystemCheckBox = new BCheckBox("systembox", TR("Search only system folders"),
		new BMessage);

	BButton* cancel = new BButton("cancel", TR("Cancel"),
		new BMessage(B_QUIT_REQUESTED));

	BButton* open = new BButton("open", TR("Open"), new BMessage(M_FIND_FILE));

	BLayoutBuilder::Group<>(top, B_VERTICAL)
		.AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
			.Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0)
			.Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0)
			.Add(fSystemCheckBox, 1, 1)
			.End()
		.AddGlue()
		.AddGroup(B_HORIZONTAL)
			.AddGlue()
			.Add(cancel)
			.Add(open)
			.End()
		.SetInsets(B_USE_WINDOW_INSETS)
		.End();

	BString text = panelText;
	if (text.CountChars() > 1) {
		fNameTextControl->SetText(text.String());
		int32 position = text.FindLast(".");
		if (position > 0)
			fNameTextControl->TextView()->Select(0, position);
		else
			fNameTextControl->TextView()->SelectAll();
	} else {
		fNameTextControl->SetText(".h");
		fNameTextControl->TextView()->GoToLine(0);
	}

	open->MakeDefault(true);

	fNameTextControl->MakeFocus(true);

	CenterOnScreen();
}
Example #13
0
int32_t
PRosterTeamFor(void *pobject, void *in, void *out, void *ptr)
{
	if (!pobject || !in || !out)
		return B_ERROR;
	
	PRoster *roster = static_cast<PRoster*>(pobject);
	if (!roster)
		return B_BAD_TYPE;
	
	PArgs *args = static_cast<PArgs*>(in);
	
	BString path;
	if (args->FindString("path", &path) != B_OK)
		path = "";
	
	BString signature;
	if (args->FindString("signature", &signature) != B_OK)
		signature = "";
	
	team_id team;
	if (path.CountChars() > 1)
	{
		entry_ref pathRef;
		BEntry entry(path.String());
		entry.GetRef(&pathRef);
		
		team = be_roster->TeamFor(&pathRef);
	}
	else if(signature.CountChars() < 1)
	{
		team = be_roster->TeamFor(signature.String());
	}
	else
		return B_ERROR;
	
	PArgs *outArgs = static_cast<PArgs*>(out);
	outArgs->MakeEmpty();
	outArgs->AddInt32("value", team);
	
	return B_OK;
}
Example #14
0
BString
DTipWatcherView::GetTip(BView *view)
{
	BString text = fDataMap[view];
	while (view && text.CountChars() < 1)
	{
		view = view->Parent();
		text = fDataMap[view];
	}
	return text;
}
Example #15
0
void
Project::CompileFile(SourceFile *file)
{
	if (!file)
	{
		return;
	}
	
	BString compileString;
	if (Debug())
		compileString << "-g -O0 ";
	else
	{
		compileString << "-O" << (int)OpLevel() << " ";
		
		if (OpForSize())
			compileString << "-Os ";
	}
	
	if (Profiling())
		compileString << "-p ";
	
	if (fExtraCompilerOptions.CountChars() > 0)
		compileString << fExtraCompilerOptions << " ";
	
	compileString << "-I '" << fPath.GetFolder() << "' ";
	for (int32 i = 0; i < fLocalIncludeList.CountItems(); i++)
		compileString << "-I '" << fLocalIncludeList.ItemAt(i)->Absolute() << "' ";

	for (int32 i = 0; i < fSystemIncludeList.CountItems(); i++)
	{
		BString item = *fSystemIncludeList.ItemAt(i);
		
		if (item == ".")
			item = GetPath().GetFolder();
		else if (item.CountChars() >= 2 && item[0] == '.' && item[1] == '/')
			item.ReplaceFirst(".",GetPath().GetFolder());
		else if (item[0] != '/')
		{
			item.Prepend("/");
			item.Prepend(GetPath().GetFolder());
		}
		
		compileString << "-I '" << item.String() << "' ";
	}

	DPath projfolder(GetPath().GetFolder());
	file->Compile(fBuildInfo,compileString.String());
}
Example #16
0
void
FindWindow::ReplaceAll(void)
{
	// This function is called from the FinderThread function, so locking is
	// required when accessing any member variables.
	
	
	Lock();
	BString errorLog;
	
	BString findText(fFindBox->Text());
	BString replaceText(fReplaceBox->Text());
		
	if (!fIsRegEx)
	{
		findText.CharacterEscape("^$()%.[]*+-?", '\\');
	}
		
	BString replaceTerms;
	replaceTerms << "'" << findText << "' '" << replaceText << "'";
		
	ShellHelper shell;
	shell << "pwd; find ";
	shell.AddEscapedArg(fWorkingDir);
	BString sStr("'s/");
	sStr << findText.String() << "/";
	sStr << replaceText.String() << "/";
	sStr << "'";
	shell << " -type f | xargs sed -i " << sStr.String();
		
	STRACE(2,("Shell command: %s\n",shell.AsString().String()));
		
	Unlock();
	BString out;
	shell.RunInPipe(out,false);
	STRACE(2,("Command output: %s\n",out.String()));
	
	if (errorLog.CountChars() > 0)
	{
		BString errorString = B_TRANSLATE("The following files had problems replacing the search terms:\n");
		errorString << errorLog;
		
		ShowAlert(errorString.String());
	}
	
	PostMessage(M_FIND);
}
Example #17
0
bool
Project::IsProject(const entry_ref &ref)
{
	BNode node(&ref);
	BString type;
	node.ReadAttrString("BEOS:TYPE",&type);
	if (type.CountChars() > 0 && type == PROJECT_MIME_TYPE)
		return true;
	
	BString extension = BPath(&ref).Path();
	int32 pos = extension.FindLast(".");
	if (pos >= 0)
	{
		extension = extension.String() + pos;
		if (extension.ICompare(".pld") == 0)
			return true;
	}
	return false;
}
Example #18
0
void
Project::UpdateResources(void)
{
	DPath targetpath(fPath.GetFolder());
	targetpath.Append(GetTargetName());
	
	BString resFileString;
	int32 resCount = 0;

	for (int32 i = 0; i < CountGroups(); i++)
	{
		SourceGroup *group = GroupAt(i);
		
		for (int32 j = 0; j < group->filelist.CountItems(); j++)
		{
			SourceFile *file = group->filelist.ItemAt(j);
			
			if (file->GetResourcePath(fBuildInfo).GetFullPath())
			{
				resFileString << "'" << file->GetResourcePath(fBuildInfo).GetFullPath() << "' ";
				resCount++;
			}
		}
	}
	
	if (resCount > 0)
	{
		BString resString = "xres -o ";
		resString << "'" << targetpath.GetFullPath() << "' " << resFileString;		
		BString errmsg;
		PipeCommand(resString.String(),errmsg);
		
		STRACE(1,("Resources for %s:\n%s\nErrors:%s\n",GetName(),resString.String(),errmsg.String()));
		
		if (errmsg.CountChars() > 0)
			printf("Resource errors: %s\n",errmsg.String());
	}
	else
	{
		STRACE(1,("Resources for %s: No resource files to add\n",GetName()));
	}
}
Example #19
0
int32_t
PRosterGetAppList(void *pobject, void *in, void *out, void *ptr)
{
	if (!pobject || !in || !out)
		return B_ERROR;
	
	PRoster *roster = static_cast<PRoster*>(pobject);
	if (!roster)
		return B_BAD_TYPE;
	
	PArgs *args = static_cast<PArgs*>(in);
	
	BString signature;
	PArgs teamList;
	if (args->FindString("signature", &signature) != B_OK)
		signature = "";
	
	BList idList;
	if (signature.CountChars() > 0)
		be_roster->GetAppList(signature.String(), &idList);
	else
		be_roster->GetAppList(&idList);
	
	PArgs outList;
	for (int32 i = 0; i < idList.CountItems(); i++)
	{
		team_id *team = (team_id*)idList.ItemAt(i);
		
		BString indexString;
		indexString << i;
		
		outList.AddInt32(indexString.String(), *team);
	}
	
	PArgs *outArgs = static_cast<PArgs*>(out);
	outArgs->MakeEmpty();
	outArgs->AddPArg("teams", *outArgs);
	
	return B_OK;
}
Example #20
0
void
ExpanderApp::AboutRequested()
{
	BString appName = B_TRANSLATE("Expander");
	int nameLength = appName.CountChars();
	BAlert* alert = new BAlert("about",
		appName.Append(B_TRANSLATE("\n\twritten by Jérôme Duval\n"
			"\tCopyright 2004-2006, Haiku Inc.\n\noriginal Be version by \n"
			"Dominic, Hiroshi, Peter, Pavel and Robert\n")),
		B_TRANSLATE("OK"));
	BTextView* view = alert->TextView();
	BFont font;

	view->SetStylable(true);

	view->GetFont(&font);
	font.SetSize(18);
	font.SetFace(B_BOLD_FACE);
	view->SetFontAndColor(0, nameLength, &font);

	alert->Go();
}
Example #21
0
status_t
CDDBServer::_ParseAddress(const BString& cddbServer)
{
	// Set up server address.
	int32 pos = cddbServer.FindFirst(":");
	if (pos == B_ERROR) {
		// It seems we do not have the address:port format. Use hostname as-is.
		fServerAddress.SetTo(cddbServer.String(), kDefaultPortNumber);
		if (fServerAddress.InitCheck() == B_OK)
			return B_OK;
	} else {
		// Parse address:port format.
		int32 port;
		BString newCddbServer(cddbServer);
		BString portString;
		newCddbServer.MoveInto(portString, pos + 1,
			newCddbServer.CountChars() - pos + 1);
		if (portString.CountChars() > 0) {
			char* firstInvalid;
			errno = 0;
			port = strtol(portString.String(), &firstInvalid, 10);
			if ((errno == ERANGE && (port == INT32_MAX || port == INT32_MIN))
				|| (errno != 0 && port == 0)) {
				return B_ERROR;
			}
			if (firstInvalid == portString.String()) {
				return B_ERROR;
			}

			newCddbServer.RemoveAll(":");
			fServerAddress.SetTo(newCddbServer.String(), port);
			if (fServerAddress.InitCheck() == B_OK)
				return B_OK;
		}
	}

	return B_ERROR;
}
Example #22
0
void
DTipWatcherView::Pulse(void)
{
	// Check to see if there has been any activity. If so, just reset.
	BPoint pt;
	uint32 buttons;
	GetMouse(&pt,&buttons);
	ConvertToScreen(&pt);
	
	if (pt != fLastPoint || buttons)
	{
		fDelayCounter = 0;
		fLastPoint = pt;
		HideTip();
		return;
	}
	fLastPoint = pt;
	
	if (!Window()->IsHidden())
		return;
	
	fDelayCounter += Window()->PulseRate();
	if (fDelayCounter < fDelayMax)
		return;
	
	// We got this far, so it's time to show a tip
	BView *view = ViewForPoint(pt);
	if (!view)
		return;
	
	BString text = GetTip(view);
	if (text.CountChars() < 1)
		return;
	
	ShowTip(pt, text.String());
}
Example #23
0
bool
IsLocationMatch(const BMessage &test, const entry_ref &ref)
{
	BString value;
	if (test.FindString("value",&value) != B_OK)
	{
		debugger("Couldn't get value in IsLocationMatch");
		return false;
	}
	
	BString compare;
	if (test.FindString("mode",&compare) != B_OK)
	{
		debugger("Couldn't get mode in IsLocationMatch");
		return false;
	}
	
	// This is a little tricky -- we resolve symlinks in the location test
	entry_ref realref;
	BEntry(&ref).GetRef(&realref);
	
	BPath path(&realref);
	BString filepath(path.Path());
	filepath.RemoveLast(path.Leaf());
	
	if (value[value.CountChars() - 1] != '/')
		value << "/";
	
	bool result = StringCompare(value,filepath.String(),compare.String(),true);
	
	printf("\tLocation test: %s %s %s - %s\n",filepath.String(),
								compare.String(),value.String(),
								result ? "MATCH" : "NO MATCH");
	
	return result;
}
Example #24
0
status_t
TextDocument::Insert(int32 textOffset, const BString& text,
	const CharacterStyle& characterStyle, const ParagraphStyle& paragraphStyle)
{
	int32 paragraphOffset;
	int32 index = ParagraphIndexFor(textOffset, paragraphOffset);
	if (index < 0)
		return B_BAD_VALUE;

	textOffset -= paragraphOffset;

	bool hasLineBreaks = text.FindFirst('\n', 0) >= 0;

	if (hasLineBreaks) {
		// Split paragraph at textOffset
		Paragraph paragraph1(ParagraphAt(index).Style());
		Paragraph paragraph2(paragraphStyle);
		const TextSpanList& textSpans = ParagraphAt(index).TextSpans();
		int32 spanCount = textSpans.CountItems();
		for (int32 i = 0; i < spanCount; i++) {
			const TextSpan& span = textSpans.ItemAtFast(i);
			int32 spanLength = span.CountChars();
			if (textOffset >= spanLength) {
				paragraph1.Append(span);
				textOffset -= spanLength;
			} else if (textOffset > 0) {
				paragraph1.Append(
					span.SubSpan(0, textOffset));
				paragraph2.Append(
					span.SubSpan(textOffset, spanLength - textOffset));
				textOffset = 0;
			} else {
				paragraph2.Append(span);
			}
		}

		fParagraphs.Remove(index);

		// Insert TextSpans, splitting 'text' into Paragraphs at line breaks.
		int32 length = text.CountChars();
		int32 chunkStart = 0;
		while (chunkStart < length) {
			int32 chunkEnd = text.FindFirst('\n', chunkStart);
			bool foundLineBreak = chunkEnd >= chunkStart;
			if (foundLineBreak)
				chunkEnd++;
			else
				chunkEnd = length;

			BString chunk;
			text.CopyCharsInto(chunk, chunkStart, chunkEnd - chunkStart);
			TextSpan span(chunk, characterStyle);

			if (foundLineBreak) {
				if (!paragraph1.Append(span))
					return B_NO_MEMORY;
				if (paragraph1.Length() > 0) {
					if (!fParagraphs.Add(paragraph1, index))
						return B_NO_MEMORY;
					index++;
				}
				paragraph1 = Paragraph(paragraphStyle);
			} else {
				if (!paragraph2.Prepend(span))
					return B_NO_MEMORY;
			}

			chunkStart = chunkEnd + 1;
		}

		if (paragraph2.IsEmpty()) {
			// Make sure Paragraph has at least one TextSpan, even
			// if its empty.
			const TextSpanList& spans = paragraph1.TextSpans();
			const TextSpan& span = spans.LastItem();
			paragraph2.Append(TextSpan("", span.Style()));
		}

		if (!fParagraphs.Add(paragraph2, index))
			return B_NO_MEMORY;
	} else {
		Paragraph paragraph(ParagraphAt(index));
		paragraph.Insert(textOffset, TextSpan(text, characterStyle));
		if (!fParagraphs.Replace(index, paragraph))
			return B_NO_MEMORY;
	}

	return B_OK;
}
Example #25
0
void
PackageView::AttachedToWindow()
{
	status_t ret = fInfo.InitCheck();
	if (ret != B_OK && ret != B_NO_INIT) {
		BAlert* warning = new BAlert("parsing_failed",
				B_TRANSLATE("The package file is not readable.\nOne of the "
				"possible reasons for this might be that the requested file "
				"is not a valid BeOS .pkg package."), B_TRANSLATE("OK"),
				NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		warning->SetFlags(warning->Flags() | B_CLOSE_ON_ESCAPE);
		warning->Go();

		Window()->PostMessage(B_QUIT_REQUESTED);
		return;
	}

	// Set the window title
	BWindow* parent = Window();
	BString title;
	BString name = fInfo.GetName();
	if (name.CountChars() == 0) {
		title = B_TRANSLATE("Package installer");
	} else {
		title = B_TRANSLATE("Install %name%");
		title.ReplaceAll("%name%", name);
	}
	parent->SetTitle(title.String());
	fBeginButton->SetTarget(this);

	fOpenPanel->SetTarget(BMessenger(this));
	fInstallTypes->SetTargetForItems(this);

	if (ret != B_OK)
		return;

	// If the package is valid, we can set up the default group and all
	// other things. If not, then the application will close just after
	// attaching the view to the window
	_InstallTypeChanged(0);

	fStatusWindow = new PackageStatus(B_TRANSLATE("Installation progress"),
		NULL, NULL, this);

	// Show the splash screen, if present
	BMallocIO* image = fInfo.GetSplashScreen();
	if (image != NULL) {
		PackageImageViewer* imageViewer = new PackageImageViewer(image);
		imageViewer->Go();
	}

	// Show the disclaimer/info text popup, if present
	BString disclaimer = fInfo.GetDisclaimer();
	if (disclaimer.Length() != 0) {
		PackageTextViewer* text = new PackageTextViewer(
			disclaimer.String());
		int32 selection = text->Go();
		// The user didn't accept our disclaimer, this means we cannot
		// continue.
		if (selection == 0)
			parent->Quit();
	}
}
Example #26
0
void
MainWindow::AddControl(const BString &type)
{
	if (type.CountChars() < 1)
		return;
	
	PObjectBroker *broker = PObjectBroker::GetBrokerInstance();
	PObject *pobj = broker->MakeObject(type.String());
	
	if (!pobj || !pobj->UsesInterface("PView"))
		return;
		
	PView *pview = dynamic_cast<PView*>(pobj);
	if (!pview)
		return;
	
	BString name(pview->GetType());
	name << pview->GetID();
	pview->AddProperty(new StringProperty("Name",name.String(),"The name for this view"),0,0);
	
	if (pview->GetType().Compare("PTextControl") == 0)
	{
		// Create each text control with some more useful defaults for the GUI
		pview->SetStringProperty("Text", "Text");
		pview->SetStringProperty("Label", "Label");
		
		PArgs in, out;
		pview->RunMethod("SetPreferredDivider", in.ListRef(), out.ListRef());
	}
	
	FloatValue pw, ph;
	pview->GetProperty("PreferredWidth", &pw);
	pview->GetProperty("PreferredHeight", &ph);
	
	if (*pw.value > 0.0)
		pview->SetFloatProperty("Width",*pw.value);
	else
		pview->SetFloatProperty("Width",100);
	
	if (*ph.value > 0.0)
		pview->SetFloatProperty("Height",*ph.value);
	else
		pview->SetFloatProperty("Height",100);
	
	// If we have a PWindow selected in the window, we will add the view as a child of the
	// selected window. If there is no selection, we will add the item at the end with no
	// parent
	
	ObjectItem *item = new ObjectItem(pview);
	int32 selection = fListView->FullListCurrentSelection();
	if (selection < 0)
		fListView->AddItem(item);
	
	ObjectItem *oitem = dynamic_cast<ObjectItem*>(fListView->FullListItemAt(selection));
	if (!oitem)
		return;
	
	PWindow *pwin = dynamic_cast<PWindow*>(oitem->GetObject());
	if (pwin)
	{
		PArgs args,out;
		
		if (pview->GetType().Compare("PView") == 0 && 
			pwin->RunMethod("CountChildren",args.ListRef(),out.ListRef()) == B_OK)
		{
			int32 count;
			if (out.FindInt32("count",&count) == B_OK && count == 0)
			{
				float winWidth, winHeight;
				pwin->GetFloatProperty("Width",winWidth);
				pwin->GetFloatProperty("Height",winHeight);
				pview->SetFloatProperty("Width",winWidth);
				pview->SetFloatProperty("Height",winHeight);
				pview->SetIntProperty("HResizingMode",RESIZE_BOTH);
				pview->SetIntProperty("VResizingMode",RESIZE_BOTH);
			}
			pview->SetColorProperty("BackColor",ui_color(B_PANEL_BACKGROUND_COLOR));
		}
		
		args.AddInt64("id",item->GetObject()->GetID());
		if (pwin->RunMethod("AddChild", args.ListRef(), out.ListRef()) == B_OK)
			fListView->AddUnder(item,oitem);
		else
			fListView->AddItem(item);
	}
	else
	{
		if (oitem->GetObject()->UsesInterface("PView"))
		{
			PView *parent = dynamic_cast<PView*>(oitem->GetObject());
			PArgs args,out;
			args.AddInt64("id",item->GetObject()->GetID());
			if(parent->RunMethod("AddChild", args.ListRef(), out.ListRef()) == B_OK)
				fListView->AddUnder(item,oitem);
			else
				fListView->AddItem(item);
		}
		else
		{
			// Not a view or window, so just add it on at the end
			fListView->AddItem(item);
		}
	}
	
	pview->ConnectEvent("FocusChanged", PViewFocusChanged);
	pview->ConnectEvent("MouseDown", PViewMouseDown);
	pview->SetMsgHandler(M_FLOATER_ACTION, PViewHandleFloaterMsg);
	
	pview->SetBoolProperty("Focus", true);
	
	fListView->Select(fListView->FullListIndexOf(item));
}
/*
* Message Handling Function
* If it's a node monitor message,
* then figure out what to do based on it.
* Otherwise, let BApplication handle it.
*/
void
App::MessageReceived(BMessage *msg)
{
  printf("message received:\n");
  msg->PrintToStream();
  switch(msg->what)
  {
    case MY_DELTA_CONST:
    {
      printf("Pulling changes from Dropbox\n");
      pull_and_apply_deltas();
      break;
    }
    case B_NODE_MONITOR:
    {
      printf("Received Node Monitor Alert\n");
      status_t err;
      int32 opcode;
      err = msg->FindInt32("opcode",&opcode);
      if(err == B_OK)
      {
        switch(opcode)
        {
          case B_ENTRY_CREATED:
          {
            printf("CREATED NEW FILE\n");
            entry_ref ref;
            BPath path;
            const char * name;

            // unpack the message
            msg->FindInt32("device",&ref.device);
            msg->FindInt64("directory",&ref.directory);
            msg->FindString("name",&name);
            ref.set_name(name);

            BEntry new_file = BEntry(&ref);
            new_file.GetPath(&path);


            //if we said to ignore a `NEW` msg from the path, then ignore it
            if(this->ignore_created(&path)) return;

            this->track_file(&new_file);

            if(new_file.IsDirectory())
            {
               add_folder_to_dropbox(path.Path());
               BDirectory new_dir = BDirectory(&new_file);
               this->recursive_watch(&new_dir);
            }
            else
            {
              BString *result = add_file_to_dropbox(path.Path());
              BString *real_path = parse_path(result);
              BString *parent_rev = parse_parent_rev(result);
              delete result;

              printf("path:|%s|\nparent_rev:|%s|\n",real_path->String(),parent_rev->String());

              BNode node = BNode(&new_file);
              set_parent_rev(&node,parent_rev);
              delete parent_rev;
              BPath new_path = BPath(db_to_local_filepath(real_path->String()).String());

              if(strcmp(new_path.Leaf(),path.Leaf()) != 0)
              {
                printf("moving %s to %s\n", path.Leaf(), new_path.Leaf());
                BEntry entry = BEntry(path.Path()); //entry for local path
                status_t err = entry.Rename(new_path.Leaf(),true);
                if(err != B_OK) printf("error moving: %s\n",strerror(err));
              }
              
              delete real_path;
              watch_entry(&new_file,B_WATCH_STAT);
            }
            break;
          }
          case B_ENTRY_MOVED:
          {
            printf("MOVED FILE\n");
            entry_ref eref;
            BDirectory from_dir, to_dir;
            node_ref from_ref,to_ref,nref;
            BPath path;
            const char* name;

            msg->FindInt32("device",&from_ref.device);
            msg->FindInt32("device",&to_ref.device);
            msg->FindInt32("device",&eref.device);
            msg->FindInt32("device",&nref.device);

            msg->FindInt64("from directory",&from_ref.node);
            msg->FindInt64("to directory",&to_ref.node);
            msg->FindInt64("to directory",&eref.directory);

            msg->FindInt64("node",&nref.node);

            msg->FindString("name",&name);
            eref.set_name(name);

            err = from_dir.SetTo(&from_ref);
            err = to_dir.SetTo(&to_ref);

            BEntry dest_entry = BEntry(&eref);
            BEntry test = BEntry("/boot/home/Dropbox/hi");
            BDirectory dropbox_local = BDirectory(local_path_string);
            bool into_dropbox = dropbox_local.Contains(&dest_entry);
            int32 index = this->find_nref_in_tracked_files(nref);
            if((index >= 0) && into_dropbox)
            {
              printf("moving within dropbox\n");
              BPath *old_path = (BPath*)this->tracked_filepaths.ItemAt(index);
              BPath new_path;
              dest_entry.GetPath(&new_path);

              char *argv[3];
              argv[0] = "db_mv.py";
              BString opath = local_to_db_filepath(old_path->Path());
              BString npath = local_to_db_filepath(new_path.Path());
              char not_const_o[opath.CountChars()];
              char not_const_n[npath.CountChars()];
              strcpy(not_const_o,opath.String());
              strcpy(not_const_n,npath.String());
              argv[1] = not_const_o;
              argv[2] = not_const_n;
              run_python_script(argv,3);

              old_path->SetTo(&dest_entry);
            }
            else if(index >= 0)
            {
              printf("moving the file out of dropbox\n");
              BPath *old_path = (BPath*)this->tracked_filepaths.ItemAt(index);
              delete_file_on_dropbox(old_path->Path());
              this->tracked_files.RemoveItem(index);
              this->tracked_filepaths.RemoveItem(index);
            }
            else if(into_dropbox)
            {
              printf("moving file into dropbox\n");
              BPath new_path;
              dest_entry.GetPath(&new_path);

              this->track_file(&dest_entry);

              if(dest_entry.IsDirectory())
              {
                 add_folder_to_dropbox(new_path.Path());
                 BDirectory new_dir = BDirectory(&dest_entry);
                 this->recursive_watch(&new_dir);
              }
              else
              {
                add_file_to_dropbox(new_path.Path());
                watch_entry(&dest_entry,B_WATCH_STAT);
              }
            }
            else
            {
              printf("moving unrelated file...?\n");
            }

            break;
          }
          case B_ENTRY_REMOVED:
          {
            printf("DELETED FILE\n");
            node_ref nref;
            msg->FindInt32("device", &nref.device);
            msg->FindInt64("node", &nref.node);

            int32 index = this->find_nref_in_tracked_files(nref);
            if(index >= 0)
            {
              BPath *path = (BPath*)this->tracked_filepaths.ItemAt(index);
              printf("local file %s deleted\n",path->Path());
              
              if(ignore_removed(path)) return;

              delete_file_on_dropbox(path->Path());
              this->tracked_files.RemoveItem(index);
              this->tracked_filepaths.RemoveItem(index);
            }
            else
            {
              printf("could not find deleted file\n");
            }

            break;
          }
          case B_STAT_CHANGED:
          {
            printf("EDITED FILE\n");
            node_ref nref;
            msg->FindInt32("device", &nref.device);
            msg->FindInt64("node", &nref.node);

            int32 index = this->find_nref_in_tracked_files(nref);
            if(index >= 0)
            {
              BPath *path = (BPath*)this->tracked_filepaths.ItemAt(index);
              if(ignore_edited(path)) return;
              BNode node = BNode(path->Path());
              BString * rev = get_parent_rev(&node);
              printf("parent_rev:|%s|\n",rev->String());
              
              update_file_in_dropbox(path->Path(),rev->String());
            }
            else
            {
              printf("Could not find edited file\n");
            }
            break;
          }
          default:
          {
            printf("default case opcode...\n");
          }
        }
      }
      break;
    }
    default:
    {
      BApplication::MessageReceived(msg);
      break;
    }
  }
}
/*
* Given a single line of the output of db_delta.py
* Figures out what to do and does it.
* (adds and removes files and directories)
*/
int
App::parse_command(BString command)
{
  command.RemoveAll("\n"); //remove trailing whitespace
  if(command.Compare("RESET") == 0)
  {
    printf("Burn Everything. 8D\n");

    status_t err = stop_watching(be_app_messenger);
    if(err != B_OK) printf("stop_watching error: %s\n",strerror(err));

    BDirectory dir = BDirectory(local_path_string);
    rm_rf(&dir);

    BString str = BString("/"); //create_local_path wants a remote path 
    create_local_directory(&str);

    this->recursive_watch(&dir);
  }
  else if(command.Compare("FILE ",5) == 0)
  {
    BString path, dirpath, partial_path;
    BPath *bpath;
    int32 last_space = command.FindLast(" ");
    command.CopyInto(path,5,last_space - 5);

    path.CopyInto(dirpath,0,path.FindLast("/"));

    create_local_directory(&dirpath);
    //TODO fix watching new dirs
    bpath = new BPath(db_to_local_filepath(path.String()).String());
    BEntry new_file = BEntry(bpath->Path());
    if(new_file.InitCheck() && new_file.Exists()) {
      this->new_paths.AddItem((void*)bpath);
    } else {
      this->edited_paths.AddItem((void*)bpath);
    }

    printf("create a file at |%s|\n",path.String());
    char *argv[3];
    argv[0] = "db_get.py";
    char not_const1[path.CountChars() + 1];
    strcpy(not_const1,path.String());
    argv[1] = not_const1;
    BString tmp = db_to_local_filepath(path.String());
    char not_const2[tmp.CountChars() + 1]; //plus one for null
    strcpy(not_const2,tmp.String());
    argv[2] = not_const2;

    //create/update file
    //potential problem: takes awhile to do this step
    // having watching for dir turned off is risky.    
    BString * b = run_python_script(argv,3);
    delete b;

    //start watching the new/updated file
    node_ref nref;
    new_file = BEntry(db_to_local_filepath(path.String()).String());
    new_file.GetNodeRef(&nref);
    status_t err = watch_node(&nref,B_WATCH_STAT,be_app_messenger);

    BString parent_rev;
    command.CopyInto(parent_rev,last_space + 1, command.CountChars() - (last_space+1));
    BNode node = BNode(db_to_local_filepath(path.String()).String());
    set_parent_rev(&node,&parent_rev);
  }
  else if(command.Compare("FOLDER ",7) == 0)
  {
    BString path;
    command.CopyInto(path,7,command.FindLast(" ") - 7);

    //ignore the creation message
    BPath bpath = BPath(db_to_local_filepath(path.String()).String());
    BPath *actually_exists = find_existing_subpath(&bpath);
    this->new_paths.AddItem((void*)actually_exists);

    //create all nescessary dirs in path
    printf("create a folder at |%s|\n", path.String());
    create_local_directory(&path);

    //start watching the new dir
    BDirectory existing_dir = BDirectory(actually_exists->Path());
    recursive_watch(&existing_dir);
  }
  else if(command.Compare("REMOVE ",7) == 0)
  {
    //TODO: deal with Dropbox file paths being case-insensitive
    //which here means all lower case
    BString path;
    command.CopyInto(path,7,command.Length() - 7);

    const char * pathstr = db_to_local_filepath(path.String()).String();
    BPath *bpath = new BPath(pathstr);
    //TODO: check if it exists...
    this->removed_paths.AddItem((void*)bpath);

    printf("Remove whatever is at |%s|\n", pathstr);

    BEntry entry = BEntry(pathstr);
    status_t err = entry.Remove();
    if(err != B_OK)
      printf("Removal error: %s\n", strerror(err));
  }
  else
  {
    printf("Did not recognize command.\n");
    return B_ERROR;
  }
  return B_OK;
}
Example #29
0
int32
ReadReturnValues(lua_State *L, PArgs *list, PMethodInterface pmi, int tableIndex)
{
	// This function is for reading in all of the data returned from a Lua hook function,
	// which is expected to be a table
	
	if (!list)
		return B_ERROR;
	
	if (pmi.CountArgs() == 0 && pmi.CountReturnValues() == 0)
		return 0;
	
	PArgs args(list);
	args.MakeEmpty();
	
	int32 returnCount = 0;
	for (int32 i = 0; i < pmi.CountReturnValues(); i++)
	{
		BString name = pmi.ReturnNameAt(i);
		if (name.CountChars() < 1)
			continue;
		
		lua_pushstring(L, name);
		lua_gettable(L, tableIndex);
		
		if (lua_isnil(L, -1) && (pmi.ReturnFlagsAt(i) & PMIFLAG_OPTIONAL) == 0)
		{
			// Not an optional flag, so we have to bail.
			fprintf(stderr, "Missing required argument %s\n", name.String());
			lua_pop(L, 1);
			return B_ERROR;
		}
		
		switch (pmi.ReturnTypeAt(i))
		{
			case B_INT8_TYPE:
			{
				args.AddInt8(name.String(), lua_tointeger(L, -1));
				break;
			}
			case B_INT16_TYPE:
			{
				args.AddInt16(name.String(), lua_tointeger(L, -1));
				break;
			}
			case B_INT32_TYPE:
			{
				args.AddInt32(name.String(), lua_tointeger(L, -1));
				break;
			}
			case B_INT64_TYPE:
			{
				args.AddInt64(name.String(), lua_tointeger(L, -1));
				break;
			}
			case B_FLOAT_TYPE:
			{
				args.AddFloat(name.String(), lua_tonumber(L, -1));
				break;
			}
			case B_DOUBLE_TYPE:
			{
				args.AddDouble(name.String(), lua_tonumber(L, -1));
				break;
			}
			case B_BOOL_TYPE:
			{
				args.AddBool(name.String(), lua_toboolean(L, -1));
				break;
			}
			case B_CHAR_TYPE:
			{
				args.AddChar(name.String(), lua_tointeger(L, -1));
				break;
			}
			case B_STRING_TYPE:
			{
				args.AddString(name.String(), lua_tostring(L, -1));
				break;
			}
			case B_RECT_TYPE:
			{
				BRect r;
				
				lua_pushstring(L, "left");
				lua_gettable(L, -1);
				r.left = lua_tonumber(L, -1);
				lua_pop(L, 1);
				
				lua_pushstring(L, "top");
				lua_gettable(L, -1);
				r.top = lua_tonumber(L, -1);
				lua_pop(L, 1);
				
				lua_pushstring(L, "right");
				lua_gettable(L, -1);
				r.right = lua_tonumber(L, -1);
				lua_pop(L, 1);
				
				lua_pushstring(L, "bottom");
				lua_gettable(L, -1);
				r.bottom = lua_tonumber(L, -1);
				lua_pop(L, 1);
				
				args.AddRect(name.String(), r);
				break;
			}
			case B_POINT_TYPE:
			{
				BPoint pt;
				
				lua_pushstring(L, "x");
				lua_gettable(L, -1);
				pt.x = lua_tonumber(L, -1);
				lua_pop(L, 1);
				
				lua_pushstring(L, "y");
				lua_gettable(L, -1);
				pt.y = lua_tonumber(L, -1);
				lua_pop(L, 1);
				
				args.AddPoint(name.String(), pt);
				break;
			}
			case B_RGB_COLOR_TYPE:
			{
				rgb_color c;
				
				lua_pushstring(L, "reg");
				lua_gettable(L, -1);
				c.red = lua_tointeger(L, -1);
				lua_pop(L, 1);
				
				lua_pushstring(L, "green");
				lua_gettable(L, -1);
				c.green = lua_tointeger(L, -1);
				lua_pop(L, 1);
				
				lua_pushstring(L, "blue");
				lua_gettable(L, -1);
				c.blue = lua_tointeger(L, -1);
				lua_pop(L, 1);
				
				lua_pushstring(L, "alpha");
				lua_gettable(L, -1);
				c.alpha = lua_tointeger(L, -1);
				lua_pop(L, 1);
				
				args.AddColor(name.String(), c);
				break;
			}
			case B_POINTER_TYPE:
			{
				args.AddPointer(name.String(), (void*)lua_topointer(L, -1));
				break;
			}
			case PARG_LIST:
			{
				debugger("List handling unsupported for argument passing from Lua. Sorry!");
				break;
			}
			default:
			{
				printf("Unsupported retyrn type set to method\n");
				lua_pop(L, 1);
				break;
			}			
		}
		lua_pop(L, 1);
		returnCount++;
	}
	return returnCount;
}
Example #30
0
status_t LoadStatusses(BPath statFilePath)
{
	status_t error = B_OK;
	//open file
	BFile statFile(statFilePath.Path(), B_READ_ONLY);
	error = statFile.InitCheck();
	if (error != B_ERROR)
	{
		StringList *tokenList = new StringList();
		//read line
		off_t fileSize;
		if (statFile.GetSize(&fileSize) == B_OK)
		{			
			ssize_t bytesRead = 0;
			BString* token = new BString("");
			bool newToken = false;			
			do
			{
				char c[2];				
				bytesRead += statFile.Read(c,1);
				c[1] = '\0';				
				
				if (c[0] == '\t' || c[0] == '\n')
				{
					//clear token
					if (!newToken)
					{
						//add token to list
						tokenList->AddItem(token);						
						token = new BString("");				
						newToken = true;
					}
				}
				else 
				{
					token->Append(c);
					newToken = false;
				}
			}
			while (bytesRead < fileSize);
		}
		
		int32 startIndex = -1;
		int32 endIndex = -1;
		for (int32 i = 0; i < tokenList->CountItems(); i++)
		{
			if ((*tokenList)[i].ICompare("<status>") == 0)
				startIndex = i;
			else if ((*tokenList)[i].ICompare("</status>") == 0)
			{
				endIndex = i;
				break;
			}
		}
		
		if (startIndex != -1 && endIndex != -1)
		{
			//start past the <status> tag
			startIndex++;
			for (int32 i = startIndex; i < endIndex; i++)
			{
				int32 lastLineIndex = i + 4;

				if (lastLineIndex < endIndex)
				{
					//parse lines
					BString bitmapString = (*tokenList)[i];
					BString statusName = (*tokenList)[i+1];
					BString abbreviation = (*tokenList)[i+2];
					bool userChoice = atoi((*tokenList)[i+3].String());				
					BString colourString = (*tokenList)[i+4];
					i += 4;
					//construct bitmap path
					BPath bitmapPath;
					statFilePath.GetParent(&bitmapPath);
					bitmapPath.Append(bitmapString.String());
					BBitmap *icon = BTranslationUtils::GetBitmap(bitmapPath.Path());
					//construct status object
					Status *status = FindStatus(abbreviation);
					if (status != NULL)
					{
						status->AddIcon(icon);
					}
					else
					{
						//remove brackets from colourString
						colourString.RemoveAll("{");						
						colourString.RemoveAll("}");
						
						int32 colours[4];
						int32 startIndex = 0;						
						for (int i = 0; i < 4; i++)
						{
							int32 commaIndex = colourString.FindFirst(",",startIndex);							
							if (commaIndex != B_ERROR)
							{
								BString colourValue;
								colourString.CopyInto(colourValue,startIndex, commaIndex-startIndex);
								colours[i] = atoi(colourValue.String());
								startIndex = commaIndex + 1;
							}
							else if (i < 3)
							{								
								BString colourValue;								
								colourString.CopyInto(colourValue, startIndex, colourString.CountChars() - startIndex);
								colours[i] = atoi(colourValue.String());								
							}		
							else if (i == 3)
							{
								colours[i] = 255;
							}						
						}
						//construct status colour
						rgb_color statusColour;
						statusColour.red = colours[0];
						statusColour.green = colours[1];
						statusColour.blue = colours[2];
						statusColour.alpha = colours[3];
						//construct new status object
						Status *status = new Status(statusName,abbreviation, icon, userChoice, statusColour);
						statLock.Lock();
						statusses[abbreviation] = status;
						statLock.Unlock();	
							
					}		
				}
			}
		}
				
		StringList::deleteStrings(tokenList);
		delete tokenList;
	}	
	else
	{
		error = B_ERROR;
	}	
	return error;
}