X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fplatform%2FTizen%2FContact%2FContactSearchEngine.cpp;h=8e9c16be6613d3470b038e549055f017bf47be9f;hb=1c5040afa54de91e8cc3ff0c43f71b4234dbb67b;hp=e19183cb3611c2bf7c8c3cdb8e3c01c4bd91aec7;hpb=f7d6a7695dfc4f7c03732ece121fc9f4a8a5ad2f;p=profile%2Fivi%2Fwrt-plugins-tizen.git diff --git a/src/platform/Tizen/Contact/ContactSearchEngine.cpp b/src/platform/Tizen/Contact/ContactSearchEngine.cpp index e19183c..8e9c16b 100755 --- a/src/platform/Tizen/Contact/ContactSearchEngine.cpp +++ b/src/platform/Tizen/Contact/ContactSearchEngine.cpp @@ -26,6 +26,7 @@ #include #include +#include "Contact.h" #include "ContactSearchEngine.h" namespace TizenApis { @@ -37,8 +38,6 @@ using namespace TizenApis::Api::Tizen; using namespace WrtDeviceApis::Commons; using namespace std; -using TizenApis::Api::Contact::Contact; - map ContactSearchEngine::attrEnumMap = { {"id", contact_attribute_e::CONTACT_ID}, {"readOnly", contact_attribute_e::ATTRIBUTE_MAX}, @@ -106,6 +105,14 @@ void ContactSearchEngine::setCondition(FilterPtr filter) filter->travel(filterQuery); } +void ContactSearchEngine::setCondition(string contactId) +{ + if(contactId == "") + ThrowMsg(InvalidArgumentException, "contactId id empty."); + + query_set_condition(m_contact_query_service, getPlatformAttr("id"), EQUAL, contactId.c_str()); +} + void ContactSearchEngine::setSortMode(SortModePtr attr) { if(attr) @@ -187,7 +194,7 @@ ContactArrayPtr ContactSearchEngine::getContactSearchResult() str = query_get_attribute(m_contact_query_service, ACCOUNT_ID, &err); if( str ) - contact->getAccount()->setAccountId(str); + contact->getAccount()->setAccountServiceId(str); str = query_get_attribute(m_contact_query_service, CONTACT_IS_FAVORITE, &err); if( str ) @@ -195,7 +202,7 @@ ContactArrayPtr ContactSearchEngine::getContactSearchResult() str = query_get_attribute(m_contact_query_service, CONTACT_RINGTONE, &err); if( str ) - contact->setRingtoneURI(str); + contact->setRingtoneURI(std::string("file://") + str); str = query_get_attribute(m_contact_query_service, CONTACT_NOTE, &err); if( str ) @@ -207,7 +214,7 @@ ContactArrayPtr ContactSearchEngine::getContactSearchResult() str = query_get_attribute(m_contact_query_service, CONTACT_PHOTO_URI, &err); if( str ) - contact->setPhotoURI(str); + contact->setPhotoURI(std::string("file://") + str); str = query_get_attribute(m_contact_query_service, CONTACT_LAST_UPDATED_TIME_STAMP, &err); if( str ) @@ -220,31 +227,14 @@ ContactArrayPtr ContactSearchEngine::getContactSearchResult() contact->setLastUpdated(time_stamp); } - ContactNamePtr contactName = contact->getName(); - - str = query_get_attribute(m_contact_query_service, NAME_FIRST, &err); - if( str ) - contactName->setFirstName(str); - - str = query_get_attribute(m_contact_query_service, NAME_LAST, &err); - if( str ) - contactName->setLastName(str); - - str = query_get_attribute(m_contact_query_service, NAME_MIDDLE, &err); - if( str ) - contactName->setMiddleName(str); - - str = query_get_attribute(m_contact_query_service, NAME_DISPLAY, &err); - if( str ) - contactName->setDisplayName(str); - - str = query_get_attribute(m_contact_query_service, NAME_PREFIX, &err); - if( str ) - contactName->setPrefix(str); + char *firstName = query_get_attribute(m_contact_query_service, NAME_FIRST, &err); + char *lastName = query_get_attribute(m_contact_query_service, NAME_LAST, &err); + char *middleName = query_get_attribute(m_contact_query_service, NAME_MIDDLE, &err); + char *displayName = query_get_attribute(m_contact_query_service, NAME_DISPLAY, &err); + char *prefix = query_get_attribute(m_contact_query_service, NAME_PREFIX, &err); + char *phoneticName = query_get_attribute(m_contact_query_service, NAME_PHONETIC, &err); - str = query_get_attribute(m_contact_query_service, NAME_PHONETIC, &err); - if( str ) - contactName->setPhoneticName(str); + setName(contact, prefix, firstName, middleName, lastName, phoneticName, displayName); nameAlreadyChecked = true; } @@ -339,14 +329,24 @@ ContactArrayPtr ContactSearchEngine::getContactSearchResult() } else if (!nicknameAlreadyChecked && (pattr == NICKNAME_NAME)) { + ContactNamePtr contactName(NULL); + + if(!contact->getNameIsSet()) + contactName = ContactNamePtr(new ContactName()); + else + contactName = contact->getName(); + do { char *nickname = query_get_attribute(m_contact_query_service, NICKNAME_NAME, &err); if(nickname) - contact->getName()->addNickname(string(nickname)); + contactName->addNickname(string(nickname)); } while ( fetch_next_row(m_contact_query_service) == QUERY_SUCCESS ); + if(!contact->getNameIsSet()) + contact->setName(contactName); + nicknameAlreadyChecked = true; } else if (!categoryAlreadyChecked && (pattr == CATEGORY_INFO)) @@ -398,70 +398,46 @@ void ContactSearchEngine::visitPostComposite(FilterType& type, int depth) query_set_condition_append(m_contact_query_service, RIGHT_BRACKET); } -void ContactSearchEngine::visitAttribute(string& attrName, AnyArrayPtr& matchValues, string& matchFlag, bool caseSensitive, int depth) +void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag, AnyPtr& matchValue, int depth) { + if(matchValue == NULL) + return; + contact_attribute_e attr; attr = getPlatformAttr(attrName); string matchValueStr; - if(matchFlag == "EXISTS") + if(matchFlag == MATCH_EXISTS) { query_set_condition(m_contact_query_service, attr, EXISTS, NULL); } - else if(attrName == "id" && (matchFlag == "" || matchFlag == "EXACTLY")) - { - visitAttributeID(matchValues); - } - else if(matchValues->size() == 1) + else { condition_e cond; - if(matchFlag == "EXACTLY") + if(matchFlag == MATCH_EXACTLY) cond = EQUAL; - else if (matchFlag == "STARTSWITH" || matchFlag == "ENDSWITH") + else if (matchFlag == MATCH_STARTSWITH || matchFlag == MATCH_ENDSWITH) cond = LIKE; else cond = EQUAL; - AnyPtr matchValue = matchValues->at(0); - visitAttributeEach(attr, matchValue, cond); } - else if(matchValues->size() > 1) - { - condition_e cond; - if(matchFlag == "EXACTLY") - cond = EQUAL; - else if (matchFlag == "STARTSWITH" || matchFlag == "ENDSWITH") - cond = LIKE; - else - cond = EQUAL; - - query_set_condition_append(m_contact_query_service, LEFT_BRACKET); - - AnyArray::iterator iter; - for(iter = matchValues->begin(); iter != matchValues->end(); iter++) - { - AnyPtr matchValue = *iter; - if(iter != matchValues->begin()) - query_set_condition_append(m_contact_query_service, OR); - - visitAttributeEach(attr, matchValue, cond); - } - - query_set_condition_append(m_contact_query_service, RIGHT_BRACKET); - } } void ContactSearchEngine::visitAttributeRange(string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth) { + if(initialValue == NULL || endValue == NULL) + return; + contact_attribute_e attr; string initialValueStr; string endValueStr; - if(initialValue->getType() == PrimitiveType_Time) + if(initialValue->isType(PrimitiveType_Time)) { - tm date = DPL::DynamicPointerCast< Any_T >(initialValue)->getValue(); + tm date = initialValue->getDateTm(); initialValueStr = toDateDbStr(date); } else @@ -469,9 +445,9 @@ void ContactSearchEngine::visitAttributeRange(string& attrName, AnyPtr& initialV initialValueStr = initialValue->toString(); } - if(endValue->getType() == PrimitiveType_Time) + if(endValue->isType(PrimitiveType_Time)) { - tm date = DPL::DynamicPointerCast< Any_T >(endValue)->getValue(); + tm date = endValue->getDateTm(); endValueStr = toDateDbStr(date); } else @@ -490,9 +466,9 @@ void ContactSearchEngine::visitAttributeRange(string& attrName, AnyPtr& initialV void ContactSearchEngine::visitAttributeEach(contact_attribute_e attr, AnyPtr& matchValue, condition_e flag) { string valueStr; - if(matchValue->getType() == PrimitiveType_Time) + if(matchValue->isType(PrimitiveType_Time)) { - tm date = DPL::DynamicPointerCast< Any_T >(matchValue)->getValue(); + tm date = matchValue->getDateTm(); valueStr = toDateDbStr(date); } else @@ -633,6 +609,43 @@ void ContactSearchEngine::setPlatformAttrValue(Contact& contact, contact_attribu } #endif +void ContactSearchEngine::setName(ContactPtr& contact, + char *prefix, char *firstName, char *middleName, + char *lastName, char *phoneticName, char *displayName) +{ + if(prefix == NULL && firstName == NULL && middleName == NULL + && lastName == NULL && phoneticName == NULL && displayName == NULL) + return; + + ContactNamePtr contactName(NULL); + + if(!contact->getNameIsSet()) + contactName = ContactNamePtr(new ContactName); + else + contactName = contact->getName(); + + if( prefix ) + contactName->setFirstName(prefix); + + if( firstName ) + contactName->setLastName(firstName); + + if( middleName ) + contactName->setMiddleName(middleName); + + if( lastName ) + contactName->setDisplayName(lastName); + + if( phoneticName ) + contactName->setPrefix(phoneticName); + + if( phoneticName ) + contactName->setPhoneticName(phoneticName); + + if(!contact->getNameIsSet()) + contact->setName(contactName); +} + void ContactSearchEngine::setPhoneNumber(ContactPtr& contact, char *number, char *type) { if(number == NULL) @@ -649,7 +662,36 @@ void ContactSearchEngine::setPhoneNumber(ContactPtr& contact, char *number, char tokenize(type,tokens, ","); for (unsigned int i=0; iaddType(tokens[i]); + { + if (tokens[i].compare("WORK") == 0) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_WORK); + else if (tokens[i].compare("PREF")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_PREF); + else if (tokens[i].compare("HOME")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_HOME); + else if (tokens[i].compare("VOICE")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_VOICE); + else if (tokens[i].compare("FAX")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_FAX); + else if (tokens[i].compare("MSG")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_MSG); + else if (tokens[i].compare("CELL")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_CELL); + else if (tokens[i].compare("PAGER")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_PAGER); + else if (tokens[i].compare("BBS")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_BBS); + else if (tokens[i].compare("MODEM")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_MODEM); + else if (tokens[i].compare("CAR")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_CAR); + else if (tokens[i].compare("IDSN")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_ISDN); + else if (tokens[i].compare("VIDEO")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_VIDEO); + else if (tokens[i].compare("PCS")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_PCS); + } } contact->addPhoneNumber(numberType); @@ -770,6 +812,9 @@ void ContactSearchEngine::setEvent(ContactPtr& contact, char *date, char *type) void ContactSearchEngine::setOrganization(ContactPtr& contact, char* org_name, char* org_dept, char* org_title, char* org_role) { + if(org_name == NULL && org_dept == NULL && org_title == NULL && org_role == NULL) + return; + ContactOrganizationPtr org = ContactOrganizationPtr(new ContactOrganization()); if(org_name)