| | 1403 | |
|---|
| | 1404 | static osync_bool _palmcontact_address(OSyncXMLFormat *xmlformat, PSyncContactEntry *entry, OSyncError **error) |
|---|
| | 1405 | { |
|---|
| | 1406 | if (!(has_entry(entry, entryAddress) |
|---|
| | 1407 | || has_entry(entry, entryCity) || has_entry(entry, entryState) |
|---|
| | 1408 | || has_entry(entry, entryZip) || has_entry(entry, entryCountry))) |
|---|
| | 1409 | return TRUE; |
|---|
| | 1410 | |
|---|
| | 1411 | char *tmp_address = return_next_entry(entry, entryAddress); |
|---|
| | 1412 | char *tmp_city = return_next_entry(entry, entryCity); |
|---|
| | 1413 | char *tmp_state = return_next_entry(entry, entryState); |
|---|
| | 1414 | char *tmp_zip = return_next_entry(entry, entryZip); |
|---|
| | 1415 | char *tmp_country = return_next_entry(entry, entryCountry); |
|---|
| | 1416 | |
|---|
| | 1417 | OSyncXMLField *xmlfield = osync_xmlfield_new(xmlformat, "Address", error); |
|---|
| | 1418 | if (!xmlfield) |
|---|
| | 1419 | return FALSE; |
|---|
| | 1420 | |
|---|
| | 1421 | //Street |
|---|
| | 1422 | if (tmp_address) { |
|---|
| | 1423 | osync_xmlfield_set_key_value(xmlfield, "Street", tmp_address); |
|---|
| | 1424 | g_free(tmp_address); |
|---|
| | 1425 | } |
|---|
| | 1426 | |
|---|
| | 1427 | //City |
|---|
| | 1428 | if (tmp_city) { |
|---|
| | 1429 | osync_xmlfield_set_key_value(xmlfield, "City", tmp_city); |
|---|
| | 1430 | g_free(tmp_city); |
|---|
| | 1431 | } |
|---|
| | 1432 | |
|---|
| | 1433 | //Region |
|---|
| | 1434 | if (tmp_state) { |
|---|
| | 1435 | osync_xmlfield_set_key_value(xmlfield, "Region", tmp_state); |
|---|
| | 1436 | g_free(tmp_state); |
|---|
| | 1437 | } |
|---|
| | 1438 | |
|---|
| | 1439 | //Code |
|---|
| | 1440 | if (tmp_zip) { |
|---|
| | 1441 | osync_xmlfield_set_key_value(xmlfield, "PostalCode", tmp_zip); |
|---|
| | 1442 | g_free(tmp_zip); |
|---|
| | 1443 | } |
|---|
| | 1444 | |
|---|
| | 1445 | //Country |
|---|
| | 1446 | if (tmp_country) { |
|---|
| | 1447 | osync_xmlfield_set_key_value(xmlfield, "Country", tmp_country); |
|---|
| | 1448 | g_free(tmp_country); |
|---|
| | 1449 | } |
|---|
| | 1450 | |
|---|
| | 1451 | return TRUE; |
|---|
| | 1452 | } |
|---|
| | 1453 | |
|---|
| | 1454 | static osync_bool _palmcontact_name(OSyncXMLFormat *xmlformat, PSyncContactEntry *entry, OSyncError **error) |
|---|
| | 1455 | { |
|---|
| | 1456 | if (!(has_entry(entry, entryLastname) || has_entry(entry, entryFirstname))) |
|---|
| | 1457 | return TRUE; |
|---|
| | 1458 | |
|---|
| | 1459 | char *tmp_first = return_next_entry(entry, entryFirstname); |
|---|
| | 1460 | char *tmp_last = return_next_entry(entry, entryLastname); |
|---|
| | 1461 | |
|---|
| | 1462 | OSyncXMLField *xmlfield = osync_xmlfield_new(xmlformat, "Name", error); |
|---|
| | 1463 | if (!xmlfield) |
|---|
| | 1464 | return FALSE; |
|---|
| | 1465 | |
|---|
| | 1466 | //First Name |
|---|
| | 1467 | if (tmp_first) { |
|---|
| | 1468 | osync_xmlfield_set_key_value(xmlfield, "FirstName", tmp_first); |
|---|
| | 1469 | g_free(tmp_first); |
|---|
| | 1470 | } |
|---|
| | 1471 | |
|---|
| | 1472 | //Last Name |
|---|
| | 1473 | if (tmp_last) { |
|---|
| | 1474 | osync_xmlfield_set_key_value(xmlfield, "LastName", tmp_last); |
|---|
| | 1475 | g_free(tmp_last); |
|---|
| | 1476 | } |
|---|
| | 1477 | |
|---|
| | 1478 | return TRUE; |
|---|
| | 1479 | } |
|---|
| | 1480 | |
|---|
| | 1481 | static osync_bool _palmcontact_organization(OSyncXMLFormat *xmlformat, PSyncContactEntry *entry, OSyncError **error) |
|---|
| | 1482 | { |
|---|
| | 1483 | char *tmp = return_next_entry(entry, entryCompany); |
|---|
| | 1484 | |
|---|
| | 1485 | // Empty? |
|---|
| | 1486 | if (!tmp) |
|---|
| | 1487 | return TRUE; |
|---|
| | 1488 | |
|---|
| | 1489 | OSyncXMLField *xmlfield = osync_xmlfield_new(xmlformat, "Organization", error); |
|---|
| | 1490 | if (!xmlfield) |
|---|
| | 1491 | return FALSE; |
|---|
| | 1492 | |
|---|
| | 1493 | osync_xmlfield_set_key_value(xmlfield, "Name", tmp); |
|---|
| | 1494 | g_free(tmp); |
|---|
| | 1495 | |
|---|
| | 1496 | return TRUE; |
|---|
| | 1497 | } |
|---|
| | 1498 | |
|---|
| | 1499 | static osync_bool _palmcontact_telephone(OSyncXMLFormat *xmlformat, PSyncContactEntry *entry, OSyncError **error) |
|---|
| | 1500 | { |
|---|
| | 1501 | int i; |
|---|
| | 1502 | char *tmp = NULL; |
|---|
| | 1503 | OSyncXMLField *xmlfield = NULL; |
|---|
| | 1504 | for (i = entryPhone1; i <= entryPhone5; i++) { |
|---|
| | 1505 | tmp = return_next_entry(entry, i); |
|---|
| | 1506 | if (!tmp) |
|---|
| | 1507 | continue; |
|---|
| | 1508 | |
|---|
| | 1509 | osync_trace(TRACE_SENSITIVE, "phone #%i: [%i][telephone type /email == 4]", i, entry->address.phoneLabel[i - 3]); |
|---|
| | 1510 | |
|---|
| | 1511 | xmlfield = NULL; |
|---|
| | 1512 | |
|---|
| | 1513 | if (entry->address.phoneLabel[i - 3] == 4) |
|---|
| | 1514 | xmlfield = osync_xmlfield_new(xmlformat, "EMail", error); |
|---|
| | 1515 | else |
|---|
| | 1516 | xmlfield = osync_xmlfield_new(xmlformat, "Telephone", error); |
|---|
| | 1517 | |
|---|
| | 1518 | if (!xmlfield) |
|---|
| | 1519 | return FALSE; |
|---|
| | 1520 | |
|---|
| | 1521 | osync_xmlfield_set_key_value(xmlfield, "Content", tmp); |
|---|
| | 1522 | g_free(tmp); |
|---|
| | 1523 | |
|---|
| | 1524 | switch (entry->address.phoneLabel[i - 3]) { |
|---|
| | 1525 | case 0: |
|---|
| | 1526 | // Work |
|---|
| | 1527 | osync_xmlfield_set_attr(xmlfield, "Location", "Work"); |
|---|
| | 1528 | break; |
|---|
| | 1529 | case 1: |
|---|
| | 1530 | // Home |
|---|
| | 1531 | osync_xmlfield_set_attr(xmlfield, "Location", "Home"); |
|---|
| | 1532 | break; |
|---|
| | 1533 | case 2: |
|---|
| | 1534 | // Fax |
|---|
| | 1535 | osync_xmlfield_set_attr(xmlfield, "Type", "Fax"); |
|---|
| | 1536 | break; |
|---|
| | 1537 | case 3: |
|---|
| | 1538 | // Other FIXME Voice!=Other .. Other is not part of xmlformat-contact xsd |
|---|
| | 1539 | osync_xmlfield_set_attr(xmlfield, "Type", "Voice"); |
|---|
| | 1540 | break; |
|---|
| | 1541 | case 4: |
|---|
| | 1542 | // E Mail |
|---|
| | 1543 | break; |
|---|
| | 1544 | case 5: |
|---|
| | 1545 | // Main FIXME Mail != Prefered !? |
|---|
| | 1546 | osync_xmlfield_set_attr(xmlfield, "Preferred", "true"); |
|---|
| | 1547 | break; |
|---|
| | 1548 | case 6: |
|---|
| | 1549 | // Pager |
|---|
| | 1550 | osync_xmlfield_set_attr(xmlfield, "Type", "Pager"); |
|---|
| | 1551 | break; |
|---|
| | 1552 | case 7: |
|---|
| | 1553 | // Mobile / Cellular |
|---|
| | 1554 | osync_xmlfield_set_attr(xmlfield, "Type", "Cellular"); |
|---|
| | 1555 | break; |
|---|
| | 1556 | } |
|---|
| | 1557 | |
|---|
| | 1558 | } |
|---|
| | 1559 | return TRUE; |
|---|
| | 1560 | } |
|---|
| | 1561 | |
|---|
| | 1562 | //Title |
|---|
| | 1563 | static osync_bool _palmcontact_title(OSyncXMLFormat *xmlformat, PSyncContactEntry *entry, OSyncError **error) |
|---|
| | 1564 | { |
|---|
| | 1565 | char *tmp = return_next_entry(entry, entryTitle); |
|---|
| | 1566 | if (!tmp) |
|---|
| | 1567 | return TRUE; |
|---|
| | 1568 | |
|---|
| | 1569 | OSyncXMLField *xmlfield = osync_xmlfield_new(xmlformat, "Title", error); |
|---|
| | 1570 | if (!xmlfield) |
|---|
| | 1571 | return FALSE; |
|---|
| | 1572 | |
|---|
| | 1573 | osync_xmlfield_set_key_value(xmlfield, "Content", tmp); |
|---|
| | 1574 | g_free(tmp); |
|---|
| | 1575 | |
|---|
| | 1576 | return TRUE; |
|---|
| | 1577 | } |
|---|
| | 1578 | |
|---|
| | 1579 | |
|---|
| | 1580 | //Note |
|---|
| | 1581 | static osync_bool _palmcontact_note(OSyncXMLFormat *xmlformat, PSyncContactEntry *entry, OSyncError **error) |
|---|
| | 1582 | { |
|---|
| | 1583 | char *tmp = return_next_entry(entry, entryNote); |
|---|
| | 1584 | if (!tmp) |
|---|
| | 1585 | return TRUE; |
|---|
| | 1586 | |
|---|
| | 1587 | |
|---|
| | 1588 | OSyncXMLField *xmlfield = osync_xmlfield_new(xmlformat, "Note", error); |
|---|
| | 1589 | if (!xmlfield) |
|---|
| | 1590 | return FALSE; |
|---|
| | 1591 | |
|---|
| | 1592 | osync_xmlfield_set_key_value(xmlfield, "Content", tmp); |
|---|
| | 1593 | g_free(tmp); |
|---|
| | 1594 | |
|---|
| | 1595 | return TRUE; |
|---|
| | 1596 | } |
|---|
| | 1597 | |
|---|
| | 1598 | // Categories |
|---|
| | 1599 | static osync_bool _palmcontact_categories(OSyncXMLFormat *xmlformat, PSyncContactEntry *entry, OSyncError **error) |
|---|
| | 1600 | { |
|---|
| | 1601 | GList *c = NULL; |
|---|
| | 1602 | OSyncXMLField *xmlfield = NULL; |
|---|
| | 1603 | |
|---|
| | 1604 | for (c = entry->categories; c; c = c->next) { |
|---|
| | 1605 | if (!xmlfield) |
|---|
| | 1606 | xmlfield = osync_xmlfield_new(xmlformat, "Categories", error); |
|---|
| | 1607 | |
|---|
| | 1608 | if (!xmlfield) |
|---|
| | 1609 | return FALSE; |
|---|
| | 1610 | |
|---|
| | 1611 | char *tmp = conv_enc_palm_to_xml((char *) c->data); |
|---|
| | 1612 | osync_xmlfield_set_key_value(xmlfield, "Category", tmp); |
|---|
| | 1613 | g_free(tmp); |
|---|
| | 1614 | } |
|---|
| | 1615 | |
|---|
| | 1616 | return TRUE; |
|---|
| | 1617 | } |
|---|
| | 1618 | |
|---|
| 1425 | | //Names |
|---|
| 1426 | | if (has_entry(entry, entryLastname) || has_entry(entry, entryFirstname)) { |
|---|
| 1427 | | GString *formatted_name = g_string_new(""); |
|---|
| 1428 | | |
|---|
| 1429 | | char *tmp_first = return_next_entry(entry, entryFirstname); |
|---|
| 1430 | | char *tmp_last = return_next_entry(entry, entryLastname); |
|---|
| 1431 | | |
|---|
| 1432 | | if (tmp_first || tmp_last) { |
|---|
| 1433 | | xmlfield = osync_xmlfield_new(xmlformat, "Name", error); |
|---|
| 1434 | | |
|---|
| 1435 | | |
|---|
| 1436 | | //First Name |
|---|
| 1437 | | if (tmp_first) { |
|---|
| 1438 | | osync_xmlfield_set_key_value(xmlfield, "FirstName", tmp_first); |
|---|
| 1439 | | g_free(tmp_first); |
|---|
| 1440 | | } |
|---|
| 1441 | | |
|---|
| 1442 | | //Last Name |
|---|
| 1443 | | if (tmp_last) { |
|---|
| 1444 | | osync_xmlfield_set_key_value(xmlfield, "LastName", tmp_last); |
|---|
| 1445 | | g_free(tmp_last); |
|---|
| 1446 | | } |
|---|
| 1447 | | |
|---|
| 1448 | | } |
|---|
| 1449 | | } |
|---|
| 1450 | | |
|---|
| 1451 | | //Company |
|---|
| 1452 | | tmp = return_next_entry(entry, entryCompany); |
|---|
| 1453 | | if (tmp) { |
|---|
| 1454 | | xmlfield = osync_xmlfield_new(xmlformat, "Organization", error); |
|---|
| 1455 | | osync_xmlfield_set_key_value(xmlfield, "Name", tmp); |
|---|
| 1456 | | g_free(tmp); |
|---|
| 1457 | | } |
|---|
| 1458 | | |
|---|
| 1459 | | //Telephones and email |
|---|
| 1460 | | for (i = entryPhone1; i <= entryPhone5; i++) { |
|---|
| 1461 | | tmp = return_next_entry(entry, i); |
|---|
| 1462 | | if (tmp) { |
|---|
| 1463 | | osync_trace(TRACE_SENSITIVE, "phone #%i: [%i][telephone type /email == 4]", i, entry->address.phoneLabel[i - 3]); |
|---|
| 1464 | | if (entry->address.phoneLabel[i - 3] == 4) |
|---|
| 1465 | | xmlfield = osync_xmlfield_new(xmlformat, "EMail", error); |
|---|
| 1466 | | else |
|---|
| 1467 | | xmlfield = osync_xmlfield_new(xmlformat, "Telephone", error); |
|---|
| 1468 | | |
|---|
| 1469 | | osync_xmlfield_set_key_value(xmlfield, "Content", tmp); |
|---|
| 1470 | | g_free(tmp); |
|---|
| 1471 | | |
|---|
| 1472 | | switch (entry->address.phoneLabel[i - 3]) { |
|---|
| 1473 | | case 0: |
|---|
| 1474 | | // Work |
|---|
| 1475 | | osync_xmlfield_set_attr(xmlfield, "Location", "Work"); |
|---|
| 1476 | | break; |
|---|
| 1477 | | case 1: |
|---|
| 1478 | | // Home |
|---|
| 1479 | | osync_xmlfield_set_attr(xmlfield, "Location", "Home"); |
|---|
| 1480 | | break; |
|---|
| 1481 | | case 2: |
|---|
| 1482 | | // Fax |
|---|
| 1483 | | osync_xmlfield_set_attr(xmlfield, "Type", "Fax"); |
|---|
| 1484 | | break; |
|---|
| 1485 | | case 3: |
|---|
| 1486 | | // Other FIXME Voice!=Other .. Other is not part of xmlformat-contact xsd |
|---|
| 1487 | | osync_xmlfield_set_attr(xmlfield, "Type", "Voice"); |
|---|
| 1488 | | break; |
|---|
| 1489 | | case 4: |
|---|
| 1490 | | // E Mail |
|---|
| 1491 | | break; |
|---|
| 1492 | | case 5: |
|---|
| 1493 | | // Main FIXME Mail != Prefered !? |
|---|
| 1494 | | osync_xmlfield_set_attr(xmlfield, "Preferred", "true"); |
|---|
| 1495 | | break; |
|---|
| 1496 | | case 6: |
|---|
| 1497 | | // Pager |
|---|
| 1498 | | osync_xmlfield_set_attr(xmlfield, "Type", "Pager"); |
|---|
| 1499 | | break; |
|---|
| 1500 | | case 7: |
|---|
| 1501 | | // Mobile / Cellular |
|---|
| 1502 | | osync_xmlfield_set_attr(xmlfield, "Type", "Cellular"); |
|---|
| 1503 | | break; |
|---|
| 1504 | | } |
|---|
| 1505 | | } |
|---|
| 1506 | | |
|---|
| 1507 | | } |
|---|
| 1508 | | |
|---|
| 1509 | | //Address |
|---|
| 1510 | | if (has_entry(entry, entryAddress) || has_entry(entry, entryCity) || has_entry(entry, entryState) || has_entry(entry, entryZip) || has_entry(entry, entryCountry)) { |
|---|
| 1511 | | char *tmp_address = return_next_entry(entry, entryAddress); |
|---|
| 1512 | | char *tmp_city = return_next_entry(entry, entryCity); |
|---|
| 1513 | | char *tmp_state = return_next_entry(entry, entryState); |
|---|
| 1514 | | char *tmp_zip = return_next_entry(entry, entryZip); |
|---|
| 1515 | | char *tmp_country = return_next_entry(entry, entryCountry); |
|---|
| 1516 | | |
|---|
| 1517 | | if (tmp_address || tmp_city || tmp_state || tmp_zip || tmp_country) { |
|---|
| 1518 | | xmlfield = osync_xmlfield_new(xmlformat, "Address", error); |
|---|
| 1519 | | //Street |
|---|
| 1520 | | if (tmp_address) { |
|---|
| 1521 | | osync_xmlfield_set_attr(xmlfield, "Street", tmp_address); |
|---|
| 1522 | | g_free(tmp_address); |
|---|
| 1523 | | } |
|---|
| 1524 | | |
|---|
| 1525 | | //City |
|---|
| 1526 | | if (tmp_city) { |
|---|
| 1527 | | osync_xmlfield_set_attr(xmlfield, "City", tmp_city); |
|---|
| 1528 | | g_free(tmp_city); |
|---|
| 1529 | | } |
|---|
| 1530 | | |
|---|
| 1531 | | //Region |
|---|
| 1532 | | if (tmp_state) { |
|---|
| 1533 | | osync_xmlfield_set_attr(xmlfield, "Region", tmp_state); |
|---|
| 1534 | | g_free(tmp_state); |
|---|
| 1535 | | } |
|---|
| 1536 | | |
|---|
| 1537 | | //Code |
|---|
| 1538 | | if (tmp_zip) { |
|---|
| 1539 | | osync_xmlfield_set_attr(xmlfield, "PostalCode", tmp_zip); |
|---|
| 1540 | | g_free(tmp_zip); |
|---|
| 1541 | | } |
|---|
| 1542 | | |
|---|
| 1543 | | //Country |
|---|
| 1544 | | if (tmp_country) { |
|---|
| 1545 | | osync_xmlfield_set_attr(xmlfield, "Country", tmp_country); |
|---|
| 1546 | | g_free(tmp_country); |
|---|
| 1547 | | } |
|---|
| 1548 | | } |
|---|
| 1549 | | } |
|---|
| 1550 | | |
|---|
| 1551 | | //Title |
|---|
| 1552 | | tmp = return_next_entry(entry, entryTitle); |
|---|
| 1553 | | if (tmp) { |
|---|
| 1554 | | xmlfield = osync_xmlfield_new(xmlformat, "Title", error); |
|---|
| 1555 | | osync_xmlfield_set_attr(xmlfield, "Content", tmp); |
|---|
| 1556 | | g_free(tmp); |
|---|
| 1557 | | } |
|---|
| 1558 | | |
|---|
| 1559 | | //Note |
|---|
| 1560 | | tmp = return_next_entry(entry, entryNote); |
|---|
| 1561 | | if (tmp) { |
|---|
| 1562 | | xmlfield = osync_xmlfield_new(xmlformat, "Note", error); |
|---|
| 1563 | | osync_xmlfield_set_attr(xmlfield, "Content", tmp); |
|---|
| 1564 | | g_free(tmp); |
|---|
| 1565 | | } |
|---|
| 1566 | | |
|---|
| 1567 | | GList *c = NULL; |
|---|
| 1568 | | xmlfield = NULL; |
|---|
| 1569 | | for (c = entry->categories; c; c = c->next) { |
|---|
| 1570 | | if (!current) |
|---|
| 1571 | | xmlfield = osync_xmlfield_new(xmlformat, "Categories", error); |
|---|
| 1572 | | |
|---|
| 1573 | | tmp = conv_enc_palm_to_xml((char *) c->data); |
|---|
| 1574 | | osync_xmlfield_set_attr(xmlfield, "Category", tmp); |
|---|
| 1575 | | g_free(tmp); |
|---|
| 1576 | | } |
|---|
| 1577 | | |
|---|
| | 1641 | // Address |
|---|
| | 1642 | if (!_palmcontact_address(xmlformat, entry, error)) |
|---|
| | 1643 | goto error; |
|---|
| | 1644 | |
|---|
| | 1645 | // Categories |
|---|
| | 1646 | if (!_palmcontact_categories(xmlformat, entry, error)) |
|---|
| | 1647 | goto error; |
|---|
| | 1648 | // Name |
|---|
| | 1649 | if (!_palmcontact_name(xmlformat, entry, error)) |
|---|
| | 1650 | goto error; |
|---|
| | 1651 | |
|---|
| | 1652 | // Note |
|---|
| | 1653 | if (!_palmcontact_note(xmlformat, entry, error)) |
|---|
| | 1654 | goto error; |
|---|
| | 1655 | |
|---|
| | 1656 | // Organization |
|---|
| | 1657 | if (!_palmcontact_organization(xmlformat, entry, error)) |
|---|
| | 1658 | goto error; |
|---|
| | 1659 | |
|---|
| | 1660 | // Title |
|---|
| | 1661 | if (!_palmcontact_title(xmlformat, entry, error)) |
|---|
| | 1662 | goto error; |
|---|
| | 1663 | |
|---|
| | 1664 | // Telephone |
|---|
| | 1665 | if (!_palmcontact_telephone(xmlformat, entry, error)) |
|---|
| | 1666 | goto error; |
|---|
| | 1667 | |
|---|
| | 1668 | |
|---|