00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "AddressBookSource.h"
00020 #include "SyncEvolutionUtil.h"
00021
00022 static EvolutionSyncSource *createSource(const EvolutionSyncSourceParams ¶ms)
00023 {
00024 pair <string, string> sourceType = EvolutionSyncSource::getSourceType(params.m_nodes);
00025 bool isMe = sourceType.first == "apple-contacts";
00026
00027 #ifndef ENABLE_ADDRESSBOOK
00028 return isMe ? RegisterSyncSource::InactiveSource : NULL;
00029 #else
00030 bool maybeMe = sourceType.first == "addressbook";
00031
00032 if (isMe || maybeMe) {
00033
00034
00035
00036 bool vCard3 = false;
00037 PersistentEvolutionSyncSourceConfig config(params.m_name, params.m_nodes);
00038 if (config.getURI() && !strcmp(config.getURI(), "card3")) {
00039 vCard3 = true;
00040 }
00041
00042 if (sourceType.second == "text/x-vcard") {
00043 vCard3 = false;
00044 } else if (sourceType.second == "text/vcard") {
00045 vCard3 = true;
00046 }
00047
00048 return new AddressBookSource(params, vCard3);
00049 }
00050 return NULL;
00051 #endif
00052 }
00053
00054 static RegisterSyncSource registerMe("iPhone/Mac OS X Address Book",
00055 #ifdef ENABLE_ADDRESSBOOK
00056 true,
00057 #else
00058 false,
00059 #endif
00060 createSource,
00061 "Mac OS X or iPhone Address Book = addressbook = contacts = apple-contacts\n"
00062 " vCard 2.1 (default) = text/x-vcard\n"
00063 " vCard 3.0 = text/vcard\n",
00064 Values() +
00065 (Aliases("apple-contacts") + "Mac OS X Address Book" + "iPhone Address Book"));
00066
00067 #ifdef ENABLE_ADDRESSBOOK
00068 #ifdef ENABLE_UNIT_TESTS
00069
00070 class EvolutionAddressbookTest : public CppUnit::TestFixture {
00071 CPPUNIT_TEST_SUITE(EvolutionAddressbookTest);
00072 CPPUNIT_TEST(testInstantiate);
00073 CPPUNIT_TEST_SUITE_END();
00074
00075 protected:
00076 void testInstantiate() {
00077 boost::shared_ptr<EvolutionSyncSource> source;
00078 source.reset(EvolutionSyncSource::createTestingSource("contacts", "contacts", true));
00079 source.reset(EvolutionSyncSource::createTestingSource("contacts", "addressbook", true));
00080 source.reset(EvolutionSyncSource::createTestingSource("contacts", "apple-contacts", true));
00081 source.reset(EvolutionSyncSource::createTestingSource("contacts", "Mac OS X Address Book:text/vcard", true));
00082 source.reset(EvolutionSyncSource::createTestingSource("contacts", "iPhone Address Book:text/x-vcard", true));
00083 }
00084 };
00085
00086 SYNCEVOLUTION_TEST_SUITE_REGISTRATION(EvolutionAddressbookTest);
00087
00088 #endif // ENABLE_UNIT_TESTS
00089
00090 #ifdef ENABLE_INTEGRATION_TESTS
00091 namespace {
00092 #if 0
00093 }
00094 #endif
00095
00096 static class VCard21Test : public RegisterSyncSourceTest {
00097 public:
00098 VCard21Test() : RegisterSyncSourceTest("addressbook_vcard21", "vcard21") {}
00099
00100 virtual void updateConfig(ClientTestConfig &config) const
00101 {
00102 config.type = "apple-contacts:text/x-vcard";
00103 }
00104 } vCard21Test;
00105
00106 static class VCard30Test : public RegisterSyncSourceTest {
00107 public:
00108 VCard30Test() : RegisterSyncSourceTest("addressbook_vcard30", "vcard30") {}
00109
00110 virtual void updateConfig(ClientTestConfig &config) const
00111 {
00112 config.type = "apple-contacts:text/vcard";
00113 }
00114 } vCard30Test;
00115
00116 }
00117 #endif // ENABLE_INTEGRATION_TESTS
00118
00119 #endif // ENABLE_ADDRESSBOOK