Example #1
0
/**
 * Modify an existing contact.
 */
void AppMoblet::modifyContact()
{
    MAHandle list = maPimListOpen(MA_PIM_CONTACTS);
    MAHandle item = maPimListNext(list);
    PIMContact* contact = new PIMContact(item);
    contact->modifyAddressField();
    maPimItemClose(item);
    maPimListClose(list);
}
Example #2
0
/**
 * Test maPimItemRemove syscall.
 */
void AppMoblet::deleteAllContactsFromAddressBook()
{
    MAHandle list = maPimListOpen(MA_PIM_CONTACTS);
    while(true)
    {
        MAHandle item = maPimListNext(list);
        if (item != 0)
        {
            maPimItemRemove(list, item);
        }
        else
        {
            break;
        }
    }
    maPimListClose(list);
}
ContactScreen::ContactScreen(MainScreen *previous) {
	this->previous = previous;
	lprintfln("ContactScreen::Memory Heap %d, Free Heap %d", heapTotalMemory(), heapFreeMemory());
	moved = 0;
	index = -1;
	isBusy = false;

	layout = Util::createMainLayout("Search", "Back", "", false);

	listBox = (KineticListBox*) layout->getChildren()[0]->getChildren()[2];

	notice = (Label*) layout->getChildren()[0]->getChildren()[1];

	label = new Label(0,0, scrWidth-PADDING*2, 24, NULL, "Enter contact name", 0, Util::getDefaultFont());
	listBox->add(label);

	label = Util::createEditLabel("");
	editBoxSearch = new NativeEditBox(0, 0, label->getWidth()-PADDING*2, 48-PADDING*2, 64, MA_TB_TYPE_ANY, label, "",L"Search term:");
#if defined(MA_PROF_SUPPORT_STYLUS)

#else
	editBoxSearch->setInputMode(NativeEditBox::IM_NUMBERS);
#endif
	editBoxSearch->setDrawBackground(false);
	label->addWidgetListener(this);
	listBox->add(label);

	contactListBox = new KineticListBox(0, 0, scrWidth, listBox->getHeight() - editBoxSearch->getParent()->getHeight() - 24,
		listBox, KineticListBox::LBO_VERTICAL, KineticListBox::LBA_LINEAR, false);

	this->setMain(layout);

	listBox->setSelectedIndex(1);
	editBoxSearch->setSelected(true);

	//load all the contacts into a list
	Contact *temp;
	char *name, *number;
	String strName, strNumber;

	MAHandle mContactsListHandle = maPimListOpen(MA_PIM_CONTACTS);
	MAHandle pimItemHandle = maPimListNext(mContactsListHandle);

	MA_PIM_ARGS args;
	args.item = pimItemHandle;
	args.bufSize = 512;
	char *mBuffer;
	mBuffer = new char[512];
	args.buf = mBuffer;

	while (pimItemHandle > 0) {
		strName = "";
		strNumber = "";

		args.item = pimItemHandle;

		int countFields = maPimItemCount(pimItemHandle);
		if (countFields >= 0)
		{
			args.field = MA_PIM_FIELD_CONTACT_NAME;

			// Get value from name field at position 0.
			maPimItemGetValue(&args, 0);

			// there can be up to 8 parts of a name
			for (int i = 0; i < 8; i++)
			{
				const wchar* contactNameValue = Util::getWCharArrayFromBuf(args.buf, i);
				if (contactNameValue && *contactNameValue != 0)
				{
					name = new char[wcslen(contactNameValue)];
					memset(name, '\0', wcslen(contactNameValue));
					sprintf(name, "%S", contactNameValue);

					if (strName.length() > 0) {
						strName.append(", ", 2);
					}
					strName.append(name, strlen(name));

					delete name;
				}
			}

			//printf("name: %s", strName.c_str());

			args.field = MA_PIM_FIELD_CONTACT_TEL;

			// Get the number of values.
			int countValues =
				maPimItemFieldCount(pimItemHandle, MA_PIM_FIELD_CONTACT_TEL);

			for (int i = 0; i < countValues; i++)
			{
				int result = maPimItemGetValue(&args, i);

				if (result >= 0) {
					number = new char[wcslen((wchar*) args.buf)];
					memset(number, '\0', wcslen((wchar*) args.buf));
					sprintf(number, "%S", (wchar*) args.buf);
				}

				strNumber = number;
				temp = new Contact(strName, strNumber);
				allContacts.add(temp);

				delete number;
				//printf("number: %s", strNumber.c_str());
			}
		}

		maPimItemClose(pimItemHandle);
		pimItemHandle = maPimListNext(mContactsListHandle);
	}
	maPimListClose(mContactsListHandle);
}