PersonWindow*
TPeopleApp::_FindWindow(const entry_ref& ref) const
{
	for (int32 i = 0; BWindow* window = WindowAt(i); i++) {
		PersonWindow* personWindow = dynamic_cast<PersonWindow*>(window);
		if (personWindow == NULL)
			continue;
		if (personWindow->RefersContactFile(ref))
			return personWindow;
	}
	return NULL;
}
void
TPeopleApp::RefsReceived(BMessage* message)
{
	int32 index = 0;
	while (message->HasRef("refs", index)) {
		entry_ref ref;
		message->FindRef("refs", index++, &ref);
		PersonWindow* window = _FindWindow(ref);
		if (window != NULL) {
			window->Activate(true);
		} else {
			BFile* file = new BFile(&ref, B_READ_WRITE);
			if (file->InitCheck() == B_OK)
				_NewWindow(&ref, file);
		}
	}
}
PersonWindow*
TPeopleApp::_NewWindow(const entry_ref* ref, BFile* file)
{
	BRawContact* rawContact;
	if (file == NULL)
		rawContact = new BRawContact(B_CONTACT_FORMAT);
	else
		rawContact = new BRawContact(B_CONTACT_ANY, file);

	BContact* contact = new BContact(rawContact);

	if (contact->InitCheck() != B_OK) {
		BAlert *alert = new BAlert("Alert",
			B_TRANSLATE("Contact initialization failed!."),"OK");
		alert->Go();
		return NULL;
	}

	PersonWindow* window = new PersonWindow(fPosition,
		B_TRANSLATE("New contact"), ref, file, contact);

	window->Show();
	window->Activate(true);

	fWindowCount++;

	// Offset the position for the next window which will be opened and
	// reset it if it would open outside the screen bounds.
	fPosition.OffsetBy(20, 20);
	BScreen screen(window);
	if (fPosition.bottom > screen.Frame().bottom)
		fPosition.OffsetTo(fPosition.left, TITLE_BAR_HEIGHT);
	if (fPosition.right > screen.Frame().right)
		fPosition.OffsetTo(6, fPosition.top);

	return window;
}
Пример #4
0
PersonWindow*
TPeopleApp::_NewWindow(const entry_ref* ref, BFile* file)
{

	BRawContact* rawContact;
	if (file == NULL)
		rawContact = new BRawContact(B_CONTACT_FORMAT, NULL);
	else
		rawContact = new BRawContact(B_CONTACT_ANY, file);

	BContact* contact = new BContact(rawContact);
	//ObjectDeleter<BContact> deleter(contact);

	if (contact->InitCheck() != B_OK) {
		printf("BContact initcheck error\n");
		// BAlert here
		return NULL;
	}

	PersonWindow* window = new PersonWindow(BRect(50, 50, 300, 400),
		B_TRANSLATE("New contact"), ref, contact);

	window->Show();

	fWindowCount++;

	// Offset the position for the next window which will be opened and
	// reset it if it would open outside the screen bounds.
	/*fPosition.OffsetBy(20, 20);
	BScreen screen(window);
	if (fPosition.bottom > screen.Frame().bottom)
		fPosition.OffsetTo(fPosition.left, TITLE_BAR_HEIGHT);
	if (fPosition.right > screen.Frame().right)
		fPosition.OffsetTo(6, fPosition.top);*/

	return window;
}